473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 programmatically 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,status_id.status,chronology.complete d,chronology.completeddate
,chronology.completedtime,activities_id.activity,c hronology.activities_activ
ity,chronology.activities_attachment,chronology.ac tivities_available_to_all,
chronology.upcards_firstnamelastname,upcard_id.id, chronology.feedbackrequire
d,chronology.landondate,chronology.hasspecifictime ,chronology.datetoperform,
chronology.timetoperform,chronology.duration,chron ology.weekends,chronology.
prefix,statusactivitieisid.id,associateresponsible .username,activities_usern
ameid.username,chronology.editFlag FROM
chronology,status,activities,upcards,statusactivit ies,associates
INNER JOIN status status_id on chronology.status_id=status_id.id
INNER JOIN activities activities_id on
chronology.activities_id=activities_id.id
INNER JOIN upcards upcard_id on chronology.upcard_id=upcard_id.id
INNER JOIN statusactivities statusactivitieisid on
chronology.statusactivitieisid=statusactivitieisid .id
INNER JOIN associates associateresponsible on
chronology.associateresponsible=associateresponsib le.id
INNER JOIN associates activities_usernameid on
chronology.activities_usernameid=activities_userna meid.id
WHERE chronology.upcard_id = 18"
Jul 19 '05 #1
10 2147

"Ike" <rx*@hotmail.com> schrieb im Newsbeitrag
news:xb*******************@newsread2.news.atl.eart hlink.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 programmatically 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,status_id.status,chronology.complete d,chronology.completedda
te ,chronology.completedtime,activities_id.activity,c hronology.activities_act
iv ity,chronology.activities_attachment,chronology.ac tivities_available_to_al
l, chronology.upcards_firstnamelastname,upcard_id.id, chronology.feedbackrequi
re d,chronology.landondate,chronology.hasspecifictime ,chronology.datetoperfor
m, chronology.timetoperform,chronology.duration,chron ology.weekends,chronolog
y. prefix,statusactivitieisid.id,associateresponsible .username,activities_use
rn ameid.username,chronology.editFlag FROM
chronology,status,activities,upcards,statusactivit ies,associates
INNER JOIN status status_id on chronology.status_id=status_id.id
INNER JOIN activities activities_id on
chronology.activities_id=activities_id.id
INNER JOIN upcards upcard_id on chronology.upcard_id=upcard_id.id
INNER JOIN statusactivities statusactivitieisid on
chronology.statusactivitieisid=statusactivitieisid .id
INNER JOIN associates associateresponsible on
chronology.associateresponsible=associateresponsib le.id
INNER JOIN associates activities_usernameid on
chronology.activities_usernameid=activities_userna meid.id
WHERE chronology.upcard_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.com> schrieb im Newsbeitrag
news:xb*******************@newsread2.news.atl.eart hlink.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 programmatically 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,status_id.status,chronology.complete d,chronology.completedda
te ,chronology.completedtime,activities_id.activity,c hronology.activities_act
iv ity,chronology.activities_attachment,chronology.ac tivities_available_to_al
l, chronology.upcards_firstnamelastname,upcard_id.id, chronology.feedbackrequi
re d,chronology.landondate,chronology.hasspecifictime ,chronology.datetoperfor
m, chronology.timetoperform,chronology.duration,chron ology.weekends,chronolog
y. prefix,statusactivitieisid.id,associateresponsible .username,activities_use
rn ameid.username,chronology.editFlag FROM
chronology,status,activities,upcards,statusactivit ies,associates
INNER JOIN status status_id on chronology.status_id=status_id.id
INNER JOIN activities activities_id on
chronology.activities_id=activities_id.id
INNER JOIN upcards upcard_id on chronology.upcard_id=upcard_id.id
INNER JOIN statusactivities statusactivitieisid on
chronology.statusactivitieisid=statusactivitieisid .id
INNER JOIN associates associateresponsible on
chronology.associateresponsible=associateresponsib le.id
INNER JOIN associates activities_usernameid on
chronology.activities_usernameid=activities_userna meid.id
WHERE chronology.upcard_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.net> wrote in message
news:bp*************@ID-52924.news.uni-berlin.de...

"Ike" <rx*@hotmail.com> schrieb im Newsbeitrag
news:xb*******************@newsread2.news.atl.eart hlink.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 programmatically 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,status_id.status,chronology.complete d,chronology.completedda
te

,chronology.completedtime,activities_id.activity,c hronology.activities_act
iv

ity,chronology.activities_attachment,chronology.ac tivities_available_to_al
l,

chronology.upcards_firstnamelastname,upcard_id.id, chronology.feedbackrequi
re

d,chronology.landondate,chronology.hasspecifictime ,chronology.datetoperfor
m,

chronology.timetoperform,chronology.duration,chron ology.weekends,chronolog
y.

prefix,statusactivitieisid.id,associateresponsible .username,activities_use
rn
ameid.username,chronology.editFlag FROM
chronology,status,activities,upcards,statusactivit ies,associates
INNER JOIN status status_id on chronology.status_id=status_id.id
INNER JOIN activities activities_id on
chronology.activities_id=activities_id.id
INNER JOIN upcards upcard_id on chronology.upcard_id=upcard_id.id
INNER JOIN statusactivities statusactivitieisid on
chronology.statusactivitieisid=statusactivitieisid .id
INNER JOIN associates associateresponsible on
chronology.associateresponsible=associateresponsib le.id
INNER JOIN associates activities_usernameid on
chronology.activities_usernameid=activities_userna meid.id
WHERE chronology.upcard_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.net> wrote in message
news:bp*************@ID-52924.news.uni-berlin.de...

