Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


32,000 records - simple SELECT is slow


32,000 records - simple SELECT is slow

Author
Message
RVO
RVO
SSC-Enthusiastic
SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)

Group: General Forum Members
Points: 132 Visits: 380
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?
durai nagarajan
durai nagarajan
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1107 Visits: 2771
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
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8249 Visits: 14368
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
RVO
RVO
SSC-Enthusiastic
SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)

Group: General Forum Members
Points: 132 Visits: 380
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?
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21089 Visits: 18259
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, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

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