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

Optimizer Trace Produces Invalid JSON for Quoted Table Alias

    XMLWordPrintable

Details

    • Not for Release Notes

    Description

      Hi,

      I found MariaDB produces invalid JSON in optimizer trace output when a table alias contains a double quote. The query itself runs successfully, but the generated trace is malformed because the double quote in the alias is not escaped correctly.

      This test case can reproduce this:

      CREATE TABLE t(a INT);
      INSERT INTO t VALUES (1);
       
      SET optimizer_trace='enabled=on';
       
      SELECT * FROM t AS `a"b` WHERE a=1;
       
      -- a
      -- 1
       
      SELECT JSON_VALID(trace) AS optimizer_trace_is_valid_json FROM information_schema.optimizer_trace; -- 0
       
      EXPLAIN FORMAT=JSON
      SELECT * FROM t AS `a"b` WHERE a=1;
       
      EXPLAIN
      {
        "query_block": {
          "select_id": 1,
          "cost": 0.0110178,
          "nested_loop": [
            {
              "table": {
                "table_name": "a"b",
                "access_type": "ALL",
                "loops": 1,
                "rows": 1,
                "cost": 0.0110178,
                "filtered": 100,
                "attached_condition": "`a"b`.a = 1"
              }
            }
          ]
        }
      }
      

      I can reproduce this with the commit version f6e44c1b7819f9befa3824f07866822288231528 of MariaDB server on github repo.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ChiZhang Chi Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.