Commit 6c45d903 authored by unknown's avatar unknown

Fix LP BUG#718578

This bug extends the fix for LP BUG#715027 to cover one
more case of an Item being transformed, and its property
Item::with_subselect not being updated because
quick_fix_fields doesn't recalculate any properties.
parent 1be11803
...@@ -3969,3 +3969,19 @@ WHERE t1.f1 AND alias2.f10 ...@@ -3969,3 +3969,19 @@ WHERE t1.f1 AND alias2.f10
ORDER BY field1 ; ORDER BY field1 ;
field1 field1
drop table t1,t2; drop table t1,t2;
#
# LP BUG#718578 Yet another Assertion `!table ||
# (!table->read_set || bitmap_is_set(table->read_set, field_index))'
CREATE TABLE t1 ( f1 int(11), f2 int(11), f3 int(11)) ;
INSERT IGNORE INTO t1 VALUES (28,5,6),(29,NULL,4);
CREATE TABLE t2 ( f10 varchar(1) );
INSERT IGNORE INTO t2 VALUES (NULL);
SELECT f1 AS field1
FROM ( SELECT * FROM t1 ) AS alias1
WHERE (SELECT t1.f1
FROM t2 JOIN t1 ON t1.f2
WHERE alias1.f3 AND t1.f3) AND f2
ORDER BY field1;
field1
28
drop table t1,t2;
...@@ -418,3 +418,22 @@ WHERE ( ...@@ -418,3 +418,22 @@ WHERE (
ORDER BY field1 ; ORDER BY field1 ;
drop table t1,t2; drop table t1,t2;
--echo #
--echo # LP BUG#718578 Yet another Assertion `!table ||
--echo # (!table->read_set || bitmap_is_set(table->read_set, field_index))'
CREATE TABLE t1 ( f1 int(11), f2 int(11), f3 int(11)) ;
INSERT IGNORE INTO t1 VALUES (28,5,6),(29,NULL,4);
CREATE TABLE t2 ( f10 varchar(1) );
INSERT IGNORE INTO t2 VALUES (NULL);
SELECT f1 AS field1
FROM ( SELECT * FROM t1 ) AS alias1
WHERE (SELECT t1.f1
FROM t2 JOIN t1 ON t1.f2
WHERE alias1.f3 AND t1.f3) AND f2
ORDER BY field1;
drop table t1,t2;
...@@ -175,12 +175,13 @@ static int join_ft_read_first(JOIN_TAB *tab); ...@@ -175,12 +175,13 @@ static int join_ft_read_first(JOIN_TAB *tab);
static int join_ft_read_next(READ_RECORD *info); static int join_ft_read_next(READ_RECORD *info);
int join_read_always_key_or_null(JOIN_TAB *tab); int join_read_always_key_or_null(JOIN_TAB *tab);
int join_read_next_same_or_null(READ_RECORD *info); int join_read_next_same_or_null(READ_RECORD *info);
static COND *make_cond_for_table(Item *cond,table_map table, static COND *make_cond_for_table(THD *thd, Item *cond,table_map table,
table_map used_table, table_map used_table,
uint join_tab_idx_arg, uint join_tab_idx_arg,
bool exclude_expensive_cond, bool exclude_expensive_cond,
bool retain_ref_cond); bool retain_ref_cond);
static COND *make_cond_for_table_from_pred(Item *root_cond, Item *cond, static COND *make_cond_for_table_from_pred(THD *thd, Item *root_cond,
Item *cond,
table_map tables, table_map tables,
table_map used_table, table_map used_table,
uint join_tab_idx_arg, uint join_tab_idx_arg,
...@@ -928,7 +929,8 @@ JOIN::optimize() ...@@ -928,7 +929,8 @@ JOIN::optimize()
if (conds && !(thd->lex->describe & DESCRIBE_EXTENDED)) if (conds && !(thd->lex->describe & DESCRIBE_EXTENDED))
{ {
COND *table_independent_conds= COND *table_independent_conds=
make_cond_for_table(conds, PSEUDO_TABLE_BITS, 0, MAX_TABLES, FALSE, FALSE); make_cond_for_table(thd, conds, PSEUDO_TABLE_BITS, 0, MAX_TABLES,
FALSE, FALSE);
DBUG_EXECUTE("where", DBUG_EXECUTE("where",
print_where(table_independent_conds, print_where(table_independent_conds,
"where after opt_sum_query()", "where after opt_sum_query()",
...@@ -2310,7 +2312,7 @@ JOIN::exec() ...@@ -2310,7 +2312,7 @@ JOIN::exec()
table_map used_tables= (curr_join->const_table_map | table_map used_tables= (curr_join->const_table_map |
curr_table->table->map); curr_table->table->map);
Item* sort_table_cond= make_cond_for_table(curr_join->tmp_having, Item* sort_table_cond= make_cond_for_table(thd, curr_join->tmp_having,
used_tables, used_tables,
(table_map)0, MAX_TABLES, (table_map)0, MAX_TABLES,
FALSE, FALSE); FALSE, FALSE);
...@@ -2342,7 +2344,7 @@ JOIN::exec() ...@@ -2342,7 +2344,7 @@ JOIN::exec()
DBUG_EXECUTE("where",print_where(curr_table->select->cond, DBUG_EXECUTE("where",print_where(curr_table->select->cond,
"select and having", "select and having",
QT_ORDINARY);); QT_ORDINARY););
curr_join->tmp_having= make_cond_for_table(curr_join->tmp_having, curr_join->tmp_having= make_cond_for_table(thd, curr_join->tmp_having,
~ (table_map) 0, ~ (table_map) 0,
~used_tables, MAX_TABLES, ~used_tables, MAX_TABLES,
FALSE, FALSE); FALSE, FALSE);
...@@ -6061,7 +6063,8 @@ int JOIN_TAB::make_scan_filter() ...@@ -6061,7 +6063,8 @@ int JOIN_TAB::make_scan_filter()
*get_first_inner_table()->on_expr_ref : join->conds; *get_first_inner_table()->on_expr_ref : join->conds;
if (cond && if (cond &&
(tmp=make_cond_for_table(cond, join->const_table_map | table->map, (tmp= make_cond_for_table(join->thd, cond,
join->const_table_map | table->map,
table->map, MAX_TABLES, FALSE, TRUE))) table->map, MAX_TABLES, FALSE, TRUE)))
{ {
DBUG_EXECUTE("where",print_where(tmp,"cache", QT_ORDINARY);); DBUG_EXECUTE("where",print_where(tmp,"cache", QT_ORDINARY););
...@@ -6846,7 +6849,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -6846,7 +6849,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
*/ */
{ // Check const tables { // Check const tables
join->exec_const_cond= join->exec_const_cond=
make_cond_for_table(cond, make_cond_for_table(thd, cond,
join->const_table_map, join->const_table_map,
(table_map) 0, MAX_TABLES, FALSE, FALSE); (table_map) 0, MAX_TABLES, FALSE, FALSE);
/* Add conditions added by add_not_null_conds(). */ /* Add conditions added by add_not_null_conds(). */
...@@ -6862,7 +6865,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -6862,7 +6865,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (*tab->on_expr_ref) if (*tab->on_expr_ref)
{ {
JOIN_TAB *cond_tab= tab->first_inner; JOIN_TAB *cond_tab= tab->first_inner;
COND *tmp= make_cond_for_table(*tab->on_expr_ref, COND *tmp= make_cond_for_table(thd, *tab->on_expr_ref,
join->const_table_map, join->const_table_map,
(table_map) 0, MAX_TABLES, (table_map) 0, MAX_TABLES,
FALSE, FALSE); FALSE, FALSE);
...@@ -6957,7 +6960,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -6957,7 +6960,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
tmp= NULL; tmp= NULL;
if (cond) if (cond)
tmp= make_cond_for_table(cond, used_tables, current_map, i, FALSE, FALSE); tmp= make_cond_for_table(thd, cond, used_tables, current_map, i,
FALSE, FALSE);
/* Add conditions added by add_not_null_conds(). */ /* Add conditions added by add_not_null_conds(). */
if (tab->select_cond) if (tab->select_cond)
add_cond_and_fix(thd, &tmp, tab->select_cond); add_cond_and_fix(thd, &tmp, tab->select_cond);
...@@ -7018,8 +7022,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -7018,8 +7022,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (thd->variables.engine_condition_pushdown && !first_inner_tab) if (thd->variables.engine_condition_pushdown && !first_inner_tab)
{ {
COND *push_cond= COND *push_cond=
make_cond_for_table(tmp, current_map, current_map, MAX_TABLES, make_cond_for_table(thd, tmp, current_map, current_map,
FALSE, FALSE); MAX_TABLES, FALSE, FALSE);
if (push_cond) if (push_cond)
{ {
/* Push condition to handler */ /* Push condition to handler */
...@@ -7168,7 +7172,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -7168,7 +7172,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (*join_tab->on_expr_ref) if (*join_tab->on_expr_ref)
{ {
JOIN_TAB *cond_tab= join_tab->first_inner; JOIN_TAB *cond_tab= join_tab->first_inner;
COND *tmp= make_cond_for_table(*join_tab->on_expr_ref, COND *tmp= make_cond_for_table(thd, *join_tab->on_expr_ref,
join->const_table_map, join->const_table_map,
(table_map) 0, MAX_TABLES, FALSE, FALSE); (table_map) 0, MAX_TABLES, FALSE, FALSE);
if (!tmp) if (!tmp)
...@@ -7205,7 +7209,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -7205,7 +7209,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
{ {
current_map= tab->table->map; current_map= tab->table->map;
used_tables2|= current_map; used_tables2|= current_map;
COND *tmp_cond= make_cond_for_table(on_expr, used_tables2, COND *tmp_cond= make_cond_for_table(thd, on_expr, used_tables2,
current_map, (tab - first_tab), current_map, (tab - first_tab),
FALSE, FALSE); FALSE, FALSE);
if (tab == first_inner_tab && tab->on_precond) if (tab == first_inner_tab && tab->on_precond)
...@@ -15034,19 +15038,20 @@ bool test_if_ref(Item *root_cond, Item_field *left_item,Item *right_item) ...@@ -15034,19 +15038,20 @@ bool test_if_ref(Item *root_cond, Item_field *left_item,Item *right_item)
*/ */
static Item * static Item *
make_cond_for_table(Item *cond, table_map tables, table_map used_table, make_cond_for_table(THD *thd, Item *cond, table_map tables,
table_map used_table,
uint join_tab_idx_arg, uint join_tab_idx_arg,
bool exclude_expensive_cond __attribute__((unused)), bool exclude_expensive_cond __attribute__((unused)),
bool retain_ref_cond) bool retain_ref_cond)
{ {
return make_cond_for_table_from_pred(cond, cond, tables, used_table, return make_cond_for_table_from_pred(thd, cond, cond, tables, used_table,
join_tab_idx_arg, join_tab_idx_arg,
exclude_expensive_cond, exclude_expensive_cond,
retain_ref_cond); retain_ref_cond);
} }
static Item * static Item *
make_cond_for_table_from_pred(Item *root_cond, Item *cond, make_cond_for_table_from_pred(THD *thd, Item *root_cond, Item *cond,
table_map tables, table_map used_table, table_map tables, table_map used_table,
uint join_tab_idx_arg, uint join_tab_idx_arg,
bool exclude_expensive_cond __attribute__((unused)), bool exclude_expensive_cond __attribute__((unused)),
...@@ -15067,7 +15072,7 @@ make_cond_for_table_from_pred(Item *root_cond, Item *cond, ...@@ -15067,7 +15072,7 @@ make_cond_for_table_from_pred(Item *root_cond, Item *cond,
Item *item; Item *item;
while ((item=li++)) while ((item=li++))
{ {
Item *fix=make_cond_for_table_from_pred(root_cond, item, Item *fix=make_cond_for_table_from_pred(thd, root_cond, item,
tables, used_table, tables, used_table,
join_tab_idx_arg, join_tab_idx_arg,
exclude_expensive_cond, exclude_expensive_cond,
...@@ -15082,10 +15087,11 @@ make_cond_for_table_from_pred(Item *root_cond, Item *cond, ...@@ -15082,10 +15087,11 @@ make_cond_for_table_from_pred(Item *root_cond, Item *cond,
return new_cond->argument_list()->head(); return new_cond->argument_list()->head();
default: default:
/* /*
Item_cond_and do not need fix_fields for execution, its parameters Call fix_fields to propagate all properties of the children to
are fixed or do not need fix_fields, too the new parent Item. This should not be expensive because all
children of Item_cond_and should be fixed by now.
*/ */
new_cond->quick_fix_field(); new_cond->fix_fields(thd, 0);
new_cond->used_tables_cache= new_cond->used_tables_cache=
((Item_cond_and*) cond)->used_tables_cache & ((Item_cond_and*) cond)->used_tables_cache &
tables; tables;
...@@ -15101,7 +15107,7 @@ make_cond_for_table_from_pred(Item *root_cond, Item *cond, ...@@ -15101,7 +15107,7 @@ make_cond_for_table_from_pred(Item *root_cond, Item *cond,
Item *item; Item *item;
while ((item=li++)) while ((item=li++))
{ {
Item *fix=make_cond_for_table_from_pred(root_cond, item, Item *fix=make_cond_for_table_from_pred(thd, root_cond, item,
tables, 0L, tables, 0L,
join_tab_idx_arg, join_tab_idx_arg,
exclude_expensive_cond, exclude_expensive_cond,
...@@ -15111,10 +15117,11 @@ make_cond_for_table_from_pred(Item *root_cond, Item *cond, ...@@ -15111,10 +15117,11 @@ make_cond_for_table_from_pred(Item *root_cond, Item *cond,
new_cond->argument_list()->push_back(fix); new_cond->argument_list()->push_back(fix);
} }
/* /*
Item_cond_and do not need fix_fields for execution, its parameters Call fix_fields to propagate all properties of the children to
are fixed or do not need fix_fields, too the new parent Item. This should not be expensive because all
children of Item_cond_and should be fixed by now.
*/ */
new_cond->quick_fix_field(); new_cond->fix_fields(thd, 0);
new_cond->used_tables_cache= ((Item_cond_or*) cond)->used_tables_cache; new_cond->used_tables_cache= ((Item_cond_or*) cond)->used_tables_cache;
new_cond->top_level_item(); new_cond->top_level_item();
return new_cond; return new_cond;
...@@ -16333,8 +16340,9 @@ static bool fix_having(JOIN *join, Item **having) ...@@ -16333,8 +16340,9 @@ static bool fix_having(JOIN *join, Item **having)
table_map used_tables= join->const_table_map | table->table->map; table_map used_tables= join->const_table_map | table->table->map;
DBUG_EXECUTE("where",print_where(*having,"having", QT_ORDINARY);); DBUG_EXECUTE("where",print_where(*having,"having", QT_ORDINARY););
Item* sort_table_cond=make_cond_for_table(*having, used_tables, used_tables, Item* sort_table_cond= make_cond_for_table(join->thd, *having, used_tables,
MAX_TABLES, FALSE, FALSE); used_tables, MAX_TABLES,
FALSE, FALSE);
if (sort_table_cond) if (sort_table_cond)
{ {
if (!table->select) if (!table->select)
...@@ -16352,7 +16360,8 @@ static bool fix_having(JOIN *join, Item **having) ...@@ -16352,7 +16360,8 @@ static bool fix_having(JOIN *join, Item **having)
DBUG_EXECUTE("where",print_where(table->select_cond, DBUG_EXECUTE("where",print_where(table->select_cond,
"select and having", "select and having",
QT_ORDINARY);); QT_ORDINARY););
*having= make_cond_for_table(*having,~ (table_map) 0,~used_tables, *having= make_cond_for_table(join->thd, *having,
~ (table_map) 0,~used_tables,
MAX_TABLES, FALSE, FALSE); MAX_TABLES, FALSE, FALSE);
DBUG_EXECUTE("where", DBUG_EXECUTE("where",
print_where(*having,"having after make_cond", QT_ORDINARY);); print_where(*having,"having after make_cond", QT_ORDINARY););
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment