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

后端 未结 8 816
闹比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

    As per your description of the execution plan, I would believe it's the best possible execution.

    The Index Scan reads the entire index as stored (not in index order), the HASH MATCH does the distinct.

    There might be other ways around your problem. In SQL Server, Indexed Views come to my mind. However, that might give you a big hit for write's on that table.

提交回复
热议问题