Commit 97419304 authored by Galina Shalygina's avatar Galina Shalygina

MDEV-18636 The test case for bug mdev-16765 crashes the server

in the tree bb-10.4-mdev7486

The crash was caused because of the similar problem as in mdev-16765:
Item_cond::excl_dep_on_group_fields_for_having_pushdown() was missing.
parent d25af331
......@@ -10040,6 +10040,202 @@ DROP TABLE t1,t2,t3;
#
CREATE TABLE t1(a INT, b INT);
INSERT INTO t1 VALUES (1,2), (3,4), (2,3);
SELECT *
FROM
(
SELECT CASE WHEN ((tab2.max_a=1) OR (tab2.max_a=2))
THEN 1 ELSE 0 END AS max_a,b
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
max_a b
1 2
1 3
EXPLAIN FORMAT=JSON SELECT *
FROM
(
SELECT CASE WHEN ((tab2.max_a=1) OR (tab2.max_a=2))
THEN 1 ELSE 0 END AS max_a,b
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "<derived3>",
"access_type": "ALL",
"rows": 3,
"filtered": 100,
"attached_condition": "case when (tab2.max_a = 1 or tab2.max_a = 2) then 1 else 0 end = 1",
"materialized": {
"query_block": {
"select_id": 3,
"having_condition": "case when (max_a = 1 or max_a = 2) then 1 else 0 end = 1",
"filesort": {
"sort_key": "t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 3,
"filtered": 100
}
}
}
}
}
}
}
}
SELECT *
FROM
(
SELECT CASE WHEN ((tab2.max_a=1) OR ((tab2.max_a>2) AND (tab2.max_a<4)))
THEN 1 ELSE 0 END AS max_a,b
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
max_a b
1 2
1 4
EXPLAIN FORMAT=JSON SELECT *
FROM
(
SELECT CASE WHEN ((tab2.max_a=1) OR ((tab2.max_a>2) AND (tab2.max_a<4)))
THEN 1 ELSE 0 END AS max_a,b
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "<derived3>",
"access_type": "ALL",
"rows": 3,
"filtered": 100,
"attached_condition": "case when (tab2.max_a = 1 or tab2.max_a > 2 and tab2.max_a < 4) then 1 else 0 end = 1",
"materialized": {
"query_block": {
"select_id": 3,
"having_condition": "case when (max_a = 1 or max_a > 2 and max_a < 4) then 1 else 0 end = 1",
"filesort": {
"sort_key": "t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 3,
"filtered": 100
}
}
}
}
}
}
}
}
SELECT *
FROM
(
SELECT CASE WHEN ((tab2.max_a>1) AND ((tab2.max_a=2) OR (tab2.max_a>2)))
THEN 1 ELSE 0 END AS max_a,b
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
max_a b
1 3
1 4
EXPLAIN FORMAT=JSON SELECT *
FROM
(
SELECT CASE WHEN ((tab2.max_a>1) AND ((tab2.max_a=2) OR (tab2.max_a>2)))
THEN 1 ELSE 0 END AS max_a,b
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "<derived3>",
"access_type": "ALL",
"rows": 3,
"filtered": 100,
"attached_condition": "case when (tab2.max_a > 1 and (tab2.max_a = 2 or tab2.max_a > 2)) then 1 else 0 end = 1",
"materialized": {
"query_block": {
"select_id": 3,
"having_condition": "case when (max_a > 1 and (max_a = 2 or max_a > 2)) then 1 else 0 end = 1",
"filesort": {
"sort_key": "t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 3,
"filtered": 100
}
}
}
}
}
}
}
}
SELECT *
FROM
(
SELECT CASE WHEN ((tab2.b=2) OR (tab2.b=4))
THEN 1 ELSE 0 END AS max_a,b
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
max_a b
1 2
1 4
EXPLAIN FORMAT=JSON SELECT *
FROM
(
SELECT CASE WHEN ((tab2.b=2) OR (tab2.b=4))
THEN 1 ELSE 0 END AS max_a,b
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "<derived3>",
"access_type": "ALL",
"rows": 3,
"filtered": 100,
"attached_condition": "case when (tab2.b = 2 or tab2.b = 4) then 1 else 0 end = 1",
"materialized": {
"query_block": {
"select_id": 3,
"filesort": {
"sort_key": "t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 3,
"filtered": 100,
"attached_condition": "case when (t1.b = 2 or t1.b = 4) then 1 else 0 end = 1"
}
}
}
}
}
}
}
}
DROP TABLE t1;
#
# MDEV-16803: pushdown condition with IN predicate in the derived table
......
......@@ -1981,8 +1981,8 @@ FROM
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
# EVAL $query;
# EVAL EXPLAIN FORMAT=JSON $query;
EVAL $query;
EVAL EXPLAIN FORMAT=JSON $query;
LET $query=
SELECT *
......@@ -1993,8 +1993,8 @@ FROM
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
# EVAL $query;
# EVAL EXPLAIN FORMAT=JSON $query;
EVAL $query;
EVAL EXPLAIN FORMAT=JSON $query;
LET $query=
SELECT *
......@@ -2005,8 +2005,8 @@ FROM
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
# EVAL $query;
# EVAL EXPLAIN FORMAT=JSON $query;
EVAL $query;
EVAL EXPLAIN FORMAT=JSON $query;
LET $query=
SELECT *
......@@ -2017,8 +2017,8 @@ FROM
FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
) AS tab1
WHERE (tab1.max_a=1);
# EVAL $query;
# EVAL EXPLAIN FORMAT=JSON $query;
EVAL $query;
EVAL EXPLAIN FORMAT=JSON $query;
DROP TABLE t1;
......
......@@ -5222,6 +5222,22 @@ bool Item_cond::excl_dep_on_grouping_fields(st_select_lex *sel)
}
bool
Item_cond::excl_dep_on_group_fields_for_having_pushdown(st_select_lex *sel)
{
if (has_rand_bit())
return false;
List_iterator_fast<Item> li(list);
Item *item;
while ((item= li++))
{
if (!item->excl_dep_on_group_fields_for_having_pushdown(sel))
return false;
}
return true;
}
void Item_cond_and::mark_as_condition_AND_part(TABLE_LIST *embedding)
{
List_iterator<Item> li(list);
......
......@@ -3011,6 +3011,7 @@ class Item_cond :public Item_bool_func
bool eval_not_null_tables(void *opt_arg);
Item *build_clone(THD *thd);
bool excl_dep_on_grouping_fields(st_select_lex *sel);
bool excl_dep_on_group_fields_for_having_pushdown(st_select_lex *sel);
};
template <template<class> class LI, class T> class Item_equal_iterator;
......
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