Wednesday, February 2, 2011

SQL Server: Indexes for GROUP BY Columns, a Good Choice


Every one of us knows that index on the columns referred to in an ORDER BY clause are helpful for optimizer to organize the output fast because columns values are already in sorted form.
Same way, columns which are part of GROUP BY benefit from indexes on the corresponding columns as GROUP BY clause columns are sorted first because sorted column values allow the adjacent matching values to be grouped quickly.
Indexes are also helpful for aggregate functions like MIN and MAX. Indexes on such columns are helpful for optimizer which need table/clustered index scan to find MIN or MAX values for a given column.

1 comment:

  1. Indexes also improve the speed for queries of large databases.

    ReplyDelete

All suggestions are welcome