Skip to content

Commit e640373

Browse files
committed
Revert "MDEV-26427 MariaDB Server SEGV on INSERT .. SELECT"
This reverts commit 49e1400 as it introduces regression MDEV-29935 and has to be reconsidered in general
1 parent 271b737 commit e640373

File tree

8 files changed

+59
-264
lines changed

8 files changed

+59
-264
lines changed

mysql-test/main/insert_select.result

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -883,76 +883,6 @@ INSERT INTO t1 SELECT a*2 FROM t1 ORDER BY a;
883883
Warnings:
884884
Warning 1264 Out of range value for column 'a' at row 4
885885
DROP TABLE t1;
886-
CREATE TABLE t1 (a INT, b INT);
887-
INSERT INTO t1 (a) SELECT SUM(1);
888-
INSERT INTO t1 (a, b) SELECT AVG(2), MIN(3);
889-
INSERT INTO t1 (b) SELECT AVG('x') OVER ();
890-
ERROR 22007: Truncated incorrect DOUBLE value: 'x'
891-
INSERT INTO t1 SELECT MIN(7) OVER (), MAX(8) OVER();
892-
SELECT * FROM t1;
893-
a b
894-
1 NULL
895-
2 3
896-
7 8
897-
PREPARE stmt FROM 'INSERT INTO t1 (a) SELECT AVG(?)';
898-
EXECUTE stmt USING 9;
899-
EXECUTE stmt USING 10;
900-
PREPARE stmt FROM 'INSERT INTO t1 SELECT MIN(?), MAX(?)';
901-
EXECUTE stmt USING 11, 12;
902-
EXECUTE stmt USING 13, 14;
903-
DEALLOCATE PREPARE stmt;
904-
SELECT * FROM t1;
905-
a b
906-
1 NULL
907-
2 3
908-
7 8
909-
9 NULL
910-
10 NULL
911-
11 12
912-
13 14
913-
CREATE PROCEDURE p1(param_a INT, param_b INT)
914-
BEGIN
915-
INSERT INTO t1 SELECT MIN(param_a) OVER (), MAX(param_b);
916-
END//
917-
CALL p1(21, 22);
918-
CALL p1(23, 24);
919-
SELECT * FROM t1;
920-
a b
921-
1 NULL
922-
2 3
923-
7 8
924-
9 NULL
925-
10 NULL
926-
11 12
927-
13 14
928-
21 22
929-
23 24
930-
CREATE TABLE t2 (
931-
a DECIMAL UNIQUE CHECK (CASE 0 * 27302337.000000 WHEN 34 THEN
932-
+ 'x' LIKE 'x' OR a NOT IN (-1 / TRUE ^ 2) ELSE 7105743.000000 END));
933-
INSERT INTO t2 VALUES (90),( -1),(31152443.000000),(-32768),(NULL),(NULL);
934-
INSERT INTO t2 SELECT AVG('x') OVER (
935-
PARTITION BY ((NOT AVG(76698761.000000))) IS NOT NULL);
936-
ERROR 22007: Truncated incorrect DOUBLE value: 'x'
937-
INSERT IGNORE INTO t2 () VALUES (0),('x'),(3751286.000000),
938-
('x'),((a = 'x' AND 0 AND 0));
939-
Warnings:
940-
Warning 1366 Incorrect decimal value: 'x' for column `test`.`t2`.`a` at row 2
941-
Warning 1062 Duplicate entry '0' for key 'a'
942-
Warning 1366 Incorrect decimal value: 'x' for column `test`.`t2`.`a` at row 4
943-
Warning 1062 Duplicate entry '0' for key 'a'
944-
Warning 1062 Duplicate entry '0' for key 'a'
945-
INSERT INTO t2 VALUES (127);
946-
INSERT INTO t2 SELECT -2147483648 END FROM t2 AS TEXT JOIN t2 JOIN t2 TABLES;
947-
ERROR 23000: Duplicate entry '-2147483648' for key 'a'
948-
ALTER TABLE t2 ADD (
949-
b INT UNIQUE CHECK ((a = 'x' AND ((-(+(BINARY 49730460.000000)))) = 'x'
950-
BETWEEN 'x' AND 'x')));
951-
ERROR 22007: Truncated incorrect DECIMAL value: 'x'
952-
UPDATE t2 SET a = -128 WHERE a IS NULL ORDER BY 78 IN ('x','x'),a;
953-
ERROR 23000: Duplicate entry '-128' for key 'a'
954-
DROP TABLE t1, t2;
955-
DROP PROCEDURE p1;
956886
# End of 10.2 test
957887
#
958888
# MDEV-28617: INSERT ... SELECT with redundant IN subquery in GROUP BY

