You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My issue is that the index used in ORDER BY clauses in SQL statements have precedence over any index that could be used to evaluate the WHERE clause(s), even though WHERE is evaluated before ORDER BY. This seems wrong to me – and makes some of our queries, like in example 3 below, many times slower.
Example 1
SQL query 1:
SELECT IP FROMMopedo.Database.Device ORDER BY UsedCount
Here the Device_UsedCount index takes precedence over Device_IP, which is clearly not the fastest way to evaluate the query. You could argue that ORDER BY should only be used when expecting multiple result rows – but still my conjecture is that using the index on WHERE (especially if the table contains thousands and thousands of rows like in this case) should be more efficient. Please correct me if I'm wrong about this.
@miyconst
I have a database class
Mopedo.Database.Device
(see below for class definition). I have a couple of indexes on this table:My issue is that the index used in
ORDER BY
clauses in SQL statements have precedence over any index that could be used to evaluate theWHERE
clause(s), even thoughWHERE
is evaluated beforeORDER BY
. This seems wrong to me – and makes some of our queries, like in example 3 below, many times slower.Example 1
SQL query 1:
Query plan 1:
Here the
Device_UsedCount
index is used, which of course is what we want.Example 2
SQL query 2:
Query plan 2:
Here the
Device_IP
index is used, which – again – is what we expect.Example 3
SQL query 3:
Query plan 3:
Here the
Device_UsedCount
index takes precedence overDevice_IP
, which is clearly not the fastest way to evaluate the query. You could argue thatORDER BY
should only be used when expecting multiple result rows – but still my conjecture is that using the index onWHERE
(especially if the table contains thousands and thousands of rows like in this case) should be more efficient. Please correct me if I'm wrong about this.Mopedo.Database.Device
definitionThe text was updated successfully, but these errors were encountered: