473,785 Members | 2,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does this query take forever?

Ike
For some reason, I have a rather large (to me) query, with numerous inner
joins, accessing a remote server, and it is taking about twenty times longer
than most queries to the same database.
The query itself is built programmaticall y within my application, and
example of which is below. I am hoping someone in the group may have some
insight into why this query is so slow, suggesting perhaps a better
structure for it, such that I can go back in and rewrite my code that
creates such queries.

Thanks in advance, Ike

"SELECT DISTINCT
chronology.id,s tatus_id.status ,chronology.com pleted,chronolo gy.completeddat e
,chronology.com pletedtime,acti vities_id.activ ity,chronology. activities_acti v
ity,chronology. activities_atta chment,chronolo gy.activities_a vailable_to_all ,
chronology.upca rds_firstnamela stname,upcard_i d.id,chronology .feedbackrequir e
d,chronology.la ndondate,chrono logy.hasspecifi ctime,chronolog y.datetoperform ,
chronology.time toperform,chron ology.duration, chronology.week ends,chronology .
prefix,statusac tivitieisid.id, associaterespon sible.username, activities_user n
ameid.username, chronology.edit Flag FROM
chronology,stat us,activities,u pcards,statusac tivities,associ ates
INNER JOIN status status_id on chronology.stat us_id=status_id .id
INNER JOIN activities activities_id on
chronology.acti vities_id=activ ities_id.id
INNER JOIN upcards upcard_id on chronology.upca rd_id=upcard_id .id
INNER JOIN statusactivitie s statusactivitie isid on
chronology.stat usactivitieisid =statusactiviti eisid.id
INNER JOIN associates associaterespon sible on
chronology.asso ciateresponsibl e=associateresp onsible.id
INNER JOIN associates activities_user nameid on
chronology.acti vities_username id=activities_u sernameid.id
WHERE chronology.upca rd_id = 18"
Jul 19 '05 #1
10 2177

"Ike" <rx*@hotmail.co m> schrieb im Newsbeitrag
news:xb******** ***********@new sread2.news.atl .earthlink.net. ..
For some reason, I have a rather large (to me) query, with numerous inner joins, accessing a remote server, and it is taking about twenty times longer than most queries to the same database.
The query itself is built programmaticall y within my application, and
example of which is below. I am hoping someone in the group may have some insight into why this query is so slow, suggesting perhaps a better
structure for it, such that I can go back in and rewrite my code that
creates such queries.

Thanks in advance, Ike

"SELECT DISTINCT
chronology.id,s tatus_id.status ,chronology.com pleted,chronolo gy.completedda
te ,chronology.com pletedtime,acti vities_id.activ ity,chronology. activities_act
iv ity,chronology. activities_atta chment,chronolo gy.activities_a vailable_to_al
l, chronology.upca rds_firstnamela stname,upcard_i d.id,chronology .feedbackrequi
re d,chronology.la ndondate,chrono logy.hasspecifi ctime,chronolog y.datetoperfor
m, chronology.time toperform,chron ology.duration, chronology.week ends,chronolog
y. prefix,statusac tivitieisid.id, associaterespon sible.username, activities_use
rn ameid.username, chronology.edit Flag FROM
chronology,stat us,activities,u pcards,statusac tivities,associ ates
INNER JOIN status status_id on chronology.stat us_id=status_id .id
INNER JOIN activities activities_id on
chronology.acti vities_id=activ ities_id.id
INNER JOIN upcards upcard_id on chronology.upca rd_id=upcard_id .id
INNER JOIN statusactivitie s statusactivitie isid on
chronology.stat usactivitieisid =statusactiviti eisid.id
INNER JOIN associates associaterespon sible on
chronology.asso ciateresponsibl e=associateresp onsible.id
INNER JOIN associates activities_user nameid on
chronology.acti vities_username id=activities_u sernameid.id
WHERE chronology.upca rd_id = 18"


First I'd check whether all those joined tables have indexes on the id
field. If they don't, create them and check again.

If you don't have duplicates you can omit the "DISTINCT" saving the db a
lot of work.

robert

Jul 19 '05 #2

"Ike" <rx*@hotmail.co m> schrieb im Newsbeitrag
news:xb******** ***********@new sread2.news.atl .earthlink.net. ..
For some reason, I have a rather large (to me) query, with numerous inner joins, accessing a remote server, and it is taking about twenty times longer than most queries to the same database.
The query itself is built programmaticall y within my application, and
example of which is below. I am hoping someone in the group may have some insight into why this query is so slow, suggesting perhaps a better
structure for it, such that I can go back in and rewrite my code that
creates such queries.

Thanks in advance, Ike

"SELECT DISTINCT
chronology.id,s tatus_id.status ,chronology.com pleted,chronolo gy.completedda
te ,chronology.com pletedtime,acti vities_id.activ ity,chronology. activities_act
iv ity,chronology. activities_atta chment,chronolo gy.activities_a vailable_to_al
l, chronology.upca rds_firstnamela stname,upcard_i d.id,chronology .feedbackrequi
re d,chronology.la ndondate,chrono logy.hasspecifi ctime,chronolog y.datetoperfor
m, chronology.time toperform,chron ology.duration, chronology.week ends,chronolog
y. prefix,statusac tivitieisid.id, associaterespon sible.username, activities_use
rn ameid.username, chronology.edit Flag FROM
chronology,stat us,activities,u pcards,statusac tivities,associ ates
INNER JOIN status status_id on chronology.stat us_id=status_id .id
INNER JOIN activities activities_id on
chronology.acti vities_id=activ ities_id.id
INNER JOIN upcards upcard_id on chronology.upca rd_id=upcard_id .id
INNER JOIN statusactivitie s statusactivitie isid on
chronology.stat usactivitieisid =statusactiviti eisid.id
INNER JOIN associates associaterespon sible on
chronology.asso ciateresponsibl e=associateresp onsible.id
INNER JOIN associates activities_user nameid on
chronology.acti vities_username id=activities_u sernameid.id
WHERE chronology.upca rd_id = 18"


First I'd check whether all those joined tables have indexes on the id
field. If they don't, create them and check again.

If you don't have duplicates you can omit the "DISTINCT" saving the db a
lot of work.

robert

Jul 19 '05 #3
Ike
Hmmm, all the id's do have indexes. Peculiarly, when I remove distinct....it
returns nothing? Ike

"Robert Klemme" <bo******@gmx.n et> wrote in message
news:bp******** *****@ID-52924.news.uni-berlin.de...

"Ike" <rx*@hotmail.co m> schrieb im Newsbeitrag
news:xb******** ***********@new sread2.news.atl .earthlink.net. ..
For some reason, I have a rather large (to me) query, with numerous

inner
joins, accessing a remote server, and it is taking about twenty times

longer
than most queries to the same database.
The query itself is built programmaticall y within my application, and
example of which is below. I am hoping someone in the group may have

some
insight into why this query is so slow, suggesting perhaps a better
structure for it, such that I can go back in and rewrite my code that
creates such queries.

Thanks in advance, Ike

"SELECT DISTINCT

chronology.id,s tatus_id.status ,chronology.com pleted,chronolo gy.completedda
te

,chronology.com pletedtime,acti vities_id.activ ity,chronology. activities_act
iv

ity,chronology. activities_atta chment,chronolo gy.activities_a vailable_to_al
l,

chronology.upca rds_firstnamela stname,upcard_i d.id,chronology .feedbackrequi
re

d,chronology.la ndondate,chrono logy.hasspecifi ctime,chronolog y.datetoperfor
m,

chronology.time toperform,chron ology.duration, chronology.week ends,chronolog
y.

prefix,statusac tivitieisid.id, associaterespon sible.username, activities_use
rn
ameid.username, chronology.edit Flag FROM
chronology,stat us,activities,u pcards,statusac tivities,associ ates
INNER JOIN status status_id on chronology.stat us_id=status_id .id
INNER JOIN activities activities_id on
chronology.acti vities_id=activ ities_id.id
INNER JOIN upcards upcard_id on chronology.upca rd_id=upcard_id .id
INNER JOIN statusactivitie s statusactivitie isid on
chronology.stat usactivitieisid =statusactiviti eisid.id
INNER JOIN associates associaterespon sible on
chronology.asso ciateresponsibl e=associateresp onsible.id
INNER JOIN associates activities_user nameid on
chronology.acti vities_username id=activities_u sernameid.id
WHERE chronology.upca rd_id = 18"


First I'd check whether all those joined tables have indexes on the id
field. If they don't, create them and check again.

If you don't have duplicates you can omit the "DISTINCT" saving the db a
lot of work.

robert

Jul 19 '05 #4
Ike
Hmmm, all the id's do have indexes. Peculiarly, when I remove distinct....it
returns nothing? Ike

"Robert Klemme" <bo******@gmx.n et> wrote in message
news:bp******** *****@ID-52924.news.uni-berlin.de...

"Ike" <rx*@hotmail.co m> schrieb im Newsbeitrag
news:xb******** ***********@new sread2.news.atl .earthlink.net. ..
For some reason, I have a rather large (to me) query, with numerous

inner
joins, accessing a remote server, and it is taking about twenty times

longer
than most queries to the same database.
The query itself is built programmaticall y within my application, and
example of which is below. I am hoping someone in the group may have

some
insight into why this query is so slow, suggesting perhaps a better
structure for it, such that I can go back in and rewrite my code that
creates such queries.

Thanks in advance, Ike

"SELECT DISTINCT

chronology.id,s tatus_id.status ,chronology.com pleted,chronolo gy.completedda
te

,chronology.com pletedtime,acti vities_id.activ ity,chronology. activities_act
iv

ity,chronology. activities_atta chment,chronolo gy.activities_a vailable_to_al
l,

chronology.upca rds_firstnamela stname,upcard_i d.id,chronology .feedbackrequi
re

d,chronology.la ndondate,chrono logy.hasspecifi ctime,chronolog y.datetoperfor
m,

chronology.time toperform,chron ology.duration, chronology.week ends,chronolog
y.

prefix,statusac tivitieisid.id, associaterespon sible.username, activities_use
rn
ameid.username, chronology.edit Flag FROM
chronology,stat us,activities,u pcards,statusac tivities,associ ates
INNER JOIN status status_id on chronology.stat us_id=status_id .id
INNER JOIN activities activities_id on
chronology.acti vities_id=activ ities_id.id
INNER JOIN upcards upcard_id on chronology.upca rd_id=upcard_id .id
INNER JOIN statusactivitie s statusactivitie isid on
chronology.stat usactivitieisid =statusactiviti eisid.id
INNER JOIN associates associaterespon sible on
chronology.asso ciateresponsibl e=associateresp onsible.id
INNER JOIN associates activities_user nameid on
chronology.acti vities_username id=activities_u sernameid.id
WHERE chronology.upca rd_id = 18"


First I'd check whether all those joined tables have indexes on the id
field. If they don't, create them and check again.

If you don't have duplicates you can omit the "DISTINCT" saving the db a
lot of work.

robert

Jul 19 '05 #5

"Ike" <rx*@hotmail.co m> schrieb im Newsbeitrag
news:ho******** ***********@new sread2.news.atl .earthlink.net. ..
Hmmm, all the id's do have indexes.
Darn. If it's MS SQL Server you could throw it into the query analyzer
and look at the execution plan to get more hints about db optimization.
There's even an index optimizing wizard...
Peculiarly, when I remove distinct....it
returns nothing? Ike


That's irritating. If anything it should return *more* without DISTINCT -
not less.

robert

Jul 19 '05 #6

"Ike" <rx*@hotmail.co m> schrieb im Newsbeitrag
news:ho******** ***********@new sread2.news.atl .earthlink.net. ..
Hmmm, all the id's do have indexes.
Darn. If it's MS SQL Server you could throw it into the query analyzer
and look at the execution plan to get more hints about db optimization.
There's even an index optimizing wizard...
Peculiarly, when I remove distinct....it
returns nothing? Ike


That's irritating. If anything it should return *more* without DISTINCT -
not less.

robert

Jul 19 '05 #7
Ike
LOL, I know....I was fearing a cartesian join! -Ike

"Robert Klemme" <bo******@gmx.n et> wrote in message
news:bq******** *****@ID-52924.news.uni-berlin.de...

"Ike" <rx*@hotmail.co m> schrieb im Newsbeitrag
news:ho******** ***********@new sread2.news.atl .earthlink.net. ..
Hmmm, all the id's do have indexes.


Darn. If it's MS SQL Server you could throw it into the query analyzer
and look at the execution plan to get more hints about db optimization.
There's even an index optimizing wizard...
Peculiarly, when I remove distinct....it
returns nothing? Ike


That's irritating. If anything it should return *more* without DISTINCT -
not less.

robert

Jul 19 '05 #8
Ike
LOL, I know....I was fearing a cartesian join! -Ike

"Robert Klemme" <bo******@gmx.n et> wrote in message
news:bq******** *****@ID-52924.news.uni-berlin.de...

"Ike" <rx*@hotmail.co m> schrieb im Newsbeitrag
news:ho******** ***********@new sread2.news.atl .earthlink.net. ..
Hmmm, all the id's do have indexes.


Darn. If it's MS SQL Server you could throw it into the query analyzer
and look at the execution plan to get more hints about db optimization.
There's even an index optimizing wizard...
Peculiarly, when I remove distinct....it
returns nothing? Ike


That's irritating. If anything it should return *more* without DISTINCT -
not less.

robert

Jul 19 '05 #9
which database server are you using (sql server, oracle, db2)?

