How can I further optimize a derived table query which performs better than the JOINed equivalent?

后端 未结 4 1754
庸人自扰
庸人自扰 2020-12-08 11:07

UPDATE: I found a solution. See my Answer below.

My Question

How can I optimize this query to minimize my downtime? I need to update over

4条回答
  •  我在风中等你
    2020-12-08 11:42

    About BETWEEN

    SELECT * FROM a WHERE a.column BETWEEN x AND y 
    
    • is indexable and corresponds to a range lookup on index a.column (if you have one)
    • is 100% equivalent to a.column >= x AND a.column <= y

    While this:

    SELECT * FROM a WHERE somevalue BETWEEN a.column1 AND a.column2
    
    • is 100% equivalent to somevalue >= a.column1 AND somevalue <= a.column2
    • is a very different thing from the first one above
    • is not indexable by a range lookup (there is no range, you got 2 columns here)
    • generally leads to horrible query performance

    I think there was confusion about this in the debate on "between" above.

    OP has the first kind, so no worry.

提交回复
热议问题