473,756 Members | 3,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help speed up my query!


Hi there,

had to rush some sql and am now going back to it due to a slow db
performance. I have a db for sales leads and have created 3 views based
on the data I need to produce.

However one o the views, which has subqueries to the other views is VERY
slow and it needs to be speeded up, but am unsure how, can anyone
help... below is the sql?

SELECT CGAMain.CGAMain Id,CGAMain.Salu tation,CGAMain. FirstName,

CGAMain.LastNam e,CGAMain.Salut ation2,CGAMain. FirstName2,CGAM ain.LastName
2,
cgamain.telepho ne,CGAMain.[Post Code],
other.dbo.users .UserName, other.dbo.agent s.[agent_name],
LEADSTATUS.CURR ENTSTATUS,leads tatus.activesta tus,Leadstatus.[no
answer],CGAMain.rescod e,
Agent_displayna me As 'Called By'
FROM Leadstatus INNER JOIN CGAMain ON Leadstatus.CGAM ainId =
CGAMain.CGAmain Id
INNER JOIN other.dbo.users ON Leadstatus.LTAi d = other.dbo.users .userref
INNER JOIN other.dbo.agent s ON Leadstatus.agen tid = other.dbo.agent s.id
WHERE
(StatusAssigned = 1)
AND (leadstatus.act ivestatus = 'Active')

please help???

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
2 1929
m3ckon (an*******@devd ex.com) writes:
had to rush some sql and am now going back to it due to a slow db
performance. I have a db for sales leads and have created 3 views based
on the data I need to produce.

However one o the views, which has subqueries to the other views is VERY
slow and it needs to be speeded up, but am unsure how, can anyone
help... below is the sql?

SELECT CGAMain.CGAMain Id,CGAMain.Salu tation,CGAMain. FirstName,

CGAMain.LastNam e,CGAMain.Salut ation2,CGAMain. FirstName2,CGAM ain.LastName
2,
cgamain.telepho ne,CGAMain.[Post Code],
other.dbo.users .UserName, other.dbo.agent s.[agent_name],
LEADSTATUS.CURR ENTSTATUS,leads tatus.activesta tus,Leadstatus.[no
answer],CGAMain.rescod e,
Agent_displayna me As 'Called By'
FROM Leadstatus INNER JOIN CGAMain ON Leadstatus.CGAM ainId =
CGAMain.CGAmain Id
INNER JOIN other.dbo.users ON Leadstatus.LTAi d = other.dbo.users .userref
INNER JOIN other.dbo.agent s ON Leadstatus.agen tid = other.dbo.agent s.id
WHERE
(StatusAssigned = 1)
AND (leadstatus.act ivestatus = 'Active')

please help???


If you help us to help you, you may get help. Just the query alone is
not much to work from. In general, optimizing queries often requires
access to the database, since there is a lot of information that one
might need to know. But some issues can be easy to spot from a distance.
So, please post the following:

o CREATE TABLE statements for the tables in question.
o All CREATE INDEX statements for the tables. (Incluing PK and UNIQUE
constraints.)
o If any of Leadstatus, users, agents are views, please post the source
for the views.
o Approxamite number of rows per table.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
Some general advice:
- make sure all tables have a primary key (which automatically means the
key is indexed)
- make sure all foreign keys are indexed
- make sure the foreign keys have exactly the same definition (data type
and size) as the primary key
- you may want to experiment with covering indexes when you access
tables only because of the WHERE clause. In this case, a covering index
on leadstatus(acti vestatus,CGAMai nID) and/or on
leadstatus(CGAM ainID,activesta tus) might help

HTH,
Gert-Jan
m3ckon wrote:

Hi there,

had to rush some sql and am now going back to it due to a slow db
performance. I have a db for sales leads and have created 3 views based
on the data I need to produce.

However one o the views, which has subqueries to the other views is VERY
slow and it needs to be speeded up, but am unsure how, can anyone
help... below is the sql?

SELECT CGAMain.CGAMain Id,CGAMain.Salu tation,CGAMain. FirstName,

