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

Non-strict XMLTYPE cast returns NULL but IS NULL evaluates false

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 12.3, 13.1, 12.3.3
    • 12.3, 13.1
    • XML
    • Linux/amd64

    Description

      In MariaDB 12.3.3 on Linux/amd64, casting invalid XML text to XMLTYPE in a non-strict session returns NULL, but applying IS NULL to the same expression returns false. A WHERE clause using the predicate consequently omits the affected row.

      Reproducer

      CREATE DATABASE xml_cast_case;
      USE xml_cast_case;
      CREATE TABLE xml_samples(id INT PRIMARY KEY,a VARCHAR(20) NOT NULL) ENGINE=InnoDB;
      INSERT INTO xml_samples VALUES(1,'<a/>'),(2,'text');
      SET SESSION sql_mode='';
      SELECT 'c_projection',id,CAST(a AS XMLTYPE) FROM xml_samples ORDER BY id;
      SELECT 'c_predicate',id,CAST(a AS XMLTYPE) IS NULL FROM xml_samples ORDER BY id;
      SELECT 'c_filter',COUNT(*) FROM xml_samples WHERE CAST(a AS XMLTYPE) IS NULL;
      SET SESSION sql_mode='STRICT_TRANS_TABLES';
      SELECT 'c_strict',id,CAST(a AS XMLTYPE) IS NULL FROM xml_samples ORDER BY id;
      SELECT 'c_strict_filter',COUNT(*) FROM xml_samples WHERE CAST(a AS XMLTYPE) IS NULL;

      The client returns:

      c_projection	1	<a/>
      c_projection	2	NULL
      c_predicate	1	0
      c_predicate	2	0
      c_filter	0
      c_strict	1	0
      c_strict	2	1
      c_strict_filter	1

      The non-strict projection returns NULL for row 2, while IS NULL returns 0 and the filter matches no rows. In strict mode, IS NULL returns 1 for the same row and the filter matches it.

      Whenever CAST(a AS XMLTYPE) evaluates to NULL, CAST(a AS XMLTYPE) IS NULL should evaluate to true, and a WHERE clause using that predicate should select the row. This follows from SQL null-predicate semantics and should not depend on strictness mode.

      Enabling strict mode or validating XML before casting provides a workaround.

      This occurs when invalid XML text is cast to XMLTYPE and tested with IS NULL in a non-strict session.

      Attachments

        Issue Links

          Activity

            People

              holyfoot Alexey Botchkov
              faner fan
              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.