"Ike" <rx*@hotmail.com> schrieb im Newsbeitrag
news:xb*******************@newsread2.news.atl.eart hlink.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 programmatically 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,status_id.status,chronology.complete d,chronology.completedda
te

,chronology.completedtime,activities_id.activity,c hronology.activities_act
iv

ity,chronology.activities_attachment,chronology.ac tivities_available_to_al
l,

chronology.upcards_firstnamelastname,upcard_id.id, chronology.feedbackrequi
re

d,chronology.landondate,chronology.hasspecifictime ,chronology.datetoperfor
m,

chronology.timetoperform,chronology.duration,chron ology.weekends,chronolog
y.

prefix,statusactivitieisid.id,associateresponsible .username,activities_use
rn
ameid.username,chronology.editFlag FROM
chronology,status,activities,upcards,statusactivit ies,associates
INNER JOIN status status_id on chronology.status_id=status_id.id
INNER JOIN activities activities_id on
chronology.activities_id=activities_id.id
INNER JOIN upcards upcard_id on chronology.upcard_id=upcard_id.id
INNER JOIN statusactivities statusactivitieisid on
chronology.statusactivitieisid=statusactivitieisid .id
INNER JOIN associates associateresponsible on
chronology.associateresponsible=associateresponsib le.id
INNER JOIN associates activities_usernameid on
chronology.activities_usernameid=activities_userna meid.id
WHERE chronology.upcard_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.com> schrieb im Newsbeitrag
news:ho*******************@newsread2.news.atl.eart hlink.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.com> schrieb im Newsbeitrag
news:ho*******************@newsread2.news.atl.eart hlink.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.net> wrote in message
news:bq*************@ID-52924.news.uni-berlin.de...

"Ike" <rx*@hotmail.com> schrieb im Newsbeitrag
news:ho*******************@newsread2.news.atl.eart hlink.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.net> wrote in message
news:bq*************@ID-52924.news.uni-berlin.de...

"Ike" <rx*@hotmail.com> schrieb im Newsbeitrag
news:ho*******************@newsread2.news.atl.eart hlink.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.com> wrote in message
news:xb*******************@newsread2.news.atl.eart hlink.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 programmatically 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,status_id.status,chronology.complete d,chronology.completeddate ,chronology.completedtime,activities_id.activity,c hronology.activities_activ ity,chronology.activities_attachment,chronology.ac tivities_available_to_all, chronology.upcards_firstnamelastname,upcard_id.id, chronology.feedbackrequire d,chronology.landondate,chronology.hasspecifictime ,chronology.datetoperform, chronology.timetoperform,chronology.duration,chron ology.weekends,chronology. prefix,statusactivitieisid.id,associateresponsible .username,activities_usern ameid.username,chronology.editFlag FROM
chronology,status,activities,upcards,statusactivit ies,associates
INNER JOIN status status_id on chronology.status_id=status_id.id
INNER JOIN activities activities_id on
chronology.activities_id=activities_id.id
INNER JOIN upcards upcard_id on chronology.upcard_id=upcard_id.id
INNER JOIN statusactivities statusactivitieisid on
chronology.statusactivitieisid=statusactivitieisid .id
INNER JOIN associates associateresponsible on
chronology.associateresponsible=associateresponsib le.id
INNER JOIN associates activities_usernameid on
chronology.activities_usernameid=activities_userna meid.id
WHERE chronology.upcard_id = 18"

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

"Ike" <rx*@hotmail.com> wrote in message
news:xb*******************@newsread2.news.atl.eart hlink.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 programmatically 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,status_id.status,chronology.complete d,chronology.completeddate ,chronology.completedtime,activities_id.activity,c hronology.activities_activ ity,chronology.activities_attachment,chronology.ac tivities_available_to_all, chronology.upcards_firstnamelastname,upcard_id.id, chronology.feedbackrequire d,chronology.landondate,chronology.hasspecifictime ,chronology.datetoperform, chronology.timetoperform,chronology.duration,chron ology.weekends,chronology. prefix,statusactivitieisid.id,associateresponsible .username,activities_usern ameid.username,chronology.editFlag FROM
chronology,status,activities,upcards,statusactivit ies,associates
INNER JOIN status status_id on chronology.status_id=status_id.id
INNER JOIN activities activities_id on
chronology.activities_id=activities_id.id
INNER JOIN upcards upcard_id on chronology.upcard_id=upcard_id.id
INNER JOIN statusactivities statusactivitieisid on
chronology.statusactivitieisid=statusactivitieisid .id
INNER JOIN associates associateresponsible on
chronology.associateresponsible=associateresponsib le.id
INNER JOIN associates activities_usernameid on
chronology.activities_usernameid=activities_userna meid.id
WHERE chronology.upcard_id = 18"

Jul 19 '05 #11

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

Similar topics

1
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...
54
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...
5
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...
5
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
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
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...
1
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...
13
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.