Skip to content

Commit aa4c751

Browse files
author
Tor Didriksen
committed
Bug#20086791 ASSERT ! IS_SET() IN DIAGNOSTICS_AREA::SET_OK_STATUS ON DELETE (ER_SUBQUERY..)
Don't continue execution in JOIN::optimize() if make_join_select() returns an error.
1 parent 4a06abe commit aa4c751

File tree

3 files changed

+197
-1
lines changed

3 files changed

+197
-1
lines changed

mysql-test/r/delete.result

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,3 +644,90 @@ ERROR 42S22: Unknown column 'z' in 'field list'
644644
INSERT INTO t2 VALUES('a');
645645
DELETE FROM t2 WHERE 1 = a;
646646
DROP TABLE t1, t2;
647+
#
648+
# Bug#20086791 ASSERT `! IS_SET()` IN DIAGNOSTICS_AREA::SET_OK_STATUS
649+
# ON DELETE (ER_SUBQUERY..)
650+
#
651+
SET sql_mode='';
652+
CREATE TABLE t1 (
653+
col_int_key int,
654+
pk integer auto_increment,
655+
col_datetime_key datetime,
656+
/*Indices*/
657+
key (col_int_key ),
658+
primary key (pk),
659+
key (col_datetime_key )
660+
) ENGINE=memory;
661+
CREATE TABLE t2 (
662+
col_varchar_key varchar (1),
663+
col_date_key date,
664+
pk integer auto_increment,
665+
/*Indices*/
666+
key (col_varchar_key ),
667+
key (col_date_key ),
668+
primary key (pk)
669+
) ENGINE=memory;
670+
INSERT INTO t2 VALUES
671+
('v', '2002-05-01', NULL) ,
672+
('d', '2001-01-01', NULL)
673+
;
674+
CREATE TABLE t3 (
675+
pk integer auto_increment,
676+
col_int_key int,
677+
col_varchar_key varchar (1),
678+
/*Indices*/
679+
primary key (pk),
680+
key (col_int_key ),
681+
key (col_varchar_key ))
682+
ENGINE=memory;
683+
INSERT INTO t3 VALUES
684+
(NULL, 3, 'n') ,
685+
(NULL, 1, 'r')
686+
;
687+
CREATE TABLE t4 (
688+
pk integer auto_increment,
689+
col_varchar_key varchar (1),
690+
col_int_key int,
691+
/*Indices*/
692+
primary key (pk),
693+
key (col_varchar_key ),
694+
key (col_int_key )
695+
) ENGINE=memory;
696+
CREATE TABLE t5 (
697+
col_datetime_key datetime,
698+
pk integer auto_increment,
699+
col_int_key int,
700+
/*Indices*/
701+
key (col_datetime_key ),
702+
primary key (pk),
703+
key (col_int_key ))
704+
ENGINE=memory;
705+
INSERT INTO t5 VALUES
706+
('2007-10-01', NULL, 8) ,
707+
('2002-10-01', NULL, 3)
708+
;
709+
DELETE OUTR1.* FROM t2 AS OUTR1
710+
JOIN t3 AS OUTR2
711+
ON ( OUTR1 . col_varchar_key = OUTR2 . col_varchar_key )
712+
WHERE OUTR1 . col_varchar_key NOT IN
713+
( SELECT INNR1 . col_varchar_key AS y FROM t5 AS INNR2
714+
RIGHT JOIN t4 AS INNR1 ON ( INNR2 . pk < INNR1 . col_int_key )
715+
WHERE INNR1 . col_int_key <= INNR1 . col_int_key
716+
AND OUTR2 . col_int_key >= 3 );
717+
DELETE QUICK
718+
FROM OUTR1.* USING t2 AS OUTR1
719+
LEFT OUTER JOIN t1 AS OUTR2
720+
ON ( OUTR1 . col_date_key = OUTR2 . col_datetime_key )
721+
WHERE OUTR1 . pk NOT IN ( SELECT 2 UNION SELECT 7 );
722+
DELETE OUTR1.*
723+
FROM t2 AS OUTR1
724+
LEFT JOIN t1 AS OUTR2
725+
ON ( OUTR1 . pk = OUTR2 . col_int_key )
726+
WHERE OUTR1 . pk <> (
727+
SELECT DISTINCT INNR1 . col_int_key AS y
728+
FROM t5 AS INNR1 WHERE OUTR1 . pk <= 5
729+
ORDER BY INNR1 . col_datetime_key
730+
);
731+
ERROR 21000: Subquery returns more than 1 row
732+
DROP TABLE t1, t2, t3, t4, t5;
733+
SET sql_mode=default;

mysql-test/t/delete.test

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ DROP TABLE t1;
333333
#
334334
# Bug#27525: table not found when using multi-table-deletes with aliases over
335335
# several databas
336-
# Bug#21148: MULTI-DELETE fails to resolve a table by alias if it's from a
336+
# Bug#21148: MULTI-DELETE fails to resolve a table by alias if it is from a
337337
# different database
338338
#
339339

