summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/func_group.result11
-rw-r--r--mysql-test/t/func_group.test12
-rw-r--r--sql/field.cc2
-rw-r--r--sql/item_sum.cc6
4 files changed, 26 insertions, 5 deletions
diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result
index 69bce1c8bd8..b90eb2a4c0f 100644
--- a/mysql-test/r/func_group.result
+++ b/mysql-test/r/func_group.result
@@ -1746,4 +1746,15 @@ MAX(LENGTH(a)) LENGTH(MAX(a)) MIN(a) MAX(a) CONCAT(MIN(a)) CONCAT(MAX(a))
20 20 18446668621106209655 18446668621106209655 18446668621106209655 18446668621106209655
DROP TABLE t1;
#
+# Bug #11766270 59343: YEAR(4): INCORRECT RESULT AND VALGRIND WARNINGS WITH MIN/MAX, UNION
+#
+CREATE TABLE t1(f1 YEAR(4));
+INSERT INTO t1 VALUES (0000),(2001);
+(SELECT MAX(f1) FROM t1) UNION (SELECT MAX(f1) FROM t1);
+Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
+def MAX(f1) MAX(f1) 13 4 4 Y 32864 0 63
+MAX(f1)
+2001
+DROP TABLE t1;
+#
End of 5.1 tests
diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test
index 600b46fcde6..177a1ca2471 100644
--- a/mysql-test/t/func_group.test
+++ b/mysql-test/t/func_group.test
@@ -1128,5 +1128,17 @@ SELECT MAX(LENGTH(a)), LENGTH(MAX(a)), MIN(a), MAX(a), CONCAT(MIN(a)), CONCAT(MA
DROP TABLE t1;
--echo #
+--echo # Bug #11766270 59343: YEAR(4): INCORRECT RESULT AND VALGRIND WARNINGS WITH MIN/MAX, UNION
+--echo #
+
+CREATE TABLE t1(f1 YEAR(4));
+INSERT INTO t1 VALUES (0000),(2001);
+--enable_metadata
+(SELECT MAX(f1) FROM t1) UNION (SELECT MAX(f1) FROM t1);
+--disable_metadata
+DROP TABLE t1;
+
+
+--echo #
--echo End of 5.1 tests
diff --git a/sql/field.cc b/sql/field.cc
index 1ad5e408e07..3707c5b056f 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -5467,6 +5467,7 @@ double Field_year::val_real(void)
longlong Field_year::val_int(void)
{
ASSERT_COLUMN_MARKED_FOR_READ;
+ DBUG_ASSERT(field_length == 2 || field_length == 4);
int tmp= (int) ptr[0];
if (field_length != 4)
tmp%=100; // Return last 2 char
@@ -5479,6 +5480,7 @@ longlong Field_year::val_int(void)
String *Field_year::val_str(String *val_buffer,
String *val_ptr __attribute__((unused)))
{
+ DBUG_ASSERT(field_length < 5);
val_buffer->alloc(5);
val_buffer->length(field_length);
char *to=(char*) val_buffer->ptr();
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 2a8aea68f7a..c62738abac0 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -612,17 +612,13 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref)
switch (hybrid_type= item->result_type()) {
case INT_RESULT:
- max_length= 20;
- break;
case DECIMAL_RESULT:
+ case STRING_RESULT:
max_length= item->max_length;
break;
case REAL_RESULT:
max_length= float_length(decimals);
break;
- case STRING_RESULT:
- max_length= item->max_length;
- break;
case ROW_RESULT:
default:
DBUG_ASSERT(0);