Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Why does this query take forever?

 
   Database Help (Home) -> mySQL RSS
Next:  XAPool 1.3.3 released under LGPL  
Author Message
Ike

External


Since: Aug 19, 2003
Posts: 49



(Msg. 1) Posted: Tue Nov 25, 2003 4:55 pm
Post subject: Why does this query take forever?
Archived from groups: mailing>database>mysql, others (more info?)

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.completed,chronology.completeddate
,chronology.completedtime,activities_id.activity,chronology.activities_activ
ity,chronology.activities_attachment,chronology.activities_available_to_all,
chronology.upcards_firstnamelastname,upcard_id.id,chronology.feedbackrequire
d,chronology.landondate,chronology.hasspecifictime,chronology.datetoperform,
chronology.timetoperform,chronology.duration,chronology.weekends,chronology.
prefix,statusactivitieisid.id,associateresponsible.username,activities_usern
ameid.username,chronology.editFlag FROM
chronology,status,activities,upcards,statusactivities,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=associateresponsible.id
INNER JOIN associates activities_usernameid on
chronology.activities_usernameid=activities_usernameid.id
WHERE chronology.upcard_id = 18"

 >> Stay informed about: Why does this query take forever? 
Back to top
Login to vote
Robert Klemme

External


Since: Oct 01, 2003
Posts: 48



(Msg. 2) Posted: Tue Nov 25, 2003 6:54 pm
Post subject: Re: Why does this query take forever? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Ike" schrieb im Newsbeitrag

 > 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.completed,chronology.completedda
te
 >
,chronology.completedtime,activities_id.activity,chronology.activities_act
iv
 >
ity,chronology.activities_attachment,chronology.activities_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,chronology.weekends,chronolog
y.
 >
prefix,statusactivitieisid.id,associateresponsible.username,activities_use
rn
 > ameid.username,chronology.editFlag FROM
 > chronology,status,activities,upcards,statusactivities,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=associateresponsible.id
 > INNER JOIN associates activities_usernameid on
 > chronology.activities_usernameid=activities_usernameid.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

 >> Stay informed about: Why does this query take forever? 
Back to top
Login to vote
Ike

External


Since: Aug 19, 2003
Posts: 49



(Msg. 3) Posted: Tue Nov 25, 2003 7:25 pm
Post subject: Re: Why does this query take forever? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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

"Robert Klemme" wrote in message

 >


  > > 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.completed,chronology.completedda
 > te
  > >
 > ,chronology.completedtime,activities_id.activity,chronology.activities_act
 > iv
  > >
 > ity,chronology.activities_attachment,chronology.activities_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,chronology.weekends,chronolog
 > y.
  > >
 > prefix,statusactivitieisid.id,associateresponsible.username,activities_use
 > rn
  > > ameid.username,chronology.editFlag FROM
  > > chronology,status,activities,upcards,statusactivities,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=associateresponsible.id
  > > INNER JOIN associates activities_usernameid on
  > > chronology.activities_usernameid=activities_usernameid.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
 >
 >> Stay informed about: Why does this query take forever? 
Back to top
Login to vote
Robert Klemme

External


Since: Oct 01, 2003
Posts: 48



(Msg. 4) Posted: Tue Nov 25, 2003 8:40 pm
Post subject: Re: Why does this query take forever? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Ike" schrieb im Newsbeitrag

 > 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
 >> Stay informed about: Why does this query take forever? 
Back to top
Login to vote
Ike

External


Since: Aug 19, 2003
Posts: 49



(Msg. 5) Posted: Tue Nov 25, 2003 8:40 pm
Post subject: Re: Why does this query take forever? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

LOL, I know....I was fearing a cartesian join! -Ike

"Robert Klemme" wrote in message

 >


  > > 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
 >
 >> Stay informed about: Why does this query take forever? 
Back to top
Login to vote
Moran Ben-David

External


Since: Nov 26, 2003
Posts: 4



(Msg. 6) Posted: Wed Nov 26, 2003 9:39 pm
Post subject: Re: Why does this query take forever? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

which database server are you using (sql server, oracle, db2)?

"Ike" wrote in message

 > 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.completed,chronology.completeddate
 >
,chronology.completedtime,activities_id.activity,chronology.activities_activ
 >
ity,chronology.activities_attachment,chronology.activities_available_to_all,
 >
chronology.upcards_firstnamelastname,upcard_id.id,chronology.feedbackrequire
 >
d,chronology.landondate,chronology.hasspecifictime,chronology.datetoperform,
 >
chronology.timetoperform,chronology.duration,chronology.weekends,chronology.
 >
prefix,statusactivitieisid.id,associateresponsible.username,activities_usern
 > ameid.username,chronology.editFlag FROM
 > chronology,status,activities,upcards,statusactivities,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=associateresponsible.id
 > INNER JOIN associates activities_usernameid on
 > chronology.activities_usernameid=activities_usernameid.id
 > WHERE chronology.upcard_id = 18"
 >
 >
 >> Stay informed about: Why does this query take forever? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Select Query Help - I'm struggling - with my limited knowledge of SQL - to write a query that does what I want it to, and I was hoping that someone here may be able to help out. I have a table with two columns, user1 and user2, which store user ID's. For example: ..

Query MySQL from Excel - Is it possible to pick up information from a MySQL database using a macro in Excel? Don

a brand new query tool is out on beta, we need feedback, s.. - We at Nob Hill Software are working on a new query tool: http://www.nobhillsoft.com/MarieAlix.aspx?HeardVia=ptut You can read all about it on the above web page, but basically, its a very ambitious project to create what we call 'the query tool to....

Which is faster - MySQL query, or PHP loop - In theory, which of these would be faster? Assume a few thousands rows: $query = "SELECT category FROM classifieds; $sth_classifieds = mysql_query($query); while (list($category) = mysql_fetch_array($sth_classifieds)) { if..

select query on latin1 or utf8 column: which is faster? - Assume you have two varchar (or Text) columns named L and U which are identical except that the charset for L is latin1 and the charset for U is utf8. All the records in L and U are identical in terms of content, consisting of only 7 bit ASCII characters...
   Database Help (Home) -> mySQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]