Index a sum column

后端 未结 5 1514
执念已碎
执念已碎 2021-02-07 02:07

Is creating an index for a column that is being summed is faster than no index?

5条回答
  •  深忆病人
    2021-02-07 02:36

    If you want to make the summation faster, you can pre-materialized the result. On Oracle, use Materialized Views, on MS SQL use Indexed Views.

    On your specific question "Is creating an index for a column that is being summed is faster than no index?", answer is No.

    The answer to your question lies on Spencer's answer:

    "An aggregate function (count, max, min, sum, avg) has to run through all the entries in a columns being summed regardless."

    Just clarified the context of columns in Spencer's answer. His answer is correct nonetheless.

提交回复
热议问题