Skip to content

Commit 3fcd84c

Browse files
author
Alexander Barkov
committed
MDEV-8741 Equal field propagation leaves some remainders after simplifying WH ERE zerofill_column=2010 AND zerofill_column>=2010
1 parent 4cb6edb commit 3fcd84c

12 files changed

+157
-36
lines changed

mysql-test/r/null.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,15 +1369,15 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND NULLIF(10.1,a) IS NULL;
13691369
id select_type table type possible_keys key key_len ref rows filtered Extra
13701370
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
13711371
Warnings:
1372-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2010) and 1)
1372+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010)
13731373
SELECT * FROM t1 WHERE a=2010 AND CASE WHEN 10.1=a THEN NULL ELSE 10.1 END IS NULL;
13741374
a
13751375
2010
13761376
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND CASE WHEN 10.1=a THEN NULL ELSE 10.1 END IS NULL;
13771377
id select_type table type possible_keys key key_len ref rows filtered Extra
13781378
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
13791379
Warnings:
1380-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2010) and 1)
1380+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010)
13811381
DROP TABLE t1;
13821382
# Two warnings expected
13831383
CREATE TABLE t1 AS SELECT

mysql-test/r/type_float.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,5 +625,16 @@ Warnings:
625625
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 1.10e0) and (<cache>(length(1.100)) <> rand()))
626626
DROP TABLE t1;
627627
#
628+
# MDEV-8741 Equal field propagation leaves some remainders after simplifying WHERE zerofill_column=2010 AND zerofill_column>=2010
629+
#
630+
CREATE TABLE t1 (a DOUBLE ZEROFILL);
631+
INSERT INTO t1 VALUES (2010),(2020);
632+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010e0 AND a>=2010e0;
633+
id select_type table type possible_keys key key_len ref rows filtered Extra
634+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
635+
Warnings:
636+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010e0)
637+
DROP TABLE t1;
638+
#
628639
# End of 10.1 tests
629640
#

mysql-test/r/type_int.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Start of 10.1 tests
3+
#
4+
#
5+
# MDEV-8741 Equal field propagation leaves some remainders after simplifying WHERE zerofill_column=2010 AND zerofill_column>=2010
6+
#
7+
CREATE TABLE t1 (a INT ZEROFILL);
8+
INSERT INTO t1 VALUES (2010),(2020);
9+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
10+
id select_type table type possible_keys key key_len ref rows filtered Extra
11+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
12+
Warnings:
13+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010)
14+
DROP TABLE t1;
15+
#
16+
# End of 10.1 tests
17+
#

mysql-test/r/type_newdecimal.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,5 +2145,16 @@ Warnings:
21452145
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 1.10) and (<cache>(length(1.100)) <> rand()))
21462146
DROP TABLE t1;
21472147
#
2148+
# MDEV-8741 Equal field propagation leaves some remainders after simplifying WHERE zerofill_column=2010 AND zerofill_column>=2010
2149+
#
2150+
CREATE TABLE t1 (a DECIMAL(10,1) ZEROFILL);
2151+
INSERT INTO t1 VALUES (2010),(2020);
2152+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010.0 AND a>=2010.0;
2153+
id select_type table type possible_keys key key_len ref rows filtered Extra
2154+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
2155+
Warnings:
2156+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010.0)
2157+
DROP TABLE t1;
2158+
#
21482159
# End of 10.1 tests
21492160
#