CGAMain.LastNam e,CGAMain.Salut ation2,CGAMain. FirstName2,CGAM ain.LastName
2,
cgamain.telepho ne,CGAMain.[Post Code],
other.dbo.users .UserName, other.dbo.agent s.[agent_name],
LEADSTATUS.CURR ENTSTATUS,leads tatus.activesta tus,Leadstatus.[no
answer],CGAMain.rescod e,
Agent_displayna me As 'Called By'
FROM Leadstatus INNER JOIN CGAMain ON Leadstatus.CGAM ainId =
CGAMain.CGAmain Id
INNER JOIN other.dbo.users ON Leadstatus.LTAi d = other.dbo.users .userref
INNER JOIN other.dbo.agent s ON Leadstatus.agen tid = other.dbo.agent s.id
WHERE
(StatusAssigned = 1)
AND (leadstatus.act ivestatus = 'Active')

please help???

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3313
by: Markku Uttula | last post by:
I think I'm doing something wrong. I'm able to connect to Oracle just fine, execute queries and all, but I'm having serious problems with the speed :( For example, the following PHP-script on my machine executes about 6 seconds: <? $db_conn = ocilogon("my_username", "my_password", "my_database"); $loop_count = 1000;
2
1850
by: Wouter | last post by:
Hi, I was wandering. Does the query speed also depend on the colums that you don't use in the query (so not in the where and not in the select part). I have a lange unused backup field in every row. I only put the backup information into that field once. But never use it on my live database.
5
2732
by: JENS CONSER | last post by:
Hello NG, We have a performance problem in using a client server solution based on MS SQL-Server 2000 through a VPN tunnel (via broadband internet connection). The SQL Server is running on a Windows 2003 Server which is configured as VPN server as well. We figured out that not the performance
2
2778
by: jphelan | last post by:
Ever since I successfully applied some techniques for increasing the speed of my 17 meg. Application; it has only made me hunger for more. First, let me list what I have done so far: 1. Split the application and database into front and back-ends, 2. Increased the load-time of my application by "pre-loading my heaviest forms when the database is initially opened, 3. When forms do open, under, "Filter Lookup" I use, "Never", 4. I set...
27
3244
by: SQL Learner | last post by:
Hi all, I have an Access db with two large tables - 3,100,000 (tblA) and 7,000 (tblB) records. I created a select query using Inner Join by partial matching two fields (X from tblA and Y from tblB). The size of the db is about 200MBs. Now my issue is, the query has been running for over 3 hours already - I have no idea when it will end. I am using Access 2003. Are there ways to improve the speed performance? (Also, would the...
0
1176
by: hooked888 | last post by:
Hi, I have a database and a query both 100% (with specific index) identical and install and run in my laptop and server but resulting slightly different time frame to complete. Run a query in my laptop 1GB RAM, INTEL 1.66GHz Core 2 took me 1 minute 38 seconds. Run the same query in server 4GB RAM, ZEON 3.0GHz took me 1 minute 36 seconds. Both using MS SQL 2000, windows server 2003.
8
6491
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table using a code loop and an INSERT INTO query. About 800,000 records of raw text. Later, I can then loop through and parse these 800,000 strings into usable data using more code. The problem I have is that the conversion of the text file, using a...
3
7844
by: victorporton | last post by:
D.K. is traveling from City A to City B. He can stop at some designated spots only. I am trying to use Dijkstra’s algorithm to determine the “spot-to-spot” path that will get D.K. from City A to the City B in the minimum amount of time. The input in my program is an integer n and the 2D coordinates of n spots. Some assumptions have been made about the physical layout of the problem: 1) All the spots are considered to be in a square of...
5
2688
by: loveshack | last post by:
Can anyone help me please (i am quite a novice, but having fun learning). Im not sure if this is an ASP problem, a javascript problem or a browser problem. Firstly, everything i have written works fine in IE7 and beta IE8. My pages do not work however in Safari or Firefox, and please dont beat me, but i use Frontpage to write my site, and i use iframes as ive not discovered how to do this any differently! So the issue is this, i have a...
6
1503
by: spider661 | last post by:
im trying to make a perl file that will take all the info from a spell_us.txt file and place it into an sql file i can import into my database but its not working can anyone help please? #!/usr/bin/perl -w # # Imports spells from spell_us.txt to spell table, as described in the config below $spellfile="spells_us.txt"; $sqlspellfile="allspells.sql"; $tbspells = "spells";
0
9455
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9271
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10031
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.