
Ordering Columns in CREATE INDEX Statements
Components of the missing indexes feature list equality, inequality, and included columns in their output.
For example, the XML Showplan MissingIndexes element indicates whether an index key column is used for equality (=) or inequality (<, >, and so on) in the Transact-SQL statement predicate, or is just included to cover a query. It displays this information as one of the following values for the Usage attribute of the ColumnGroup subelement:
<ColumnGroup Usage="EQUALITY">
<ColumnGroup Usage="INEQUALITY">
<ColumnGroup Usage="INCLUDE">
The dynamic management objects sys.dm_db_missing_index_details and sys.dm_db_missing_index_columns return results that indicate whether an index key column is an equality, inequality, or included column. The result set of sys.dm_db_missing_index_details returns this information in the equality_columns, inequality_columns, and included_columns columns. The result set returned by sys.dm_db_missing_index_columns returns this information in its column_usage column.
Use the following guidelines for ordering columns in the CREATE INDEX statements you write from the missing indexes feature component output:
-
List the equality columns first (leftmost in the column list).
-
List the inequality columns after the equality columns (to the right of equality columns listed).
-
List the include columns in the INCLUDE clause of the CREATE INDEX statement.
-
To determine an effective order for the equality columns, order them based on their selectivity; that is, list the most selective columns first.