Query with 2 x subquery
I have a query that is bugging me. I "just" need the latest recorded values within for a given partid before a certain sessionid
SELECT sessionid, varid, val FROM data_i16 WHERE ROW(sessionid, varid) IN
(SELECT MAX(sessionid) as sessionid, varid FROM data_i16 WHERE sessionid IN
(SELECT sessionid FROM session WHERE partid='5' AND sessionid<1611659) GROUP BY varid ORDER BY sessionid DESC);
Here is the EXPLAIN - the type ALL in the outermost query seems to be the killer.
1 PRIMARY data_i16 ALL 19945718 Using where
2 SUBQUERY session range PRIMARY,Index 1 PRIMARY 8 946256 Using where; Using temporary; Using filesort
2 SUBQUERY data_i16 ref PRIMARY,ui16_idx ui16_idx 8 nodejstest.session.sessionid 5 Using index
The problem is that the query is taking roughly 30s to deliver the correct 108 rows out of 16M rows.
Running the two subquerys isolated results in subsecond returns.
I am open to suggestions, and a "not possible to optimize is also interesing.
Best regards
Subject
Views
Written By
Posted
Query with 2 x subquery
1834
April 29, 2016 06:44AM
974
April 29, 2016 08:01AM
1024
May 02, 2016 03:45AM
1015
May 02, 2016 05:32AM
1050
May 02, 2016 02:16AM
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.