Oceanbase使用BenchmarkSQL 进行tpcc测试及执行计划查询

本文主要是介绍Oceanbase使用BenchmarkSQL 进行tpcc测试及执行计划查询,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Oceanbase使用BenchmarkSQL 进行tpcc测试及执行计划查询

文章目录

  • Oceanbase使用BenchmarkSQL 进行tpcc测试及执行计划查询
    • 环境介绍
    • 配置BenchmarkSQL
    • 开始BenchmarkSQL测试
    • 查看执行计划
      • 查询top sql
      • 查看执行计划
    • 总结
    • 参考文档

环境介绍

操作系统:redhat7.9

内核版本:3.10.0-1160.el7.x86_64

Ocaenbase集群版本:社区版单副本集群,3.1.0,租户为mysql模式

Benchmarksql要求jdk8版本及以上的java环境

[admin@rac04 ~]$ java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)

配置BenchmarkSQL

创建ob的tpcc数据库和tpcc用户

create database tpcc;
create user tpcc identified by 'tpcc';
grant all on *.* to tpcc;

修改ob的超时设置

set global ob_query_timeout=36000000000;
set global ob_trx_timeout=36000000000;-- 为了获得top sql,需要将sql审计打开,默认是开启的
show variables like 'ob_enable_sql_audit';
MySQL [tpcc]> show variables like 'ob_enable_sql_audit';
+---------------------+-------+
| Variable_name       | Value |
+---------------------+-------+
| ob_enable_sql_audit | ON    |
+---------------------+-------+

下载BenchmarkSQL

su - admin
wget -O benchmarksql-5.0.zip https://github.com/meiq4096/benchmarksql-5.0/archive/refs/heads/master.zip

配置benchmarksql

unzip benchmarksql-5.0.zip
cd benchmarksql-5.0-master/run
# 编辑props.ob配置文件
cp props.ob props.ob.bak20240312
vi props.obdb=oceanbase
driver=com.alipay.oceanbase.obproxy.mysql.jdbc.Driver
conn=jdbc:oceanbase://127.1:2883/tpcc?useUnicode=true&characterEncoding=utf-8
user=tpcc@yw#obcluster
password=tpcc// 仓库数为2
warehouses=2
// 并发数为5
loadWorkers=5terminals=2
//To run specified transactions per terminal- runMins must equal zero
runTxnsPerTerminal=0
//To run for specified minutes- runTxnsPerTerminal must equal zero
// 运行10分钟
runMins=10
//Number of total transactions per minute
limitTxnsPerMin=0//Set to true to run in 4.x compatible mode. Set to false to use the
//entire configured database evenly.
terminalWarehouseFixed=true//The following five values must add up to 100
newOrderWeight=45
paymentWeight=43
orderStatusWeight=4
deliveryWeight=4
stockLevelWeight=4// Directory name to create for collecting detailed result data.
// Comment this out to suppress.
resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS
osCollectorScript=./misc/os_collector_linux.py
osCollectorInterval=1

修改创建表的脚本

cd /sql.oceanbase
cp tableCreates.sql tableCreates.sql.bak20240312
# varchar2类型字段,与mysql租户不兼容,修改varchar2为varchar
sed -i 's/varchar2/varchar/g' tableCreates.sql
# 脚本中创建表组的语句有误,表组名称不能使用双引号
sed -i 's/\"tpcc_group\"/tpcc_group/g' tableCreates.sql
# mysql类型的租户不支持sequence,删除创建sequence的语句
sed -i 's/create sequence bmsql_hist_id_seq;//g' tableCreates.sql
cat tableCreates.sql

创建表

[admin@rac04 run]$ pwd 
/software/benchmarksql-5.0-master/run
[admin@rac04 run]$ ./runSQL.sh props.ob sql.oceanbase/tableCreates.sql

校验表

MySQL [tpcc]> show tables;
+------------------+
| Tables_in_tpcc   |
+------------------+
| bmsql_config     |
| bmsql_customer   |
| bmsql_district   |
| bmsql_history    |
| bmsql_item       |
| bmsql_new_order  |
| bmsql_oorder     |
| bmsql_order_line |
| bmsql_stock      |
| bmsql_warehouse  |
+------------------+
10 rows in set (0.004 sec)

加载数据入表

[admin@rac04 run]$ ./runLoader.sh props.ob
Starting BenchmarkSQL LoadDatadriver=com.alipay.oceanbase.obproxy.mysql.jdbc.Driver
conn=jdbc:oceanbase://127.1:2883/tpcc?useUnicode=true&characterEncoding=utf-8
user=tpcc@yw#obcluster
password=***********
warehouses=2
loadWorkers=5
fileLocation (not defined)
csvNullValue (not defined - using default 'NULL')Worker 000: Loading ITEM
Worker 001: Loading Warehouse      1
Worker 002: Loading Warehouse      2
Worker 000: Loading ITEM done
Worker 001: Loading Warehouse      1 done
Worker 002: Loading Warehouse      2 done

创建索引

[admin@rac04 run]$ ./runSQL.sh props.ob sql.oceanbase/indexCreates.sql
# ------------------------------------------------------------
# Loading SQL file sql.oceanbase/indexCreates.sql
# ------------------------------------------------------------
create index bmsql_customer_idx1
on  bmsql_customer (c_w_id, c_d_id, c_last, c_first) local;
create  index bmsql_oorder_idx1
on  bmsql_oorder (o_w_id, o_d_id, o_carrier_id, o_id) local;

开始BenchmarkSQL测试

开始测试之前,手动做一次合并

MySQL [oceanbase]> alter system major freeze;
Query OK, 0 rows affected (0.007 sec)

开始测试

[admin@rac04 run]$ ./runBenchmark.sh props.ob
01:27:24,021 [main] INFO   jTPCC : Term-00, 
01:27:24,028 [main] INFO   jTPCC : Term-00, +-------------------------------------------------------------+
01:27:24,029 [main] INFO   jTPCC : Term-00,      BenchmarkSQL v5.0
01:27:24,029 [main] INFO   jTPCC : Term-00, +-------------------------------------------------------------+
01:27:24,029 [main] INFO   jTPCC : Term-00,  (c) 2003, Raul Barbosa
01:27:24,029 [main] INFO   jTPCC : Term-00,  (c) 2004-2016, Denis Lussier
01:27:24,031 [main] INFO   jTPCC : Term-00,  (c) 2016, Jan Wieck
01:27:24,031 [main] INFO   jTPCC : Term-00, +-------------------------------------------------------------+
01:27:24,031 [main] INFO   jTPCC : Term-00, 
01:27:24,031 [main] INFO   jTPCC : Term-00, db=oracle
01:27:24,032 [main] INFO   jTPCC : Term-00, driver=com.alipay.oceanbase.obproxy.mysql.jdbc.Driver
01:27:24,032 [main] INFO   jTPCC : Term-00, conn=jdbc:oceanbase://127.1:2883/tpcc?useUnicode=true&characterEncoding=utf-8
01:27:24,032 [main] INFO   jTPCC : Term-00, user=tpcc@yw#obcluster
01:27:24,032 [main] INFO   jTPCC : Term-00, 
01:27:24,032 [main] INFO   jTPCC : Term-00, warehouses=2
01:27:24,032 [main] INFO   jTPCC : Term-00, terminals=2
01:27:24,033 [main] INFO   jTPCC : Term-00, runMins=10
01:27:24,033 [main] INFO   jTPCC : Term-00, limitTxnsPerMin=0
01:27:24,034 [main] INFO   jTPCC : Term-00, terminalWarehouseFixed=true
01:27:24,034 [main] INFO   jTPCC : Term-00, 
01:27:24,034 [main] INFO   jTPCC : Term-00, newOrderWeight=45
01:27:24,034 [main] INFO   jTPCC : Term-00, paymentWeight=43
01:27:24,034 [main] INFO   jTPCC : Term-00, orderStatusWeight=4
01:27:24,034 [main] INFO   jTPCC : Term-00, deliveryWeight=4
01:27:24,034 [main] INFO   jTPCC : Term-00, stockLevelWeight=4
01:27:24,034 [main] INFO   jTPCC : Term-00, 
01:27:24,034 [main] INFO   jTPCC : Term-00, resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS
01:27:24,034 [main] INFO   jTPCC : Term-00, osCollectorScript=./misc/os_collector_linux.py
01:27:24,034 [main] INFO   jTPCC : Term-00, 
01:27:24,045 [main] INFO   jTPCC : Term-00, copied props.ob to my_result_2024-03-12_012724/run.properties
01:27:24,045 [main] INFO   jTPCC : Term-00, created my_result_2024-03-12_012724/data/runInfo.csv for runID 6
01:27:24,046 [main] INFO   jTPCC : Term-00, writing per transaction results to my_result_2024-03-12_012724/data/result.csv
01:27:24,047 [main] INFO   jTPCC : Term-00, osCollectorScript=./misc/os_collector_linux.py
01:27:24,047 [main] INFO   jTPCC : Term-00, osCollectorInterval=1
01:27:24,047 [main] INFO   jTPCC : Term-00, osCollectorSSHAddr=null
01:27:24,047 [main] INFO   jTPCC : Term-00, osCollectorDevices=null
01:27:24,134 [main] INFO   jTPCC : Term-00,
01:27:24,420 [main] INFO   jTPCC : Term-00, C value for C_LAST during load: 19
01:27:24,421 [main] INFO   jTPCC : Term-00, C value for C_LAST this run:    122
01:27:24,421 [main] INFO   jTPCC : Term-00, 
……
……Term-00, Running Average tpmTOTAL: 1434.69    Current tpmTOTAL: 95832    Memory Usage: 18MB / 196MB          
01:37:24,679 [Thread-1] INFO   jTPCC : Term-00, 
01:37:24,679 [Thread-1] INFO   jTPCC : Term-00, 
01:37:24,679 [Thread-1] INFO   jTPCC : Term-00, Measured tpmC (NewOrders) = 637.1
01:37:24,680 [Thread-1] INFO   jTPCC : Term-00, Measured tpmTOTAL = 1434.47
01:37:24,680 [Thread-1] INFO   jTPCC : Term-00, Session Start     = 2024-03-12 01:27:24
01:37:24,680 [Thread-1] INFO   jTPCC : Term-00, Session End       = 2024-03-12 01:37:24
01:37:24,680 [Thread-1] INFO   jTPCC : Term-00, Transaction Count = 14348

