Bug #116701 MASTER_AUTO_POSITION is 0 but still needs to obtain retrieved_gtid
Submitted: 19 Nov 5:45 Modified: 19 Nov 16:48
Reporter: karry zhang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Replication Severity:S4 (Feature request)
Version:8.0.40 OS:Any
Assigned to: CPU Architecture:Any

[19 Nov 5:45] karry zhang
Description:
When set MASTER_AUTO_POSITION 0, it means we use file name and position to determine where the replication starts.
But we see that when replication is initialized, MySQL still needs to scan the relay log to get the retrieved gtid, as shown in the following function call:

|->ReplicaInitializer::ReplicaInitializer
| |->ReplicaInitializer::init_replica
| | |->Rpl_info_factory::create_slave_info_objects
| | | |->Rpl_info_factory::create_mi_and_rli_objects
| | | | |->load_mi_and_rli_from_repositories
| | | | | |->Relay_log_info::rli_init_info
| | | | | | |->MYSQL_BIN_LOG::init_gtid_sets
| | | | | | | |->read_gtids_and_update_trx_parser_from_relaylog

I think this step is meaningless for MASTER_AUTO_POSITION of 0 and introduces unnecessary overhead.

How to repeat:
See the call stack of the above code.

Suggested fix:
When MASTER_AUTO_POSITION is 0, no need to call MYSQL_BIN_LOG::init_gtid_sets.
[19 Nov 15:34] Jean-François Gagné
> I think this step is meaningless for MASTER_AUTO_POSITION of 0 and introduces unnecessary overhead.

I think you are right with "unnecessary overhead", but without this, SHOW REPLICA STATUS would not be able to print "retrieved gtid".  Are you suggestion to not print this, or print NULL, when MASTER_AUTO_POSITION is 0 ?  Because this would be a braking change.

Maybe way "backward compatible" way to remove this overhead would be to introduce a new configuration variable, disabled by default, which would if enabled, not compute retrived gtid in SHOW REPLICA STATUS (suggested name show_replica_status_no_retrieved_gtid_when_master_auto_position_disabled).

My suggestion above would have to be completed / refined for the matching p_s tables.
[19 Nov 16:48] MySQL Verification Team
Hi,
I will be logging this as feature request.