Commit af2f7ce3 authored by Nirbhay Choubey's avatar Nirbhay Choubey

MDEV-8464 : ALTER VIEW not replicated in some cases

In galera, like other DDLs, CREATE/ALTER VIEW commands are recreated
and replicated during parsing. The ALGORITHM clause is internally set
to VIEW_ALGORITHM_INHERIT if its not explicitly specified by the user.
But since its not a valid type to be used in a command, it leads to an
assertion failure. The solution is to not include the ALGORITHM clause
in the command if its not explicitly specified (or INHERIT).
parent 71d1f358
#
# MDEV-8464 : ALTER VIEW not replicated in some cases
#
# On node_1
USE test;
CREATE TABLE t1(i INT) ENGINE=INNODB;
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT * FROM t1;
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t1;
CREATE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t1;
CREATE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
# On node_2
USE test;
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v2;
View Create View character_set_client collation_connection
v2 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v3;
View Create View character_set_client collation_connection
v3 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v4;
View Create View character_set_client collation_connection
v4 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
# On node_1
ALTER ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
ALTER ALGORITHM=UNDEFINED VIEW v2 AS SELECT * FROM t1;
ALTER DEFINER=CURRENT_USER VIEW v3 AS SELECT * FROM t1;
ALTER ALGORITHM=TEMPTABLE DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
# On node_2
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v2;
View Create View character_set_client collation_connection
v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v3;
View Create View character_set_client collation_connection
v3 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v4;
View Create View character_set_client collation_connection
v4 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
# Cleanup
DROP VIEW v1, v2, v3, v4;
DROP TABLE t1;
# End of tests
--source include/galera_cluster.inc
--source include/have_innodb.inc
--echo #
--echo # MDEV-8464 : ALTER VIEW not replicated in some cases
--echo #
--echo # On node_1
--connection node_1
USE test;
CREATE TABLE t1(i INT) ENGINE=INNODB;
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT * FROM t1;
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t1;
CREATE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t1;
CREATE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
--echo # On node_2
--connection node_2
USE test;
SHOW CREATE VIEW v1;
SHOW CREATE VIEW v2;
SHOW CREATE VIEW v3;
SHOW CREATE VIEW v4;
--echo # On node_1
--connection node_1
ALTER ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
ALTER ALGORITHM=UNDEFINED VIEW v2 AS SELECT * FROM t1;
ALTER DEFINER=CURRENT_USER VIEW v3 AS SELECT * FROM t1;
ALTER ALGORITHM=TEMPTABLE DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
--echo # On node_2
--connection node_2
SHOW CREATE VIEW v1;
SHOW CREATE VIEW v2;
SHOW CREATE VIEW v3;
SHOW CREATE VIEW v4;
--echo # Cleanup
DROP VIEW v1, v2, v3, v4;
DROP TABLE t1;
--echo # End of tests
...@@ -119,9 +119,6 @@ static void get_cs_converted_string_value(THD *thd, ...@@ -119,9 +119,6 @@ static void get_cs_converted_string_value(THD *thd,
bool use_hex); bool use_hex);
#endif #endif
static void
append_algorithm(TABLE_LIST *table, String *buff);
static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table); static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table);
/*************************************************************************** /***************************************************************************
...@@ -1972,32 +1969,30 @@ static void store_key_options(THD *thd, String *packet, TABLE *table, ...@@ -1972,32 +1969,30 @@ static void store_key_options(THD *thd, String *packet, TABLE *table,
} }
} }
void
view_store_options(THD *thd, TABLE_LIST *table, String *buff)
{
append_algorithm(table, buff);
append_definer(thd, buff, &table->definer.user, &table->definer.host);
if (table->view_suid)
buff->append(STRING_WITH_LEN("SQL SECURITY DEFINER "));
else
buff->append(STRING_WITH_LEN("SQL SECURITY INVOKER "));
}
/* /*
Append DEFINER clause to the given buffer. Append ALGORITHM clause to the given buffer.
SYNOPSIS SYNOPSIS
append_definer() append_algorithm()
thd [in] thread handle table [in] table list
buffer [inout] buffer to hold DEFINER clause buff [inout] buffer to hold the ALGORITHM clause
definer_user [in] user name part of definer check_inherit [in] if true, do nothing if algorithm is INHERIT
definer_host [in] host name part of definer
*/ */
static void append_algorithm(TABLE_LIST *table, String *buff) static void append_algorithm(TABLE_LIST *table, String *buff,
bool check_inherit)
{ {
int16 algorithm= (int16) table->algorithm;
DBUG_ENTER("append_algorithm");
/*
Handle a special case when ALGORITHM is not specified, in which case we
simply return.
*/
if (check_inherit && (algorithm == VIEW_ALGORITHM_INHERIT))
DBUG_VOID_RETURN;
buff->append(STRING_WITH_LEN("ALGORITHM=")); buff->append(STRING_WITH_LEN("ALGORITHM="));
switch ((int16)table->algorithm) { switch ((int16)table->algorithm) {
case VIEW_ALGORITHM_UNDEFINED: case VIEW_ALGORITHM_UNDEFINED:
...@@ -2012,6 +2007,8 @@ static void append_algorithm(TABLE_LIST *table, String *buff) ...@@ -2012,6 +2007,8 @@ static void append_algorithm(TABLE_LIST *table, String *buff)
default: default:
DBUG_ASSERT(0); // never should happen DBUG_ASSERT(0); // never should happen
} }
DBUG_VOID_RETURN;
} }
/* /*
...@@ -2035,6 +2032,23 @@ void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user, ...@@ -2035,6 +2032,23 @@ void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
buffer->append(' '); buffer->append(' ');
} }
void
view_store_options4(THD *thd, TABLE_LIST *table, String *buff,
bool check_inherit)
{
append_algorithm(table, buff, check_inherit);
append_definer(thd, buff, &table->definer.user, &table->definer.host);
if (table->view_suid)
buff->append(STRING_WITH_LEN("SQL SECURITY DEFINER "));
else
buff->append(STRING_WITH_LEN("SQL SECURITY INVOKER "));
}
void
view_store_options(THD *thd, TABLE_LIST *table, String *buff)
{
view_store_options4(thd, table, buff, false);
}
int int
view_store_create_info(THD *thd, TABLE_LIST *table, String *buff) view_store_create_info(THD *thd, TABLE_LIST *table, String *buff)
......
...@@ -115,6 +115,8 @@ void free_status_vars(); ...@@ -115,6 +115,8 @@ void free_status_vars();
void reset_status_vars(); void reset_status_vars();
bool show_create_trigger(THD *thd, const sp_name *trg_name); bool show_create_trigger(THD *thd, const sp_name *trg_name);
void view_store_options(THD *thd, TABLE_LIST *table, String *buff); void view_store_options(THD *thd, TABLE_LIST *table, String *buff);
void view_store_options4(THD *thd, TABLE_LIST *table, String *buff,
bool check_inherit);
void init_fill_schema_files_row(TABLE* table); void init_fill_schema_files_row(TABLE* table);
bool schema_table_store_record(THD *thd, TABLE *table); bool schema_table_store_record(THD *thd, TABLE *table);
......
...@@ -1193,7 +1193,7 @@ create_view_query(THD *thd, uchar** buf, size_t* buf_len) ...@@ -1193,7 +1193,7 @@ create_view_query(THD *thd, uchar** buf, size_t* buf_len)
views->view_suid = lex->create_view_suid; views->view_suid = lex->create_view_suid;
views->with_check = lex->create_view_check; views->with_check = lex->create_view_check;
view_store_options(thd, views, &buff); view_store_options4(thd, views, &buff, true);
buff.append(STRING_WITH_LEN("VIEW ")); buff.append(STRING_WITH_LEN("VIEW "));
/* Test if user supplied a db (ie: we did not use thd->db) */ /* Test if user supplied a db (ie: we did not use thd->db) */
if (views->db && views->db[0] && if (views->db && views->db[0] &&
......
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