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

NULLIF-wrapped integer multiplication reports VARCHAR(3) for the value 9801

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 10.11, 11.4, 11.8, 12.3, 13.1, 12.3.3
    • 10.11, 11.4, 11.8, 12.3, 13.1
    • Data types
    • None
    • Linux x86_64, MariaDB.org Ubuntu 24.04 binary distribution

    Description

      A multiplication whose integer operands are wrapped in NULLIF produces the four-character value 9801, but MariaDB infers VARCHAR(3) when the expression is passed to CONCAT. The equivalent multiplication without NULLIF is inferred as VARCHAR(5). This was reproduced on MariaDB 12.3.3.

      This occurs when metadata is inferred for a string expression containing multiplication of NULLIF-wrapped integer literals.

      Steps to reproduce

      1. Save the following as test.sql. The zero-row CREATE TEMPORARY TABLE ... SELECT exposes the inferred metadata without introducing an insertion or SQL-mode error.

      CREATE DATABASE width_test;
      USE width_test;
      CREATE TEMPORARY TABLE widths AS
      SELECT CONCAT(NULLIF(99,0) * NULLIF(99,0)) AS wrapped,
             CONCAT(99 * 99) AS direct
      WHERE FALSE;
      SHOW COLUMNS FROM widths;
      SELECT 'values' AS case_name,
       CONCAT(NULLIF(99,0) * NULLIF(99,0)), CONCAT(99 * 99);
      DROP TEMPORARY TABLE widths;
      DROP DATABASE width_test;

      1. Run the script with the MariaDB client:

      mariadb < test.sql

      Actual result

      The recorded execution returned:

      Field    Type        Null  Key  Default  Extra
      wrapped  varchar(3)  YES        NULL
       direct  varchar(5)  YES        NULL
       
      values   9801        9801

      The NULLIF-wrapped expression therefore generates four characters but is assigned a declared width of three.

      Expected result

      The inferred type of each expression should be wide enough to hold the value generated by that expression. Exact equality between the two inferred widths is not required, and the direct expression may remain conservatively sized, but wrapped must be at least VARCHAR(4) for 9801.

      Source context

      The supplied source suggests that NULLIF copies result attributes from its operand without the generic normalization used by some other expression wrappers. Generic integer precision is then derived from that display width, and multiplication uses the operand precisions to determine its result width. This is consistent with the observed VARCHAR(3) metadata, but is presented as a source-supported explanation rather than a proven complete root cause.

      Attachments

        Activity

          People

            raghunandan.bhat Raghunandan Bhat
            Milo liu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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