If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > slow query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-04, 15:50
narcis010 narcis010 is offline
Registered User
 
Join Date: Oct 2003
Posts: 5
slow query

Hello,

Just a little question. I'm creating an online catalog and there is a category that returns me about 140.000 entries.

It is a relational query, I've already created indexes, but it takes a long time to execute the sentence.

Is there a way to increase the speed of the query? It currently takes about 40 seconds!

Here is the one I use:

SELECT TABLE1.FIELD1, TABLE1.FIELD2, TABLE1.FIELD1, TABLE2.FIELD1 FROM TABLE1, TABLE2 WHERE TABLE1.FIELD5='%s' AND TABLE2.FIELDINDEX=TABLE1.FILEINDEX GROUP BY TABLE1.FIELD1 ASC",$varQUERY);
$query_limit_rsQUERY = sprintf("%s LIMIT %d, %d", $query_rsQUERY, $startRow_rsQUERY, $maxRows_rsQUERY);

Thanks a lot!

NArcís
Reply With Quote
  #2 (permalink)  
Old 02-10-04, 16:33
reneeb reneeb is offline
Registered User
 
Join Date: Jan 2004
Location: Germany
Posts: 167
The result of your query is a cross join. This is many times slower than an inner join. Try this query:

SELECT TABLE1.FIELD1, TABLE1.FIELD2, TABLE1.FIELD1, TABLE2.FIELD1 FROM TABLE1 INNER JOIN TABLE2 ON TABLE2.FIELDINDEX = TABLE1.FIELDINDEX WHERE TABLE1.FIELD5='%s' GROUP BY TABLE1.FIELD1 ASC;
__________________
board.perl-community.de - The German Perl-Community
Reply With Quote
  #3 (permalink)  
Old 02-11-04, 04:38
narcis010 narcis010 is offline
Registered User
 
Join Date: Oct 2003
Posts: 5
Hello reneeb,

Thanks a lot for your help, I've changed the query but page loading has just improved about 3 seconds. However that makes browsing the other parts of the catalog faster!

I feel that the problem is that we get too many results, and I would like to know if I could limit it a little bit as querys with about 2.000 results work perfectly. I tried the same query but removing the cros query and it takes the same time.

I was thinking in a kind of mysql option that made large tables run faster, or a way to stop the query when it has more than 5.000 results (as it make not sense having so many results).

Thanks a lot,

Narcís
Reply With Quote
  #4 (permalink)  
Old 02-11-04, 04:52
reneeb reneeb is offline
Registered User
 
Join Date: Jan 2004
Location: Germany
Posts: 167
a limitation of results??

Take this:

SELECT TABLE1.FIELD1, TABLE1.FIELD2, TABLE1.FIELD1, TABLE2.FIELD1 FROM TABLE1 INNER JOIN TABLE2 ON TABLE2.FIELDINDEX = TABLE1.FIELDINDEX WHERE TABLE1.FIELD5='%s' GROUP BY TABLE1.FIELD1 ASC LIMIT 2000;



If you have an index on table1.field5 it would run faster...
__________________
board.perl-community.de - The German Perl-Community
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On