Re: Alternative for IN+Subselect in this case
Posted by:
Rick James
Date: November 16, 2012 08:33PM
# what you have:
SELECT col1, col2
FROM table b
WHERE b.id IN (
SELECT id
FROM idxmail i
JOIN matching m ON i.proxyaddress = m.proxyaddress
WHERE m.mailnickname = '@var1');
# Plan A:
SELECT col1, col2
FROM table b
JOIN idxmail i ON i.id = b.id
JOIN matching m ON i.proxyaddress = m.proxyaddress
WHERE m.mailnickname = '@var1';
# Plan B:
SELECT col1, col2
FROM table b
JOIN
( SELECT id
FROM idxmail i
JOIN matching m ON i.proxyaddress = m.proxyaddress
WHERE m.mailnickname = '@var1'
) x ON x.id = b.id;
You need
b: INDEX(id) (or PRIMARY KEY(id))
i: INDEX(proxyaddress)
m: INDEX(mailnickname, proxyaddress)
If you don't understand the "compound" index I am suggesting for m, please study
http://mysql.rjweb.org/doc.php/index1
Subject
Views
Written By
Posted
1606
November 14, 2012 01:59AM
Re: Alternative for IN+Subselect in this case
836
November 16, 2012 08:33PM
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.