Skip to content

Commit

Permalink
MDEV-11060 sql/protocol.cc:532: void Protocol::end_statement(): Asser…
Browse files Browse the repository at this point in the history
…tion `0' failed

In file sql/opt_range.cc,when calculate_cond_selectivity_for_table() is called with optimizer_use_condition_selectivity=4 then
	- thd->no_errors is set to 1
	- the original value of thd->no_error is not restored to its original value
	- this is causing the assertion to fail in the subsequent queries

Fixed by restoring the original value of thd->no_errors
  • Loading branch information
varunraiko committed Dec 14, 2016
1 parent 0c79de2 commit f41bd7e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mysql-test/r/selectivity_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,26 @@ DROP TABLE t1,t2;
#
# End of 10.0 tests
#
#
# Start of 10.1 tests
#
#
# MDEV-11060: sql/protocol.cc:532: void Protocol::end_statement(): Assertion `0' failed
#
set optimizer_use_condition_selectivity=4;
drop view if exists v1;
create table t1 (a int not null, b int, c int) engine=InnoDB;
create trigger trgi before insert on t1 for each row set new.a=if(new.a is null,new.b,new.c);
create table t2 (d int, e int) engine=InnoDB;
update t1, t2 set a=NULL, b=2, c=NULL where b=d and e=200;
create view v1 as select * from t1, t2 where d=2;
insert v1 (a,c) values (NULL, 20);
ERROR 23000: Column 'a' cannot be null
drop table t1,t2;
drop view v1;
#
# End of 10.1 tests
#
set use_stat_tables= @tmp_ust;
set optimizer_use_condition_selectivity= @tmp_oucs;
SET SESSION STORAGE_ENGINE=DEFAULT;
33 changes: 33 additions & 0 deletions mysql-test/t/selectivity_innodb.test
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,39 @@ DROP TABLE t1,t2;
--echo # End of 10.0 tests
--echo #


--echo #
--echo # Start of 10.1 tests
--echo #

--echo #
--echo # MDEV-11060: sql/protocol.cc:532: void Protocol::end_statement(): Assertion `0' failed
--echo #


set optimizer_use_condition_selectivity=4;

--disable_warnings
drop view if exists v1;
--enable_warnings

create table t1 (a int not null, b int, c int) engine=InnoDB;
create trigger trgi before insert on t1 for each row set new.a=if(new.a is null,new.b,new.c);

create table t2 (d int, e int) engine=InnoDB;
update t1, t2 set a=NULL, b=2, c=NULL where b=d and e=200;

create view v1 as select * from t1, t2 where d=2;
--error ER_BAD_NULL_ERROR
insert v1 (a,c) values (NULL, 20);

drop table t1,t2;
drop view v1;

--echo #
--echo # End of 10.1 tests
--echo #

set use_stat_tables= @tmp_ust;
set optimizer_use_condition_selectivity= @tmp_oucs;
SET SESSION STORAGE_ENGINE=DEFAULT;
1 change: 1 addition & 0 deletions sql/opt_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3112,6 +3112,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
}

free_alloc:
thd->no_errors= 0;
thd->mem_root= param.old_root;
free_root(&alloc, MYF(0));

Expand Down

0 comments on commit f41bd7e

Please sign in to comment.