Solved

SQL Queries are getting slower

Posted on 2003-12-05
14
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

626 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