mysql-test/main/insert_select.test

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -459,60 +459,6 @@ INSERT INTO t1 SELECT a*2 FROM t1 ORDER BY a;
459459

460460
DROP TABLE t1;
461461

462-
#
463-
# MDEV-26427 MariaDB Server SEGV on INSERT .. SELECT
464-
#
465-
CREATE TABLE t1 (a INT, b INT);
466-
INSERT INTO t1 (a) SELECT SUM(1);
467-
INSERT INTO t1 (a, b) SELECT AVG(2), MIN(3);
468-
469-
--error ER_TRUNCATED_WRONG_VALUE
470-
INSERT INTO t1 (b) SELECT AVG('x') OVER ();
471-
INSERT INTO t1 SELECT MIN(7) OVER (), MAX(8) OVER();
472-
SELECT * FROM t1;
473-
474-
PREPARE stmt FROM 'INSERT INTO t1 (a) SELECT AVG(?)';
475-
EXECUTE stmt USING 9;
476-
EXECUTE stmt USING 10;
477-
478-
PREPARE stmt FROM 'INSERT INTO t1 SELECT MIN(?), MAX(?)';
479-
EXECUTE stmt USING 11, 12;
480-
EXECUTE stmt USING 13, 14;
481-
DEALLOCATE PREPARE stmt;
482-
SELECT * FROM t1;
483-
484-
DELIMITER //;
485-
CREATE PROCEDURE p1(param_a INT, param_b INT)
486-
BEGIN
487-
INSERT INTO t1 SELECT MIN(param_a) OVER (), MAX(param_b);
488-
END//
489-
DELIMITER ;//
490-
CALL p1(21, 22);
491-
CALL p1(23, 24);
492-
SELECT * FROM t1;
493-
494-
CREATE TABLE t2 (
495-
a DECIMAL UNIQUE CHECK (CASE 0 * 27302337.000000 WHEN 34 THEN
496-
+ 'x' LIKE 'x' OR a NOT IN (-1 / TRUE ^ 2) ELSE 7105743.000000 END));
497-
INSERT INTO t2 VALUES (90),( -1),(31152443.000000),(-32768),(NULL),(NULL);
498-
--error ER_TRUNCATED_WRONG_VALUE
499-
INSERT INTO t2 SELECT AVG('x') OVER (
500-
PARTITION BY ((NOT AVG(76698761.000000))) IS NOT NULL);
501-
INSERT IGNORE INTO t2 () VALUES (0),('x'),(3751286.000000),
502-
('x'),((a = 'x' AND 0 AND 0));
503-
INSERT INTO t2 VALUES (127);
504-
--error ER_DUP_ENTRY
505-
INSERT INTO t2 SELECT -2147483648 END FROM t2 AS TEXT JOIN t2 JOIN t2 TABLES;
506-
--error ER_TRUNCATED_WRONG_VALUE
507-
ALTER TABLE t2 ADD (
508-
b INT UNIQUE CHECK ((a = 'x' AND ((-(+(BINARY 49730460.000000)))) = 'x'
509-
BETWEEN 'x' AND 'x')));
510-
--error ER_DUP_ENTRY
511-
UPDATE t2 SET a = -128 WHERE a IS NULL ORDER BY 78 IN ('x','x'),a;
512-
513-
DROP TABLE t1, t2;
514-
DROP PROCEDURE p1;
515-
516462
--echo # End of 10.2 test
517463

518464
--echo #

mysql-test/main/view.result

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,8 +1503,6 @@ execute stmt1 using @a;
15031503
set @a= 301;
15041504
execute stmt1 using @a;
15051505
deallocate prepare stmt1;
1506-
insert into v3(a) select sum(302);
1507-
insert into v3(a) select sum(303) over ();
15081506
select * from v3;
15091507
a b
15101508
100 0
@@ -1523,14 +1521,6 @@ a b
15231521
301 10
15241522
301 1000
15251523
301 2000
1526-
302 0
1527-
302 10
1528-
302 1000
1529-
302 2000
1530-
303 0
1531-
303 10
1532-
303 1000
1533-
303 2000
15341524
drop view v3;
15351525
drop tables t1,t2;
15361526
create table t1(f1 int);

