Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
10.1(EOL), 10.2(EOL), 10.3(EOL)
Description
I run this script:
SET sql_mode=STRICT_ALL_TABLES; |
DROP TABLE IF EXISTS t1; |
CREATE TABLE t1 ( |
id bigint(11) NOT NULL PRIMARY KEY, |
dt datetime(6)
|
);
|
INSERT INTO t1 VALUES (1,'2001-01-01 11:22:33.123456'); |
CREATE OR REPLACE VIEW v1 AS SELECT EXTRACT(MINUTE_MICROSECOND FROM dt) AS dt2 FROM t1; |
DESCRIBE v1;
|
SELECT * FROM v1; |
It correctly reports that the data type for EXTRACT(MINUTE_MICROSECOND) is BIGINT:
+-------+------------+------+-----+---------+-------+
|
| Field | Type | Null | Key | Default | Extra |
|
+-------+------------+------+-----+---------+-------+
|
| dt2 | bigint(11) | YES | | NULL | |
|
+-------+------------+------+-----+---------+-------+
|
and returns the correct value which is outside of the signed 32-bit range:
+------------+
|
| dt2 |
|
+------------+
|
| 2233123456 |
|
+------------+
|
Now I want to create a table as follows:
CREATE OR REPLACE TABLE t2 AS SELECT MAX(dt2) FROM v1; |
It unexpectedly returns an error:
ERROR 1264 (22003): Out of range value for column 'MAX(dt2)' at row 2
|
Adding LIMIT 0 shows that it erroneously creates an INT rather than BIGINT column:
CREATE OR REPLACE TABLE t2 AS SELECT MAX(dt2) FROM v1 LIMIT 0; |
DESCRIBE t2;
|
+----------+---------+------+-----+---------+-------+
|
| Field | Type | Null | Key | Default | Extra |
|
+----------+---------+------+-----+---------+-------+
|
| MAX(dt2) | int(11) | YES | | NULL | |
|
+----------+---------+------+-----+---------+-------+
|
The problem is in Item_sum::create_tmp_field:
Field *create_tmp_field(bool group, TABLE *table) |
{
|
return Item::create_tmp_field(group, table, MY_INT32_NUM_DECIMAL_DIGITS); |
}
|
It creates BIGINT only if max_char_length() is greater than MY_INT32_NUM_DECIMAL_DIGITS, i.e. starting from 12.
Attachments
Issue Links
- blocks
-
MDEV-4912 Data type plugin API version 1
-
- Closed
-
- relates to
-
MDEV-12858 Out-of-range error for CREATE..SELECT unsigned_int_column+1
-
- Closed
-
-
MDEV-12859 Out-of-range error for CREATE..SELECT @a:=EXTRACT(MINUTE_MICROSECOND FROM..)
-
- Closed
-
Activity
Field | Original Value | New Value |
---|---|---|
Component/s | OTHER [ 10125 ] |
Labels | datatype |
Link |
This issue relates to |
Link |
This issue relates to |
Description |
I run this script:
{code:sql} SET sql_mode=STRICT_ALL_TABLES; DROP TABLE IF EXISTS t1; CREATE TABLE t1 ( id bigint(11) NOT NULL PRIMARY KEY, dt datetime(6) ); INSERT INTO t1 VALUES (1,'2001-01-01 11:22:33.123456'); CREATE OR REPLACE VIEW v1 AS SELECT EXTRACT(MINUTE_MICROSECOND FROM dt) AS dt2 FROM t1; DESCRIBE v1; SELECT * FROM v1; {code} It correctly reports that the data type for {{EXTRACT(MINUTE_MICROSECOND)}} is {{BIGINT}}: {noformat} +-------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------+------+-----+---------+-------+ | dt2 | bigint(11) | YES | | NULL | | +-------+------------+------+-----+---------+-------+ {noformat} and returns the correct value which is outside of the 32-bit range: {noformat} +------------+ | dt2 | +------------+ | 2233123456 | +------------+ {noformat} Now I want to create a table as follows: {code:sql} CREATE OR REPLACE TABLE t2 AS SELECT MAX(dt2) FROM v1; {code} It unexpectedly returns an error: {noformat} ERROR 1264 (22003): Out of range value for column 'MAX(dt2)' at row 2 {noformat} Adding {{LIMIT 0}} shows that it erroneously creates an {{INT}} rather than {{BIGINT}} column: {code:sql} CREATE OR REPLACE TABLE t2 AS SELECT MAX(dt2) FROM v1 LIMIT 0; DESCRIBE t2; {code} {noformat} +----------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+---------+------+-----+---------+-------+ | MAX(dt2) | int(11) | YES | | NULL | | +----------+---------+------+-----+---------+-------+ {noformat} The problem is in {{Item_sum::create_tmp_field}}: {code:cpp} Field *create_tmp_field(bool group, TABLE *table) { return Item::create_tmp_field(group, table, MY_INT32_NUM_DECIMAL_DIGITS); } {code} It creates {{BIGINT}} only if {{max_char_length()}} is greater than {{MY_INT32_NUM_DECIMAL_DIGITS}}, i.e. starting from {{12}}. |
I run this script:
{code:sql} SET sql_mode=STRICT_ALL_TABLES; DROP TABLE IF EXISTS t1; CREATE TABLE t1 ( id bigint(11) NOT NULL PRIMARY KEY, dt datetime(6) ); INSERT INTO t1 VALUES (1,'2001-01-01 11:22:33.123456'); CREATE OR REPLACE VIEW v1 AS SELECT EXTRACT(MINUTE_MICROSECOND FROM dt) AS dt2 FROM t1; DESCRIBE v1; SELECT * FROM v1; {code} It correctly reports that the data type for {{EXTRACT(MINUTE_MICROSECOND)}} is {{BIGINT}}: {noformat} +-------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------+------+-----+---------+-------+ | dt2 | bigint(11) | YES | | NULL | | +-------+------------+------+-----+---------+-------+ {noformat} and returns the correct value which is outside of the signed 32-bit range: {noformat} +------------+ | dt2 | +------------+ | 2233123456 | +------------+ {noformat} Now I want to create a table as follows: {code:sql} CREATE OR REPLACE TABLE t2 AS SELECT MAX(dt2) FROM v1; {code} It unexpectedly returns an error: {noformat} ERROR 1264 (22003): Out of range value for column 'MAX(dt2)' at row 2 {noformat} Adding {{LIMIT 0}} shows that it erroneously creates an {{INT}} rather than {{BIGINT}} column: {code:sql} CREATE OR REPLACE TABLE t2 AS SELECT MAX(dt2) FROM v1 LIMIT 0; DESCRIBE t2; {code} {noformat} +----------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+---------+------+-----+---------+-------+ | MAX(dt2) | int(11) | YES | | NULL | | +----------+---------+------+-----+---------+-------+ {noformat} The problem is in {{Item_sum::create_tmp_field}}: {code:cpp} Field *create_tmp_field(bool group, TABLE *table) { return Item::create_tmp_field(group, table, MY_INT32_NUM_DECIMAL_DIGITS); } {code} It creates {{BIGINT}} only if {{max_char_length()}} is greater than {{MY_INT32_NUM_DECIMAL_DIGITS}}, i.e. starting from {{12}}. |
Status | Open [ 1 ] | In Progress [ 3 ] |
Fix Version/s | 10.3.1 [ 22532 ] | |
Fix Version/s | 10.3 [ 22126 ] | |
Resolution | Fixed [ 1 ] | |
Status | In Progress [ 3 ] | Closed [ 6 ] |
Workflow | MariaDB v3 [ 80872 ] | MariaDB v4 [ 152190 ] |
Pushed to bb-10.2-ext