Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-12886

Different data type and default for INT and BIGINT columns in a VIEW for a SELECT with ROLLUP

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.0(EOL), 10.1(EOL), 10.2(EOL), 10.3(EOL)
    • 10.3.1
    • Views

    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().

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.