[MDEV-12886] Different data type and default for INT and BIGINT columns in a VIEW for a SELECT with ROLLUP Created: 2017-05-24  Updated: 2017-05-27  Resolved: 2017-05-25

Status: Closed
Project: MariaDB Server
Component/s: Views
Affects Version/s: 10.0, 10.1, 10.2, 10.3
Fix Version/s: 10.3.1

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: datatype

Issue Links:
Relates
relates to MDEV-9410 VIEW over a ROLLUP query reports too ... Closed

 Description   

I run this script:

CREATE OR REPLACE TABLE t1 (a int(11) NOT NULL);
INSERT INTO t1 VALUES (1),(2);
CREATE OR REPLACE VIEW v1 AS SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
DESCRIBE v1;

+-----------+------------+------+-----+---------+-------+
| Field     | Type       | Null | Key | Default | Extra |
+-----------+------------+------+-----+---------+-------+
| a         | bigint(11) | YES  |     | NULL    |       |
| LENGTH(a) | bigint(10) | YES  |     | NULL    |       |
| COUNT(*)  | bigint(21) | NO   |     | 0       |       |
+-----------+------------+------+-----+---------+-------+

Notice, it reports the data type of v1.a as BIGINT for some reasons. The expected data type is INT.

Now I change the data type from int to bigint:

CREATE OR REPLACE TABLE t1 (a bigint(11) NOT NULL);
INSERT INTO t1 VALUES (1),(2);
CREATE OR REPLACE VIEW v1 AS SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
DESCRIBE v1;

+-----------+------------+------+-----+---------+-------+
| Field     | Type       | Null | Key | Default | Extra |
+-----------+------------+------+-----+---------+-------+
| a         | bigint(20) | YES  |     | 0       |       |
| LENGTH(a) | bigint(10) | YES  |     | NULL    |       |
| COUNT(*)  | bigint(21) | NO   |     | 0       |       |
+-----------+------------+------+-----+---------+-------+

Notice, field "a" has different default:

  • NULL for int
  • 0 for BIGINT.

Looks suspicious.

The difference happens because int does not pass this condition, while bigint does:

    if (orig_type != Item::DEFAULT_VALUE_ITEM && field->field->eq_def(result))
      *default_field= field->field;

See sql_select.cc, create_tmp_field().



 Comments   
Comment by Alexander Barkov [ 2017-05-25 ]

Pushed to bb-10.2-ext.

Reporting 5 hours, as it took around 15 hours for a joint patch fixing 3 bugs:

  • MDEV-12875 Wrong VIEW column data type for COALESCE(int_column)
  • MDEV-12886 Different default for INT and BIGINT column in a VIEW for a SELECT with ROLLUP
  • MDEV-12916 Wrong column data type for an INT field of a cursor-anchored ROW variable
Generated at Thu Feb 08 08:01:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.