作者:杨涛涛
资深数据库专家,专研 MySQL 十余年。擅长 MySQL、PostgreSQL、MongoDB 等开源数据库相关的备份恢复、SQL 调优、监控运维、高可用架构设计等。目前任职于爱可生,为各大运营商及银行金融企业提供 MySQL 相关技术支持、MySQL 相关课程培训等工作。
本文来源:原创投稿
1. 绑定执行计划,人为引导优化器选择最优执行路径。比如创建 OUTLINE 让 SQL 语句绑定固定执行计划。
2. 手工进行转储或者合并来清理无用数据。
比如在 MySQL 、Oracle 租户下都创建一张表t2,指定表 table_mode='queuing' 。
<mysql:5.6.25:ytt>create table t2 (id int primary key, r1 int,r2 varchar(100)) table_mode='queuing';
Query OK, 0 rows affected (0.032 sec)
MySQL 租户下执行下面语句:
<mysql:5.6.25:ytt>insert into t2 with recursive tmp(a,b,c) as (select 1,1,'mysql' union all select a+1,ceil(rand()*200),'actionsky' from tmp where a < 20000) select * from tmp;
Query OK, 20000 rows affected (0.916 sec)
Records: 20000 Duplicates: 0 Warnings: 0
<mysql:5.6.25:ytt>delete from t2;
Query OK, 20000 rows affected (0.056 sec)
Oracle 租户下可以执行下面语句:
<mysql:5.6.25:SYS>insert into t2 select level,100,'oracle' from dual connect by level <=20000;delete from t2;
Query OK, 20000 rows affected (0.070 sec)
Records: 20000 Duplicates: 0 Warnings: 0
Query OK, 20000 rows affected (0.088 sec)
多次执行上面这些语句后,可以在sys租户下查看MySQL租户、Oracle租户后台针对表t2的单独转储记录:字段 action 为 buf minor merge 的行。
<mysql:5.6.25:oceanbase>SELECT *
-> FROM
-> (SELECT c.tenant_name,
-> a.table_name,
-> d.type,
-> d.action,
-> d.version,
-> d.start_time
-> FROM __all_virtual_table a
-> JOIN __all_virtual_meta_table b using(table_id)
-> JOIN __all_tenant c
-> ON (b.tenant_id=c.tenant_id)
-> AND c.tenant_name in ('mysql','oracle')
-> JOIN gv$merge_info d
-> ON d.table_id =a.table_id
-> where d.action like 'buf minor merge'
-> ORDER BY d.start_time DESC limit 2 ) T
-> ORDER BY start_time asc;
+-------------+------------+-------+-----------------+------------------+----------------------------+
| tenant_name | table_name | type | action | version | start_time |
+-------------+------------+-------+-----------------+------------------+----------------------------+
| mysql | t2 | minor | buf minor merge | 1678867962096191 | 2023-03-15 16:13:14.774809 |
| oracle | T2 | minor | buf minor merge | 1678871458311991 | 2023-03-15 17:11:38.426437 |
+-------------+------------+-------+-----------------+------------------+----------------------------+
2 rows in set (0.008 sec)