D
D
DarkMatter2016-07-04 15:22:46
MySQL
DarkMatter, 2016-07-04 15:22:46

How do you define indexes at the design stage of a database?

The table has columns:
id, uid, interval, data, oldstatus, newstatus, email
In the process, it turns out that we need indexes on id, uid, email composite on interval+data
Then there is a condition:
WHERE oldstatus != newstatus AND email=1
I I do not really understand the composite index on which fields is needed for such a request?
Already at least 5 indexes are coming out, and I cannot yet know which one will be used how often. How, under these conditions, not to miss some necessary index but also not to slow down the INSERT time too much when the database grows?
Or does it make sense not to make composite indexes yet, but to get by with a simple one for each column?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Alekhin, 2016-07-04
@Settler1

Indexes are generally put on those columns on which there is a selection where.
If your condition:
then bet on them.
As for the id, if you have it primary, then this is the index, you don’t need to add anything additional

D
devian3000, 2016-07-04
@devian3000

Composite indexes are hung up in the order - we reduce selection - we select from the remained.
Those. if you have only two statuses and 1000 emails, then the index should be (email, status). Further by analogy.
How to choose something - looks at the functionality, and / or statistics. (Put a log on requests).
Also collect all the requests that are. View intersections, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question