Skip to content

Commit

Permalink
MDEV-17738 Server crashes in Item::delete_self on closing connection …
Browse files Browse the repository at this point in the history
…after unsuccessful PS

Also fixes:
MDEV-17741 Assertion `thd->Item_change_list::is_empty()' failed in mysql_parse after unsuccessful PS

The problem was introduced by:
  commit f033fbd
  Changed the test case for MDEV-15571

It was later fixed, but in 10.3 only:

  commit ce2cf85
  MDEV-16043 Assertion thd->Item_change_list::is_empty() failed in mysql_parse
  upon SELECT from a view reading from a versioned table

This patch is a backport of ce2cf85 to 10.2
  • Loading branch information
abarkov committed Dec 21, 2018
1 parent dc2856a commit e631ea4
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 3 deletions.
73 changes: 73 additions & 0 deletions mysql-test/r/ps_error.result
@@ -0,0 +1,73 @@
#
# MDEV-17741 Assertion `thd->Item_change_list::is_empty()' failed in mysql_parse after unsuccessful PS
#
SET SQL_MODE= 'STRICT_ALL_TABLES';
CREATE TABLE t1 (a INT);
PREPARE stmt FROM "CREATE TABLE tmp AS SELECT * FROM t1 WHERE 'foo' && 0";
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'foo'
EXECUTE stmt;
ERROR 22007: Truncated incorrect INTEGER value: 'foo'
SELECT a FROM t1 GROUP BY NULL WITH ROLLUP;
a
DROP TABLE t1;
SET sql_mode=DEFAULT;
SET SQL_MODE= 'STRICT_ALL_TABLES';
CREATE TABLE t1 (a INT);
PREPARE stmt FROM "CREATE TABLE tmp AS SELECT * FROM t1 WHERE 'foo' && 0";
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'foo'
EXECUTE stmt;
ERROR 22007: Truncated incorrect INTEGER value: 'foo'
SET @a = REPLACE( @@global.optimizer_switch, '=on', '=off' ) ;
DROP TABLE t1;
SET sql_mode=DEFAULT;
#
# MDEV-17738 Server crashes in Item::delete_self on closing connection after unsuccessful PS
#
SET SQL_MODE='STRICT_ALL_TABLES';
PREPARE stmt FROM "CREATE TABLE ps AS SELECT 1 FROM DUAL WHERE 'foo' && 0";
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'foo'
EXECUTE stmt;
ERROR 22007: Truncated incorrect INTEGER value: 'foo'
SELECT 'All done';
All done
All done
SET SQL_MODE=DEFAULT;
SET SQL_MODE='STRICT_ALL_TABLES';
PREPARE stmt FROM "CREATE TABLE ps AS SELECT 1 FROM DUAL WHERE 'foo' && 0";
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'foo'
EXECUTE stmt;
ERROR 22007: Truncated incorrect INTEGER value: 'foo'
DEALLOCATE PREPARE stmt;
SELECT 'All done';
All done
All done
SET SQL_MODE=DEFAULT;
SET SQL_MODE= 'STRICT_ALL_TABLES';
CREATE TABLE t1 (a INT);
PREPARE stmt FROM "CREATE TABLE tmp AS SELECT * FROM t1 WHERE 'foo' && 0";
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'foo'
EXECUTE stmt;
ERROR 22007: Truncated incorrect INTEGER value: 'foo'
SELECT a FROM t1 GROUP BY a;
a
SELECT * FROM t1;
a
DROP TABLE t1;
SET SQL_MODE=DEFAULT;
SET SQL_MODE= 'STRICT_ALL_TABLES';
CREATE TABLE t1 (a INT);
PREPARE stmt FROM "CREATE TABLE tmp AS SELECT * FROM t1 WHERE 'foo' && 0";
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'foo'
EXECUTE stmt;
ERROR 22007: Truncated incorrect INTEGER value: 'foo'
SELECT a FROM t1 GROUP BY a;
a
INSERT t1 SELECT * FROM ( SELECT * FROM t1 ) sq;
DROP TABLE t1;
SET SQL_MODE=DEFAULT;
66 changes: 66 additions & 0 deletions mysql-test/t/ps_error.test
@@ -0,0 +1,66 @@
#
# Tests related to PS returning errors rather than doing successfull execution
#

