Correct indexing when using OR operator

前端 未结 2 1500
遥遥无期
遥遥无期 2020-12-31 18:49

I have a query like this:

SELECT fields FROM table
WHERE field1=\'something\' OR field2=\'something\' 
OR field3=\'something\' OR field4=\'something\'
         


        
2条回答
  •  滥情空心
    2020-12-31 19:14

    In addition to previous comment: Some RDMS like Mysql/PostgreSql can use index merge if optimizer thinks that it's good idea. So you can create different indexes for each field or create some composite indexes like field1,field2 and field3,field4. Finally, you should try several different solutions and choose with best explain plan.

提交回复
热议问题