mysql-test/main/view.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,8 +1334,6 @@ execute stmt1 using @a;
13341334
set @a= 301;
13351335
execute stmt1 using @a;
13361336
deallocate prepare stmt1;
1337-
insert into v3(a) select sum(302);
1338-
insert into v3(a) select sum(303) over ();
13391337
--sorted_result
13401338
select * from v3;
13411339

sql/sql_base.cc

Lines changed: 51 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -7708,39 +7708,6 @@ bool setup_fields(THD *thd, Ref_ptr_array ref_pointer_array,
77087708
DBUG_RETURN(MY_TEST(thd->is_error()));
77097709
}
77107710

7711-
/*
7712-
make list of leaves for a single TABLE_LIST
7713-
7714-
SYNOPSIS
7715-
make_leaves_for_single_table()
7716-
thd Thread handler
7717-
leaves List of leaf tables to be filled
7718-
table TABLE_LIST object to process
7719-
full_table_list Whether to include tables from mergeable derived table/view
7720-
*/
7721-
void make_leaves_for_single_table(THD *thd, List<TABLE_LIST> &leaves,
7722-
TABLE_LIST *table, bool& full_table_list,
7723-
TABLE_LIST *boundary)
7724-
{
7725-
if (table == boundary)
7726-
full_table_list= !full_table_list;
7727-
if (full_table_list && table->is_merged_derived())
7728-
{
7729-
SELECT_LEX *select_lex= table->get_single_select();
7730-
/*
7731-
It's safe to use select_lex->leaf_tables because all derived
7732-
tables/views were already prepared and has their leaf_tables
7733-
set properly.
7734-
*/
7735-
make_leaves_list(thd, leaves, select_lex->get_table_list(),
7736-
full_table_list, boundary);
7737-
}
7738-
else
7739-
{
7740-
leaves.push_back(table, thd->mem_root);
7741-
}
7742-
}
7743-
77447711

77457712
/*
77467713
Perform checks like all given fields exists, if exists fill struct with
@@ -7767,79 +7734,40 @@ int setup_returning_fields(THD* thd, TABLE_LIST* table_list)
77677734
77687735
SYNOPSIS
77697736
make_leaves_list()
7770-
leaves List of leaf tables to be filled
7771-
tables Table list
7772-
full_table_list Whether to include tables from mergeable derived table/view.
7773-
We need them for checks for INSERT/UPDATE statements only.
7737+
list pointer to pointer on list first element
7738+
tables table list
7739+
full_table_list whether to include tables from mergeable derived table/view.
7740+
we need them for checks for INSERT/UPDATE statements only.
7741+
7742+
RETURN pointer on pointer to next_leaf of last element
77747743
*/
77757744

