![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| 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 | |||
|
| | #2 | ||
| 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. | |||
|
| Featured Websites | ||||
|
![]() |
| Tags: infinite, loop, mysql |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| redo the nth loop | SpamBait | PHP | 1 | 07-01-2007 5:25 PM |
| call a PHP script from a while loop over & over | pprince | PHP | 1 | 07-01-2007 3:49 PM |
| using for loop with str_replace & $_files array | Eric Haskins | PHP | 2 | 07-01-2007 3:35 PM |
| Loop Emulation...is it possible? | Abraxas | Software Programming | 0 | 06-12-2007 11:28 PM |
| Infinite Level MLM - and it's International!! | Sweetpuppy | Building An Internet Business | 0 | 05-29-2007 2:36 AM |
| Featured Websites | ||||
|