MySQL Forums
Forum List  »  Performance

Re: Reg table design and query performances
Posted by: Øystein Grøvlen
Date: April 26, 2016 06:35AM


Then I suggest you merge the subqueries into the main query. I do not see that they serve any purpose. In other words:

select a.user_id, a.value as department, b.value as role, c.value as location
from attribute_value a join attribute_value b on a.user_id=b.user_id
join attribute_value b on a.user_id=c.user_id
where'department' and a.value='Sales'
and'role' and b.value!='broker'
and'location' and c.value='Seattle';

MySQL 5.7 will do this rewrite automatically.

For the given query, an index on (value, name) is probably be better since then all brokers can easily be skipped.

Hope this helps,

Øystein Grøvlen,
Senior Principal Software Engineer,
MySQL Group, Oracle,
Trondheim, Norway

Options: ReplyQuote

Written By
Re: Reg table design and query performances
April 26, 2016 06:35AM

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.