Commit 58b0bf9
committed
DISTMYSQL-243 - Orchestrator uses inefficient subquery in REPLACE to update cluster aliases
Problem:
--------
Orchestrator has backend table cluster_alias to store aliases.
At certain intervals, orchestrator will update the aliases or insert new host aliases.
To do this, it uses the below query in UpdateClusterAliases():
```
replace into
cluster_alias (alias, cluster_name, last_registered)
select
suggested_cluster_alias,
cluster_name,
now()
from
database_instance
left join database_instance_downtime using (hostname, port)
where
suggested_cluster_alias!=''
/* exclude newly demoted, downtimed masters */
and ifnull(
database_instance_downtime.downtime_active = 1
and database_instance_downtime.end_timestamp > now()
and database_instance_downtime.reason = ?
, 0) = 0
order by
ifnull(last_checked <= last_seen, 0) asc,
read_only desc,
num_slave_hosts asc
```
The problem with the select query is it will generated the same alias,cluster_name multiple times. REPLACE does this operation
by doing DELETE+INSERT. REPLACE repeatedly does the same work for all the duplicated records.
This creates un-necessary work for two sub systems in InnoDB
1. Purge
2. SELECTS (ReadView)
All those delete marked records create stress on Purge.
SELECTs, when they have to build a older version of record, they have to build a long chain of old version records (using undo log).
So the un-necessary REPLACE work will create a long chain of records to be built.
Fix:
----
Use GROUPBY to filter duplicate records in subquery in REPLACE.1 parent 22cfcd4 commit 58b0bf9
1 file changed
+3
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 136 | + | |
| 137 | + | |
139 | 138 | | |
140 | 139 | | |
141 | 140 | | |
| |||
0 commit comments