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

Partition COMMENT containing an apostrophe causes CREATE TABLE error under NO_BACKSLASH_ESCAPES

    XMLWordPrintable

Details

    Description

      In MariaDB 12.3.3 on Linux/amd64, the doubled-apostrophe literal 'O''Hara' is accepted as a table-level comment and as a partition comment in the default SQL mode, but the partitioned CREATE TABLE fails with error 1064 when NO_BACKSLASH_ESCAPES is enabled. A partition comment without an apostrophe also succeeds in that mode.

      Run the following statements:

      CREATE DATABASE `partition_comment_test`;
      SET SESSION sql_mode='NO_BACKSLASH_ESCAPES';
      USE `partition_comment_test`;
      SELECT HEX('O''Hara');
      CREATE TABLE `partitioned_table` (id INT) ENGINE=InnoDB PARTITION BY RANGE (id) (PARTITION `range_partition` VALUES LESS THAN (MAXVALUE) COMMENT='O''Hara');

      The SELECT confirms that the literal is valid and evaluates to the expected bytes:

      4F2748617261

      The CREATE TABLE then fails:

      ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' ENGINE = InnoDB)' at line 2

      For comparison, execute these controls independently in the same database and SQL mode:

      CREATE TABLE `plain_partition_comment` (id INT) ENGINE=InnoDB PARTITION BY RANGE (id) (PARTITION `range_partition` VALUES LESS THAN (MAXVALUE) COMMENT='plain');
      CREATE TABLE `table_comment` (id INT) ENGINE=InnoDB COMMENT='O''Hara';

      Both controls succeed. The equivalent partitioned statement also succeeds when NO_BACKSLASH_ESCAPES is disabled. In addition, a partitioned table created in the default mode emits SHOW CREATE TABLE text containing a backslash-escaped apostrophe, and replaying that generated definition under NO_BACKSLASH_ESCAPES fails with the same syntax error.

      CREATE TABLE should accept 'O''Hara' as a partition COMMENT under NO_BACKSLASH_ESCAPES, preserve the bytes 4F2748617261, and emit SHOW CREATE TABLE syntax that can be replayed under the same mode. Current source is consistent with the observed behavior: partition comments are serialized through append_for_single_quote(), which emits backslash escapes, while internal partition-definition parsing can retain NO_BACKSLASH_ESCAPES.

      This occurs when a partition comment containing an apostrophe is created or replayed in a session using NO_BACKSLASH_ESCAPES.

      Attachments

        Issue Links

          Activity

            People

              ycp Yuchen Pei
              noob liu
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - Not Specified
                  Not Specified
                  Logged:
                  Time Spent - 0.75h
                  0.75h

                  Git Integration

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