Skip to content

Commit 6fbbb08

Browse files
committed
MDEV-18968 Both (WHERE 0.1) and (WHERE NOT 0.1) return empty set
1 parent ed643f4 commit 6fbbb08

File tree

8 files changed

+55
-20
lines changed

8 files changed

+55
-20
lines changed

mysql-test/r/func_group.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,8 +1979,8 @@ FROM t2);
19791979
MIN(t2.pk)
19801980
NULL
19811981
Warnings:
1982-
Warning 1292 Truncated incorrect INTEGER value: 'j'
1983-
Warning 1292 Truncated incorrect INTEGER value: 'j'
1982+
Warning 1292 Truncated incorrect DOUBLE value: 'j'
1983+
Warning 1292 Truncated incorrect DOUBLE value: 'j'
19841984

19851985
EXPLAIN
19861986
SELECT MIN(t2.pk)
@@ -1993,8 +1993,8 @@ id select_type table type possible_keys key key_len ref rows Extra
19931993
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
19941994
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2
19951995
Warnings:
1996-
Warning 1292 Truncated incorrect INTEGER value: 'j'
1997-
Warning 1292 Truncated incorrect INTEGER value: 'j'
1996+
Warning 1292 Truncated incorrect DOUBLE value: 'j'
1997+
Warning 1292 Truncated incorrect DOUBLE value: 'j'
19981998

19991999
#
20002000
# 2) Test that subquery materialization is setup for query with

mysql-test/r/type_decimal.result

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,3 +1019,23 @@ cast('-0.0' as decimal(5,1)) < 0
10191019
#
10201020
# End of 5.5 tests
10211021
#
1022+
#
1023+
# Start of 10.1 tests
1024+
#
1025+
#
1026+
# MDEV-18968 Both (WHERE 0.1) and (WHERE NOT 0.1) return empty set
1027+
#
1028+
CREATE TABLE t1 (a INT);
1029+
INSERT INTO t1 VALUES (10);
1030+
SELECT CASE WHEN 0.1 THEN 'TRUE' ELSE 'FALSE' END FROM t1;
1031+
CASE WHEN 0.1 THEN 'TRUE' ELSE 'FALSE' END
1032+
TRUE
1033+
SELECT * FROM t1 WHERE 0.1;
1034+
a
1035+
10
1036+
SELECT * FROM t1 WHERE NOT 0.1;
1037+
a
1038+
DROP TABLE t1;
1039+
#
1040+
# End of 10.1 tests
1041+
#

mysql-test/t/type_decimal.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,24 @@ select cast('-0.0' as decimal(5,1)) < 0;
612612
--echo #
613613
--echo # End of 5.5 tests
614614
--echo #
615+
616+
617+
--echo #
618+
--echo # Start of 10.1 tests
619+
--echo #
620+
621+
--echo #
622+
--echo # MDEV-18968 Both (WHERE 0.1) and (WHERE NOT 0.1) return empty set
623+
--echo #
624+
625+
CREATE TABLE t1 (a INT);
626+
INSERT INTO t1 VALUES (10);
627+
SELECT CASE WHEN 0.1 THEN 'TRUE' ELSE 'FALSE' END FROM t1;
628+
SELECT * FROM t1 WHERE 0.1;
629+
SELECT * FROM t1 WHERE NOT 0.1;
630+
DROP TABLE t1;
631+
632+
633+
--echo #
634+
--echo # End of 10.1 tests
635+
--echo #

sql/item.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,13 @@ class Item: public Value_source,
10001000
virtual bool val_bool();
10011001
virtual String *val_nodeset(String*) { return 0; }
10021002

1003+
bool eval_const_cond()
1004+
{
1005+
DBUG_ASSERT(const_item());
1006+
DBUG_ASSERT(!is_expensive());
1007+
return val_bool();
1008+
}
1009+
10031010
/*
10041011
save_val() is method of val_* family which stores value in the given
10051012
field.

sql/item_cmpfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4667,7 +4667,7 @@ Item_cond::fix_fields(THD *thd, Item **ref)
46674667
if (item->const_item() && !item->with_param &&
46684668
!item->is_expensive() && !cond_has_datetime_is_null(item))
46694669
{
4670-
if (item->val_int() == is_and_cond && top_level())
4670+
if (item->eval_const_cond() == is_and_cond && top_level())
46714671
{
46724672
/*
46734673
a. This is "... AND true_cond AND ..."

sql/item_func.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,6 @@ bool check_reserved_words(LEX_STRING *name)
6868
}
6969

7070

71-
/**
72-
@return
73-
TRUE if item is a constant
74-
*/
75-
76-
bool
77-
eval_const_cond(COND *cond)
78-
{
79-
return ((Item_func*) cond)->val_int() ? TRUE : FALSE;
80-
}
81-
82-
8371
/**
8472
Test if the sum of arguments overflows the ulonglong range.
8573
*/

sql/item_func.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,6 @@ extern enum_field_types agg_field_type(Item **items, uint nitems,
22792279
Item *find_date_time_item(Item **args, uint nargs, uint col);
22802280
double my_double_round(double value, longlong dec, bool dec_unsigned,
22812281
bool truncate);
2282-
bool eval_const_cond(COND *cond);
22832282

22842283
extern bool volatile mqh_used;
22852284

sql/sql_select.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15644,7 +15644,7 @@ Item::remove_eq_conds(THD *thd, Item::cond_result *cond_value, bool top_level_ar
1564415644
{
1564515645
if (const_item() && !is_expensive())
1564615646
{
15647-
*cond_value= eval_const_cond(this) ? Item::COND_TRUE : Item::COND_FALSE;
15647+
*cond_value= eval_const_cond() ? Item::COND_TRUE : Item::COND_FALSE;
1564815648
return (COND*) 0;
1564915649
}
1565015650
*cond_value= Item::COND_OK;
@@ -15658,7 +15658,7 @@ Item_bool_func2::remove_eq_conds(THD *thd, Item::cond_result *cond_value,
1565815658
{
1565915659
if (const_item() && !is_expensive())
1566015660
{
15661-
*cond_value= eval_const_cond(this) ? Item::COND_TRUE : Item::COND_FALSE;
15661+
*cond_value= eval_const_cond() ? Item::COND_TRUE : Item::COND_FALSE;
1566215662
return (COND*) 0;
1566315663
}
1566415664
if ((*cond_value= eq_cmp_result()) != Item::COND_OK)

0 commit comments

Comments
 (0)