1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

MDEV-31297 Create table as select on system versioned tables do not

work consistently on replication

Row-based replication does not execute CREATE .. SELECT but instead
CREATE TABLE. CREATE .. SELECT creates implict system fields on
unusual place: in-between declared fields and select fields. That was
done because select_field_pos logic requires select fields go last in
create_list.

So, CREATE .. SELECT on master and CREATE TABLE on slave create system
fields on different positions and replication gets field mismatch.

To fix this we've changed CREATE .. SELECT to create implicit system
fields on usual place in the end and updated select_field_pos for
handling this case.
This commit is contained in:
Aleksey Midenkov
2024-10-08 13:08:10 +03:00
parent 4e4c7dd4f5
commit d37bb140b1
6 changed files with 74 additions and 5 deletions

View File

@ -8017,6 +8017,21 @@ bool Table_scope_and_contents_source_st::vers_fix_system_fields(
}
int get_select_field_pos(Alter_info *alter_info, int select_field_count,
bool versioned)
{
int select_field_pos= alter_info->create_list.elements - select_field_count;
if (select_field_count && versioned &&
/*
ALTER_PARSER_ADD_COLUMN indicates system fields was created implicitly,
select_field_count guarantees it's not ALTER TABLE
*/
alter_info->flags & ALTER_PARSER_ADD_COLUMN)
select_field_pos-= 2;
return select_field_pos;
}
bool Table_scope_and_contents_source_st::vers_check_system_fields(
THD *thd, Alter_info *alter_info, const Lex_table_name &table_name,
const Lex_table_name &db, int select_count)
@ -8030,6 +8045,8 @@ bool Table_scope_and_contents_source_st::vers_check_system_fields(
{
uint fieldnr= 0;
List_iterator<Create_field> field_it(alter_info->create_list);
uint select_field_pos= (uint) get_select_field_pos(alter_info, select_count,
true);
while (Create_field *f= field_it++)
{
/*
@ -8040,7 +8057,7 @@ bool Table_scope_and_contents_source_st::vers_check_system_fields(
SELECT go last there.
*/
bool is_dup= false;
if (fieldnr >= alter_info->create_list.elements - select_count)
if (fieldnr >= select_field_pos && f->invisible < INVISIBLE_SYSTEM)
{
List_iterator<Create_field> dup_it(alter_info->create_list);
for (Create_field *dup= dup_it++; !is_dup && dup != f; dup= dup_it++)