1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-32086 Server crash when inserting from derived table containing insert target table

Use original solution for INSERT ... SELECT - select result buferisation.

Also fix MDEV-36447 and MDEV-33139
This commit is contained in:
Oleksandr Byelkin
2025-04-01 20:57:29 +02:00
parent 2f5c260f55
commit 9b313d2de1
7 changed files with 260 additions and 79 deletions

View File

@@ -1030,6 +1030,133 @@ a
3
DROP VIEW v1;
DROP TABLE t1;
create table t1 (pk int, id int);
insert into t1 values (2,2), (3,3), (4,4);
insert into t1
select 1,10
from
(
select dt2.id from (select id from t1) dt2, t1 t where t.id=dt2.id
) dt
where dt.id=3;
select * from t1;
pk id
2 2
3 3
4 4
1 10
explain insert into t1
select 1,10
from
(
select dt2.id from (select id from t1) dt2, t1 t where t.id=dt2.id
) dt
where dt.id=3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where; Using temporary
1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
explain format=json insert into t1
select 1,10
from
(
select dt2.id from (select id from t1) dt2, t1 t where t.id=dt2.id
) dt
where dt.id=3;
EXPLAIN
{
"query_block": {
"select_id": 1,
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 4,
"filtered": 100,
"attached_condition": "t1.`id` = 3"
},
"block-nl-join": {
"table": {
"table_name": "t",
"access_type": "ALL",
"rows": 4,
"filtered": 100,
"attached_condition": "t.`id` = 3"
},
"buffer_type": "flat",
"buffer_size": "65",
"join_type": "BNL"
}
}
}
}
prepare stmt from "insert into t1
select 1,10
from
(
select dt2.id from (select id from t1) dt2, t1 t where t.id=dt2.id
) dt
where dt.id=3";
execute stmt;
select * from t1;
pk id
2 2
3 3
4 4
1 10
1 10
execute stmt;
select * from t1;
pk id
2 2
3 3
4 4
1 10
1 10
1 10
deallocate prepare stmt;
create procedure p() insert into t1
select 1,10
from
(
select dt2.id from (select id from t1) dt2, t1 t where t.id=dt2.id
) dt
where dt.id=3;
call p();
select * from t1;
pk id
2 2
3 3
4 4
1 10
1 10
1 10
1 10
call p();
select * from t1;
pk id
2 2
3 3
4 4
1 10
1 10
1 10
1 10
1 10
drop procedure p;
drop table t1;
#
# End of 10.5 test
# MDEV-33139: Crash of INSERT SELECT when preparing structures for
# split optimization
#
CREATE TABLE v0 ( v1 INT UNIQUE ) ;
INSERT INTO v0 ( v1 ) VALUES
( ( SELECT 1
FROM
( SELECT v1
FROM v0 GROUP BY v1 ) AS v6 NATURAL JOIN
v0 AS v2 NATURAL JOIN
v0 AS v4 NATURAL JOIN
v0 AS v3 NATURAL JOIN
( SELECT v1 FROM v0 ) AS v7 ) ) ;
DROP TABLE v0;
# End of 10.5 tests