查看执行计划

查询top sql

查找性能测试期间,执行时间top5 sql

这里着重解释一下request_time的条件,以性能测试结束时间为基点,查找请求时间位于2024-03-12 01:37:24及之前10分钟内的sql。需要注意的是将request_time的值是距离 1970-01-01 00:00:00.000000 的微秒数,因此需要调用time_to_usec函数转换时间。

SELECT/*+ PARALLEL(4)*/ sql_id,query_sql,plan_id, elapsed_time , trace_id    FROM oceanbase.gv$sql_audit     WHERE   tenant_id = 1001 and IS_EXECUTOR_RPC = 0 and request_time > (time_to_usec(date_format('2024-03-12 01:37:24','%Y-%m-%d %T')) - 10000000*6*10) AND request_time < time_to_usec(date_format('2024-03-12 01:37:24','%Y-%m-%d %T')) ORDER BY elapsed_time DESC LIMIT 10;MySQL [tpcc]> SELECT/*+ PARALLEL(4)*/ sql_id,query_sql,plan_id, elapsed_time , trace_id    ->          FROM oceanbase.gv$sql_audit     ->          WHERE   tenant_id = 1001 ->          and IS_EXECUTOR_RPC = 0 ->          and request_time > (time_to_usec(date_format('2024-03-12 01:37:24','%Y-%m-%d %T')) - 10000000*6*10) ->          AND request_time < time_to_usec(date_format('2024-03-12 01:37:24','%Y-%m-%d %T')) ->          ORDER BY elapsed_time DESC LIMIT 10\G
*************************** 1. row ***************************sql_id: FFFCA4D67EA0A788813031B8BBC3B329query_sql: SELECT count(*) AS low_stock FROM (    SELECT s_w_id, s_i_id, s_quantity         FROM bmsql_stock         WHERE s_w_id = 2 AND s_quantity < 12 AND s_i_id IN (            SELECT ol_i_id                 FROM bmsql_district                 JOIN bmsql_order_line ON ol_w_id = d_w_id                  AND ol_d_id = d_id                  AND ol_o_id >= d_next_o_id - 20                  AND ol_o_id < d_next_o_id                 WHERE d_w_id = 2 AND d_id = 5         )     )plan_id: 130
elapsed_time: 19786trace_id: YB420B0B0B0E-00061364401FFA67
*************************** 2. row ***************************sql_id: FFFCA4D67EA0A788813031B8BBC3B329query_sql: SELECT count(*) AS low_stock FROM (    SELECT s_w_id, s_i_id, s_quantity         FROM bmsql_stock         WHERE s_w_id = 1 AND s_quantity < 13 AND s_i_id IN (            SELECT ol_i_id                 FROM bmsql_district                 JOIN bmsql_order_line ON ol_w_id = d_w_id                  AND ol_d_id = d_id                  AND ol_o_id >= d_next_o_id - 20                  AND ol_o_id < d_next_o_id                 WHERE d_w_id = 1 AND d_id = 10         )     )plan_id: 130
elapsed_time: 18749trace_id: YB420B0B0B0E-000613643FFFF583
*************************** 3. row ***************************sql_id: FFFCA4D67EA0A788813031B8BBC3B329query_sql: SELECT count(*) AS low_stock FROM (    SELECT s_w_id, s_i_id, s_quantity         FROM bmsql_stock         WHERE s_w_id = 1 AND s_quantity < 16 AND s_i_id IN (            SELECT ol_i_id                 FROM bmsql_district                 JOIN bmsql_order_line ON ol_w_id = d_w_id                  AND ol_d_id = d_id                  AND ol_o_id >= d_next_o_id - 20                  AND ol_o_id < d_next_o_id                 WHERE d_w_id = 1 AND d_id = 10         )     )plan_id: 130
elapsed_time: 18074trace_id: YB420B0B0B0E-00061364402FC346
*************************** 4. row ***************************sql_id: FFFCA4D67EA0A788813031B8BBC3B329query_sql: SELECT s_quantity, s_data,        s_dist_01, s_dist_02, s_dist_03, s_dist_04,        s_dist_05, s_dist_06, s_dist_07, s_dist_08,        s_dist_09, s_dist_10     FROM bmsql_stock     WHERE s_w_id = 2 AND s_i_id = 68621     FOR UPDATEplan_id: 116
elapsed_time: 17701trace_id: YB420B0B0B0E-00061364404FC6E5
*************************** 5. row ***************************sql_id: FFFCA4D67EA0A788813031B8BBC3B329query_sql: SELECT s_quantity, s_data,        s_dist_01, s_dist_02, s_dist_03, s_dist_04,        s_dist_05, s_dist_06, s_dist_07, s_dist_08,        s_dist_09, s_dist_10     FROM bmsql_stock     WHERE s_w_id = 2 AND s_i_id = 59773     FOR UPDATEplan_id: 116
elapsed_time: 16933trace_id: YB420B0B0B0E-00061364400FF6EF
*************************** 6. row ***************************sql_id:                                 query_sql: SELECT s_quantity, s_data,        s_dist_01, s_dist_02, s_dist_03, s_dist_04,        s_dist_05, s_dist_06, s_dist_07, s_dist_08,        s_dist_09, s_dist_10     FROM bmsql_stock     WHERE s_w_id = 2 AND s_i_id = 45283     FOR UPDATEplan_id: 116
elapsed_time: 16895trace_id: YB420B0B0B0E-00061364401FFAE2
*************************** 7. row ***************************sql_id: FFFCA4D67EA0A788813031B8BBC3B329query_sql: SELECT s_quantity, s_data,        s_dist_01, s_dist_02, s_dist_03, s_dist_04,        s_dist_05, s_dist_06, s_dist_07, s_dist_08,        s_dist_09, s_dist_10     FROM bmsql_stock     WHERE s_w_id = 2 AND s_i_id = 83525     FOR UPDATEplan_id: 116
elapsed_time: 15588trace_id: YB420B0B0B0E-00061364401FF927
*************************** 8. row ***************************sql_id: FFFCA4D67EA0A788813031B8BBC3B329query_sql: SELECT i_price, i_name, i_data     FROM bmsql_item     WHERE i_id = 39891plan_id: 113
elapsed_time: 15104trace_id: YB420B0B0B0E-00061364403FC65B
*************************** 9. row ***************************sql_id: FFFCA4D67EA0A788813031B8BBC3B329query_sql: SELECT c_first, c_middle, c_last, c_street_1, c_street_2,        c_city, c_state, c_zip, c_phone, c_since, c_credit,        c_credit_lim, c_discount, c_balance     FROM bmsql_customer     WHERE c_w_id = 2 AND c_d_id = 4 AND c_id = 193     FOR UPDATEplan_id: 118
elapsed_time: 15015trace_id: YB420B0B0B0E-00061364401FF7C1
*************************** 10. row ***************************sql_id: FFFCA4D67EA0A788813031B8BBC3B329query_sql: SELECT i_price, i_name, i_data     FROM bmsql_item     WHERE i_id = 4421plan_id: 113
elapsed_time: 14234trace_id: YB420B0B0B0E-00061364400FFABC
10 rows in set (0.026 sec)

