1
- /* Copyright (c) 2018, 2019 , Oracle and/or its affiliates. All rights reserved.
1
+ /* Copyright (c) 2018, 2020 , Oracle and/or its affiliates. All rights reserved.
2
2
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License, version 2.0,
@@ -213,6 +213,8 @@ static bool fold_or_convert_dec(THD *thd, Item **const_val,
213
213
constant (at execution time). May be modified if
214
214
we replace or fold the constant.
215
215
@param ft the function type of the comparison
216
+ @param left_has_field
217
+ the field is the left operand
216
218
@param[out] place the placement of the const_val relative to
217
219
the range of f
218
220
@param[out] discount_equal
@@ -222,6 +224,7 @@ static bool fold_or_convert_dec(THD *thd, Item **const_val,
222
224
*/
223
225
static bool analyze_int_field_constant (THD *thd, Item_field *f,
224
226
Item **const_val, Item_func::Functype ft,
227
+ bool left_has_field,
225
228
Range_placement *place,
226
229
bool *discount_equal) {
227
230
const bool field_unsigned = f->unsigned_flag ;
@@ -300,20 +303,21 @@ static bool analyze_int_field_constant(THD *thd, Item_field *f,
300
303
if (d == nullptr ) d = (*const_val)->val_decimal (&d_buff);
301
304
if (ft == Item_func::LT_FUNC || ft == Item_func::LE_FUNC) {
302
305
/*
303
- Round up the decimal to next integral value, then try to convert
304
- that to a longlong, or short circuit
306
+ Round up (or down if field is the right operand) the decimal to next
307
+ integral value, then try to convert that to a longlong, or short
308
+ circuit
305
309
*/
306
- if (round_fold_or_convert_dec (thd, const_val, place, f, d, true ,
307
- discount_equal))
310
+ if (round_fold_or_convert_dec (thd, const_val, place, f, d,
311
+ left_has_field, discount_equal))
308
312
return true ;
309
313
if (*place != RP_INSIDE) return false ;
310
314
} else if (ft == Item_func::GT_FUNC || ft == Item_func::GE_FUNC) {
311
315
/*
312
- Round down the decimal to next integral value, then try to convert
313
- that to a longlong
316
+ Round down (or up) the decimal to next integral value, then try to
317
+ convert that to a longlong
314
318
*/
315
- if (round_fold_or_convert_dec (thd, const_val, place, f, d, false ,
316
- discount_equal))
319
+ if (round_fold_or_convert_dec (thd, const_val, place, f, d,
320
+ !left_has_field, discount_equal))
317
321
return true ;
318
322
if (*place != RP_INSIDE) return false ;
319
323
} else { // for =, <>
@@ -972,6 +976,8 @@ static bool analyze_time_field_constant(THD *thd, Item **const_val) {
972
976
constant (at execution time). May be modified if
973
977
we replace or fold the constant.
974
978
@param func the function of the comparison
979
+ @param left_has_field
980
+ the field is the left operand
975
981
@param[out] place the placement of the const_val relative to
976
982
the range of f
977
983
@param[out] discount_equal
@@ -981,8 +987,9 @@ static bool analyze_time_field_constant(THD *thd, Item **const_val) {
981
987
@returns true on error
982
988
*/
983
989
static bool analyze_field_constant (THD *thd, Item_field *f, Item **const_val,
984
- Item_func *func, Range_placement *place,
985
- bool *discount_equal, bool *negative) {
990
+ Item_func *func, bool left_has_field,
991
+ Range_placement *place, bool *discount_equal,
992
+ bool *negative) {
986
993
*place = RP_INSIDE; // a priori
987
994
988
995
if ((*const_val)->is_null ()) return false ;
@@ -995,8 +1002,8 @@ static bool analyze_field_constant(THD *thd, Item_field *f, Item **const_val,
995
1002
case MYSQL_TYPE_INT24:
996
1003
case MYSQL_TYPE_LONG:
997
1004
case MYSQL_TYPE_LONGLONG:
998
- return analyze_int_field_constant (thd, f, const_val, ft, place ,
999
- discount_equal);
1005
+ return analyze_int_field_constant (thd, f, const_val, ft, left_has_field ,
1006
+ place, discount_equal);
1000
1007
case MYSQL_TYPE_NEWDECIMAL:
1001
1008
return analyze_decimal_field_constant (thd, f, const_val, ft, place,
1002
1009
negative);
@@ -1369,7 +1376,7 @@ bool fold_condition(THD *thd, Item *cond, Item **retcond,
1369
1376
1370
1377
if (analyze_field_constant (
1371
1378
thd, down_cast<Item_field *>(args[!left_has_field]->real_item ()), c,
1372
- func, &place, &discount_eq, &negative))
1379
+ func, left_has_field, &place, &discount_eq, &negative))
1373
1380
return true ; /* purecov: inspected */
1374
1381
1375
1382
if (discount_eq &&
0 commit comments