N
N
nikivanz2020-07-15 12:57:25
MySQL
nikivanz, 2020-07-15 12:57:25

How does searching on combined indexes work?

Hello!

The question is this: Let's say there is a test table, the fields in it are:
id, language_id, english_word, word, word_id

id, of course, let it be PK.
If I create 2 combined indexes:
language_id, english_word
and
word, word_id

And then I look for the table like this:

WHERE language_id=...
AND english_word=...
AND word=...
AND word_id=...


Are the two previously created indexes included in the work? Those. does it give rise?

I know it's best to check it out yourself! Just don't have time yet and hope someone here already has some solid knowledge on this.

Thanks for the help!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Melkij, 2020-07-15
@melkij

The scheduler has this option. bitmap index scan can combine a pass over multiple indexes. Whether the scheduler will use this plan or prefer something else, and, moreover, whether it will be cheaper - depends on the statistics of data distribution, settings, hardware capabilities.
How the scheduler in your system will decide - explain will answer. How much something really costs in runtime - will answer explain (analyze,buffers)
Didn't pay attention to the second tag, it was about postgresql.
mysql can do the same, it's called Index Merge. Whether it will be used is again at the discretion of the scheduler.

R
Rsa97, 2020-07-15
@Rsa97

Only one index will be used, in whole or in part.
Depends on the selectivity of the index for this condition.

I
Ivan Shumov, 2020-07-15
@inoise

do EXPLAIN ..... and it answers all your questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question