Commit c5ac1f95 authored by Igor Babaev's avatar Igor Babaev

Fixed mdev-14880: Assertion `inj_cond_list.elements' failed

in JOIN::inject_best_splitting_cond

The value of SplM_opt_info::last_plan should be set to NULL
before any search for a splitting plan for a splittable
materialized table.
parent 7349b9ab
...@@ -14788,3 +14788,68 @@ id select_type table type possible_keys key key_len ref rows filtered Extra ...@@ -14788,3 +14788,68 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings: Warnings:
Note 1003 with cte as (/* select#2 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where 0 group by `test`.`t1`.`pk`)/* select#1 */ select NULL AS `pk` from `cte` Note 1003 with cte as (/* select#2 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where 0 group by `test`.`t1`.`pk`)/* select#1 */ select NULL AS `pk` from `cte`
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-14880: assertion failure in optimizer when splitting is applied
#
CREATE TABLE t1 (pk1 INT PRIMARY KEY, f INT) ENGINE=Aria;
INSERT INTO t1 VALUES (1,0),(2,0);
CREATE TABLE t2 (pk2 INT PRIMARY KEY) ENGINE=Aria;
INSERT INTO t2 VALUES (1),(2),(3);
CREATE VIEW v2 AS SELECT pk2, COUNT(*) AS cnt FROM t2 GROUP BY pk2;
SELECT * FROM t1 INNER JOIN v2 ON pk1 = pk2 WHERE f <> 5;
pk1 f pk2 cnt
1 0 1 1
2 0 2 1
EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN v2 ON pk1 = pk2 WHERE f <> 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 2 100.00 Using where
1 PRIMARY <derived2> ref key0 key0 4 test.t1.pk1 2 100.00
2 LATERAL DERIVED t2 eq_ref PRIMARY PRIMARY 4 test.t1.pk1 1 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`f` AS `f`,`v2`.`pk2` AS `pk2`,`v2`.`cnt` AS `cnt` from `test`.`t1` join `test`.`v2` where `v2`.`pk2` = `test`.`t1`.`pk1` and `test`.`t1`.`f` <> 5
EXPLAIN FORMAT=JSON SELECT * FROM t1 INNER JOIN v2 ON pk1 = pk2 WHERE f <> 5;
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t1",
"access_type": "ALL",
"possible_keys": ["PRIMARY"],
"rows": 2,
"filtered": 100,
"attached_condition": "t1.f <> 5"
},
"table": {
"table_name": "<derived2>",
"access_type": "ref",
"possible_keys": ["key0"],
"key": "key0",
"key_length": "4",
"used_key_parts": ["pk2"],
"ref": ["test.t1.pk1"],
"rows": 2,
"filtered": 100,
"materialized": {
"query_block": {
"select_id": 2,
"outer_ref_condition": "t1.pk1 is not null",
"table": {
"table_name": "t2",
"access_type": "eq_ref",
"possible_keys": ["PRIMARY"],
"key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["pk2"],
"ref": ["test.t1.pk1"],
"rows": 1,
"filtered": 100,
"using_index": true
}
}
}
}
}
}
DROP VIEW v2;
DROP TABLE t1,t2;
...@@ -2535,3 +2535,25 @@ eval $q; ...@@ -2535,3 +2535,25 @@ eval $q;
eval EXPLAIN EXTENDED $q; eval EXPLAIN EXTENDED $q;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-14880: assertion failure in optimizer when splitting is applied
--echo #
CREATE TABLE t1 (pk1 INT PRIMARY KEY, f INT) ENGINE=Aria;
INSERT INTO t1 VALUES (1,0),(2,0);
CREATE TABLE t2 (pk2 INT PRIMARY KEY) ENGINE=Aria;
INSERT INTO t2 VALUES (1),(2),(3);
CREATE VIEW v2 AS SELECT pk2, COUNT(*) AS cnt FROM t2 GROUP BY pk2;
let $q=
SELECT * FROM t1 INNER JOIN v2 ON pk1 = pk2 WHERE f <> 5;
eval $q;
eval EXPLAIN EXTENDED $q;
eval EXPLAIN FORMAT=JSON $q;
DROP VIEW v2;
DROP TABLE t1,t2;
...@@ -922,6 +922,7 @@ SplM_plan_info * JOIN_TAB::choose_best_splitting(double record_count, ...@@ -922,6 +922,7 @@ SplM_plan_info * JOIN_TAB::choose_best_splitting(double record_count,
} }
while (keyuse_ext->table == table); while (keyuse_ext->table == table);
} }
spl_opt_info->last_plan= 0;
if (best_table) if (best_table)
{ {
/* /*
...@@ -963,7 +964,6 @@ SplM_plan_info * JOIN_TAB::choose_best_splitting(double record_count, ...@@ -963,7 +964,6 @@ SplM_plan_info * JOIN_TAB::choose_best_splitting(double record_count,
reset_validity_vars_for_keyuses(best_key_keyuse_ext_start, best_table, reset_validity_vars_for_keyuses(best_key_keyuse_ext_start, best_table,
best_key, remaining_tables, false); best_key, remaining_tables, false);
} }
spl_opt_info->last_plan= 0;
if (spl_plan) if (spl_plan)
{ {
if(record_count * spl_plan->cost < spl_opt_info->unsplit_cost) if(record_count * spl_plan->cost < spl_opt_info->unsplit_cost)
......
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