Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
Administering
»
32,000 records - simple SELECT is slow
32,000 records - simple SELECT is slow
Rate Topic
Display Mode
Topic Options
Author
Message
RVO
RVO
Posted Monday, March 11, 2013 12:51 PM
SSC Rookie
Group: General Forum Members
Last Login: Monday, April 08, 2013 1:32 PM
Points: 33,
Visits: 78
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
durai nagarajan
durai nagarajan
Posted Tuesday, March 12, 2013 12:06 AM
SSC Eights!
Group: General Forum Members
Last Login: Yesterday @ 10:16 AM
Points: 863,
Visits: 2,135
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
opc.three
opc.three
Posted Tuesday, March 12, 2013 5:03 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 1:24 PM
Points: 6,826,
Visits: 11,950
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
Believe you can and you're halfway there.
--Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler
--Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them.
--Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples.
--Giordy
Post #1429680
RVO
RVO
Posted Tuesday, March 12, 2013 11:02 AM
SSC Rookie
Group: General Forum Members
Last Login: Monday, April 08, 2013 1:32 PM
Points: 33,
Visits: 78
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
SQLRNNR
SQLRNNR
Posted Tuesday, March 12, 2013 11:40 AM
SSCoach
Group: General Forum Members
Last Login: Today @ 2:37 PM
Points: 18,853,
Visits: 12,437
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 2008
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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.