Can I optimize a SELECT DISTINCT x FROM hugeTable query by creating an index on column x?

后端 未结 8 826
闹比i
闹比i 2021-01-01 11:51

I have a huge table, having a much smaller number (by orders of magnitude) of distinct values on some column x.

I need to do a query like SELECT D

8条回答
  •  爱一瞬间的悲伤
    2021-01-01 12:12

    When doing a SELECT DISTINCT on an indexed field, an index scan makes sense, as execution still has to scan each value in the index for the entire table (assuming no WHERE clause, as seems to be the case by your example).

    Indexes usually have more of an impact on WHERE conditions, JOINS, and ORDER BY clauses.

提交回复
热议问题