[Commits] 79b48d9a665: c
revision-id: 79b48d9a6656b5cf7aa43742e28aa53e6c110604 (mariadb-10.1.37-65-g79b48d9a665) parent(s): 71463b21321ea3532d6e78f811b191eee61e7841 author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2019-01-18 14:30:15 +0100 message: c --- sql/sql_view.cc | 31 ++++++++++++------------------- sql/sql_view.h | 2 +- sql/table.cc | 21 ++++++++++++++------- sql/table.h | 26 ++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 27 deletions(-) diff --git a/sql/sql_view.cc b/sql/sql_view.cc index ee169de4c93..45f5426b117 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1135,7 +1135,6 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, DBUG_RETURN(error); } -#define MD5_LEN 32 /** Check is TABLE_LEST and SHARE match @param[in] view TABLE_LIST of the view @@ -1144,28 +1143,22 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, @return false on error or misspatch */ -bool mariadb_view_version_check(TABLE_LIST *view, TABLE_SHARE *share) +bool mariadb_view_version_get(TABLE_SHARE *share) { - LEX_STRING md5; - char md5_buffer[MD5_LEN + 1]; - md5.str= md5_buffer; - md5.length= MD5_LEN; + DBUG_ASSERT(share->is_view); - /* - Check that both were views (view->is_view() could not be checked - because it is not opened). - */ - if (!share->is_view || view->md5.length != MD5_LEN) - return FALSE; + if (!(share->tabledef_version.str= + (uchar*) alloc_root(&share->mem_root, VIEW_MD5_LEN + 1))) + return TRUE; + share->tabledef_version.length= VIEW_MD5_LEN; DBUG_ASSERT(share->view_def != NULL); - if (share->view_def->parse((uchar*)&md5, NULL, - view_md5_parameters, - 1, - &file_parser_dummy_hook)) - return FALSE; - DBUG_ASSERT(md5.length == MD5_LEN); - return (strncmp(md5.str, view->md5.str, MD5_LEN) == 0); + if (share->view_def->parse((uchar *) &share->tabledef_version, NULL, + view_md5_parameters, 1, + &file_parser_dummy_hook)) + return TRUE; + DBUG_ASSERT(share->tabledef_version.length == VIEW_MD5_LEN); + return FALSE; } /** diff --git a/sql/sql_view.h b/sql/sql_view.h index 1685169420d..67187a0624a 100644 --- a/sql/sql_view.h +++ b/sql/sql_view.h @@ -37,7 +37,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *view, bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, bool open_view_no_parse); -bool mariadb_view_version_check(TABLE_LIST *view, TABLE_SHARE *share); +bool mariadb_view_version_get(TABLE_SHARE *share); bool mysql_drop_view(THD *thd, TABLE_LIST *view, enum_drop_mode drop_mode); diff --git a/sql/table.cc b/sql/table.cc index 60f263ee841..7d1d5d3a85a 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -609,7 +609,11 @@ enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, uint flags) if (!share->view_def) share->error= OPEN_FRM_ERROR_ALREADY_ISSUED; else + { share->error= OPEN_FRM_OK; + if (mariadb_view_version_get(share)) + share->error= OPEN_FRM_CORRUPTED; + } } else share->error= OPEN_FRM_NOT_A_TABLE; @@ -7504,19 +7508,22 @@ bool TABLE_LIST::is_table_ref_id_equal(TABLE_SHARE *s) bool res= m_table_ref_version == s->get_table_ref_version(); /* - If definition is different object with view we can check MD5 in frm - to check if the same view got into table definition cache again. + If definition is different check content version */ - if (!res && - tp == TABLE_REF_VIEW && - mariadb_view_version_check(this, s)) + if (tabledef_version.length && + tabledef_version.length == s->tabledef_version.length && + memcmp(tabledef_version.str, s->tabledef_version.str, + tabledef_version.length) == 0) { - // to avoid relatively expensive parsing of frm next time - set_table_ref_id(s); + set_table_id(s); return TRUE; } + else + tabledef_version.length= 0; return res; } + else + set_tabledef_version(s); return FALSE; } diff --git a/sql/table.h b/sql/table.h index 9e1a061e606..c9dd8d0146c 100644 --- a/sql/table.h +++ b/sql/table.h @@ -61,6 +61,8 @@ class TDC_element; */ typedef ulonglong nested_join_map; +#define VIEW_MD5_LEN 32 + #define tmp_file_prefix "#sql" /**< Prefix for tmp tables */ #define tmp_file_prefix_length 4 @@ -1998,6 +2000,10 @@ struct TABLE_LIST to view with SQL SECURITY DEFINER) */ Security_context *security_ctx; + uchar tabledef_version_buf[MY_UUID_SIZE > VIEW_MD5_LEN ? + MY_UUID_SIZE + 1 : VIEW_MD5_LEN + 1]; + LEX_CUSTRING tabledef_version; + /* This view security context (non-zero only for views with SQL SECURITY DEFINER) @@ -2290,6 +2296,26 @@ struct TABLE_LIST m_table_ref_version= table_ref_version_arg; } + void set_table_id(TABLE_SHARE *s) + { + set_table_ref_id(s); + set_tabledef_version(s); + } + + void set_tabledef_version(TABLE_SHARE *s) + { + if (!tabledef_version.length && s->tabledef_version.length) + { + DBUG_ASSERT(s->tabledef_version.length < + sizeof(tabledef_version_buf)); + tabledef_version.str= tabledef_version_buf; + memcpy(tabledef_version_buf, s->tabledef_version.str, + (tabledef_version.length= s->tabledef_version.length)); + // safety + tabledef_version_buf[tabledef_version.length]= 0; + } + } + /* Set of functions returning/setting state of a derived table/view. */ inline bool is_non_derived() {
participants (1)
-
Oleksandr Byelkin