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

Reading data from view with useless comparison results in inconsistent data type

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 10.5(EOL), 10.9(EOL)
    • None
    • None
    • None

    Description

      When reading data from a view into a stored table, the datatype will be read incorrectly when the field has a strange IF(comparison, field1, field2)/CASE structure in the view, where the comparison is non-sensical.

      Example for the non-sensical comparison:
      Both field1 and field2 are NULLABLE DOUBLE(3,1), and can never contain an empty string as a value.
      Comparison: IF(field1 IS NULL OR field1 = '', field2, field1)

      Tested on 10.5 and 10.9 (on Fedora Linux), with "DOUBLE(3,1)" (signed and unsigned), but presumably at least other floating point fields will have the same issue.

      Minimal recreation:
      CREATE TABLE doubleValues (
      id INT PRIMARY KEY auto_increment,
      dbl1 double(3,1) NULL,
      dbl2 double(3,1) NULL
      );

      CREATE OR REPLACE VIEW doubleValues_view AS
      SELECT id, IF(dbl1 is NULL OR dbl1 = '', dbl2, dbl1) as dbl
      FROM doubleValues;

      CREATE TABLE doubleReadValues (
      id INT PRIMARY KEY,
      dbl double(3,1) NULL
      );

      INSERT INTO doubleValues (dbl1, dbl2) VALUES (null, 2.0), (1.0, 4.2), (3, null);

      INSERT INTO doubleReadValues (id, dbl)
      SELECT id, dbl FROM doubleValues_view;

      This will result in the following error:
      [22007][1292] (conn=1068) Truncated incorrect DOUBLE value: ''

      Obviously, the correct course of action is remove the unnecessary comparison for an empty string. But it was a bit of a long walk to find the actual error in our real database.

      Attachments

        Activity

          People

            Unassigned Unassigned
            chofer Carla Hofer
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.