mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fixed LP bug #939009.
The result of materialization of the right part of an IN subquery predicate is placed into a temporary table. Each row of the materialized table is distinct. A unique key over all fields of the temporary table is defined and created. It allows to perform key look-ups into the table. The table created for a materialized subquery can be accessed by key as any other table. The function best_access-path search for the best access to join a table to a given partial join. With some where conditions this function considers a possibility of a ref_or_null access. If such access employs the unique key on the temporary table then when estimating the cost this access the function tries to use the array rec_per_key. Yet, such array is not built for this unique key. This causes a crash of the server. Rows returned by the subquery that contain nulls don't have to be placed into temporary table, as they cannot be match any row produced by the left part of the subquery predicate. So all fields of the temporary table can be defined as non-nullable. In this case any ref_or_null access to the temporary table does not make any sense and it does not make sense to estimate such an access. The fix makes sure that the temporary table for a materialized IN subquery is defined with columns that are all non-nullable. The also ensures that any row with nulls returned by the subquery is not placed into the temporary table.
This commit is contained in:
@ -802,7 +802,7 @@ INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii','iiii','ffff','ffff','ffff','f
|
||||
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
|
||||
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 13 func,func 1 100.00
|
||||
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 11 func,func 1 100.00
|
||||
2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Rowid-ordered scan
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`pk` > 0))
|
||||
@ -1053,8 +1053,8 @@ AND t1.val IN (SELECT t3.val FROM t3
|
||||
WHERE t3.val LIKE 'a%' OR t3.val LIKE 'e%');
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 5
|
||||
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 14 func 1
|
||||
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 14 func 1
|
||||
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 13 func 1
|
||||
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 13 func 1
|
||||
3 MATERIALIZED t3 ALL NULL NULL NULL NULL 5 Using where
|
||||
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 Using where
|
||||
SELECT *
|
||||
@ -1633,9 +1633,9 @@ select * from t1 A, t1 B
|
||||
where A.a = B.a and A.a in (select a from t2 C) and B.a in (select a from t2 D);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY A ALL NULL NULL NULL NULL 3
|
||||
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
|
||||
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
|
||||
1 PRIMARY B ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
|
||||
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 5 func 1
|
||||
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
|
||||
2 MATERIALIZED C ALL NULL NULL NULL NULL 3
|
||||
3 MATERIALIZED D ALL NULL NULL NULL NULL 3
|
||||
drop table t1, t2;
|
||||
@ -2323,7 +2323,7 @@ explain
|
||||
SELECT * FROM t1 WHERE (a) IN (SELECT a FROM t2 JOIN t3 ON b = a);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 9
|
||||
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
|
||||
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
|
||||
2 MATERIALIZED t3 ALL NULL NULL NULL NULL 13 Using where
|
||||
2 MATERIALIZED t2 ref b b 4 test.t3.a 1 Using index
|
||||
SELECT * FROM t1 WHERE (a) IN (SELECT a FROM t2 JOIN t3 ON b = a);
|
||||
@ -2443,7 +2443,7 @@ EXPLAIN
|
||||
SELECT * FROM t1 RIGHT JOIN t2 ON b = a WHERE t2.b IN (SELECT c FROM t3);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t2 ALL NULL NULL NULL NULL 2
|
||||
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
|
||||
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
|
||||
2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2
|
||||
SELECT * FROM t1 RIGHT JOIN t2 ON b = a WHERE t2.b IN (SELECT c FROM t3);
|
||||
|
Reference in New Issue
Block a user