Monday, February 20, 2012

query and index as follows

Select col1 from table1
where col2 < 100
In this case, if we have a covered index on col1 and col2,
would the index on (col1,col2) or (col2,col1) perform better and faster ?
I am leaning towards this order : (col2,col1) as col2 is the leading column
and col1 data is just stored along with col2 in the leaf page although col1
would be stored in an ordered fashion.
Am i correct in my theory ?For this particular query, an index on (col2, col1) would most likely be
faster. But index tuning isn't done one query at a time.
What other queries reference table1 and access col1 and col2?
You need to design indexes so that all the queries that access the table
will perform reasonably well. There may be other choices of indexes that
work well for this query, and also work well for many other queries.
What percentage of the table have col2 values less than 100?
How many rows fit per page?
Are you also performing updates to the table?
..
and many other questions need to be asked and answered to come up with the
best choices.
--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com
"Hassan" <hassan@.test.com> wrote in message
news:O5M0xm%23MIHA.1184@.TK2MSFTNGP04.phx.gbl...
> Select col1 from table1
> where col2 < 100
> In this case, if we have a covered index on col1 and col2,
> would the index on (col1,col2) or (col2,col1) perform better and faster ?
> I am leaning towards this order : (col2,col1) as col2 is the leading
> column and col1 data is just stored along with col2 in the leaf page
> although col1 would be stored in an ordered fashion.
> Am i correct in my theory ?
>
>|||Kalen, I was just verifying my theory that the order does matter in a way
and just creating a covering index on all the columns randomly may not be
ideal,assuming if the query below was the only query run with no
modifications.
"Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
news:eCvbgv%23MIHA.4808@.TK2MSFTNGP05.phx.gbl...
> For this particular query, an index on (col2, col1) would most likely be
> faster. But index tuning isn't done one query at a time.
> What other queries reference table1 and access col1 and col2?
> You need to design indexes so that all the queries that access the table
> will perform reasonably well. There may be other choices of indexes that
> work well for this query, and also work well for many other queries.
> What percentage of the table have col2 values less than 100?
> How many rows fit per page?
> Are you also performing updates to the table?
> ..
> and many other questions need to be asked and answered to come up with the
> best choices.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> www.InsideSQLServer.com
> http://sqlblog.com
>
> "Hassan" <hassan@.test.com> wrote in message
> news:O5M0xm%23MIHA.1184@.TK2MSFTNGP04.phx.gbl...
>|||> Kalen, I was just verifying my theory that the order does matter in a way
> and just creating a covering index on all the columns randomly may not be
> ideal,assuming if the query below was the only query run with no
> modifications.
Hassan,
The Books Online topic "General Index Design Guidelines
"(http://msdn2.microsoft.com/en-us/library/ms191195.aspx) provides the
following guidance in the section "Column Considerations".
"Consider the order of the columns if the index will contain multiple
columns. The column that is used in the WHERE clause in an equal to (=),
greater than (> ), less than (< ), or BETWEEN search condition, or
participates in a join, should be placed first. Additional columns should be
ordered based on their level of distinctness, that is, from the most
distinct to the least distinct. "
--
Gail Erickson [MS]
SQL Server Documentation Team
This posting is provided "AS IS" with no warranties, and confers no rights
Download the latest version of Books Online from
http://technet.microsoft.com/en-us/...r/bb428874.aspx
"Hassan" <hassan@.test.com> wrote in message
news:O0phzAFNIHA.4684@.TK2MSFTNGP06.phx.gbl...
> Kalen, I was just verifying my theory that the order does matter in a way
> and just creating a covering index on all the columns randomly may not be
> ideal,assuming if the query below was the only query run with no
> modifications.
> "Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
> news:eCvbgv%23MIHA.4808@.TK2MSFTNGP05.phx.gbl...
>

No comments:

Post a Comment