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

Inconsistent result with JSON_EXTRACT boolean through VIEW/CTE and TEMPORARY TABLE

    XMLWordPrintable

Details

    • Unexpected results

    Description

      I found an inconsistent result involving JSON_EXTRACT(), a JSON boolean value, VIEW/CTE expansion, TEMPORARY TABLE materialization, and a boolean predicate.

      The same query returns different results depending on whether JSON_EXTRACT(c2, '$') is evaluated through a VIEW, a CTE, or a TEMPORARY TABLE.

      The VIEW and CTE versions return one row with true, while the TEMPORARY TABLE version returns an empty set and produces a warning.

      Environment:

      MariaDB version:
      12.2.2-MariaDB-ubu2404

      How to repeat:

      DROP VIEW IF EXISTS v0;
      DROP TEMPORARY TABLE IF EXISTS temp_t;
      DROP TABLE IF EXISTS t0;
       
      CREATE TABLE t0 (
        c2 JSON
      );
       
      INSERT INTO t0 VALUES ('true');
       
      CREATE VIEW v0 AS
      SELECT JSON_EXTRACT(c2, '$') AS vc_1
      FROM t0;
       
      SELECT *
      FROM v0
      WHERE vc_1 OR 0;
       
      WITH CTE AS (
        SELECT JSON_EXTRACT(c2, '$') AS vc_1
        FROM t0
      )
      SELECT *
      FROM CTE
      WHERE vc_1 OR 0;
       
      CREATE TEMPORARY TABLE temp_t AS
      SELECT JSON_EXTRACT(c2, '$') AS vc_1
      FROM t0;
       
      SELECT *
      FROM temp_t
      WHERE vc_1 OR 0;
       
      SHOW WARNINGS;
      

      Actual result:

      The VIEW query returns:

      +------+
      | vc_1 |
      +------+
      | true |
      +------+
      

      The CTE query returns:

      +------+
      | vc_1 |
      +------+
      | true |
      +------+
      

      The TEMPORARY TABLE query returns:

      Empty set, 1 warning
      

      Expected result:

      The VIEW, CTE, and TEMPORARY TABLE forms should be semantically consistent.

      Either all three should return the JSON boolean true row, or all three should reject it under the same boolean conversion rules. They should not produce different results for the same expression and predicate.

      Reason:

      The table contains one JSON value:

      true
      

      The expression is:

      JSON_EXTRACT(c2, '$')
      

      The outer predicate is:

      WHERE vc_1 OR 0
      

      The VIEW and CTE versions evaluate this predicate as true and return the row.

      However, after materializing the same expression into a TEMPORARY TABLE, the same predicate returns an empty set and produces a warning.

      This suggests a possible wrong-result or type/metadata inconsistency involving JSON_EXTRACT(), boolean JSON values, TEMPORARY TABLE materialization, and boolean/numeric conversion in predicates.

      Attachments

        Activity

          People

            rucha174 Rucha Deodhar
            XiaoxuNiu Xiaoyuan Xie
            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.