From 6b4727dcb9d3451cbb5c3457e0c07c81f1c503f0 Mon Sep 17 00:00:00 2001 From: Sergey Petrunia Date: Mon, 15 Jun 2009 00:59:24 +0400 Subject: [PATCH] MWL#17: Table elimination - Fix print_join() to work both for EXPLAIN EXTENDED (after table elimination) and for CREATE VIEW (after join->prepare() but without any optimization). mysql-test/r/union.result: MWL#17: Table elimination - Adjust test results --- mysql-test/r/union.result | 2 +- sql/sql_select.cc | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index da89c7ce386..7111bd41748 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -522,7 +522,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 UNION t2 const PRIMARY PRIMARY 4 const 1 100.00 NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 (select '1' AS `a`,'1' AS `b` from `test`.`t1` where ('1' = 1)) union (select '1' AS `a`,'10' AS `b` from `test`.`t2` where ('1' = 1)) +Note 1003 (select '1' AS `a`,'1' AS `b` from `test`.`t1` where 1) union (select '1' AS `a`,'10' AS `b` from `test`.`t2` where 1) (select * from t1 where a=5) union (select * from t2 where a=1); a b 1 10 diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 56fb9ac47ba..e8186a7da36 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -16937,18 +16937,28 @@ static void print_join(THD *thd, *t= ti++; DBUG_ASSERT(tables->elements >= 1); - //pserey:TODO check! + /* + Assert that the first table in the list isn't eliminated (if it was we + would have skipped the entire join nest) + */ + DBUG_ASSERT(!eliminated_tables || + !((*table)->table && ((*table)->table->map & eliminated_tables) || + (*table)->nested_join && !((*table)->nested_join->used_tables & + ~eliminated_tables))); (*table)->print(thd, eliminated_tables, str, query_type); TABLE_LIST **end= table + tables->elements; for (TABLE_LIST **tbl= table + 1; tbl < end; tbl++) { TABLE_LIST *curr= *tbl; - // psergey-todo-todo: - // base table: check - if (curr->table && (curr->table->map & eliminated_tables) || - curr->nested_join && !(curr->nested_join->used_tables & - ~eliminated_tables)) + /* + The (*) check guards againist the case of printing the query for + CREATE VIEW. There we'll have nested_join->used_tables==0. + */ + if (eliminated_tables && // (*) + (curr->table && (curr->table->map & eliminated_tables) || + curr->nested_join && !(curr->nested_join->used_tables & + ~eliminated_tables))) { continue; }