MySQL Forums
Forum List  »  Performance

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

Hi,

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 a.name='department' and a.value='Sales'
and b.name='role' and b.value!='broker'
and c.name='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


Subject
Views
Written By
Posted
Re: Reg table design and query performances
881
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.