Mysql infinite loop?!

This is a discussion on Mysql infinite loop?! within the MySQL Database forums, part of the Database Forums category; this query doesnt work: SELECT d.cID,d.cLName,d.cFName , k.kid FROM cname d, cu_key e, rep_key f , `...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-10-2006
StockN@gmail.com
 
Posts: n/a
Default Mysql infinite loop?!

this query doesnt work:
SELECT d.cID,d.cLName,d.cFName , k.kid
FROM cname d, cu_key e, rep_key f , `key` k
WHERE (d.cLName LIKE '%') and (((e.cID = d.cID) and
(k.kID=e.keyID))or((f.repID = d.cID)
and (k.kID=f.keyID))) and
( (k.UserSupportExp >= '2001-01-01' ) and (k.UserSupportExp
<='2002-01-01') )
order by d.cLName,d.cFName LIMIT 0, 50

if i take out either of the statments connected by the or clause, the
query works, otherwise it times out after 3000 seconds.

SELECT d.cID,d.cLName,d.cFName , k.kid
FROM cname d, cu_key e, rep_key f , `key` k
WHERE (d.cLName LIKE '%') and (((e.cID = d.cID) and (k.kID=e.keyID)))
and
( (k.UserSupportExp >= '2001-01-01' ) and (k.UserSupportExp
<='2002-01-01') )
order by d.cLName,d.cFName LIMIT 0, 50

any ideals?
thanks in advance nick

Reply With Quote
  #2 (permalink)  
Old 05-10-2006
Bill Karwin
 
Posts: n/a
Default Re: Mysql infinite loop?!

StockN@gmail.com wrote:
> SELECT d.cID,d.cLName,d.cFName , k.kid
> FROM cname d, cu_key e, rep_key f , `key` k
> WHERE (d.cLName LIKE '%') and (((e.cID = d.cID) and
> (k.kID=e.keyID))or((f.repID = d.cID)
> and (k.kID=f.keyID))) and
> ( (k.UserSupportExp >= '2001-01-01' ) and (k.UserSupportExp
> <='2002-01-01') )
> order by d.cLName,d.cFName LIMIT 0, 50
>
> if i take out either of the statments connected by the or clause, the
> query works, otherwise it times out after 3000 seconds.


So it takes a long time, but this doesn't mean it's an infinite loop.
It just means your query is very expensive and takes too long.

What is the purpose of using "LIKE '%'"? This use of the wildcard
matches all rows, but ensures no index can be used, so it forces a
table-scan on your cname table. This can be costly, and probably causes
the query to take a long time, thus you're getting a timeout.

This might not be the only performance problem. What indexes do you
have in these tables? Have you used EXPLAIN to analyze the query, so
you know what additional indexes you should create?

You also have a non-normalized relationship between your tables: k.kID
and d.cID can reference either of two tables (cu_key or rep_key). I
predict that this design will become harder and harder to manage, until
it becomes completely broken. You should combine the cu_key and rep_key
tables into one table, so you can have a cleaner reference relationship
between your tables.

Regards,
Bill K.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:21 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0