Igor, On Thu, Jan 28, 2010 at 06:25:40PM +0300, Sergey Petrunya wrote:
At file:///home/psergey/dev/maria-5.3-subqueries-r3/
------------------------------------------------------------ revno: 2750 revision-id: psergey@askmonty.org-20100128152533-q0dicbcuu9fvol5p parent: psergey@askmonty.org-20100128134833-9000udjp5wa3tsff committer: Sergey Petrunya <psergey@askmonty.org> branch nick: maria-5.3-subqueries-r3 timestamp: Thu 2010-01-28 18:25:33 +0300 message: BUG#31480: Incorrect result for nested subquery when executed via semi join - Make Item_subselect store its "depth", distance to furthest_correlated_ancestor, and bitmaps of tables that it depends on in ancestor tables. This allows to have Item_subselect to update its attributes when it has been pulled out from a select to its parent.
Ok, I have ported the fix and it worked, but now I realize that the fix in this form probably won't be useful for FROM flattening. The problem is that current fix depends on the fact that the process of pullout is done as follows: - all tables in the parent select remain there and keep their table_map bits. - tables from the child select are added into the parent select and assigned the free bits. This means that 1. subquery predicates that were originally in the parent select do not depend on tables from the child select and hence do not their used_tables() to be updated. 2. subquery predicates that were in the child select do need their used_tables() to be updated but the new used_tables() can be calculated from the old ones. For FROM subqueries, this approach won't work. Consider an example: SELECT * FROM ot1, (SELECT ... FROM it1, it2) tbl WHERE oe IN (SELECT .. WHERE .. tbl.col1 ...) OR ... # --(subq1) Here, before the flattening subquery predicate will have subq1->used_tables() = {tbl} but after the flattening it will become subq1->used_tables() = <whatever of (it1, it2) are used in tbl.col1> . This means that I'll have to modify the code to do this. I've already started to do that. BR Sergey -- Sergey Petrunia, Software Developer Monty Program AB, http://askmonty.org Blog: http://s.petrunia.net/blog