MDEV-35641 bring call to use_all_columns() forward when reading from mysql.servers

TABLE::use_all_columns turn on all bits of read_set, which is
interpreted by innodb as a request to read all columns. Without doing
so before calling init_read_record(), innodb will not retrieve any
columns if mysql.servers table has been altered to use innodb as the
engine, and any foreign servers stored in the table are "lost".
This commit is contained in:
Yuchen Pei 2024-12-16 10:26:21 +11:00
parent 04408fff40
commit f862fe8b2b
No known key found for this signature in database
GPG Key ID: 3DD1B35105743563
3 changed files with 19 additions and 3 deletions

View File

@ -43,3 +43,10 @@ ERROR HY000: Can't read record in system table
drop table mysql.servers; drop table mysql.servers;
rename table mysql.servers_save to mysql.servers; rename table mysql.servers_save to mysql.servers;
drop server s1; drop server s1;
#
# MDEV-35641 foreign server "disappears" after ALTERing the servers system table to use innodb and FLUSH PRIVILEGES
#
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS (HOST '127.0.0.1');
ALTER TABLE mysql.servers ENGINE=innodb;
FLUSH PRIVILEGES;
drop server s1;

View File

@ -41,3 +41,12 @@ create server s2 foreign data wrapper foo options(user 'a');
drop table mysql.servers; drop table mysql.servers;
rename table mysql.servers_save to mysql.servers; rename table mysql.servers_save to mysql.servers;
drop server s1; drop server s1;
--echo #
--echo # MDEV-35641 foreign server "disappears" after ALTERing the servers system table to use innodb and FLUSH PRIVILEGES
--echo #
--source include/have_innodb.inc
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS (HOST '127.0.0.1');
ALTER TABLE mysql.servers ENGINE=innodb;
FLUSH PRIVILEGES;
drop server s1;

View File

@ -283,7 +283,7 @@ end:
static bool servers_load(THD *thd, TABLE_LIST *tables) static bool servers_load(THD *thd, TABLE_LIST *tables)
{ {
TABLE *table; TABLE *table= tables[0].table;
READ_RECORD read_record_info; READ_RECORD read_record_info;
bool return_val= TRUE; bool return_val= TRUE;
DBUG_ENTER("servers_load"); DBUG_ENTER("servers_load");
@ -292,7 +292,8 @@ static bool servers_load(THD *thd, TABLE_LIST *tables)
free_root(&mem, MYF(0)); free_root(&mem, MYF(0));
init_sql_alloc(key_memory_servers, &mem, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); init_sql_alloc(key_memory_servers, &mem, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0));
if (init_read_record(&read_record_info,thd,table=tables[0].table, NULL, NULL, table->use_all_columns();
if (init_read_record(&read_record_info,thd,table, NULL, NULL,
1,0, FALSE)) 1,0, FALSE))
DBUG_RETURN(1); DBUG_RETURN(1);
while (!(read_record_info.read_record())) while (!(read_record_info.read_record()))
@ -405,7 +406,6 @@ get_server_from_table_to_cache(TABLE *table)
FOREIGN_SERVER *server= (FOREIGN_SERVER *)alloc_root(&mem, FOREIGN_SERVER *server= (FOREIGN_SERVER *)alloc_root(&mem,
sizeof(FOREIGN_SERVER)); sizeof(FOREIGN_SERVER));
DBUG_ENTER("get_server_from_table_to_cache"); DBUG_ENTER("get_server_from_table_to_cache");
table->use_all_columns();
/* get each field into the server struct ptr */ /* get each field into the server struct ptr */
ptr= get_field(&mem, table->field[0]); ptr= get_field(&mem, table->field[0]);