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

SHOW CREATE TABLE produces syntactically incorrect structure

Details

    Description

      Set affected versions to 10.3-10.5 because the commit hasn't been merged up yet.

      create table t (a enum ('x') character set binary);
      show create table t;
      let $def= query_get_value(show create table t,'Create Table',1);
      drop table t;
      eval $def;
       
      # Cleanup
      drop table t;
      

      10.3 32bab2ce

      show create table t;
      Table	Create Table
      t	CREATE TABLE `t` (
        `a` enum('x') CHARACTER SET binary COLLATE binary DEFAULT NULL
      ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
      drop table t;
      CREATE TABLE `t` (
        `a` enum('x') CHARACTER SET binary COLLATE binary DEFAULT NULL
      ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
      bug.t2                                   [ fail ]
              Test ended at 2022-09-17 18:54:54
       
      CURRENT_TEST: bug.t2
      mysqltest: At line 5: query '$def' failed: 1064: 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 'binary DEFAULT NULL
      ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swe...' at line 2
      

      The failure started happening after this commit in 10.3:

      commit f1544424de2b8c9d1c3faefbbdd15543db7dfd12
      Author: Alexander Barkov
      Date:   Fri Sep 2 17:32:14 2022 +0400
       
          MDEV-29446 Change SHOW CREATE TABLE to display default collation
      

      Attachments

        Issue Links

          Activity

            This script:

            DROP TABLE t1;
            CREATE TABLE `t1` (a INT ) CHARSET=binary;
            SHOW CREATE TABLE t1;
            

            also produces a syntactically bad output:

            CREATE TABLE `t1` (
              `a` int(11) DEFAULT NULL
            ) ENGINE=InnoDB DEFAULT CHARSET=binary COLLATE=binary 
            

            bar Alexander Barkov added a comment - This script: DROP TABLE t1; CREATE TABLE `t1` (a INT ) CHARSET= binary ; SHOW CREATE TABLE t1; also produces a syntactically bad output: CREATE TABLE `t1` ( `a` int (11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET= binary COLLATE = binary

            So does this:

            DROP DATABASE IF EXIST db1;
            CREATE DATABASE db1 CHARACTER SET BINARY;
            SHOW CREATE DATABASE db1;
            

            CREATE DATABASE `db1` /*!40100 DEFAULT CHARACTER SET binary COLLATE binary */;
            

            bar Alexander Barkov added a comment - So does this: DROP DATABASE IF EXIST db1; CREATE DATABASE db1 CHARACTER SET BINARY ; SHOW CREATE DATABASE db1; CREATE DATABASE `db1` /*!40100 DEFAULT CHARACTER SET binary COLLATE binary */ ;

            So does this:

            MariaDB [test]> CREATE OR REPLACE FUNCTION f1() RETURNS ENUM('a') CHARACTER SET binary RETURN NULL; 
            Query OK, 0 rows affected (0.004 sec)
             
            MariaDB [test]> SHOW CREATE FUNCTION f1;
            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 'binary
            RETURN NULL' at line 1
            MariaDB [test]> SELECT returns FROM mysql.proc WHERE name='f1';
            +-----------------------------------------+
            | returns                                 |
            +-----------------------------------------+
            | enum('a') CHARSET binary COLLATE binary |
            +-----------------------------------------+
            1 row in set (0.001 sec)
            

            Notice, the erroneous syntax gets written to mysql.proc, so SHOW CREATE FUNCTION can't parse the syntax and returns an error.

            bar Alexander Barkov added a comment - So does this: MariaDB [test]> CREATE OR REPLACE FUNCTION f1() RETURNS ENUM( 'a' ) CHARACTER SET binary RETURN NULL ; Query OK, 0 rows affected (0.004 sec)   MariaDB [test]> SHOW CREATE FUNCTION f1; 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 'binary RETURN NULL' at line 1 MariaDB [test]> SELECT returns FROM mysql.proc WHERE name = 'f1' ; + -----------------------------------------+ | returns | + -----------------------------------------+ | enum( 'a' ) CHARSET binary COLLATE binary | + -----------------------------------------+ 1 row in set (0.001 sec) Notice, the erroneous syntax gets written to mysql.proc, so SHOW CREATE FUNCTION can't parse the syntax and returns an error.

            People

              bar Alexander Barkov
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              4 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.