mirror of
https://github.com/MariaDB/server.git
synced 2025-01-28 01:34:17 +01:00
Fixed the bug mdev-12564.
Here's what started happening after the patch that fixed the bug mdev-10454 with query reported for the bug SELECT * FROM t t1 right JOIN t t2 ON (t2.pk = t1.pk) WHERE (t2.i, t2.pk) NOT IN ( SELECT t3.i, t3.i FROM t t3, t t4 ) AND t1.c = 'foo'; The patch added an implementation of propagate_equal_fields() for the class Item_row and thus opened the possibility of equal fields substitutions. At the prepare stage after setup_conds() called for WHERE condition had completed the flag of maybe_null of the Item_row object created for (t2.i, t2.pk) was set to false, because the maybe_null flags of both elements were set to false. However the flag of maybe_null for t1.pk from the ON condition were set to true, because t1 was an inner table of an outer join. At the optimization stage the outer join was converted to inner join, but the maybe_null flags were not corrected and remained the same. So after the substitution t2.pk/t1.pk. the maybe_null flag for the row remained false while the maybe_flag for the second element of the row was true. As a result, when the in-to_exists transformation was performed for the NOT IN predicate the guards variables were not created for the elements of the row, but a guard object for the second element was created. The object were not valid because it referred to NULL as a guard variable. This ultimately caused a crash when the expression with the guard was evaluated at the execution stage. The patch made sure that the guard objects are not created without guard variables. Yet it does not resolve the problem of inconsistent maybe_null flags. and it might be that the problem will pop op in other pieces of code. The resolution of this problem is not easy, but the problem should be resolved in future versions.
This commit is contained in:
parent
44b1fb3614
commit
0906dc49e8
8 changed files with 108 additions and 4 deletions
|
@ -7204,3 +7204,17 @@ f1 f2 f3
|
|||
DROP TABLE t1, t2;
|
||||
SET NAMES default;
|
||||
End of 10.1 tests
|
||||
#
|
||||
# MDEV-12564: IN TO EXISTS transformation for rows after
|
||||
# conversion an outer join to inner join
|
||||
#
|
||||
CREATE TABLE t (
|
||||
pk int PRIMARY KEY, i int NOT NULL, c varchar(8), KEY(c)
|
||||
) ENGINE=MyISAM;
|
||||
INSERT INTO t VALUES (1,10,'foo'),(2,20,'bar');
|
||||
SELECT * FROM t t1 RIGHT JOIN t t2 ON (t2.pk = t1.pk)
|
||||
WHERE (t2.i, t2.pk) NOT IN ( SELECT t3.i, t3.i FROM t t3, t t4 ) AND t1.c = 'foo';
|
||||
pk i c pk i c
|
||||
1 10 foo 1 10 foo
|
||||
DROP TABLE t;
|
||||
End of 10.2 tests
|
||||
|
|
|
@ -7204,6 +7204,20 @@ f1 f2 f3
|
|||
DROP TABLE t1, t2;
|
||||
SET NAMES default;
|
||||
End of 10.1 tests
|
||||
#
|
||||
# MDEV-12564: IN TO EXISTS transformation for rows after
|
||||
# conversion an outer join to inner join
|
||||
#
|
||||
CREATE TABLE t (
|
||||
pk int PRIMARY KEY, i int NOT NULL, c varchar(8), KEY(c)
|
||||
) ENGINE=MyISAM;
|
||||
INSERT INTO t VALUES (1,10,'foo'),(2,20,'bar');
|
||||
SELECT * FROM t t1 RIGHT JOIN t t2 ON (t2.pk = t1.pk)
|
||||
WHERE (t2.i, t2.pk) NOT IN ( SELECT t3.i, t3.i FROM t t3, t t4 ) AND t1.c = 'foo';
|
||||
pk i c pk i c
|
||||
1 10 foo 1 10 foo
|
||||
DROP TABLE t;
|
||||
End of 10.2 tests
|
||||
set optimizer_switch=default;
|
||||
select @@optimizer_switch like '%exists_to_in=off%';
|
||||
@@optimizer_switch like '%exists_to_in=off%'
|
||||
|
|
|
@ -7197,6 +7197,20 @@ f1 f2 f3
|
|||
DROP TABLE t1, t2;
|
||||
SET NAMES default;
|
||||
End of 10.1 tests
|
||||
#
|
||||
# MDEV-12564: IN TO EXISTS transformation for rows after
|
||||
# conversion an outer join to inner join
|
||||
#
|
||||
CREATE TABLE t (
|
||||
pk int PRIMARY KEY, i int NOT NULL, c varchar(8), KEY(c)
|
||||
) ENGINE=MyISAM;
|
||||
INSERT INTO t VALUES (1,10,'foo'),(2,20,'bar');
|
||||
SELECT * FROM t t1 RIGHT JOIN t t2 ON (t2.pk = t1.pk)
|
||||
WHERE (t2.i, t2.pk) NOT IN ( SELECT t3.i, t3.i FROM t t3, t t4 ) AND t1.c = 'foo';
|
||||
pk i c pk i c
|
||||
1 10 foo 1 10 foo
|
||||
DROP TABLE t;
|
||||
End of 10.2 tests
|
||||
set optimizer_switch=default;
|
||||
select @@optimizer_switch like '%materialization=on%';
|
||||
@@optimizer_switch like '%materialization=on%'
|
||||
|
|
|
@ -7195,4 +7195,18 @@ f1 f2 f3
|
|||
DROP TABLE t1, t2;
|
||||
SET NAMES default;
|
||||
End of 10.1 tests
|
||||
#
|
||||
# MDEV-12564: IN TO EXISTS transformation for rows after
|
||||
# conversion an outer join to inner join
|
||||
#
|
||||
CREATE TABLE t (
|
||||
pk int PRIMARY KEY, i int NOT NULL, c varchar(8), KEY(c)
|
||||
) ENGINE=MyISAM;
|
||||
INSERT INTO t VALUES (1,10,'foo'),(2,20,'bar');
|
||||
SELECT * FROM t t1 RIGHT JOIN t t2 ON (t2.pk = t1.pk)
|
||||
WHERE (t2.i, t2.pk) NOT IN ( SELECT t3.i, t3.i FROM t t3, t t4 ) AND t1.c = 'foo';
|
||||
pk i c pk i c
|
||||
1 10 foo 1 10 foo
|
||||
DROP TABLE t;
|
||||
End of 10.2 tests
|
||||
set @optimizer_switch_for_subselect_test=null;
|
||||
|
|
|
@ -7210,6 +7210,20 @@ f1 f2 f3
|
|||
DROP TABLE t1, t2;
|
||||
SET NAMES default;
|
||||
End of 10.1 tests
|
||||
#
|
||||
# MDEV-12564: IN TO EXISTS transformation for rows after
|
||||
# conversion an outer join to inner join
|
||||
#
|
||||
CREATE TABLE t (
|
||||
pk int PRIMARY KEY, i int NOT NULL, c varchar(8), KEY(c)
|
||||
) ENGINE=MyISAM;
|
||||
INSERT INTO t VALUES (1,10,'foo'),(2,20,'bar');
|
||||
SELECT * FROM t t1 RIGHT JOIN t t2 ON (t2.pk = t1.pk)
|
||||
WHERE (t2.i, t2.pk) NOT IN ( SELECT t3.i, t3.i FROM t t3, t t4 ) AND t1.c = 'foo';
|
||||
pk i c pk i c
|
||||
1 10 foo 1 10 foo
|
||||
DROP TABLE t;
|
||||
End of 10.2 tests
|
||||
set optimizer_switch=default;
|
||||
select @@optimizer_switch like '%subquery_cache=on%';
|
||||
@@optimizer_switch like '%subquery_cache=on%'
|
||||
|
|
|
@ -7195,5 +7195,19 @@ f1 f2 f3
|
|||
DROP TABLE t1, t2;
|
||||
SET NAMES default;
|
||||
End of 10.1 tests
|
||||
#
|
||||
# MDEV-12564: IN TO EXISTS transformation for rows after
|
||||
# conversion an outer join to inner join
|
||||
#
|
||||
CREATE TABLE t (
|
||||
pk int PRIMARY KEY, i int NOT NULL, c varchar(8), KEY(c)
|
||||
) ENGINE=MyISAM;
|
||||
INSERT INTO t VALUES (1,10,'foo'),(2,20,'bar');
|
||||
SELECT * FROM t t1 RIGHT JOIN t t2 ON (t2.pk = t1.pk)
|
||||
WHERE (t2.i, t2.pk) NOT IN ( SELECT t3.i, t3.i FROM t t3, t t4 ) AND t1.c = 'foo';
|
||||
pk i c pk i c
|
||||
1 10 foo 1 10 foo
|
||||
DROP TABLE t;
|
||||
End of 10.2 tests
|
||||
set @optimizer_switch_for_subselect_test=null;
|
||||
set @join_cache_level_for_subselect_test=NULL;
|
||||
|
|
|
@ -6056,3 +6056,20 @@ DROP TABLE t1, t2;
|
|||
SET NAMES default;
|
||||
|
||||
--echo End of 10.1 tests
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-12564: IN TO EXISTS transformation for rows after
|
||||
--echo # conversion an outer join to inner join
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t (
|
||||
pk int PRIMARY KEY, i int NOT NULL, c varchar(8), KEY(c)
|
||||
) ENGINE=MyISAM;
|
||||
INSERT INTO t VALUES (1,10,'foo'),(2,20,'bar');
|
||||
|
||||
SELECT * FROM t t1 RIGHT JOIN t t2 ON (t2.pk = t1.pk)
|
||||
WHERE (t2.i, t2.pk) NOT IN ( SELECT t3.i, t3.i FROM t t3, t t4 ) AND t1.c = 'foo';
|
||||
|
||||
DROP TABLE t;
|
||||
|
||||
--echo End of 10.2 tests
|
||||
|
|
|
@ -2388,7 +2388,8 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join,
|
|||
(char *)"<list ref>"));
|
||||
Item *col_item= new (thd->mem_root)
|
||||
Item_cond_or(thd, item_eq, item_isnull);
|
||||
if (!abort_on_null && left_expr->element_index(i)->maybe_null)
|
||||
if (!abort_on_null && left_expr->element_index(i)->maybe_null &&
|
||||
get_cond_guard(i))
|
||||
{
|
||||
disable_cond_guard_for_const_null_left_expr(i);
|
||||
if (!(col_item= new (thd->mem_root)
|
||||
|
@ -2406,7 +2407,8 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join,
|
|||
ref_pointer_array[i],
|
||||
(char *)"<no matter>",
|
||||
(char *)"<list ref>"));
|
||||
if (!abort_on_null && left_expr->element_index(i)->maybe_null)
|
||||
if (!abort_on_null && left_expr->element_index(i)->maybe_null &&
|
||||
get_cond_guard(i) )
|
||||
{
|
||||
disable_cond_guard_for_const_null_left_expr(i);
|
||||
if (!(item_nnull_test=
|
||||
|
@ -2467,7 +2469,7 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join,
|
|||
(char *)"<no matter>",
|
||||
(char *)"<list ref>"));
|
||||
item= new (thd->mem_root) Item_cond_or(thd, item, item_isnull);
|
||||
if (left_expr->element_index(i)->maybe_null)
|
||||
if (left_expr->element_index(i)->maybe_null && get_cond_guard(i))
|
||||
{
|
||||
disable_cond_guard_for_const_null_left_expr(i);
|
||||
if (!(item= new (thd->mem_root)
|
||||
|
@ -2479,7 +2481,8 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join,
|
|||
}
|
||||
*having_item= and_items(thd, *having_item, having_col_item);
|
||||
}
|
||||
if (!abort_on_null && left_expr->element_index(i)->maybe_null)
|
||||
if (!abort_on_null && left_expr->element_index(i)->maybe_null &&
|
||||
get_cond_guard(i))
|
||||
{
|
||||
if (!(item= new (thd->mem_root)
|
||||
Item_func_trig_cond(thd, item, get_cond_guard(i))))
|
||||
|
|
Loading…
Add table
Reference in a new issue