| This is a common query generated by Hibernate SELECT b.* FROM b WHERE b.a_id IN (SELECT a.id FROM a WHERE a.id IN (100, 200)) If selecting the same column with the same value, this could be constant-folded as (100, 200) Otherwise, this involves opening two tables and doing index lookups. Since this is such a common pattern 50% of all our hibernate created queries, it makes sense to try filing a bug for it. More generally this optimization can be for any operator against any key MySQL cannot optimize it because it believes there could be rows in b with a_ids not present in a. But since we enforce this in Hibernate (not as a foreign key) it makes sense for hibernate to be smart her. |