summaryrefslogtreecommitdiff
path: root/sql/sql_view.cc
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2022-10-02 22:14:21 +0200
committerSergei Golubchik <serg@mariadb.org>2022-10-02 22:14:21 +0200
commit900d7bf3604e7ba265f06d96f76a049dc3c4c9af (patch)
treec447b67842760bdc3ccae31aebb987fee4071842 /sql/sql_view.cc
parent2ab52cc0e5c3cc792608a518625a08e6d3734ce4 (diff)
parent3a2116241b128b811ee2455845ff9710da3115ac (diff)
downloadmariadb-git-900d7bf3604e7ba265f06d96f76a049dc3c4c9af.tar.gz
Merge branch '10.5' into 10.6
Diffstat (limited to 'sql/sql_view.cc')
-rw-r--r--sql/sql_view.cc84
1 files changed, 68 insertions, 16 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 6dedd5e85be..7a52b822b9d 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -306,7 +306,8 @@ bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
{
my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
"ANY", thd->security_ctx->priv_user,
- thd->security_ctx->priv_host, tbl->table_name.str);
+ thd->security_ctx->priv_host,
+ tbl->db.str, tbl->table_name.str);
goto err;
}
/*
@@ -834,7 +835,7 @@ static File_option view_parameters[]=
my_offsetof(TABLE_LIST, with_check),
FILE_OPTIONS_ULONGLONG},
{{ STRING_WITH_LEN("timestamp")},
- my_offsetof(TABLE_LIST, timestamp),
+ my_offsetof(TABLE_LIST, hr_timestamp),
FILE_OPTIONS_TIMESTAMP},
{{ STRING_WITH_LEN("create-version")},
my_offsetof(TABLE_LIST, file_version),
@@ -858,6 +859,15 @@ static File_option view_parameters[]=
FILE_OPTIONS_STRING}
};
+
+static File_option view_timestamp_parameters[]=
+{
+
+ {{ C_STRING_WITH_LEN("timestamp")}, 0, FILE_OPTIONS_TIMESTAMP},
+ {{NullS, 0}, 0, FILE_OPTIONS_STRING}
+};
+
+
static LEX_CSTRING view_file_type[]= {{STRING_WITH_LEN("VIEW") }};
@@ -875,8 +885,8 @@ int mariadb_fix_view(THD *thd, TABLE_LIST *view, bool wrong_checksum,
&path, path_buff, sizeof(path_buff),
&file, view);
/* init timestamp */
- if (!view->timestamp.str)
- view->timestamp.str= view->timestamp_buffer;
+ if (!view->hr_timestamp.str)
+ view->hr_timestamp.str= view->timestamp_buffer;
if (swap_alg && view->algorithm != VIEW_ALGORITHM_UNDEFINED)
{
@@ -891,13 +901,13 @@ int mariadb_fix_view(THD *thd, TABLE_LIST *view, bool wrong_checksum,
swap_alg= 0;
if (wrong_checksum)
{
- if (view->md5.length != 32)
+ if (view->md5.length != VIEW_MD5_LEN)
{
- if ((view->md5.str= (char *)thd->alloc(32 + 1)) == NULL)
+ if ((view->md5.str= (char *)thd->alloc(VIEW_MD5_LEN + 1)) == NULL)
DBUG_RETURN(HA_ADMIN_FAILED);
}
view->calc_md5(const_cast<char*>(view->md5.str));
- view->md5.length= 32;
+ view->md5.length= VIEW_MD5_LEN;
}
view->mariadb_version= MYSQL_VERSION_ID;
@@ -1021,13 +1031,13 @@ static int mysql_register_view(THD *thd, DDL_LOG_STATE *ddl_log_state,
view->file_version= 2;
view->mariadb_version= MYSQL_VERSION_ID;
view->calc_md5(md5);
- if (!(view->md5.str= (char*) thd->memdup(md5, 32)))
+ if (!(view->md5.str= (char*) thd->memdup(md5, VIEW_MD5_LEN)))
{
my_error(ER_OUT_OF_RESOURCES, MYF(0));
error= -1;
goto err;
}
- view->md5.length= 32;
+ view->md5.length= VIEW_MD5_LEN;
can_be_merged= lex->can_be_merged();
if (lex->create_view->algorithm == VIEW_ALGORITHM_MERGE &&
!lex->can_be_merged())
@@ -1078,8 +1088,8 @@ loop_out:
&path, path_buff, sizeof(path_buff),
&file, view);
/* init timestamp */
- if (!view->timestamp.str)
- view->timestamp.str= view->timestamp_buffer;
+ if (!view->hr_timestamp.str)
+ view->hr_timestamp.str= view->timestamp_buffer;
/* check old .frm */
{
@@ -1224,7 +1234,32 @@ err:
DBUG_RETURN(error);
}
+/**
+ Reads view definition "version"
+ @param[in] share Share object of view
+
+ @return true on error, otherwise false
+*/
+
+bool mariadb_view_version_get(TABLE_SHARE *share)
+{
+ DBUG_ASSERT(share->is_view);
+
+ if (!(share->tabledef_version.str=
+ (uchar*) alloc_root(&share->mem_root,
+ MICROSECOND_TIMESTAMP_BUFFER_SIZE)))
+ return TRUE;
+ share->tabledef_version.length= 0; // safety if the drfinition file is brocken
+
+ DBUG_ASSERT(share->view_def != NULL);
+ if (share->view_def->parse((uchar *) &share->tabledef_version, NULL,
+ view_timestamp_parameters, 1,
+ &file_parser_dummy_hook))
+ return TRUE;
+ DBUG_ASSERT(share->tabledef_version.length == MICROSECOND_TIMESTAMP_BUFFER_SIZE-1);
+ return FALSE;
+}
/**
read VIEW .frm and create structures
@@ -1287,6 +1322,10 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
mysql_handle_single_derived(thd->lex, table, DT_REINIT);
DEBUG_SYNC(thd, "after_cached_view_opened");
+ if (!share->tabledef_version.length)
+ {
+ mariadb_view_version_get(share);
+ }
DBUG_RETURN(0);
}
@@ -1323,8 +1362,8 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
arena= thd->activate_stmt_arena_if_needed(&backup);
/* init timestamp */
- if (!table->timestamp.str)
- table->timestamp.str= table->timestamp_buffer;
+ if (!table->hr_timestamp.str)
+ table->hr_timestamp.str= table->timestamp_buffer;
/* prepare default values for old format */
table->view_suid= TRUE;
table->definer.user.str= table->definer.host.str= 0;
@@ -1340,6 +1379,19 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
required_view_parameters,
&file_parser_dummy_hook)))
goto end;
+ if (!share->tabledef_version.length)
+ {
+ share->tabledef_version.str= (const uchar *)
+ memdup_root(&share->mem_root,
+ (const void *)
+ table->hr_timestamp.str,
+ (share->tabledef_version.length=
+ table->hr_timestamp.length));
+ }
+ if (!table->tabledef_version.length)
+ {
+ table->set_view_def_version(&table->hr_timestamp);
+ }
/*
check old format view .frm
@@ -2196,10 +2248,10 @@ bool insert_view_fields(THD *thd, List<Item> *list, TABLE_LIST *view)
int view_checksum(THD *thd, TABLE_LIST *view)
{
char md5[MD5_BUFF_LENGTH];
- if (!view->view || view->md5.length != 32)
+ if (!view->view || view->md5.length != VIEW_MD5_LEN)
return HA_ADMIN_NOT_IMPLEMENTED;
view->calc_md5(md5);
- return (strncmp(md5, view->md5.str, 32) ?
+ return (strncmp(md5, view->md5.str, VIEW_MD5_LEN) ?
HA_ADMIN_WRONG_CHECKSUM :
HA_ADMIN_OK);
}
@@ -2304,7 +2356,7 @@ mysql_rename_view(THD *thd,
object for it.
*/
view_def.reset();
- view_def.timestamp.str= view_def.timestamp_buffer;
+ view_def.hr_timestamp.str= view_def.timestamp_buffer;
view_def.view_suid= TRUE;
/* get view definition and source */