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

Inconsistent string comparison behavior for JSON_UNQUOTE(BLOB) between dynamic evaluation and CTAS materialized column

    XMLWordPrintable

Details

    Description

      An inconsistency in query result occurs when comparing a CHAR column with JSON_UNQUOTE(c0) on a LONGBLOB column directly in a WHERE clause, compared to evaluating the same predicate against a materialized column created via CREATE TABLE ... AS SELECT (CTAS).

      Specifically:
      In base table t0, JSON_UNQUOTE(c0) operates dynamically on a LONGBLOB field 'cuETwagc6Hr1YZ6irrL'. The predicate c1 > JSON_UNQUOTE(c0) evaluates to TRUE (returning 1 row).
      In derived table t1 (created via CREATE TABLE t1 AS SELECT JSON_UNQUOTE(c0) AS c0, c1 FROM t0), CTAS derives a specific text data type/collation for column c0. The predicate c1 > c0 evaluates under standard string comparison logic ('K...' < 'c...') to FALSE (returning Empty set).
      How to repeat:
      DROP DATABASE IF EXISTS test;
      CREATE DATABASE test;
      USE test;

      – Step 1: Create base table t0 with LONGBLOB and CHAR columns
      CREATE TABLE t0 (c0 LONGBLOB, c1 CHAR(14));

      – Step 2: Insert sample values
      INSERT INTO t0 (c0, c1) VALUES ('cuETwagc6Hr1YZ6irrL', 'Klm5WQ1XwAGHdx');

      – Step 3: Materialize table via CTAS
      CREATE TABLE t1 AS SELECT (JSON_UNQUOTE(c0)) AS c0, c1 AS c1 FROM t0;

      – Query 1: Dynamic evaluation on base table t0
      SELECT (JSON_UNQUOTE(c0)) FROM t0 WHERE c1 > (JSON_UNQUOTE(c0));
      – Returns: 1 row ('cuETwagc6Hr1YZ6irrL')

      – Query 2: Evaluation on materialized table t1
      SELECT (c0) FROM t1 WHERE c1 > (c0);
      – Returns: Empty set (0 rows)

      Attachments

        Issue Links

          Activity

            People

              holyfoot Alexey Botchkov
              XiaoxuNiu Xiaoyuan Xie
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 0d
                  0d
                  Remaining:
                  Remaining Estimate - 1d
                  1d
                  Logged:
                  Time Spent - Not Specified
                  Not Specified

                  Git Integration

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