Is there a way to use an index to avoid file set when OR is used in a MySQL query?

I have the following query and the following 2 indexes, but I'm still getting the file port. Is there a way to optimize this further so that I avoid file management, or do I just need to live with it?

Inquiry:

SELECT * FROM table WHERE row1 > '0' OR row2 = '1' ORDER BY id DESC

Indices:

row1

row2, ID

EXPLAIN output:

Using sort_union (row1, row2_id); Use where; Using filesort

+3
source share
3 answers

ORDER BY ROW2, ID or add index to ID.

0
source

Yes, you can. Just add an index like (id, row1, row2).

, , mySQL .

, sort_union() mySQL.

0

This is a bit late for an answer, but I want to say it using "or", possibly causing this problem. You can try combining with two different queries.

0
source

Source: https://habr.com/ru/post/1784621/


All Articles