"Ike" <rx*@hotmail.co m> wrote in message
news:xb******** ***********@new sread2.news.atl .earthlink.net. ..
For some reason, I have a rather large (to me) query, with numerous inner
joins, accessing a remote server, and it is taking about twenty times longer than most queries to the same database.
The query itself is built programmaticall y within my application, and
example of which is below. I am hoping someone in the group may have some
insight into why this query is so slow, suggesting perhaps a better
structure for it, such that I can go back in and rewrite my code that
creates such queries.

Thanks in advance, Ike

"SELECT DISTINCT
chronology.id,s tatus_id.status ,chronology.com pleted,chronolo gy.completeddat e ,chronology.com pletedtime,acti vities_id.activ ity,chronology. activities_acti v ity,chronology. activities_atta chment,chronolo gy.activities_a vailable_to_all , chronology.upca rds_firstnamela stname,upcard_i d.id,chronology .feedbackrequir e d,chronology.la ndondate,chrono logy.hasspecifi ctime,chronolog y.datetoperform , chronology.time toperform,chron ology.duration, chronology.week ends,chronology . prefix,statusac tivitieisid.id, associaterespon sible.username, activities_user n ameid.username, chronology.edit Flag FROM
chronology,stat us,activities,u pcards,statusac tivities,associ ates
INNER JOIN status status_id on chronology.stat us_id=status_id .id
INNER JOIN activities activities_id on
chronology.acti vities_id=activ ities_id.id
INNER JOIN upcards upcard_id on chronology.upca rd_id=upcard_id .id
INNER JOIN statusactivitie s statusactivitie isid on
chronology.stat usactivitieisid =statusactiviti eisid.id
INNER JOIN associates associaterespon sible on
chronology.asso ciateresponsibl e=associateresp onsible.id
INNER JOIN associates activities_user nameid on
chronology.acti vities_username id=activities_u sernameid.id
WHERE chronology.upca rd_id = 18"

Jul 19 '05 #10

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

Similar topics

1
2499
by: John Ramsden | last post by:
I have a script running on PHP v4.3.6 (cgi) that hangs forever in a call to the Postgres pg_get_result() function when and only when the query length is 65536 or more bytes. The query is a simple INSERT, of a single ASCII value into a 'text' type field, and works fine for shorter queries. (As the code first calls pg_escape_string() on the value to be inserted, I'm sure the problem doesn't relate to bad characters in the data.)
54
3981
by: seberino | last post by:
Many people I know ask why Python does slicing the way it does..... Can anyone /please/ give me a good defense/justification??? I'm referring to why mystring gives me elements 0, 1, 2 and 3 but *NOT* mystring (5th element). Many people don't like idea that 5th element is not invited. (BTW, yes I'm aware of the explanation where slicing
5
3145
by: Shay | last post by:
essentially I am trying to do some counts based on some assumptions in the recordset. So I get the RS back, put the values into a variable, move to the next record in the RS and compare what is in the variable to the value in the next record in the recordset and do a count. Then overwrite the value in the variables and do the same for the next record and so. But this runs extremly slow. 5000 records takes about 10 minutes in IE6 and I...
5
1745
by: jim Bob | last post by:
Hi, Can someone help with a simple query? I have a table with the following. Firstname Lastname InterviewerID1 InterviewerID2 InterviewerID3 ...
34
4476
by: NewToCPP | last post by:
Hi, Why does a C/C++ programs crash? When there is access to a null pointer or some thing like that programs crash, but why do they crash? Thanks.
4
3134
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I might be able to accomplish the results in two steps by using two queries. If this is possible how can I do it? Thank you, Stan Hanna
1
1782
by: gkinu | last post by:
I have 2 tables with a parent-child relationship. Parent table's primary key field is Entry_no and is of type VarChar(50). This parent table has about 50 fields. The child has 3 fields, Entry_No (varchar(50), Requestor char(3) and id (integer). I need the following query QUERY 1. select p.entry_no, p.reg_date from tparent p, tchild c where p.entry_no<>c.entry_no and c.requestor='KPA' order by p.reg_date, p.entry_no; The above query...
13
4177
by: Neil | last post by:
I'm running an update query in SQL 7 from QA, and it runs forever. Has been running for 20 minutes so far! The query is quite simple: update a single field in a table, based on a join with another table. There are a total of 1200 rows that are affected (out of a total of 60,000 in the table). Should not take 20 minutes! Also, retrieving the 1200 rows using the same criteria is instantaneous. Anyone have any idea what's going on? Here's...
6
4406
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one field between them. The join field in both tables are indexed and I'm selecting 1 field from each table to lookup. The Access query is taking more than 60 second to retrieve 1 record and if I execute the same query within the Query Analyzer, it...
0
9645
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
9480
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,...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8974
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...
0
6740
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
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
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
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.