Uploaded image for project: 'MariaDB MaxScale'
  1. MariaDB MaxScale
  2. MXS-5266

Query canonicalization does not take SQL mode into account

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Trivial
    • Resolution: Unresolved
    • 21.06.17, 22.08.14, 23.02.11, 23.08.7, 24.02.3, 24.08.0
    • None
    • QueryClassifier
    • None

    Description

      The following queries:

      SELECT user, host FROM mysql.user WHERE "user" = 'foobar';
      SELECT user, host FROM mysql.user WHERE 'user' = 'foobar';
      

      both have the canonical form:

      SELECT user, host FROM mysql.user WHERE ? = ?;
      

      However, if the first query was this instead:

      SELECT user, host FROM mysql.user WHERE `user` = "foobar";
      

      The result would be:

      SELECT user, host FROM mysql.user WHERE `user` = ?;
      

      These two queries are only identical if ANSI_QUOTES SQL mode is not enabled. A common case where it is enabled is SQL_MODE=ORACLE.

      The query canonical form computation must have distinct modes of operation depending on the value of ANSI_QUOTES. Otherwise the fields accessed by the query are not accurate and the reported access statistics for it are potentially over-inflated.

      The actual effects of this are quite limited: the query type does not change if the value is a string constant or a field name and all important variables, when used as field names, would not affect the functionality of the query in any meaningful way.

      The only actual problem that it will cause is if a temporary table is created and it's accessed when SQL_MODE=ORACLE is used.

      SET SQL_MODE=ORACLE;
      CREATE TEMPORARY TABLE t1(id INT) AS SELECT 1 id;
      CREATE TABLE t2(id INT) AS SELECT 2 id;
      SELECT * FROM "t1" WHERE id <> 0;
      SELECT * FROM "t2" WHERE id <> 0;
      

      In the example above, the access to "t2" is mistaken as a read from a temporary table as it uses the query classification information of that was generated by the first select.

      Attachments

        Activity

          People

            Unassigned Unassigned
            markus makela markus makela
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.