subselect in 'IN list', Win2000, mysql 4.1.7
Hi,
I wonder about the performance of the following subselect:
----------------------------------------------------------------------
SELECT DISTINCT d.ID, sqt.policy_reference, sr.*
FROM d, dsr, sr, sqt
WHERE (d.ID = dsr.dbramm_id) AND (dsr.scs_risk_list_id = sr.ID) AND (sr.scs_base_risk_question_number = sqt.qindex)
AND (d.ID IN(SELECT DISTINCT d2.ID FROM DBRAMM AS d2 WHERE d2.real_dbramm_id = 216)))
----------------------------------------------------------------------
[requires minutes]
compared to the identical query without subselect:
----------------------------------------------------------------------
SELECT DISTINCT d.ID, sqt.policy_reference, sr.*
FROM d, dsr, sr, sqt
WHERE (d.ID = dsr.dbramm_id) AND (dsr.scs_risk_list_id = sr.ID) AND (sr.scs_base_risk_question_number = sqt.qindex)
AND (d.ID IN(1,34,15,36,324,...some more))
----------------------------------------------------------------------
[requires 8 seconds]
the sqls are the same, necessary indexes are created...the only difference is the IN list via subselect vs given as predifined id-list, like used in the pre-subselect times of mysql.
can anyone tell me the difference or how I can get this run faster?
many thanks!