D
D
DoggoTheKing2018-03-15 15:02:05
Python
DoggoTheKing, 2018-03-15 15:02:05

How to optimize ID uniqueness check?

There is a table with a field in which ID of users are stored. The table is constantly updated with new entries. Sometimes, the user ID is entered a second time. Such an entry is checked like this:
SELECT * FROM main_db WHERE ident=ID_NUMBER
But this check is somehow slow. Now there are 700k records in the database. Will be around 20k.
How to optimize?
upd: ID is not formed by me
upd2: 600 records were added for 5 hours. This is fine?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Kruglik, 2018-03-15
@kruglikdenis

You can hang a unique index on the field and remove this check:

CREATE UNIQUE INDEX ident
ON main_db (ident);

Also, as an id, you can use not the field that you received when parsing, but some of your own
and generate it as uuid 4: https://en.wikipedia.org/wiki/Universally_unique_i...
here is the library for generating uuid: https://github.com/ramsey/uid

D
Dmitry Entelis, 2018-03-15
@DmitriyEntelis

It must be very fast.
Make sure there is a unique index on the ident field.
If you suddenly need it really, really fast, take redis and store the key-value in it in the form of ident - your id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question