Solved

SQL Queries are getting slower

Posted on 2003-12-05
14
291 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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Ranking Based On Value 3 29
t-sql month question 8 43
How to query date ranges with SQL 6 24
Access Migration to Sql Server 2 21
Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

758 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

21 Experts available now in Live!

Get 1:1 Help Now