Commit 2aeb4170 authored by unknown's avatar unknown

Fix LP BUG#715027

Analysis:
Before calling:
  write_record= (select->skip_record(thd) > 0);
the function find_all_keys needs to restore the original read/write
sets of the table that is sorted if the condition select->cond
contains a subquery.

This didn't happen in this test case because the flag "with_subselect"
was not set properly for select->cond.

The reason for the flag not being set properly, was that this condition
was rewritten by add_cond_and_fix() inside make_join_select() by:

      /* Add conditions added by add_not_null_conds(). */
      if (tab->select_cond)
        add_cond_and_fix(thd, &tmp, tab->select_cond);

However, the function add_cond_and_fix() called the shortcut method
Item::quick_fix_field() that didn't update the "with_subselect"
property.

Solution:
Call the complete Item::fix_fields() to update all Item properties,
including "with_subselect".
parent cd349466
......@@ -3936,3 +3936,36 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
3 SUBQUERY t1 index NULL f3 5 NULL 2 Using index
2 DERIVED t2 ALL NULL NULL NULL NULL 2
drop table t1,t2;
#
# LP BUG#715027 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed
#
CREATE TABLE t1 ( f1 int(11), PRIMARY KEY (f1)) ;
INSERT INTO t1 VALUES (28),(29);
CREATE TABLE t2 ( f2 int(11), f3 int(11), f10 varchar(1)) ;
INSERT INTO t2 VALUES (NULL,6,'f'),(4,2,'d');
EXPLAIN
SELECT alias2.f2 AS field1
FROM t1 AS alias1 JOIN ( SELECT * FROM t2 ) AS alias2 ON alias2.f3 = alias1.f1
WHERE (
SELECT t2.f2
FROM t2 JOIN t1 ON t1.f1
WHERE t1.f1 AND alias2.f10
)
ORDER BY field1 ;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 Using where; Using filesort
1 PRIMARY alias1 eq_ref PRIMARY PRIMARY 4 alias2.f3 1 Using index
3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2
3 DEPENDENT SUBQUERY t1 index NULL PRIMARY 4 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
2 DERIVED t2 ALL NULL NULL NULL NULL 2
SELECT alias2.f2 AS field1
FROM t1 AS alias1 JOIN ( SELECT * FROM t2 ) AS alias2 ON alias2.f3 = alias1.f1
WHERE (
SELECT t2.f2
FROM t2 JOIN t1 ON t1.f1
WHERE t1.f1 AND alias2.f10
)
ORDER BY field1 ;
field1
drop table t1,t2;
......@@ -385,3 +385,36 @@ insert into t2 values (1),(2);
EXPLAIN
SELECT * FROM (SELECT * FROM t2) AS a2
WHERE (SELECT distinct SUM(distinct f3 ) FROM t1);
drop table t1,t2;
--echo #
--echo # LP BUG#715027 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed
--echo #
CREATE TABLE t1 ( f1 int(11), PRIMARY KEY (f1)) ;
INSERT INTO t1 VALUES (28),(29);
CREATE TABLE t2 ( f2 int(11), f3 int(11), f10 varchar(1)) ;
INSERT INTO t2 VALUES (NULL,6,'f'),(4,2,'d');
EXPLAIN
SELECT alias2.f2 AS field1
FROM t1 AS alias1 JOIN ( SELECT * FROM t2 ) AS alias2 ON alias2.f3 = alias1.f1
WHERE (
SELECT t2.f2
FROM t2 JOIN t1 ON t1.f1
WHERE t1.f1 AND alias2.f10
)
ORDER BY field1 ;
SELECT alias2.f2 AS field1
FROM t1 AS alias1 JOIN ( SELECT * FROM t2 ) AS alias2 ON alias2.f3 = alias1.f1
WHERE (
SELECT t2.f2
FROM t2 JOIN t1 ON t1.f1
WHERE t1.f1 AND alias2.f10
)
ORDER BY field1 ;
drop table t1,t2;
......@@ -6553,7 +6553,7 @@ JOIN::make_simple_join(JOIN *parent, TABLE *temp_table)
}
inline void add_cond_and_fix(Item **e1, Item *e2)
inline void add_cond_and_fix(THD *thd, Item **e1, Item *e2)
{
if (*e1)
{
......@@ -6563,7 +6563,7 @@ inline void add_cond_and_fix(Item **e1, Item *e2)
if ((res= new Item_cond_and(*e1, e2)))
{
*e1= res;
res->quick_fix_field();
res->fix_fields(thd, 0);
res->update_used_tables();
}
}
......@@ -6665,11 +6665,11 @@ static void add_not_null_conds(JOIN *join)
if (!tab->first_inner)
{
COND *new_cond= referred_tab->select_cond;
add_cond_and_fix(&new_cond, notnull);
add_cond_and_fix(join->thd, &new_cond, notnull);
referred_tab->set_select_cond(new_cond, __LINE__);
}
else
add_cond_and_fix(tab->first_inner->on_expr_ref, notnull);
add_cond_and_fix(join->thd, tab->first_inner->on_expr_ref, notnull);
}
}
}
......@@ -6851,7 +6851,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
(table_map) 0, MAX_TABLES, FALSE, FALSE);
/* Add conditions added by add_not_null_conds(). */
for (uint i= 0 ; i < join->const_tables ; i++)
add_cond_and_fix(&join->exec_const_cond, join->join_tab[i].select_cond);
add_cond_and_fix(thd, &join->exec_const_cond,
join->join_tab[i].select_cond);
DBUG_EXECUTE("where",print_where(join->exec_const_cond,"constants",
QT_ORDINARY););
......@@ -6959,7 +6960,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
tmp= make_cond_for_table(cond, used_tables, current_map, i, FALSE, FALSE);
/* Add conditions added by add_not_null_conds(). */
if (tab->select_cond)
add_cond_and_fix(&tmp, tab->select_cond);
add_cond_and_fix(thd, &tmp, tab->select_cond);
if (cond && !tmp && tab->quick)
{ // Outer join
if (tab->type != JT_ALL)
......@@ -7208,7 +7209,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
current_map, (tab - first_tab),
FALSE, FALSE);
if (tab == first_inner_tab && tab->on_precond)
add_cond_and_fix(&tmp_cond, tab->on_precond);
add_cond_and_fix(thd, &tmp_cond, tab->on_precond);
if (tmp_cond)
{
JOIN_TAB *cond_tab= tab < first_inner_tab ? first_inner_tab : tab;
......
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