oceanabse执行计划查看

安装benchmarksql

下载benchmarksql后解压并进行编译安装,这里是安装在/opt目录下的。网上有很多针对于执行文件或者java文件内容的更改,我这并没有更改过文件内容,且系统自带的openjdk也可满足此次测试。

https://sourceforge.net/projects/benchmarksql/

 

[root@db opt]unzip benchmarksql-5.0.zip

[root@db benchmarksql-5.0]# ant

Buildfile: /opt/benchmarksql-5.0/build.xml

init:

    [mkdir] Created dir: /opt/benchmarksql-5.0/build

compile:

    [javac] Compiling 11 source files to /opt/benchmarksql-5.0/build

dist:

    [mkdir] Created dir: /opt/benchmarksql-5.0/dist

      [jar] Building jar: /opt/benchmarksql-5.0/dist/BenchmarkSQL-5.0.jar

BUILD SUCCESSFUL

Total time: 6 seconds

由于benchmarksql目录中没有oceanabase的驱动,所以需要将驱动移动到benchmarksql的lib目录下

[root@db lib]# cp /opt/datax/plugin/reader/oceanbasev10reader/libs/oceanbase-client-1.1.10.jar ./

 

配置props.mysql文件

[root@db run]# cat props.mysql

db=oracle

driver=com.alipay.oceanbase.jdbc.Driver

conn=jdbc:oceanbase://172.17.0.2:2883/test

user=user1@obmysql#obce-single

password=user1

 

warehouses=4

loadWorkers=10

 

terminals=10

//To run specified transactions per terminal- runMins must equal zero

runTxnsPerTerminal=0

//To run for specified minutes- runTxnsPerTerminal must equal zero

runMins=1

//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

初始化表结构

因为oceanbase的事务 查询时间是10s和事务超时时间为120s所以有的时候会断开,在此将该参数值调整大一点。

设置事务超时时间

Worker 001: ERROR: Transaction is timeout

ob_query_timeout 用于设置查询超时时间,单位是微秒。

set global ob_query_timeout=36000000000;

ob_trx_timeout 用于设置事务超时时间,单位为微秒。

set global ob_trx_timeout=36000000000;

初始化表结构及数据

该部分是按照配置文件中的warehouses值进行数据的加载的,值小加载的数据少。

[root@db run]# ./runDatabaseBuild.sh props.mysql

进行压力测试

[root@db run]# ./runBenchmark.sh props.mysql

 

查询top sql并分析执行计划

分析 TPC-C TOP SQL,并查看 3条 SQL 的 解析执行计划 和 实际执行计划。

执行的sql语句都通过数据字段v$sql_audit进行统计,所以查询该数据字典即可,由于查询的sql_id基本都是乱码,所以我查询transaction_hash来过滤对应的慢sql。

select QUERY_SQL  from oceanbaMySQL [test]> SELECT TRANSACTION_HASH ,  round(avg(elapsed_time)) avg_elapsed_time,                       round(avg(execute_time)) avg_exec_time      FROM oceanbase.gv$sql_audit s      WHERE request_time >= time_to_usec(DATE_SUB(current_timestamp, INTERVAL 30 MINUTE) )         GROUP BY TRANSACTION_HASH  order by avg_elapsed_time desc limit 10;

 

按照TRANSACTION_HASH查询sql语句,并查看执行计划。

 

根据查询的sql语句,通过explain查看对应的执行计划

 

根据查询结果,前三条慢sql的plan_id都为54,查询其真实的执行计划。

实际的访问计划可以从视图 gv$plan_cache_plan_explain 查看,这个视图一定要用 ip,port,tenant_id,plan_id 这四个字段完全匹配才能够查出结果,和普通的视图是不一样的

SELECT plan_line_id,operator,name,rows,cost from oceanbase.`gv$plan_cache_plan_explain` where tenant_id=1001 AND ip = '127.0.0.1' AND port=2882 AND plan_id=54 \G;

 

 

posted on 2022-04-22 15:41  昔日丶芳华  阅读(247)  评论(0编辑  收藏  举报