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

Silent data truncation in derived table due to incorrect width estimation of implicit conversion.

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.11, 11.8.5
    • 10.11, 11.4, 11.8, 12.3
    • Optimizer
    • None
    • OS: Ubuntu 24.04
      DBMS: MariaDB
      Docker image: mariadb:11.8.5
      Image ID: bfe9184ea9e5

    Description

      Summary

      There is a logic inconsistency and data integrity issue where a CONCAT expression involving implicit type conversion results in silent data truncation when evaluated within a derived table, but remains intact in a direct query. The bug appears to stem from the optimizer underestimating the required character width for the materialized temporary table column.

      Reproduction Steps

      CREATE TABLE t0(c0 INT UNIQUE NOT NULL);
       
      INSERT INTO t0 VALUES (-1622683835);
      -- Query A
      SELECT CONCAT(t0.c0, '#',(CONCAT((- ''), 793811274))) AS sig FROM t0 WHERE 1 GROUP BY t0.c0 HAVING (COUNT(t0.c0) != 0);
      -- Query B
      SELECT ref0 FROM (SELECT CONCAT(t0.c0, '#', CONCAT((- ''), 793811274)) AS ref0, ((COUNT(t0.c0) != 0)) AS ref1 FROM t0 WHERE 1 GROUP BY t0.c0) AS s WHERE ref1;
      

      Observed Behavior

      In Query B, the result of the CONCAT operation is truncated. Specifically, the string "0793811274" (result of CONCAT(( ''), 793811274)) is stored as "-079381127". The last character '4' is missing.

      mysql> -- Query A
      mysql> SELECT CONCAT(t0.c0, '#',(CONCAT((- ''), 793811274))) AS sig FROM t0 WHERE 1 GROUP BY t0.c0 HAVING (COUNT(t0.c0) != 0);
      +-------------------------+
      | sig                     |
      +-------------------------+
      | -1622683835#-0793811274 |
      +-------------------------+
      1 row in set, 1 warning (0.00 sec)
       
      mysql> -- Query B
      mysql> SELECT ref0 FROM (SELECT CONCAT(t0.c0, '#', CONCAT((- ''), 793811274)) AS ref0, ((COUNT(t0.c0) != 0)) AS ref1 FROM t0 WHERE 1 GROUP BY t0.c0) AS s WHERE ref1;
      +------------------------+
      | ref0                   |
      +------------------------+
      | -1622683835#-079381127 |
      +------------------------+
      1 row in set, 1 warning (0.00 sec)
      

      Attachments

        Activity

          People

            psergei Sergei Petrunia
            Ce Lyu Ce Lyu
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.