@@ -713,3 +713,106 @@ INSERT INTO t1 SET z=1;
713713
INSERT INTO t2 VALUES('a');
714714
DELETE FROM t2 WHERE 1 = a;
715715
DROP TABLE t1, t2;
716+
717+
--echo #
718+
--echo # Bug#20086791 ASSERT `! IS_SET()` IN DIAGNOSTICS_AREA::SET_OK_STATUS
719+
--echo # ON DELETE (ER_SUBQUERY..)
720+
--echo #
721+
722+
SET sql_mode='';
723+
724+
CREATE TABLE t1 (
725+
col_int_key int,
726+
pk integer auto_increment,
727+
col_datetime_key datetime,
728+
/*Indices*/
729+
key (col_int_key ),
730+
primary key (pk),
731+
key (col_datetime_key )
732+
) ENGINE=memory;
733+
734+
CREATE TABLE t2 (
735+
col_varchar_key varchar (1),
736+
col_date_key date,
737+
pk integer auto_increment,
738+
/*Indices*/
739+
key (col_varchar_key ),
740+
key (col_date_key ),
741+
primary key (pk)
742+
) ENGINE=memory;
743+
744+
INSERT INTO t2 VALUES
745+
('v', '2002-05-01', NULL) ,
746+
('d', '2001-01-01', NULL)
747+
;
748+
749+
750+
CREATE TABLE t3 (
751+
pk integer auto_increment,
752+
col_int_key int,
753+
col_varchar_key varchar (1),
754+
/*Indices*/
755+
primary key (pk),
756+
key (col_int_key ),
757+
key (col_varchar_key ))
758+
ENGINE=memory;
759+
760+
INSERT INTO t3 VALUES
761+
(NULL, 3, 'n') ,
762+
(NULL, 1, 'r')
763+
;
764+
765+
CREATE TABLE t4 (
766+
pk integer auto_increment,
767+
col_varchar_key varchar (1),
768+
col_int_key int,
769+
/*Indices*/
770+
primary key (pk),
771+
key (col_varchar_key ),
772+
key (col_int_key )
773+
) ENGINE=memory;
774+
775+
CREATE TABLE t5 (
776+
col_datetime_key datetime,
777+
pk integer auto_increment,
778+
col_int_key int,
779+
/*Indices*/
780+
key (col_datetime_key ),
781+
primary key (pk),
782+
key (col_int_key ))
783+
ENGINE=memory;
784+
785+
INSERT INTO t5 VALUES
786+
('2007-10-01', NULL, 8) ,
787+
('2002-10-01', NULL, 3)
788+
;
789+
790+
DELETE OUTR1.* FROM t2 AS OUTR1
791+
JOIN t3 AS OUTR2
792+
ON ( OUTR1 . col_varchar_key = OUTR2 . col_varchar_key )
793+
WHERE OUTR1 . col_varchar_key NOT IN
794+
( SELECT INNR1 . col_varchar_key AS y FROM t5 AS INNR2
795+
RIGHT JOIN t4 AS INNR1 ON ( INNR2 . pk < INNR1 . col_int_key )
796+
WHERE INNR1 . col_int_key <= INNR1 . col_int_key
797+
AND OUTR2 . col_int_key >= 3 );
798+
799+
DELETE QUICK
800+
FROM OUTR1.* USING t2 AS OUTR1
801+
LEFT OUTER JOIN t1 AS OUTR2
802+
ON ( OUTR1 . col_date_key = OUTR2 . col_datetime_key )
803+
WHERE OUTR1 . pk NOT IN ( SELECT 2 UNION SELECT 7 );
804+
805+
--error ER_SUBQUERY_NO_1_ROW
806+
DELETE OUTR1.*
807+
FROM t2 AS OUTR1
808+
LEFT JOIN t1 AS OUTR2
809+
ON ( OUTR1 . pk = OUTR2 . col_int_key )
810+
WHERE OUTR1 . pk <> (
811+
SELECT DISTINCT INNR1 . col_int_key AS y
812+
FROM t5 AS INNR1 WHERE OUTR1 . pk <= 5
813+
ORDER BY INNR1 . col_datetime_key
814+
);
815+
816+
DROP TABLE t1, t2, t3, t4, t5;
817+
818+
SET sql_mode=default;

sql/sql_optimizer.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ JOIN::optimize()
455455

456456
if (make_join_select(this, where_cond))
457457
{
458+
if (thd->is_error())
459+
DBUG_RETURN(1);
460+
458461
zero_result_cause=
459462
"Impossible WHERE noticed after reading const tables";
460463
goto setup_subq_exit;
@@ -8743,6 +8746,9 @@ static bool make_join_select(JOIN *join, Item *cond)
87438746
if (const_cond != NULL)
87448747
{
87458748
const bool const_cond_result= const_cond->val_int() != 0;
8749+
if (thd->is_error())
8750+
DBUG_RETURN(true);
8751+
87468752
Opt_trace_object trace_const_cond(trace);
87478753
trace_const_cond.add("condition_on_constant_tables", const_cond)
87488754
.add("condition_value", const_cond_result);

0 commit comments

Comments
 (0)