Commit 5045615c authored by Sergei Golubchik's avatar Sergei Golubchik

small cleanup of the SHOW CREATE TABLE code

parent ca2ba229
......@@ -4135,15 +4135,14 @@ select_create::binlog_show_create_table(TABLE **tables, uint count)
{
/*
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(TABLE **tables, uint count)
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())
{
......
......@@ -116,8 +116,9 @@ static void get_cs_converted_string_value(THD *thd,
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 *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 *thd, String *packet,
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 *thd, String *packet,
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 *thd, String *packet,
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,33 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
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);
bool show_table_options= !(sql_mode & MODE_NO_TABLE_OPTIONS) &&
!foreign_db_mode;
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 +1630,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
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 +1669,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
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 +1726,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
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,12 +1816,8 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
}
packet->append(STRING_WITH_LEN("\n)"));
if (!(thd->variables.sql_mode & MODE_NO_TABLE_OPTIONS) && !foreign_db_mode)
if (show_table_options)
{
#ifdef WITH_PARTITION_STORAGE_ENGINE
show_table_options= TRUE;
#endif /* WITH_PARTITION_STORAGE_ENGINE */
/*
IF check_create_info
THEN add ENGINE only if it was used when creating the table
......@@ -1825,19 +1825,11 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
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 +1851,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
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 +2104,7 @@ void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
}
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 |
......
......@@ -74,10 +74,10 @@ typedef struct system_status_var STATUS_VAR;
#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);
......
......@@ -5434,7 +5434,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
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, TABLE_LIST* table,
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()))
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment