Hi there,
 
I have trouble with a SQL statement that uses too much load on our
server due to heavy traffic. MySQL uses temporary files and filesort, so
I narrowed the problem down to this one here:
 
 
TABLE A:
ID      INTEGER       PRIMARY KEY
TEXT    VARCHAR(10)
 
TABLE B:
ID      INTEGER       PRIMARY KEY
REF_ID  INTEGER
NUMBER  FLOAT(7,2)
 
No matter, how many entries I have in A and B and no matter what indexes
I create, I always get a USING TEMPORARY, USING FILESORT when EXPLAINing
the following simple statement:
 
SELECT a.id, MIN(b.number) AS low FROM a JOIN b ON (a.id = b.ref_id)
GROUP BY a.id ORDER BY low
 
What can I do to speed up this query? I need to get a list of rows from
table a with it's lowest reference number from table b.
 
Thanks in advance,
Marc

Reply via email to