Data presence (repetition) detection

Source: Internet
Author: User
I can think of three methods for the moment.

  1. To database processing, database settings UNIQUE

  2. Given to the database for processing, select is executed before each INSERT, but this increases the number of select times as the data grows

  3. To the language processing, the existing data exists in the array, with In_array and so on, but as the data increases the array will become very large

Think of the three treatment methods that are not very good
What kind of plan would you use?

Reply content:

I can think of three methods for the moment.

  1. To database processing, database settings UNIQUE

  2. Given to the database for processing, select is executed before each INSERT, but this increases the number of select times as the data grows

  3. To the language processing, the existing data exists in the array, with In_array and so on, but as the data increases the array will become very large

Think of the three treatment methods that are not very good
What kind of plan would you use?

UNIQUEuse the index, using syntax when inserting INSERT IGNORE

The benefits are:

  1. Performance is not bad, INSERT IGNORE will automatically UNIQUE check in the index for duplicates, because it is an index, so the comparison occurs in memory

  2. Good, successful returns the number of inserted rows, the failure will return 0

This method is still more reliable until your data reaches millions of.

What's the scene?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.