|
|
|
@ -5726,52 +5726,70 @@ get_mm_leaf(RANGE_OPT_PARAM *param, COND *conf_func, Field *field, |
|
|
|
field->type() == MYSQL_TYPE_DATETIME)) |
|
|
|
field->table->in_use->variables.sql_mode|= MODE_INVALID_DATES; |
|
|
|
err= value->save_in_field_no_warnings(field, 1); |
|
|
|
if (err > 0 && field->cmp_type() != value->result_type()) |
|
|
|
if (err > 0) |
|
|
|
{ |
|
|
|
if ((type == Item_func::EQ_FUNC || type == Item_func::EQUAL_FUNC) && |
|
|
|
value->result_type() == item_cmp_type(field->result_type(), |
|
|
|
value->result_type())) |
|
|
|
|
|
|
|
if (field->cmp_type() != value->result_type()) |
|
|
|
{ |
|
|
|
tree= new (alloc) SEL_ARG(field, 0, 0); |
|
|
|
tree->type= SEL_ARG::IMPOSSIBLE; |
|
|
|
goto end; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
/*
|
|
|
|
TODO: We should return trees of the type SEL_ARG::IMPOSSIBLE |
|
|
|
for the cases like int_field > 999999999999999999999999 as well. |
|
|
|
*/ |
|
|
|
tree= 0; |
|
|
|
if (err == 3 && field->type() == FIELD_TYPE_DATE && |
|
|
|
(type == Item_func::GT_FUNC || type == Item_func::GE_FUNC || |
|
|
|
type == Item_func::LT_FUNC || type == Item_func::LE_FUNC) ) |
|
|
|
if ((type == Item_func::EQ_FUNC || type == Item_func::EQUAL_FUNC) && |
|
|
|
value->result_type() == item_cmp_type(field->result_type(), |
|
|
|
value->result_type())) |
|
|
|
{ |
|
|
|
tree= new (alloc) SEL_ARG(field, 0, 0); |
|
|
|
tree->type= SEL_ARG::IMPOSSIBLE; |
|
|
|
goto end; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
/*
|
|
|
|
We were saving DATETIME into a DATE column, the conversion went ok |
|
|
|
but a non-zero time part was cut off. |
|
|
|
TODO: We should return trees of the type SEL_ARG::IMPOSSIBLE |
|
|
|
for the cases like int_field > 999999999999999999999999 as well. |
|
|
|
*/ |
|
|
|
tree= 0; |
|
|
|
if (err == 3 && field->type() == FIELD_TYPE_DATE && |
|
|
|
(type == Item_func::GT_FUNC || type == Item_func::GE_FUNC || |
|
|
|
type == Item_func::LT_FUNC || type == Item_func::LE_FUNC) ) |
|
|
|
{ |
|
|
|
/*
|
|
|
|
We were saving DATETIME into a DATE column, the conversion went ok |
|
|
|
but a non-zero time part was cut off. |
|
|
|
|
|
|
|
In MySQL's SQL dialect, DATE and DATETIME are compared as datetime |
|
|
|
values. Index over a DATE column uses DATE comparison. Changing |
|
|
|
from one comparison to the other is possible: |
|
|
|
In MySQL's SQL dialect, DATE and DATETIME are compared as datetime |
|
|
|
values. Index over a DATE column uses DATE comparison. Changing |
|
|
|
from one comparison to the other is possible: |
|
|
|
|
|
|
|
datetime(date_col)< '2007-12-10 12:34:55' -> date_col<='2007-12-10' |
|
|
|
datetime(date_col)<='2007-12-10 12:34:55' -> date_col<='2007-12-10' |
|
|
|
datetime(date_col)< '2007-12-10 12:34:55' -> date_col<='2007-12-10' |
|
|
|
datetime(date_col)<='2007-12-10 12:34:55' -> date_col<='2007-12-10' |
|
|
|
|
|
|
|
datetime(date_col)> '2007-12-10 12:34:55' -> date_col>='2007-12-10' |
|
|
|
datetime(date_col)>='2007-12-10 12:34:55' -> date_col>='2007-12-10' |
|
|
|
datetime(date_col)> '2007-12-10 12:34:55' -> date_col>='2007-12-10' |
|
|
|
datetime(date_col)>='2007-12-10 12:34:55' -> date_col>='2007-12-10' |
|
|
|
|
|
|
|
but we'll need to convert '>' to '>=' and '<' to '<='. This will |
|
|
|
be done together with other types at the end of this function |
|
|
|
(grep for field_is_equal_to_item) |
|
|
|
*/ |
|
|
|
but we'll need to convert '>' to '>=' and '<' to '<='. This will |
|
|
|
be done together with other types at the end of this function |
|
|
|
(grep for field_is_equal_to_item) |
|
|
|
*/ |
|
|
|
} |
|
|
|
else |
|
|
|
goto end; |
|
|
|
} |
|
|
|
else |
|
|
|
goto end; |
|
|
|
} |
|
|
|
} |
|
|
|
if (err < 0) |
|
|
|
|
|
|
|
/*
|
|
|
|
guaranteed at this point: err > 0; field and const of same type |
|
|
|
If an integer got bounded (e.g. to within 0..255 / -128..127) |
|
|
|
for < or >, set flags as for <= or >= (no NEAR_MAX / NEAR_MIN) |
|
|
|
*/ |
|
|
|
else if (err == 1 && field->result_type() == INT_RESULT) |
|
|
|
{ |
|
|
|
if (type == Item_func::LT_FUNC && (value->val_int() > 0)) |
|
|
|
type = Item_func::LE_FUNC; |
|
|
|
else if (type == Item_func::GT_FUNC && |
|
|
|
!((Field_num*)field)->unsigned_flag && |
|
|
|
!((Item_int*)value)->unsigned_flag && |
|
|
|
(value->val_int() < 0)) |
|
|
|
type = Item_func::GE_FUNC; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (err < 0) |
|
|
|
{ |
|
|
|
field->table->in_use->variables.sql_mode= orig_sql_mode; |
|
|
|
/* This happens when we try to insert a NULL field in a not null column */ |
|
|
|
|