How to Write Optimal SQL Queries

后端 未结 9 1570
余生分开走
余生分开走 2021-02-01 06:47

I\'ve searched around stackoverflow but everybody asks to optimize queries they\'ve already done.

I want to know, the basic stuff on what to do, what to avoid when creat

9条回答
  •  旧巷少年郎
    2021-02-01 07:34

    From what I've read, using BETWEEN instead of two checks on an index, using AND, improves performance because your database may not fully utilize the benefits of indexes when it sees that it is used on both sides of an AND, or OR.

    The query optimizer may not be able to intuit that this is a range check and that the index sorting can come in handy. Instead it may do a scan on each condition and then combine the results. On the other hand, this is very clear with a BETWEEN clause that compares the index column to two values.

提交回复
热议问题