[Commits] Rev 4274: small cleanup of the SHOW CREATE TABLE code in lp:~maria-captains/maria/10.0

Sergei Golubchik serg at mariadb.org
Sun Jul 6 00:42:16 EEST 2014


At lp:~maria-captains/maria/10.0

------------------------------------------------------------
revno: 4274
revision-id: sergii at pisem.net-20140705214216-npqtc7tz854xqjxo
parent: sergii at pisem.net-20140704190257-1z1inye8jd7k7umc
committer: Sergei Golubchik <sergii at pisem.net>
branch nick: 10.0
timestamp: Sat 2014-07-05 23:42:16 +0200
message:
  small cleanup of the SHOW CREATE TABLE code
=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2014-03-28 07:31:24 +0000
+++ b/sql/sql_insert.cc	2014-07-05 21:42:16 +0000
@@ -4135,15 +4135,14 @@ select_create::binlog_show_create_table(
 {
   /*
     Note 1: In RBR mode, we generate a CREATE TABLE statement for the
-    created table by calling store_create_info() (behaves as SHOW
-    CREATE TABLE).  In the event of an error, nothing should be
-    written to the binary log, even if the table is non-transactional;
-    therefore we pretend that the generated CREATE TABLE statement is
-    for a transactional table.  The event will then be put in the
-    transaction cache, and any subsequent events (e.g., table-map
-    events and binrow events) will also be put there.  We can then use
-    ha_autocommit_or_rollback() to either throw away the entire
-    kaboodle of events, or write them to the binary log.
+    created table by calling show_create_table().  In the event of an error,
+    nothing should be written to the binary log, even if the table is
+    non-transactional; therefore we pretend that the generated CREATE TABLE
+    statement is for a transactional table.  The event will then be put in the
+    transaction cache, and any subsequent events (e.g., table-map events and
+    binrow events) will also be put there.  We can then use
+    ha_autocommit_or_rollback() to either throw away the entire kaboodle of
+    events, or write them to the binary log.
 
     We write the CREATE TABLE statement here and not in prepare()
     since there potentially are sub-selects or accesses to information
@@ -4162,12 +4161,9 @@ select_create::binlog_show_create_table(
   tmp_table_list.table = *tables;
   query.length(0);      // Have to zero it since constructor doesn't
 
-  result= store_create_info(thd, &tmp_table_list, &query, create_info,
-                            /* show_database */ TRUE,
-                            MY_TEST(create_info->org_options &
-                                    HA_LEX_CREATE_REPLACE) ||
-                            create_info->table_was_deleted);
-  DBUG_ASSERT(result == 0); /* store_create_info() always return 0 */
+  result= show_create_table(thd, &tmp_table_list, &query, create_info,
+                            WITH_DB_NAME);
+  DBUG_ASSERT(result == 0); /* show_create_table() always return 0 */
 
   if (mysql_bin_log.is_open())
   {

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2014-06-05 22:07:27 +0000
+++ b/sql/sql_show.cc	2014-07-05 21:42:16 +0000
@@ -116,8 +116,9 @@ static void get_cs_converted_string_valu
                                           bool use_hex);
 #endif
 
-static void
-append_algorithm(TABLE_LIST *table, String *buff);
+static int show_create_view(THD *thd, TABLE_LIST *table, String *buff);
+
+static void append_algorithm(TABLE_LIST *table, String *buff);
 
 static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table);
 
@@ -1063,9 +1064,8 @@ mysqld_show_create(THD *thd, TABLE_LIST
     buffer.set_charset(table_list->view_creation_ctx->get_client_cs());
 
   if ((table_list->view ?
-       view_store_create_info(thd, table_list, &buffer) :
-       store_create_info(thd, table_list, &buffer, NULL,
-                         FALSE /* show_database */, FALSE)))
+       show_create_view(thd, table_list, &buffer) :
+       show_create_table(thd, table_list, &buffer, NULL, WITHOUT_DB_NAME)))
     goto exit;
 
   if (table_list->view)
