Domanda

In SQL, when a query is filtered by multiple conditions, a simple optimization is to list more restrictive conditions before less restrictive ones, because the conditions are evaluated in first-to-last order.

SELECT _id, col1, col2, col3 
FROM table 
WHERE 
    col1 = "most_resctrictive_condition" AND 
    col2 = "less_resctrictive_condition" AND
    col3 = "least_resctrictive_condition"

If a particular column is indexed, does SQLite evaluate the condition on the indexed column first, even if it is listed after other conditions?

For instance, if col3 is indexed but the other columns are not, will SQLite evaluate the 3rd condition first, or will it evaluate in the order the conditions appear in the query as it is written?

È stato utile?

Soluzione

SQLite ignores the order of conditions in the query, and always evaluates them in the order that it estimates to be the most efficient.

Read the documentation:
ANALYZE
EXPLAIN QUERY PLAN
Query Planning
Optimizer Overview

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top