--echo #
--echo # MDEV-17741 Assertion `thd->Item_change_list::is_empty()' failed in mysql_parse after unsuccessful PS
--echo #

SET SQL_MODE= 'STRICT_ALL_TABLES';
CREATE TABLE t1 (a INT);
PREPARE stmt FROM "CREATE TABLE tmp AS SELECT * FROM t1 WHERE 'foo' && 0";
--error ER_TRUNCATED_WRONG_VALUE
EXECUTE stmt;
SELECT a FROM t1 GROUP BY NULL WITH ROLLUP;
DROP TABLE t1;
SET sql_mode=DEFAULT;

SET SQL_MODE= 'STRICT_ALL_TABLES';
CREATE TABLE t1 (a INT);
PREPARE stmt FROM "CREATE TABLE tmp AS SELECT * FROM t1 WHERE 'foo' && 0";
--error ER_TRUNCATED_WRONG_VALUE
EXECUTE stmt;
SET @a = REPLACE( @@global.optimizer_switch, '=on', '=off' ) ;
DROP TABLE t1;
SET sql_mode=DEFAULT;


--echo #
--echo # MDEV-17738 Server crashes in Item::delete_self on closing connection after unsuccessful PS
--echo #

SET SQL_MODE='STRICT_ALL_TABLES';
PREPARE stmt FROM "CREATE TABLE ps AS SELECT 1 FROM DUAL WHERE 'foo' && 0";
--error ER_TRUNCATED_WRONG_VALUE
EXECUTE stmt;
--source include/restart_mysqld.inc
SELECT 'All done';
SET SQL_MODE=DEFAULT;

SET SQL_MODE='STRICT_ALL_TABLES';
PREPARE stmt FROM "CREATE TABLE ps AS SELECT 1 FROM DUAL WHERE 'foo' && 0";
--error ER_TRUNCATED_WRONG_VALUE
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT 'All done';
SET SQL_MODE=DEFAULT;

SET SQL_MODE= 'STRICT_ALL_TABLES';
CREATE TABLE t1 (a INT);
PREPARE stmt FROM "CREATE TABLE tmp AS SELECT * FROM t1 WHERE 'foo' && 0";
--error ER_TRUNCATED_WRONG_VALUE
EXECUTE stmt;
SELECT a FROM t1 GROUP BY a;
SELECT * FROM t1;
DROP TABLE t1;
SET SQL_MODE=DEFAULT;

SET SQL_MODE= 'STRICT_ALL_TABLES';
CREATE TABLE t1 (a INT);
PREPARE stmt FROM "CREATE TABLE tmp AS SELECT * FROM t1 WHERE 'foo' && 0";
--error ER_TRUNCATED_WRONG_VALUE
EXECUTE stmt;
SELECT a FROM t1 GROUP BY a;
INSERT t1 SELECT * FROM ( SELECT * FROM t1 ) sq;
DROP TABLE t1;
SET SQL_MODE=DEFAULT;
8 changes: 5 additions & 3 deletions sql/sql_select.cc
Expand Up @@ -1318,10 +1318,12 @@ JOIN::optimize_inner()

/* Convert all outer joins to inner joins if possible */
conds= simplify_joins(this, join_list, conds, TRUE, FALSE);
if (thd->is_error())
DBUG_RETURN(1);
if (select_lex->save_leaf_tables(thd))
if (thd->is_error() || select_lex->save_leaf_tables(thd))
{
if (arena)
thd->restore_active_arena(arena, &backup);
DBUG_RETURN(1);
}
build_bitmap_for_nested_joins(join_list, 0);

sel->prep_where= conds ? conds->copy_andor_structure(thd) : 0;
Expand Down

0 comments on commit e631ea4

Please sign in to comment.