Skip to content

Commit 5738edf

Browse files
committed
MDEV-37653 Unexpected result of prepared statement when use boolean value as parameters
IS TRUE and IS FALSE are only null-rejecting on the top level, consider, e.g. NOT (X IS TRUE)
1 parent 3241798 commit 5738edf

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

mysql-test/main/join_outer.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,4 +2911,19 @@ Z 1 Y 1 X 1
29112911
drop view v0, v1, v2, v3;
29122912
drop table t1, t2, t3;
29132913
# end of 10.3 tests
2914+
#
2915+
# MDEV-37653 Unexpected result of prepared statement when use boolean value as parameters
2916+
#
2917+
create table t0(c0 real);
2918+
create table t1 like t0;
2919+
insert into t1 values (1);
2920+
insert into t0 values (1);
2921+
select t1.c0, t0.c0 from t1 left join t0 on 0 where not (t0.c0 is true);
2922+
c0 c0
2923+
1 NULL
2924+
select t1.c0, t0.c0 from t1 left join t0 on 0 where not (t0.c0 is false);
2925+
c0 c0
2926+
1 NULL
2927+
drop table t0, t1;
2928+
# end of 10.11 tests
29142929
SET optimizer_switch=@org_optimizer_switch;

mysql-test/main/join_outer.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,4 +2434,17 @@ drop table t1, t2, t3;
24342434

24352435
--echo # end of 10.3 tests
24362436

2437+
--echo #
2438+
--echo # MDEV-37653 Unexpected result of prepared statement when use boolean value as parameters
2439+
--echo #
2440+
create table t0(c0 real);
2441+
create table t1 like t0;
2442+
insert into t1 values (1);
2443+
insert into t0 values (1);
2444+
select t1.c0, t0.c0 from t1 left join t0 on 0 where not (t0.c0 is true);
2445+
select t1.c0, t0.c0 from t1 left join t0 on 0 where not (t0.c0 is false);
2446+
drop table t0, t1;
2447+
2448+
--echo # end of 10.11 tests
2449+
24372450
SET optimizer_switch=@org_optimizer_switch;

mysql-test/main/join_outer_jcl6.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,4 +2918,19 @@ Z 1 Y 1 X 1
29182918
drop view v0, v1, v2, v3;
29192919
drop table t1, t2, t3;
29202920
# end of 10.3 tests
2921+
#
2922+
# MDEV-37653 Unexpected result of prepared statement when use boolean value as parameters
2923+
#
2924+
create table t0(c0 real);
2925+
create table t1 like t0;
2926+
insert into t1 values (1);
2927+
insert into t0 values (1);
2928+
select t1.c0, t0.c0 from t1 left join t0 on 0 where not (t0.c0 is true);
2929+
c0 c0
2930+
1 NULL
2931+
select t1.c0, t0.c0 from t1 left join t0 on 0 where not (t0.c0 is false);
2932+
c0 c0
2933+
1 NULL
2934+
drop table t0, t1;
2935+
# end of 10.11 tests
29212936
SET optimizer_switch=@org_optimizer_switch;

sql/item_cmpfunc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ class Item_func_truth : public Item_bool_func
266266
bool fix_length_and_dec(THD *thd) override;
267267
void print(String *str, enum_query_type query_type) override;
268268
enum precedence precedence() const override { return CMP_PRECEDENCE; }
269+
table_map not_null_tables() const override
270+
{ return is_top_level_item() ? not_null_tables_cache : 0; }
269271

270272
protected:
271273
Item_func_truth(THD *thd, Item *a, bool a_value, bool a_affirmative):

0 commit comments

Comments
 (0)