mysql-test/r/type_year.result

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,47 @@ select a from t1 where a=b;
394394
a
395395
drop table t1;
396396
drop function y2k;
397+
#
398+
# Start of 10.1 tests
399+
#
400+
#
401+
# MDEV-8741 Equal field propagation leaves some remainders after simplifying WHERE zerofill_column=2010 AND zerofill_column>=2010
402+
#
403+
CREATE TABLE t1 (a YEAR);
404+
INSERT INTO t1 VALUES (2010),(2020);
405+
SELECT * FROM t1 WHERE a=2010 AND a>=2010;
406+
a
407+
2010
408+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
409+
id select_type table type possible_keys key key_len ref rows filtered Extra
410+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
411+
Warnings:
412+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010)
413+
SELECT * FROM t1 WHERE a=2010 AND a>=10;
414+
a
415+
2010
416+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=10;
417+
id select_type table type possible_keys key key_len ref rows filtered Extra
418+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
419+
Warnings:
420+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010)
421+
SELECT * FROM t1 WHERE a=10 AND a>=2010;
422+
a
423+
2010
424+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=10 AND a>=2010;
425+
id select_type table type possible_keys key key_len ref rows filtered Extra
426+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
427+
Warnings:
428+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010)
429+
SELECT * FROM t1 WHERE a=10 AND a>=10;
430+
a
431+
2010
432+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=10 AND a>=10;
433+
id select_type table type possible_keys key key_len ref rows filtered Extra
434+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
435+
Warnings:
436+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010)
437+
DROP TABLE t1;
438+
#
439+
# End of 10.1 tests
440+
#

mysql-test/t/type_float.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,15 @@ SELECT * FROM t1 WHERE LENGTH(a)!=RAND() AND a=1.10e0;
446446
DROP TABLE t1;
447447

448448

449+
--echo #
450+
--echo # MDEV-8741 Equal field propagation leaves some remainders after simplifying WHERE zerofill_column=2010 AND zerofill_column>=2010
451+
--echo #
452+
CREATE TABLE t1 (a DOUBLE ZEROFILL);
453+
INSERT INTO t1 VALUES (2010),(2020);
454+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010e0 AND a>=2010e0;
455+
DROP TABLE t1;
456+
457+
449458
--echo #
450459
--echo # End of 10.1 tests
451460
--echo #

mysql-test/t/type_int.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--echo #
2+
--echo # Start of 10.1 tests
3+
--echo #
4+
5+
--echo #
6+
--echo # MDEV-8741 Equal field propagation leaves some remainders after simplifying WHERE zerofill_column=2010 AND zerofill_column>=2010
7+
--echo #
8+
9+
CREATE TABLE t1 (a INT ZEROFILL);
10+
INSERT INTO t1 VALUES (2010),(2020);
11+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
12+
DROP TABLE t1;
13+
14+
--echo #
15+
--echo # End of 10.1 tests
16+
--echo #

mysql-test/t/type_newdecimal.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,13 @@ EXPLAIN EXTENDED
16671667
SELECT * FROM t1 WHERE LENGTH(a)!=rand() AND a=1.10;
16681668
DROP TABLE t1;
16691669

1670+
--echo #
1671+
--echo # MDEV-8741 Equal field propagation leaves some remainders after simplifying WHERE zerofill_column=2010 AND zerofill_column>=2010
1672+
--echo #
1673+
CREATE TABLE t1 (a DECIMAL(10,1) ZEROFILL);
1674+
INSERT INTO t1 VALUES (2010),(2020);
1675+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010.0 AND a>=2010.0;
1676+
DROP TABLE t1;
16701677

16711678
--echo #
16721679
--echo # End of 10.1 tests

mysql-test/t/type_year.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,25 @@ drop table t1;
188188
drop function y2k;
189189

190190

191+
--echo #
192+
--echo # Start of 10.1 tests
193+
--echo #
194+
195+
--echo #
196+
--echo # MDEV-8741 Equal field propagation leaves some remainders after simplifying WHERE zerofill_column=2010 AND zerofill_column>=2010
197+
--echo #
198+
CREATE TABLE t1 (a YEAR);
199+
INSERT INTO t1 VALUES (2010),(2020);
200+
SELECT * FROM t1 WHERE a=2010 AND a>=2010;
201+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
202+
SELECT * FROM t1 WHERE a=2010 AND a>=10;
203+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=10;
204+
SELECT * FROM t1 WHERE a=10 AND a>=2010;
205+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=10 AND a>=2010;
206+
SELECT * FROM t1 WHERE a=10 AND a>=10;
207+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=10 AND a>=10;
208+
DROP TABLE t1;
209+
210+
--echo #
211+
--echo # End of 10.1 tests
212+
--echo #

