Middle+
If there is an index on columns A, B, C — can it be used when filtering only by A?
sobes.tech AI
Answer from AI
Yes, an index on columns (A, B, C) can be used when filtering only by column A. This is because composite indexes are usually structured as a tree, where the first column is the root, and searching by it is efficient.
If the query filters by A, the index will be useful for quickly finding the needed rows. However, if filtering is only by B or C without A, the index will not be used, as the order of columns is important.
Example:
- Index: (A, B, C)
- Query:
WHERE A = 5— index is used - Query:
WHERE B = 5— index is not used
This behavior is typical for most DBMSs, including PostgreSQL, MySQL, SQL Server.