查看执行计划

首先查看top10的解析执行计划,这里挑3条,plan_id分别为130,116,113。

MySQL [tpcc]> explain SELECT count(*) AS low_stock FROM (    SELECT s_w_id, s_i_id, s_quantity   FROM bmsql_stock    WHERE s_w_id = 2 AND s_quantity < 12 AND s_i_id IN (  SELECT ol_i_id    FROM bmsql_district   JOIN bmsql_order_line ON ol_w_id = d_w_id  AND ol_d_id = d_id  AND ol_o_id >= d_next_o_id - 20   AND ol_o_id < d_next_o_id   WHERE d_w_id = 2 AND d_id = 5));
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Query Plan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ==========================================================
|ID|OPERATOR            |NAME            |EST. ROWS|COST |
----------------------------------------------------------
|0 |SCALAR GROUP BY     |                |1        |46984|
|1 | NESTED-LOOP JOIN   |                |1221     |46750|
|2 |  SUBPLAN SCAN      |VIEW2           |1215     |2677 |
|3 |   HASH DISTINCT    |                |1215     |2509 |
|4 |    NESTED-LOOP JOIN|                |1219     |1239 |
|5 |     TABLE GET      |bmsql_district  |1        |53   |
|6 |     TABLE SCAN     |bmsql_order_line|3656     |1194 |
|7 |  TABLE GET         |bmsql_stock     |1        |37   |
==========================================================Outputs & filters: 
-------------------------------------0 - output([T_FUN_COUNT(*)]), filter(nil), group(nil), agg_func([T_FUN_COUNT(*)])1 - output([1]), filter(nil), conds(nil), nl_params_([VIEW2.VIEW1.ol_i_id])2 - output([VIEW2.VIEW1.ol_i_id]), filter(nil), access([VIEW2.VIEW1.ol_i_id])3 - output([bmsql_order_line.ol_i_id]), filter(nil), distinct([bmsql_order_line.ol_i_id])4 - output([bmsql_order_line.ol_i_id]), filter(nil), conds(nil), nl_params_([bmsql_district.d_next_o_id - 20], [bmsql_district.d_next_o_id])5 - output([bmsql_district.d_next_o_id]), filter([bmsql_district.d_next_o_id > bmsql_district.d_next_o_id - 20]), access([bmsql_district.d_next_o_id]), partitions(p0)6 - output([bmsql_order_line.ol_i_id]), filter(nil), access([bmsql_order_line.ol_i_id]), partitions(p0)7 - output([1]), filter([bmsql_stock.s_quantity < 12]), access([bmsql_stock.s_quantity]), partitions(p0)|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.010 sec)
MySQL [tpcc]> explain SELECT s_quantity, s_data,        s_dist_01, s_dist_02, s_dist_03, s_dist_04,        s_dist_05, s_dist_06, s_dist_07, s_dist_08,        s_dist_09, s_dist_10     FROM bmsql_stock     WHERE s_w_id = 2 AND s_i_id = 59773     FOR UPDATE;
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Query Plan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| =========================================
|ID|OPERATOR |NAME       |EST. ROWS|COST|
-----------------------------------------
|0 |TABLE GET|bmsql_stock|1        |54  |
=========================================Outputs & filters: 
-------------------------------------0 - output([bmsql_stock.s_quantity], [bmsql_stock.s_data], [bmsql_stock.s_dist_01], [bmsql_stock.s_dist_02], [bmsql_stock.s_dist_03], [bmsql_stock.s_dist_04], [bmsql_stock.s_dist_05], [bmsql_stock.s_dist_06], [bmsql_stock.s_dist_07], [bmsql_stock.s_dist_08], [bmsql_stock.s_dist_09], [bmsql_stock.s_dist_10]), filter(nil), access([bmsql_stock.s_w_id], [bmsql_stock.s_i_id], [bmsql_stock.s_quantity], [bmsql_stock.s_data], [bmsql_stock.s_dist_01], [bmsql_stock.s_dist_02], [bmsql_stock.s_dist_03], [bmsql_stock.s_dist_04], [bmsql_stock.s_dist_05], [bmsql_stock.s_dist_06], [bmsql_stock.s_dist_07], [bmsql_stock.s_dist_08], [bmsql_stock.s_dist_09], [bmsql_stock.s_dist_10]), partitions(p0)|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.005 sec)
MySQL [tpcc]> explain SELECT i_price, i_name, i_data     FROM bmsql_item     WHERE i_id = 39891;
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Query Plan                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ========================================
|ID|OPERATOR |NAME      |EST. ROWS|COST|
----------------------------------------
|0 |TABLE GET|bmsql_item|1        |53  |
========================================Outputs & filters: 
-------------------------------------0 - output([bmsql_item.i_price], [bmsql_item.i_name], [bmsql_item.i_data]), filter(nil), access([bmsql_item.i_price], [bmsql_item.i_name], [bmsql_item.i_data]), partitions(p0)|
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.004 sec)

