Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to optimize this query? Expand / Collapse
Author
Message
Posted Monday, July 28, 2014 7:12 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 10:59 PM
Points: 103, Visits: 218
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
Post #1597132
Posted Monday, July 28, 2014 7:18 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 9:09 PM
Points: 17,628, Visits: 15,487
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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1597134
Posted Monday, July 28, 2014 11:43 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 10:59 PM
Points: 103, Visits: 218
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 ?

Post #1597149
Posted Tuesday, July 29, 2014 7:33 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 9:09 PM
Points: 17,628, Visits: 15,487
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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1597287
Posted Tuesday, July 29, 2014 9:23 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 10:59 PM
Points: 103, Visits: 218
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
Post #1597560
Posted Wednesday, July 30, 2014 7:25 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 9:09 PM
Points: 17,628, Visits: 15,487
You're welcome.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1597717
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse