summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 57dff4b23a5..54ea4a8496c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -8869,8 +8869,13 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
item->name, table, item->decimals, TRUE);
break;
case INT_RESULT:
- /* Select an integer type with the minimal fit precision */
- if (item->max_length > MY_INT32_NUM_DECIMAL_DIGITS)
+ /*
+ Select an integer type with the minimal fit precision.
+ MY_INT32_NUM_DECIMAL_DIGITS is sign inclusive, don't consider the sign.
+ Values with MY_INT32_NUM_DECIMAL_DIGITS digits may or may not fit into
+ Field_long : make them Field_longlong.
+ */
+ if (item->max_length >= (MY_INT32_NUM_DECIMAL_DIGITS - 1))
new_field=new Field_longlong(item->max_length, maybe_null,
item->name, table, item->unsigned_flag);
else