7776-
void make_leaves_list(THD *thd, List<TABLE_LIST> &leaves, TABLE_LIST *tables,
7745+
void make_leaves_list(THD *thd, List<TABLE_LIST> &list, TABLE_LIST *tables,
77777746
bool full_table_list, TABLE_LIST *boundary)
77787747

77797748
{
77807749
for (TABLE_LIST *table= tables; table; table= table->next_local)
77817750
{
7782-
make_leaves_for_single_table(thd, leaves, table, full_table_list,
7783-
boundary);
7784-
}
7785-
}
7786-
7787-
7788-
/*
7789-
Setup the map and other attributes for a single TABLE_LIST object
7790-
7791-
SYNOPSIS
7792-
setup_table_attributes()
7793-
thd Thread handler
7794-
table_list TABLE_LIST object to process
7795-
first_select_table First table participating in SELECT for INSERT..SELECT
7796-
statements, NULL for other cases
7797-
tablenr Serial number of the table in the SQL statement
7798-
7799-
RETURN
7800-
false Success
7801-
true Failure
7802-
*/
7803-
bool setup_table_attributes(THD *thd, TABLE_LIST *table_list,
7804-
TABLE_LIST *first_select_table,
7805-
uint &tablenr)
7806-
{
7807-
TABLE *table= table_list->table;
7808-
if (table)
7809-
table->pos_in_table_list= table_list;
7810-
if (first_select_table && table_list->top_table() == first_select_table)
7811-
{
7812-
/* new counting for SELECT of INSERT ... SELECT command */
7813-
first_select_table= 0;
7814-
thd->lex->first_select_lex()->insert_tables= tablenr;
7815-
tablenr= 0;
7816-
}
7817-
if (table_list->jtbm_subselect)
7818-
{
7819-
table_list->jtbm_table_no= tablenr;
7820-
}
7821-
else if (table)
7822-
{
7823-
table->pos_in_table_list= table_list;
7824-
setup_table_map(table, table_list, tablenr);
7825-
7826-
if (table_list->process_index_hints(table))
7827-
return true;
7828-
}
7829-
tablenr++;
7830-
/*
7831-
We test the max tables here as we setup_table_map() should not be called
7832-
with tablenr >= 64
7833-
*/
7834-
if (tablenr > MAX_TABLES)
7835-
{
7836-
my_error(ER_TOO_MANY_TABLES, MYF(0), static_cast<int>(MAX_TABLES));
7837-
return true;
7751+
if (table == boundary)
7752+
full_table_list= !full_table_list;
7753+
if (full_table_list && table->is_merged_derived())
7754+
{
7755+
SELECT_LEX *select_lex= table->get_single_select();
7756+
/*
7757+
It's safe to use select_lex->leaf_tables because all derived
7758+
tables/views were already prepared and has their leaf_tables
7759+
set properly.
7760+
*/
7761+
make_leaves_list(thd, list, select_lex->get_table_list(),
7762+
full_table_list, boundary);
7763+
}
7764+
else
7765+
{
7766+
list.push_back(table, thd->mem_root);
7767+
}
78387768
}
7839-
return false;
78407769
}
78417770

7842-
78437771
/*
78447772
prepare tables
78457773
@@ -7896,14 +7824,7 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
78967824
leaves.empty();
78977825
if (select_lex->prep_leaf_list_state != SELECT_LEX::SAVED)
78987826
{
7899-
/*
7900-
For INSERT ... SELECT statements we must not include the first table
7901-
(where the data is being inserted into) in the list of leaves
7902-
*/
7903-
TABLE_LIST *tables_for_leaves=
7904-
select_insert ? first_select_table : tables;
7905-
make_leaves_list(thd, leaves, tables_for_leaves, full_table_list,
7906-
first_select_table);
7827+
make_leaves_list(thd, leaves, tables, full_table_list, first_select_table);
79077828
select_lex->prep_leaf_list_state= SELECT_LEX::READY;
79087829
select_lex->leaf_tables_exec.empty();
79097830
}
@@ -7914,34 +7835,37 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
79147835
leaves.push_back(table_list, thd->mem_root);
79157836
}
79167837

7917-
List_iterator<TABLE_LIST> ti(leaves);
79187838
while ((table_list= ti++))
79197839
{
7920-
if (setup_table_attributes(thd, table_list, first_select_table, tablenr))
7921-
DBUG_RETURN(1);
7922-
}
7923-
7924-
if (select_insert)
7925-
{
7926-
/*
7927-
The table/view in which the data is inserted must not be included into
7928-
the leaf_tables list. But we need this table/view to setup attributes
7929-
for it. So build a temporary list of leaves and setup attributes for
7930-
the tables included
7931-
*/
7932-
List<TABLE_LIST> leaves;
7933-
TABLE_LIST *table= tables;
7934-
7935-
make_leaves_for_single_table(thd, leaves, table, full_table_list,
7936-
first_select_table);
7937-
7938-
List_iterator<TABLE_LIST> ti(leaves);
7939-
while ((table_list= ti++))
7840+
TABLE *table= table_list->table;
7841+
if (table)
7842+
table->pos_in_table_list= table_list;
7843+
if (first_select_table &&
7844+
table_list->top_table() == first_select_table)
79407845
{
7941-
if (setup_table_attributes(thd, table_list, first_select_table,
7942-
tablenr))
7846+
/* new counting for SELECT of INSERT ... SELECT command */
7847+
first_select_table= 0;
7848+
thd->lex->select_lex.insert_tables= tablenr;
7849+
tablenr= 0;
7850+
}
7851+
if(table_list->jtbm_subselect)
7852+
{
7853+
table_list->jtbm_table_no= tablenr;
7854+
}
7855+
else if (table)
7856+
{
7857+
table->pos_in_table_list= table_list;
7858+
setup_table_map(table, table_list, tablenr);
7859+
7860+
if (table_list->process_index_hints(table))
79437861
DBUG_RETURN(1);
79447862
}
7863+
tablenr++;
7864+
}
7865+
if (tablenr > MAX_TABLES)
7866+
{
7867+
my_error(ER_TOO_MANY_TABLES,MYF(0), static_cast<int>(MAX_TABLES));
7868+
DBUG_RETURN(1);
79457869
}
79467870
}
79477871
else

0 commit comments

Comments
 (0)