@@ -1541,7 +1541,7 @@ static void append_create_options(THD *t
   Build a CREATE TABLE statement for a table.
 
   SYNOPSIS
-    store_create_info()
+    show_create_table()
     thd               The thread
     table_list        A list containing one table to write statement
                       for.
@@ -1551,8 +1551,7 @@ static void append_create_options(THD *t
                       to tailor the format of the statement.  Can be
                       NULL, in which case only SQL_MODE is considered
                       when building the statement.
-    show_database     Add database name to table name
-    create_or_replace Use CREATE OR REPLACE syntax
+    with_db_name     Add database name to table name
 
   NOTE
     Currently always return 0, but might return error code in the
@@ -1562,9 +1561,9 @@ static void append_create_options(THD *t
     0       OK
  */
 
-int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
-                      HA_CREATE_INFO *create_info_arg, bool show_database,
-                      bool create_or_replace)
+int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
+                      HA_CREATE_INFO *create_info_arg,
+                      enum_with_db_name with_db_name)
 {
   List<Item> field_list;
   char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
@@ -1578,27 +1577,32 @@ int store_create_info(THD *thd, TABLE_LI
   handler *file= table->file;
   TABLE_SHARE *share= table->s;
   HA_CREATE_INFO create_info;
-#ifdef WITH_PARTITION_STORAGE_ENGINE
   bool show_table_options= FALSE;
-#endif /* WITH_PARTITION_STORAGE_ENGINE */
-  bool foreign_db_mode=  (thd->variables.sql_mode & (MODE_POSTGRESQL |
-                                                     MODE_ORACLE |
-                                                     MODE_MSSQL |
-                                                     MODE_DB2 |
-                                                     MODE_MAXDB |
-                                                     MODE_ANSI)) != 0;
-  bool limited_mysql_mode= (thd->variables.sql_mode & (MODE_NO_FIELD_OPTIONS |
-                                                       MODE_MYSQL323 |
-                                                       MODE_MYSQL40)) != 0;
+  sql_mode_t sql_mode= thd->variables.sql_mode;
+  bool foreign_db_mode=  sql_mode & (MODE_POSTGRESQL | MODE_ORACLE |
+                                     MODE_MSSQL | MODE_DB2 |
+                                     MODE_MAXDB | MODE_ANSI);
+  bool limited_mysql_mode= sql_mode & (MODE_NO_FIELD_OPTIONS | MODE_MYSQL323 |
+                                       MODE_MYSQL40);
+  handlerton *hton;
   my_bitmap_map *old_map;
   int error= 0;
-  DBUG_ENTER("store_create_info");
+  DBUG_ENTER("show_create_table");
   DBUG_PRINT("enter",("table: %s", table->s->table_name.str));
 
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+  if (table->part_info)
+    hton= table->part_info->default_engine_type;
+  else
+#endif
+    hton= file->ht;
+
   restore_record(table, s->default_values); // Get empty record
 
   packet->append(STRING_WITH_LEN("CREATE "));
-  if (create_or_replace)
+  if (create_info_arg &&
+      (create_info_arg->org_options & HA_LEX_CREATE_REPLACE ||
+       create_info_arg->table_was_deleted))
     packet->append(STRING_WITH_LEN("OR REPLACE "));
   if (share->tmp_table)
     packet->append(STRING_WITH_LEN("TEMPORARY "));
@@ -1625,7 +1629,7 @@ int store_create_info(THD *thd, TABLE_LI
     avoid having to update gazillions of tests and result files, but
     it also saves a few bytes of the binary log.
    */
-  if (show_database)
+  if (with_db_name == WITH_DB_NAME)
   {
     const LEX_STRING *const db=
       table_list->schema_table ? &INFORMATION_SCHEMA_NAME : &table->s->db;
@@ -1664,8 +1668,7 @@ int store_create_info(THD *thd, TABLE_LI
     field->sql_type(type);
     packet->append(type.ptr(), type.length(), system_charset_info);
 
-    if (field->has_charset() &&
-        !(thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)))
+    if (field->has_charset() && !(sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)))
     {
       if (field->charset() != share->table_charset)
       {
@@ -1722,7 +1725,7 @@ int store_create_info(THD *thd, TABLE_LI
 
 
     if (field->unireg_check == Field::NEXT_NUMBER &&
-        !(thd->variables.sql_mode & MODE_NO_FIELD_OPTIONS))
+        !(sql_mode & MODE_NO_FIELD_OPTIONS))
       packet->append(STRING_WITH_LEN(" AUTO_INCREMENT"));
 
     if (field->comment.length)
@@ -1812,11 +1815,9 @@ int store_create_info(THD *thd, TABLE_LI
   }
 
   packet->append(STRING_WITH_LEN("\n)"));
-  if (!(thd->variables.sql_mode & MODE_NO_TABLE_OPTIONS) && !foreign_db_mode)
+  if (!(sql_mode & MODE_NO_TABLE_OPTIONS) && !foreign_db_mode)
   {
-#ifdef WITH_PARTITION_STORAGE_ENGINE
     show_table_options= TRUE;
-#endif /* WITH_PARTITION_STORAGE_ENGINE */
 
     /*
       IF   check_create_info
@@ -1825,19 +1826,11 @@ int store_create_info(THD *thd, TABLE_LI
     if (!create_info_arg ||
         (create_info_arg->used_fields & HA_CREATE_USED_ENGINE))
     {
-      if (thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40))
+      if (sql_mode & (MODE_MYSQL323 | MODE_MYSQL40))
         packet->append(STRING_WITH_LEN(" TYPE="));
       else
         packet->append(STRING_WITH_LEN(" ENGINE="));
-#ifdef WITH_PARTITION_STORAGE_ENGINE
-    if (table->part_info)
-      packet->append(ha_resolve_storage_engine_name(
-                        table->part_info->default_engine_type));
-    else
-      packet->append(file->table_type());
-#else
-      packet->append(file->table_type());
-#endif
+      packet->append(hton_name(hton));
     }
 
     /*
@@ -1859,9 +1852,7 @@ int store_create_info(THD *thd, TABLE_LI
       packet->append(buff, (uint) (end - buff));
     }
     
-    if (share->table_charset &&
-	!(thd->variables.sql_mode & MODE_MYSQL323) &&
-	!(thd->variables.sql_mode & MODE_MYSQL40))
+    if (share->table_charset && !(sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)))
     {
       /*
         IF   check_create_info
@@ -2114,8 +2105,7 @@ void append_definer(THD *thd, String *bu
 }
 
 
-int
-view_store_create_info(THD *thd, TABLE_LIST *table, String *buff)
+static int show_create_view(THD *thd, TABLE_LIST *table, String *buff)
 {
   my_bool compact_view_name= TRUE;
   my_bool foreign_db_mode= (thd->variables.sql_mode & (MODE_POSTGRESQL |

=== modified file 'sql/sql_show.h'
--- a/sql/sql_show.h	2014-03-23 13:43:57 +0000
+++ b/sql/sql_show.h	2014-07-05 21:42:16 +0000
@@ -74,10 +74,10 @@ typedef struct system_status_var STATUS_
 #define IS_FILES_STATUS              36
 #define IS_FILES_EXTRA               37
 
-int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
-                      HA_CREATE_INFO  *create_info_arg, bool show_database,
-                      bool create_or_replace);
-int view_store_create_info(THD *thd, TABLE_LIST *table, String *buff);
+typedef enum { WITHOUT_DB_NAME, WITH_DB_NAME } enum_with_db_name;
+int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
+                      HA_CREATE_INFO  *create_info_arg,
+                      enum_with_db_name with_db_name);
 
 int copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table);
 

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2014-06-10 12:02:46 +0000
+++ b/sql/sql_table.cc	2014-07-05 21:42:16 +0000
@@ -5434,7 +5434,7 @@ bool mysql_create_like_table(THD* thd, T
           table->open_strategy= TABLE_LIST::OPEN_NORMAL;
 
           /*
-            In order for store_create_info() to work we need to open
+            In order for show_create_table() to work we need to open
             destination table if it is not already open (i.e. if it
             has not existed before). We don't need acquire metadata
             lock in order to do this as we already hold exclusive
@@ -5458,13 +5458,9 @@ bool mysql_create_like_table(THD* thd, T
         if (!table->view)
         {
           int result __attribute__((unused))=
-            store_create_info(thd, table, &query,
-                              create_info, FALSE /* show_database */,
-                              MY_TEST(create_info->org_options &
-                                      HA_LEX_CREATE_REPLACE) ||
-                              create_info->table_was_deleted);
+            show_create_table(thd, table, &query, create_info, WITHOUT_DB_NAME);
 
-          DBUG_ASSERT(result == 0); // store_create_info() always return 0
+          DBUG_ASSERT(result == 0); // show_create_table() always return 0
           do_logging= FALSE;
           if (write_bin_log(thd, TRUE, query.ptr(), query.length()))
           {



More information about the commits mailing list