Commit 030cda30 authored by unknown's avatar unknown

MDEV-4241 fix.

Field_enum incorrectly inherited decimals() from Field_string.
Field_enum should be always integer in numeric context.
parent 2f357344
...@@ -1854,3 +1854,18 @@ a ...@@ -1854,3 +1854,18 @@ a
DROP TABLE t1; DROP TABLE t1;
End of 5.1 tests End of 5.1 tests
#
# MDEV-4241: Assertion failure: scale >= 0 && precision > 0 &&
# scale <= precision in decimal_bin_size
#
CREATE TABLE t1 (
f1 enum('1','2','3','4','5')
) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2);
SELECT AVG(f1) FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def AVG(f1) 246 7 6 Y 128 4 63
AVG(f1)
1.5000
drop table t1;
End of 5.3 tests
......
...@@ -221,3 +221,18 @@ SELECT a FROM t1 WHERE a=0; ...@@ -221,3 +221,18 @@ SELECT a FROM t1 WHERE a=0;
DROP TABLE t1; DROP TABLE t1;
--echo End of 5.1 tests --echo End of 5.1 tests
--echo #
--echo # MDEV-4241: Assertion failure: scale >= 0 && precision > 0 &&
--echo # scale <= precision in decimal_bin_size
--echo #
CREATE TABLE t1 (
f1 enum('1','2','3','4','5')
) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2);
--enable_metadata
SELECT AVG(f1) FROM t1;
--disable_metadata
drop table t1;
--echo End of 5.3 tests
......
...@@ -1982,6 +1982,7 @@ class Field_enum :public Field_str { ...@@ -1982,6 +1982,7 @@ class Field_enum :public Field_str {
bool has_charset(void) const { return TRUE; } bool has_charset(void) const { return TRUE; }
/* enum and set are sorted as integers */ /* enum and set are sorted as integers */
CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; } CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
uint decimals() const { return 0; }
private: private:
int do_save_field_metadata(uchar *first_byte); int do_save_field_metadata(uchar *first_byte);
uint is_equal(Create_field *new_field); uint is_equal(Create_field *new_field);
......
...@@ -1465,7 +1465,9 @@ int decimal_bin_size(int precision, int scale) ...@@ -1465,7 +1465,9 @@ int decimal_bin_size(int precision, int scale)
intg0=intg/DIG_PER_DEC1, frac0=scale/DIG_PER_DEC1, intg0=intg/DIG_PER_DEC1, frac0=scale/DIG_PER_DEC1,
intg0x=intg-intg0*DIG_PER_DEC1, frac0x=scale-frac0*DIG_PER_DEC1; intg0x=intg-intg0*DIG_PER_DEC1, frac0x=scale-frac0*DIG_PER_DEC1;
DBUG_ASSERT(scale >= 0 && precision > 0 && scale <= precision); DBUG_ASSERT(scale >= 0);
DBUG_ASSERT(precision > 0);
DBUG_ASSERT(scale <= precision);
return intg0*sizeof(dec1)+dig2bytes[intg0x]+ return intg0*sizeof(dec1)+dig2bytes[intg0x]+
frac0*sizeof(dec1)+dig2bytes[frac0x]; frac0*sizeof(dec1)+dig2bytes[frac0x];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment