diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 1df85759a9c..26a2601e732 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -122,7 +122,7 @@ int THD::register_slave(uchar *packet, size_t packet_length) uchar *p= packet, *p_end= packet + packet_length; const char *errmsg= "Wrong parameters to function register_slave"; - if (check_access(this, PRIV_COM_REGISTER_SLAVE, any_db, NULL, NULL, 0, 0)) + if (check_access(this, PRIV_COM_REGISTER_SLAVE, any_db.str, NULL,NULL,0,0)) return 1; if (!(si= (Slave_info*)my_malloc(key_memory_SLAVE_INFO, sizeof(Slave_info), MYF(MY_WME)))) diff --git a/sql/set_var.cc b/sql/set_var.cc index fe98d98fbd4..b24deb74177 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1089,7 +1089,7 @@ int fill_sysvars(THD *thd, TABLE_LIST *tables, COND *cond) StringBuffer strbuf(scs); const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : 0; Field **fields=tables->table->field; - bool has_file_acl= !check_access(thd, FILE_ACL, any_db, NULL, NULL, 0, 1); + bool has_file_acl= !check_access(thd, FILE_ACL, any_db.str, NULL,NULL,0,1); DBUG_ASSERT(tables->table->in_use == thd); diff --git a/sql/sp_head.cc b/sql/sp_head.cc index ec5b2d0e832..329c8e42c30 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -4948,7 +4948,7 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check) } for (; table ; table= table->next_global) - if (!table->derived && !table->schema_table) + if (!table->derived && !table->schema_table && !table->table_function) { /* Structure of key for the multi-set is "db\0table\0alias\0". diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 3b60cf2db20..84f5d1dc73f 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1407,8 +1407,7 @@ public: enum_mdl_type mdl_type= MDL_SHARED_READ, List *hints= 0, List *partition_names= 0, - LEX_STRING *option= 0, - Table_function_json_table *tfunc= 0); + LEX_STRING *option= 0); TABLE_LIST* get_table_list(); bool init_nested_join(THD *thd); TABLE_LIST *end_nested_join(THD *thd); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7ace30bfc16..cb8161817fb 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -132,7 +132,7 @@ static int show_create_db(THD *thd, LEX *lex); static bool alter_routine(THD *thd, LEX *lex); static bool drop_routine(THD *thd, LEX *lex); -const char *any_db="*any*"; // Special symbol for check_access +const LEX_CSTRING any_db= {"*any*", 0}; const LEX_CSTRING command_name[257]={ { STRING_WITH_LEN("Sleep") }, //0 @@ -3934,7 +3934,7 @@ mysql_execute_command(THD *thd) privileges_requested, all_tables, FALSE, UINT_MAX, FALSE); else - res= check_access(thd, privileges_requested, any_db, NULL, NULL, 0, 0); + res= check_access(thd, privileges_requested, any_db.str, NULL,NULL,0,0); if (!res) res= execute_sqlcom_select(thd, all_tables); @@ -4979,7 +4979,7 @@ mysql_execute_command(THD *thd) goto error; #else { - if (check_access(thd, FILE_ACL, any_db, NULL, NULL, 0, 0)) + if (check_access(thd, FILE_ACL, any_db.str, NULL, NULL, 0, 0)) goto error; res= ha_show_status(thd, lex->create_info.db_type, HA_ENGINE_LOGS); break; @@ -6694,7 +6694,7 @@ check_access(THD *thd, privilege_t want_access, DBUG_RETURN(FALSE); // CTE reference or an error later } - if (likely((db != NULL) && (db != any_db))) + if (likely((db != NULL) && (db != any_db.str))) { /* Check if this is reserved database, like information schema or @@ -6781,7 +6781,7 @@ check_access(THD *thd, privilege_t want_access, DBUG_RETURN(TRUE); /* purecov: tested */ } - if (unlikely(db == any_db)) + if (unlikely(db == any_db.str)) { /* Access granted; Allow select on *any* db. @@ -7114,8 +7114,7 @@ check_table_access(THD *thd, privilege_t requirements, TABLE_LIST *tables, } if (check_access(thd, want_access, - table_ref->table_function ? any_db : - table_ref->get_db_name(), + table_ref->get_db_name(), &table_ref->grant.privilege, &table_ref->grant.m_internal, 0, no_errors)) @@ -8161,8 +8160,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, enum_mdl_type mdl_type, List *index_hints_arg, List *partition_names, - LEX_STRING *option, - Table_function_json_table *tfunc) + LEX_STRING *option) { TABLE_LIST *ptr; TABLE_LIST *UNINIT_VAR(previous_table_ref); /* The table preceding the current one. */ @@ -8225,13 +8223,12 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (table->table.length) table->table.length= my_casedn_str(files_charset_info, (char*) table->table.str); - if (ptr->db.length && ptr->db.str != any_db) + if (ptr->db.length && ptr->db.str != any_db.str) ptr->db.length= my_casedn_str(files_charset_info, (char*) ptr->db.str); } ptr->table_name= table->table; ptr->lock_type= lock_type; - ptr->table_function= tfunc; ptr->updating= MY_TEST(table_options & TL_OPTION_UPDATING); /* TODO: remove TL_OPTION_FORCE_INDEX as it looks like it's not used */ ptr->force_index= MY_TEST(table_options & TL_OPTION_FORCE_INDEX); @@ -8276,7 +8273,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, { if (unlikely(!my_strcasecmp(table_alias_charset, alias_str.str, tables->alias.str) && - (tables->table_function || ptr->table_function || + (tables->db.str == any_db.str || ptr->db.str == any_db.str || !cmp(&ptr->db, &tables->db)) && !tables->sequence)) { diff --git a/sql/sql_parse.h b/sql/sql_parse.h index 62c3775f408..eddaa9d87e1 100644 --- a/sql/sql_parse.h +++ b/sql/sql_parse.h @@ -131,7 +131,7 @@ bool check_stack_overrun(THD *thd, long margin, uchar *dummy); /* Variables */ -extern const char* any_db; +extern const LEX_CSTRING any_db; extern uint sql_command_flags[]; extern uint server_command_flags[]; extern const LEX_CSTRING command_name[]; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 134c96fd28f..6a9cc8eed10 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1545,7 +1545,7 @@ static int mysql_test_select(Prepared_statement *stmt, if (check_table_access(thd, privilege, tables, FALSE, UINT_MAX, FALSE)) goto error; } - else if (check_access(thd, privilege, any_db, NULL, NULL, 0, 0)) + else if (check_access(thd, privilege, any_db.str, NULL, NULL, 0, 0)) goto error; if (!lex->result && !(lex->result= new (stmt->mem_root) select_send(thd))) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 9bb483448e0..a0b948b0555 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -11713,15 +11713,16 @@ table_function: MYSQL_YYABORT; sel->table_join_options= 0; if (!($$= Select->add_table_to_list(thd, - new (thd->mem_root) Table_ident(thd, &empty_clex_str, + new (thd->mem_root) Table_ident(thd, &any_db, $10, TRUE), NULL, Select->get_table_join_options() | TL_OPTION_TABLE_FUNCTION, YYPS->m_lock_type, YYPS->m_mdl_type, - 0,0,0, Lex->json_table))) + 0,0,0))) MYSQL_YYABORT; + $$->table_function= Lex->json_table; Lex->json_table= 0; status_var_increment(thd->status_var.feature_json); } @@ -15376,7 +15377,7 @@ table_ident_opt_wild: table_ident_nodb: ident { - LEX_CSTRING db={(char*) any_db,3}; + LEX_CSTRING db= any_db; $$= new (thd->mem_root) Table_ident(thd, &db, &$1, 0); if (unlikely($$ == NULL)) MYSQL_YYABORT; diff --git a/sql/table.cc b/sql/table.cc index 11d876a8a62..9811baa6337 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4951,7 +4951,7 @@ bool check_db_name(LEX_STRING *org_name) if (!name_length || name_length > NAME_LEN) return 1; - if (lower_case_table_names == 1 && name != any_db) + if (lower_case_table_names == 1 && name != any_db.str) { org_name->length= name_length= my_casedn_str(files_charset_info, name); if (check_for_path_chars)