SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to optimize this query?


How to optimize this query?

Author
Message
WhiteLotus
WhiteLotus
SSCertifiable
SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)

Group: General Forum Members
Points: 6609 Visits: 1003
Hi All,
I have a simple query as below

Select A,B,C from Table1

How to create a good index on that ?

At the moment , the table has 2 indexes :
1.
CREATE NONCLUSTERED INDEX [IX_A] ON [dbo].[Table1]
(
A ASC,
B ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

2.

ALTER TABLE [dbo].[Table1 ] ADD CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

The execution plan shows :

100% of Clustered iNdex scan

and I modified the nonclusteredindex become :

CREATE NONCLUSTERED INDEX [IX_Table1] ON [dbo].[Table1]
(
A ASC
)
INCLUDE ( [B],[C]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

the result in the execution plan becomes :
100% of Index Scan ( using the new nonclustered index that i modified)

My question , is it better in term of performance ? or any idea so it can use INDEX SEEK?

Thanks heaps
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)

Group: General Forum Members
Points: 144293 Visits: 18651
Your query mandates a table/index scan. There is no filter/predicate/where clause on the query so it will return all records from the table. For the query, an index scan is the most efficient means of getting the data for this query.

If you want it to perform a seek, add a where clause to the query.

Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Learn Extended Events

WhiteLotus
WhiteLotus
SSCertifiable
SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)

Group: General Forum Members
Points: 6609 Visits: 1003
SQLRNNR (7/28/2014)
Your query mandates a table/index scan. There is no filter/predicate/where clause on the query so it will return all records from the table. For the query, an index scan is the most efficient means of getting the data for this query.

If you want it to perform a seek, add a where clause to the query.


thanks for your response. I Appreciate it !

Do you mean index scan equal with table scan ? so it means even though that table has no index , it will still produce the same performance ?
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)

Group: General Forum Members
Points: 144293 Visits: 18651
murnilim9 (7/28/2014)
SQLRNNR (7/28/2014)
Your query mandates a table/index scan. There is no filter/predicate/where clause on the query so it will return all records from the table. For the query, an index scan is the most efficient means of getting the data for this query.

If you want it to perform a seek, add a where clause to the query.


thanks for your response. I Appreciate it !

Do you mean index scan equal with table scan ? so it means even though that table has no index , it will still produce the same performance ?



Sometimes an Index Scan is the same as a Table Scan. Sometimes one will perform better than the other. In my last post I was really meaning index or table scan when i put index/table. But if you are getting clustered index scan - that is a table scan.

Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Learn Extended Events

WhiteLotus
WhiteLotus
SSCertifiable
SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)

Group: General Forum Members
Points: 6609 Visits: 1003
SQLRNNR (7/29/2014)
murnilim9 (7/28/2014)
SQLRNNR (7/28/2014)
Your query mandates a table/index scan. There is no filter/predicate/where clause on the query so it will return all records from the table. For the query, an index scan is the most efficient means of getting the data for this query.

If you want it to perform a seek, add a where clause to the query.


thanks for your response. I Appreciate it !

Do you mean index scan equal with table scan ? so it means even though that table has no index , it will still produce the same performance ?



Sometimes an Index Scan is the same as a Table Scan. Sometimes one will perform better than the other. In my last post I was really meaning index or table scan when i put index/table. But if you are getting clustered index scan - that is a table scan.


thanks !!!
cheers
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)

Group: General Forum Members
Points: 144293 Visits: 18651
You're welcome.

Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Learn Extended Events

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search