查看top3的实际执行计划。由于执行计划已经刷出缓存,因此性能测试期间top10sql的实际执行计划没法看到。这里手动执行相关sql,再查询其执行计划。

MySQL [tpcc]> SELECT count(*) AS low_stock FROM (    SELECT s_w_id, s_i_id, s_quantity   FROM bmsql_stock    WHERE s_w_id = 2 AND s_quantity < 12 AND s_i_id IN (  SELECT ol_i_id    FROM bmsql_district   JOIN bmsql_order_line ON ol_w_id = d_w_id  AND ol_d_id = d_id  AND ol_o_id >= d_next_o_id - 20   AND ol_o_id < d_next_o_id   WHERE d_w_id = 2 AND d_id = 5));
-- 查询刚刚执行的sql的plan_id
MySQL [tpcc1]> SELECT/*+ PARALLEL(4)*/ tenant_id,svr_ip,svr_port,sql_id,query_sql,plan_id, elapsed_time , trace_id  ->          FROM oceanbase.gv$sql_audit     ->          WHERE   tenant_id = 1001 and user_name='tpcc'->          and IS_EXECUTOR_RPC = 0 ->          and request_time > (time_to_usec(now()) - 10000000*6*10) ->          AND request_time < time_to_usec(now()) ->          ORDER BY elapsed_time DESC LIMIT 10\G
*************************** 1. row ***************************tenant_id: 1001svr_ip: 11.11.11.14svr_port: 2882sql_id: 9EDED4BC6305E5F4FCF86A6366BDD638query_sql: SELECT count(*) AS low_stock FROM (    SELECT s_w_id, s_i_id, s_quantity   FROM bmsql_stock    WHERE s_w_id = 2 AND s_quantity < 12 AND s_i_id IN (  SELECT ol_i_id    FROM bmsql_district   JOIN bmsql_order_line ON ol_w_id = d_w_id  AND ol_d_id = d_id  AND ol_o_id >= d_next_o_id - 20   AND ol_o_id < d_next_o_id   WHERE d_w_id = 2 AND d_id = 5))plan_id: 273
elapsed_time: 21739trace_id: YB420B0B0B0E-00061364403FC7B5-- 根据sql_id查看实际执行计划
MySQL [tpcc1]> select * from oceanbase.gv$plan_cache_plan_explain where tenant_id=1001 and ip='11.11.11.14' and port='2882' and plan_id =273;
+-----------+-------------+------+---------+------------+--------------+--------------------------+------------------+------+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| TENANT_ID | IP          | PORT | PLAN_ID | PLAN_DEPTH | PLAN_LINE_ID | OPERATOR                 | NAME             | ROWS | COST  | PROPERTY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
+-----------+-------------+------+---------+------------+--------------+--------------------------+------------------+------+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|      1001 | 11.11.11.14 | 2882 |     273 |          0 |            0 | PHY_SCALAR_AGGREGATE     | NULL             |    1 | 46983 | NULL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|      1001 | 11.11.11.14 | 2882 |     273 |          1 |            1 |  PHY_NESTED_LOOP_JOIN    | NULL             | 1221 | 46749 | NULL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|      1001 | 11.11.11.14 | 2882 |     273 |          2 |            2 |   PHY_SUBPLAN_SCAN       | NULL             | 1215 |  2676 | NULL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|      1001 | 11.11.11.14 | 2882 |     273 |          3 |            3 |    PHY_HASH_DISTINCT     | NULL             | 1215 |  2508 | NULL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|      1001 | 11.11.11.14 | 2882 |     273 |          4 |            4 |     PHY_NESTED_LOOP_JOIN | NULL             | 1219 |  1238 | NULL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|      1001 | 11.11.11.14 | 2882 |     273 |          5 |            5 |      PHY_TABLE_SCAN      | bmsql_district   |    1 |    52 | table_rows:20, physical_range_rows:1, logical_range_rows:1, index_back_rows:0, output_rows:0, est_method:local_storage                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|      1001 | 11.11.11.14 | 2882 |     273 |          5 |            6 |      PHY_TABLE_SCAN      | bmsql_order_line | 3656 |  1193 | table_rows:663235, physical_range_rows:3655, logical_range_rows:3655, index_back_rows:0, output_rows:3655, est_method:local_storage, avaiable_index_name[bmsql_order_line], estimation info[table_id:1100611139453804, (table_type:1, version:0-1710180010831939-1710180010831939, logical_rc:32898, physical_rc:32898), (table_type:7, version:1710180000826357-1710180010831939-1710180031319922, logical_rc:0, physical_rc:0), (table_type:5, version:1710180000826357-1710180010831939-1710180031319922, logical_rc:0, physical_rc:0), (table_type:0, version:1710180031319922-1710180031319922-9223372036854775807, logical_rc:0, physical_rc:0)] |
|      1001 | 11.11.11.14 | 2882 |     273 |          2 |            7 |   PHY_TABLE_SCAN         | bmsql_stock      |    1 |    36 | table_rows:200000, physical_range_rows:1, logical_range_rows:1, index_back_rows:0, output_rows:0, est_method:local_storage, estimation info[table_id:1100611139453806, (table_type:1, version:0-1710180010831939-1710180010831939, logical_rc:200000, physical_rc:200000), (table_type:7, version:1710180000827822-1710180010831939-1710180031377423, logical_rc:0, physical_rc:0), (table_type:5, version:1710180000827822-1710180010831939-1710180031377423, logical_rc:0, physical_rc:0), (table_type:0, version:1710180031377423-1710180031377423-9223372036854775807, logical_rc:0, physical_rc:0)]                                               |
+-----------+-------------+------+---------+------------+--------------+--------------------------+------------------+------+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
8 rows in set (0.012 sec)

另外两个sql也是同样的方法

MySQL [tpcc]> SELECT s_quantity, s_data,        s_dist_01, s_dist_02, s_dist_03, s_dist_04,        s_dist_05, s_dist_06, s_dist_07, s_dist_08,        s_dist_09, s_dist_10     FROM bmsql_stock     WHERE s_w_id = 2 AND s_i_id = 59773     FOR UPDATE;
+------------+------------------------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+
| s_quantity | s_data                                   | s_dist_01                | s_dist_02                | s_dist_03                | s_dist_04                | s_dist_05                | s_dist_06                | s_dist_07                | s_dist_08                | s_dist_09                | s_dist_10                |
+------------+------------------------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+
|        104 | BpZzCr9yN9SC8clF5llHzwmg5ANR2drV0ZM553QR | mWO9fxl80umm3A23HwjvNySD | mL3z0rJqTApoGIIJjan5bGJd | xqELg15kkS8s6HTtS9hh4sXg | dTdPg5Jxlow6W9rR8rWoZxCH | tdRCLqTvKjzL00278CuyVXnb | DXL4EfkVLKtmppr1izzGfEKU | b3JcaKms9g1AwbXJyfBP8X3f | ECNsuU7KphEUcLmp9csAaWjv | PFSSM2fGrMSrNx7stdhSb5HS | Juk9PMbM4rgf0MbUcNRQJFkr |
+------------+------------------------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+
1 row in set (0.012 sec)MySQL [tpcc1]> SELECT/*+ PARALLEL(4)*/ tenant_id,svr_ip,svr_port,sql_id,query_sql,plan_id, elapsed_time , trace_id  ->          FROM oceanbase.gv$sql_audit     ->          WHERE   tenant_id = 1001 and user_name='tpcc'->          and IS_EXECUTOR_RPC = 0 ->          and request_time > (time_to_usec(now()) - 10000000*6*10) ->          AND request_time < time_to_usec(now()) ->          ORDER BY elapsed_time DESC LIMIT 10\G……
*************************** 2. row ***************************tenant_id: 1001svr_ip: 11.11.11.14svr_port: 2882sql_id: 7229213613983BC5FDA15AD11EC70D01query_sql: SELECT s_quantity, s_data,        s_dist_01, s_dist_02, s_dist_03, s_dist_04,        s_dist_05, s_dist_06, s_dist_07, s_dist_08,        s_dist_09, s_dist_10     FROM bmsql_stock     WHERE s_w_id = 2 AND s_i_id = 59773     FOR UPDATEplan_id: 285
elapsed_time: 11143trace_id: YB420B0B0B0E-00061364401FFB9AMySQL [tpcc1]> select * from oceanbase.gv$plan_cache_plan_explain where tenant_id=1001 and ip='11.11.11.14' and port='2882' and plan_id =285;
+-----------+-------------+------+---------+------------+--------------+----------------+-------------+------+------+----------------------------------------------------------------------------------------------------------------------------+
| TENANT_ID | IP          | PORT | PLAN_ID | PLAN_DEPTH | PLAN_LINE_ID | OPERATOR       | NAME        | ROWS | COST | PROPERTY                                                                                                                   |
+-----------+-------------+------+---------+------------+--------------+----------------+-------------+------+------+----------------------------------------------------------------------------------------------------------------------------+
|      1001 | 11.11.11.14 | 2882 |     285 |          0 |            0 | PHY_TABLE_SCAN | bmsql_stock |    1 |   53 | table_rows:200000, physical_range_rows:1, logical_range_rows:1, index_back_rows:0, output_rows:1, est_method:local_storage |
+-----------+-------------+------+---------+------------+--------------+----------------+-------------+------+------+----------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.008 sec)
MySQL [tpcc]> SELECT i_price, i_name, i_data     FROM bmsql_item     WHERE i_id = 39891;
+---------+------------------------+-----------------------------------------------+
| i_price | i_name                 | i_data                                        |
+---------+------------------------+-----------------------------------------------+
|   69.54 | OMb08X4TPeHtLe428FtyEC | wAUmMP35zjmdWqzAVFPMijvh9fugn6EzuSclVnNIabBy8 |
+---------+------------------------+-----------------------------------------------+
1 row in set (0.003 sec)
MySQL [tpcc1]> SELECT/*+ PARALLEL(4)*/ tenant_id,svr_ip,svr_port,sql_id,query_sql,plan_id, elapsed_time , trace_id  ->          FROM oceanbase.gv$sql_audit     ->          WHERE   tenant_id = 1001 and user_name='tpcc'->          and IS_EXECUTOR_RPC = 0 ->          and request_time > (time_to_usec(now()) - 10000000*6*10) ->          AND request_time < time_to_usec(now()) ->          ORDER BY elapsed_time DESC LIMIT 10\G
……
*************************** 2. row ***************************tenant_id: 1001svr_ip: 11.11.11.14svr_port: 2882sql_id: A460265EC2F0763A15DD27CE9E4E2200query_sql: SELECT i_price, i_name, i_data     FROM bmsql_item     WHERE i_id = 39891plan_id: 286
elapsed_time: 2816trace_id: YB420B0B0B0E-00061364403FC7C2
2 rows in set (0.018 sec)
MySQL [tpcc1]> select * from oceanbase.gv$plan_cache_plan_explain where tenant_id=1001 and ip='11.11.11.14' and port='2882' and plan_id =286;
+-----------+-------------+------+---------+------------+--------------+----------------+------------+------+------+----------------------------------------------------------------------------------------------------------------------------+
| TENANT_ID | IP          | PORT | PLAN_ID | PLAN_DEPTH | PLAN_LINE_ID | OPERATOR       | NAME       | ROWS | COST | PROPERTY                                                                                                                   |
+-----------+-------------+------+---------+------------+--------------+----------------+------------+------+------+----------------------------------------------------------------------------------------------------------------------------+
|      1001 | 11.11.11.14 | 2882 |     286 |          0 |            0 | PHY_TABLE_SCAN | bmsql_item |    1 |   52 | table_rows:100000, physical_range_rows:1, logical_range_rows:1, index_back_rows:0, output_rows:1, est_method:local_storage |
+-----------+-------------+------+---------+------------+--------------+----------------+------------+------+------+----------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.008 sec)

总结

  1. 使用benchmarksql的create_table.sql脚本创建表之前,需要修改一些内容:

    • varchar2–>varchar;
    • 创建tablegroup的语句,表组名不能使用双引号,需要删除双引号;
    • 删除创建sequence的语句。
  2. 查看执行计划的一般步骤

    • (可选)查询oceanbase.gv$sql_audit 视图获取top sql,获取tenant_id,svr_ip,svr_port,sql_id,query_sql,plan_id等关键信息

      --查看10分钟内的耗时topsql
      SELECT/*+ PARALLEL(4)*/ tenant_id,svr_ip,svr_port,sql_id,query_sql,plan_id, elapsed_time , trace_id  FROM oceanbase.gv$sql_audit     WHERE   tenant_id = 1001 and user_name='tpcc'and IS_EXECUTOR_RPC = 0 and request_time > (time_to_usec(now()) - 10000000*6*10) AND request_time < time_to_usec(now()) ORDER BY elapsed_time DESC LIMIT 10;
      
      -- 查看指定时间段内的耗时topsql,这里是2024-03-12 01:37:24至前10分钟
      SELECT/*+ PARALLEL(4)*/ *   FROM oceanbase.gv$sql_audit     WHERE   tenant_id = 1001 and IS_EXECUTOR_RPC = 0 and request_time > (time_to_usec(date_format('2024-03-12 01:37:24','%Y-%m-%d %T')) - 10000000*6*10) AND request_time < time_to_usec(date_format('2024-03-12 01:37:24','%Y-%m-%d %T')) ORDER BY elapsed_time DESC LIMIT 10;
      
    • 查询oceanbase.gv$plan_cache_plan_explain视图获取真实执行计划(缓存被清理就看不到了)

      select*
      fromoceanbase.gv$plan_cache_plan_explain
      wheretenant_id = 1001and ip = '11.11.11.14'and port = '2882'and plan_id = 286;
      
    • 对于解析执行计划,直接使用explain命令即可,比如:

      explain SELECT i_price, i_name, i_data FROM bmsql_item WHERE i_id = 39891;
      

参考文档

OceanBase分布式数据库-海量数据 笔笔算数

GitHub - meiq4096/benchmarksql-5.0: benchmarksql-5.0 for oceanbase

查询某段时间内执行时间排名 TOP N 的请求 -OceanBase 数据库-OceanBase文档中心-分布式数据库使用文档

查询排名 TOP N 的 SQL -OceanBase 数据库-OceanBase文档中心-分布式数据库使用文档

函数 -OceanBase 数据库-OceanBase文档中心-分布式数据库使用文档

这篇关于Oceanbase使用BenchmarkSQL 进行tpcc测试及执行计划查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/800551

相关文章

性能测试介绍

性能测试是一种测试方法,旨在评估系统、应用程序或组件在现实场景中的性能表现和可靠性。它通常用于衡量系统在不同负载条件下的响应时间、吞吐量、资源利用率、稳定性和可扩展性等关键指标。 为什么要进行性能测试 通过性能测试,可以确定系统是否能够满足预期的性能要求,找出性能瓶颈和潜在的问题,并进行优化和调整。 发现性能瓶颈:性能测试可以帮助发现系统的性能瓶颈,即系统在高负载或高并发情况下可能出现的问题

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

Hadoop数据压缩使用介绍

一、压缩原则 (1)运算密集型的Job,少用压缩 (2)IO密集型的Job,多用压缩 二、压缩算法比较 三、压缩位置选择 四、压缩参数配置 1)为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器 2)要在Hadoop中启用压缩,可以配置如下参数

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

字节面试 | 如何测试RocketMQ、RocketMQ?

字节面试:RocketMQ是怎么测试的呢? 答: 首先保证消息的消费正确、设计逆向用例,在验证消息内容为空等情况时的消费正确性; 推送大批量MQ,通过Admin控制台查看MQ消费的情况,是否出现消费假死、TPS是否正常等等问题。(上述都是临场发挥,但是RocketMQ真正的测试点,还真的需要探讨) 01 先了解RocketMQ 作为测试也是要简单了解RocketMQ。简单来说,就是一个分

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

活用c4d官方开发文档查询代码

当你问AI助手比如豆包,如何用python禁止掉xpresso标签时候,它会提示到 这时候要用到两个东西。https://developers.maxon.net/论坛搜索和开发文档 比如这里我就在官方找到正确的id描述 然后我就把参数标签换过来

pdfmake生成pdf的使用

实际项目中有时会有根据填写的表单数据或者其他格式的数据,将数据自动填充到pdf文件中根据固定模板生成pdf文件的需求 文章目录 利用pdfmake生成pdf文件1.下载安装pdfmake第三方包2.封装生成pdf文件的共用配置3.生成pdf文件的文件模板内容4.调用方法生成pdf 利用pdfmake生成pdf文件 1.下载安装pdfmake第三方包 npm i pdfma