Re: Optimising query with self-join and GROUP BY
Having indices on (id, segment_id) and (segment_id, id) should avoid the temporary table and the filesort. But the query proves to be still way too slow with my artificial testdata.
Here's a version that works quite well for me and only requires an index on (segment_id, id)
SELECT
a.segment_id
FROM
(SELECT DISTINCT segment_id FROM current_way_segments WHERE id = 1) a
LEFT JOIN
current_way_segments b
ON
b.segment_id = a.segment_id AND
b.id != 1
WHERE
b.segment_id IS NULL
Subject
Views
Written By
Posted
8637
May 07, 2007 01:24PM
Re: Optimising query with self-join and GROUP BY
3411
May 09, 2007 05:21PM
2740
May 13, 2007 03:12PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.