Solved

SQL Queries are getting slower

Posted on 2003-12-05
14
294 Views
Last Modified: 2012-05-04
I have a survey site that allows people to sign up for an account and create their own surveys and collect data on my server.

Before I had any customers, the speed of retrieving survey data was very fast.  But, it is becoming progressively slower to retrieve data the more customer accounts there are.  Many accounts have surveys with 20 or 30 questions and with 100+ responses.

I even did a parallel test with the same survey and retrieved survey data from one database that had just one customer account and then one from my current database with 1000+ customer accounts.  In some cases it took 3 minutes on the larger database to pull survey data that could be pulled in just a few seconds with the smaller database.

First of all, why is this happening?  Second of all, I want to determine how to optimize my site (which is written in .net (.aspx) and uses sql 2000 so it will run just as fast with a thousand accounts as it would with one account.

Any thoughts on what could be going on and what I could do to fix this? Thanks.

Andrew
0
Comment
Question by:gator93
  • 8
  • 6
14 Comments
 
LVL 9

Expert Comment

by:PaulBarbin
ID: 9885772
Do you have indexes setup?  
What does the select statement look like?
Have you checked the execution plans?

Paul
0
 

Author Comment

by:gator93
ID: 9885820
Right now I have clustered indexes on the primary key for each table, but that's it.  We are possibly planning to use an index tuning wizard to create non clustered indexes for the tables.  Does that make sense to do that?  Would that increase the performance a lot to do this?

An example of a select statement that we are using is:

select * from survey where ib = 100

What do you mean by check the execution plans?  Can you be more specific.

Thanks.
0
 
LVL 9

Expert Comment

by:PaulBarbin
ID: 9885833
I didn't realize that the queries were that straightforward.  I was asking you to press Ctrl+L (or Ctrl+K) in Query Analyzer to view the execution plan to see if you could determine the difference.  But that's not likely going to help us here.

Is "ib" the column that the clustered index is on?  I am guessing its not.

Paul
0
 
LVL 9

Expert Comment

by:PaulBarbin
ID: 9885839
Also, are you joining on the customer table?

0
 

Author Comment

by:gator93
ID: 9885866

Thats how the majority of the queries are.  There are only a couple of Join queries but none on the customers table.

All tables have a ID, and that is the Primary Id.
0
 
LVL 9

Expert Comment

by:PaulBarbin
ID: 9885877
Give me the entire query that you're running that takes 3 minutes.  Explain the tables involved and give me rough idea on the number of rows in each.

0
 

Author Comment

by:gator93
ID: 9885896
Its not just one query.  Its one page that is doing several queries and the page takes 3 min to come up when it used to take about 20 seconds.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 9

Expert Comment

by:PaulBarbin
ID: 9885897
Wait, if you don't have ANY nonclustered indexes and you're joining tables, then the problem is likely that you need nonclustered indexes on the foreign key fields.  The execution plan in Query Analyzer would show that.  

Paul
0
 

Author Comment

by:gator93
ID: 9885922
If I run a trace and put that log into the Index Tuning Wizard.  Would it tell me all the nonclustered indexes I should create.
0
 
LVL 9

Expert Comment

by:PaulBarbin
ID: 9885933
I guarantee that if you don't have nonclustered indexes and you are doing joins, that's your problem.  Lets test it and see.  If it doesn't work, then just take them back out.

Paul
0
 

Author Comment

by:gator93
ID: 9885942
But I am only using Joins a couple of times on the whole site.
0
 
LVL 9

Accepted Solution

by:
PaulBarbin earned 500 total points
ID: 9885963
We could go on like this forever!  Either post the queries that you are using joins on, or just create nonclustered indexes for all foreign keys for tables where you are joining using that column.  I can tell you that this will very likely have a significant impact on the query time!

P.S.  I am leaving soon and might not be able to check this post again tonite.  Can you just try one for me quickly?

Paul
0
 

Author Comment

by:gator93
ID: 9885976
Ill create nonclustered indexes on all my foreign keys.

Thanks Paul
0
 
LVL 9

Expert Comment

by:PaulBarbin
ID: 9885981
Good luck.  If it doesn't work, post back and we'll take it step by step.

Paul
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now