A
A
Alexey Lebedev2016-01-13 10:57:24
MySQL
Alexey Lebedev, 2016-01-13 10:57:24

Is an index needed or not?

We have:
id, uid, pid.
100k uid and for each uid 50 pid.
Choose WHERE [email protected] and [email protected];
Which index is better?
1) only uid
2) uid+pid
The reason why I ask small tables should not be stuffed with indexes.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
romy4, 2016-01-13
@romy4

in principle, id is not needed here. uid can be left as the primary key. with such a selection, the index for pid is superfluous.

R
res2001, 2016-01-13
@res2001

1. if possible - clustered index by id
2. separate indexes for uid and pid

A
Alexey Skahin, 2016-01-13
@pihel

If reads predominate over writes, then option 2 is preferable.
If records are inserted in batches and occasionally, then you can turn off the index, and then rebuild them.
If the write dominates the read, then perhaps the indexes will only get in the way.
Another option is to partition the hash by uid. Then the speed of neither reading nor writing will be lost.

I
igruschkafox, 2016-01-15
@igruschkafox

Option 2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question