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

LP:607177 - Virtual columns do not evaluate properly with set/enum and certain expressions

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • None
    • None
    • None

    Description

      set/enum columns that participate in virtual columns may lead to wrong results depending on the virtual column expression. There may be a deeper underlying problem since sometimes the expression is not evaluated properly even without a virtual column.

      The test case below evaluates one and the same expression in a virtual column context and as a normal expression in the SELECT list.

      SET @c1 = "
      CREATE TABLE `X` (
      `f1` int(11) NOT NULL DEFAULT '0',
      `f4` enum('0','1','2') NOT NULL DEFAULT '0',
      `v4` double AS
      ";

      SET @virtcol_def = " ( ROUND( 1 , NULLIF( f4 , 1 AND f1 ) ) ) ";
      SET @create = CONCAT(@c1, @virtcol_def, ")");

      PREPARE cs FROM @create;
      EXECUTE cs;

      INSERT INTO `X` (f1, f4) VALUES (7,'0');
      INSERT INTO `X` (f1, f4) VALUES (7,'0');

      SET @s1 = CONCAT("SELECT f1, f4, CAST( ",@virtcol_def," AS SIGNED) AS c1 , v4 FROM X");
      PREPARE st1 FROM @s1;
      EXECUTE st1;

      The result set is as follows:

      f1 f4 c1 v4
      7 0 1 NULL
      7 0 NULL NULL

      The first two columns show that the underlying rows of the table are the same and there is no reason for the expression to return NULL or to return a different result for each row. However, the expression does return NULL when used in a virtual column and it does return a different result for each row when used as a standard expression in the SELECT list.

      Attachments

        Activity

          People

            igor Igor Babaev (Inactive)
            philipstoev Philip Stoev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 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.