sql/field.cc

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,6 @@ Item *Field_num::convert_zerofill_number_to_string(THD *thd, Item *item) const
14031403

14041404

14051405
Item *Field_num::get_equal_zerofill_const_item(THD *thd, const Context &ctx,
1406-
Item_field *field_item,
14071406
Item *const_item)
14081407
{
14091408
switch (ctx.subst_constraint()) {
@@ -1414,7 +1413,7 @@ Item *Field_num::get_equal_zerofill_const_item(THD *thd, const Context &ctx,
14141413
}
14151414
DBUG_ASSERT(const_item->const_item());
14161415
DBUG_ASSERT(ctx.compare_type() != STRING_RESULT);
1417-
return field_item;
1416+
return const_item;
14181417
}
14191418

14201419

@@ -3292,12 +3291,10 @@ Field_new_decimal::unpack(uchar* to, const uchar *from, const uchar *from_end,
32923291

32933292

32943293
Item *Field_new_decimal::get_equal_const_item(THD *thd, const Context &ctx,
3295-
Item_field *field_item,
32963294
Item *const_item)
32973295
{
32983296
if (flags & ZEROFILL_FLAG)
3299-
return Field_num::get_equal_zerofill_const_item(thd, ctx,
3300-
field_item, const_item);
3297+
return Field_num::get_equal_zerofill_const_item(thd, ctx, const_item);
33013298
switch (ctx.subst_constraint()) {
33023299
case IDENTITY_SUBST:
33033300
if (const_item->field_type() != MYSQL_TYPE_NEWDECIMAL ||
@@ -4644,12 +4641,10 @@ bool Field_real::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate)
46444641

46454642

46464643
Item *Field_real::get_equal_const_item(THD *thd, const Context &ctx,
4647-
Item_field *field_item,
46484644
Item *const_item)
46494645
{
46504646
if (flags & ZEROFILL_FLAG)
4651-
return Field_num::get_equal_zerofill_const_item(thd, ctx,
4652-
field_item, const_item);
4647+
return Field_num::get_equal_zerofill_const_item(thd, ctx, const_item);
46534648
switch (ctx.subst_constraint()) {
46544649
case IDENTITY_SUBST:
46554650
if (const_item->decimal_scale() != Field_real::decimals())
@@ -5519,9 +5514,9 @@ bool Field_temporal::can_optimize_group_min_max(const Item_bool_func *cond,
55195514
}
55205515

55215516

5522-
Item *Field_temporal::get_equal_const_item_datetime(THD *thd, const Context &ctx,
5523-
Item_field *field_item,
5524-
Item *const_item)
5517+
Item *Field_temporal::get_equal_const_item_datetime(THD *thd,
5518+
const Context &ctx,
5519+
Item *const_item)
55255520
{
55265521
switch (ctx.subst_constraint()) {
55275522
case IDENTITY_SUBST:
@@ -5843,7 +5838,6 @@ int Field_time::store_decimal(const my_decimal *d)
58435838

58445839

58455840
Item *Field_time::get_equal_const_item(THD *thd, const Context &ctx,
5846-
Item_field *field_item,
58475841
Item *const_item)
58485842
{
58495843
switch (ctx.subst_constraint()) {
@@ -6311,7 +6305,6 @@ void Field_newdate::sql_type(String &res) const
63116305

63126306

63136307
Item *Field_newdate::get_equal_const_item(THD *thd, const Context &ctx,
6314-
Item_field *field_item,
63156308
Item *const_item)
63166309
{
63176310
switch (ctx.subst_constraint()) {

0 commit comments

Comments
 (0)