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

32,000 records - simple SELECT is slow Expand / Collapse
Author
Message
Posted Monday, March 11, 2013 12:51 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, May 29, 2014 1:35 PM
Points: 83, Visits: 201
I have "equity_ids" table (32 columns, all varchar(16)) with no Primary Key (SQL 2005)
Just 3 Non-clustered indexes on varchar fields.

[SELECT * FROM equity_ids] took 1 min.
I checked locks - nothing.

I added Primary Key IDENTITY field, refreshed table STATISTICS.
Now [SELECT * FROM equity_ids] now takes 23 seconds.
Still very slow .... ?

Actually all tables in this Database are weird - no Primary Keys.
Some kind of dumps.
All simple SELECT queries are slow in this database, from 1 to 2 min for 30,000 rows.
It's not server performance issue.
There are similar tables with 30,000 records in other databases on this server
and [SELECT * ] takes 5 seconds there.

Any ideas what's wrong with this table?
Post #1429439
Posted Tuesday, March 12, 2013 12:06 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, May 30, 2014 8:15 AM
Points: 1,056, Visits: 2,687
while select * , just try to trace the query and see how IO performs.

try moving (copy) the table to another DB which is on another drive and check performance as well.

is there any compatibility deffernce on the databases?

is that all other table in the DB performing at this speed?



Regards
Durai Nagarajan
Post #1429591
Posted Tuesday, March 12, 2013 5:03 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, September 26, 2014 7:33 AM
Points: 7,107, Visits: 12,660
Doing a SELECT * with no WHERE-clause will always do a scan, either a Table Scan in the case of a heap, or a Clustered Index Scan in the case of a table with a clustered index.

The difference in time in your first experiment was likely due to fragmentation and the presence of lots of forwarding pointers. Before you added the PK you had a heap, i.e. a table with no clustered index. When you added a PK a clustered index was also added implicitly to support the constraint and so the heap became a clustered table and was defragmented in the process, which improved performance of the scan of all the data.

In general it is considered good practice to start with the idea that all tables in SQL Server that might be accepting inserts, updates and deletes on a regular basis should have a clustered index. A primary key is also considered a good thing to have. The PK and the clustered index do not have to be on the same set of columns but it you create a PK on a table with no clustered index and you do not specify that the PK should be nonclustered SQL Server will use the PK key columns and generate the supporting index as clustered using those some key columns.


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1429680
Posted Tuesday, March 12, 2013 11:02 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, May 29, 2014 1:35 PM
Points: 83, Visits: 201
Thanks for response guys !

Some more clarification.

Looks like it's a problem with this particular table.
I did [SELECT TOP 30,000 * FROM ism_secmaster_price] which is located in the same database, it has 107,000 rows
and it takes 5 seconds to get the results. Although that table has only 9 columns, three of them are float.
[ism_secmaster_price] table has no PK, but has a clustered index.

[SELECT TOP 30,000 * FROM equity_ids]
takes 1 min 5 seconds.

So the tables are inside the same database and act very differently.
I suspect something is wrong with [equity_ids].
How do I check table defragmentation?
Post #1429981
Posted Tuesday, March 12, 2013 11:40 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 1:47 PM
Points: 17,710, Visits: 15,572
RVO (3/12/2013)
Thanks for response guys !

Some more clarification.

Looks like it's a problem with this particular table.
I did [SELECT TOP 30,000 * FROM ism_secmaster_price] which is located in the same database, it has 107,000 rows
and it takes 5 seconds to get the results. Although that table has only 9 columns, three of them are float.
[ism_secmaster_price] table has no PK, but has a clustered index.

[SELECT TOP 30,000 * FROM equity_ids]
takes 1 min 5 seconds.

So the tables are inside the same database and act very differently.
I suspect something is wrong with [equity_ids].
How do I check table defragmentation?


Here is a starter query

SELECT *
FROM sys.dm_db_index_physical_stats(NULL,NULL,NULL,NULL,'limited')





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 #1430007
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse