📢📢📢📣📣📣
哈喽!大家好,我是【IT邦德】,江湖人称jeames007,10余年DBA及大数据工作经验
一位上进心十足的【大数据领域博主】!😜😜😜
中国DBA联盟(ACDU)成员,目前服务于工业互联网
擅长主流Oracle、MySQL、PG、高斯及Greenplum运维开发,备份恢复,安装迁移,性能优化、故障应急处理等。
✨ 如果有对【数据库】感兴趣的【小可爱】,欢迎关注【IT邦德】💞💞💞
❤️❤️❤️感谢各位大可爱小可爱!❤️❤️❤️
文章目录
- 📣 1.BenmarkSQL
- ✨ 1.BenmarkSQL介绍
- ✨ 1.2 下载BenmarkSQL
- 📣 2.OceanBase4.2 集群
- ✨ 2.1 集群状态
- ✨ 2.2 测试用户
- 📣 3.配置文件修改
- 📣 4.生成数据
- 📣 5.创建索引
- 📣 6.TPCC测试
- 📣 7.TOP SQL分析
- ✨ 7.1 查询TOP
- ✨ 7.2 执行计划分析
- 📣 8.报错分析
- 📣 9.总结
本文详细介绍了OceanBase 的执行计划查看方法,包括 explain 命令和查看实际执行计划。
📣 1.BenmarkSQL
✨ 1.BenmarkSQL介绍
benchmarksql是一款符合TPC-C基准压力测试工具,TPC-C是衡量在线事务处理的基准。
TPC-C模型是模拟一个商品批发公司的销售模型,这个模型涵盖了一个批发公司面向客户对一系列商品进行销售的过程,这包括管理订单,管理库存,管理账号收支等操作。这些操作涉及到仓库、商品、客户、订单等概念,围绕这些概念,构造了数据表格,以及相应的数据库操作。
✨ 1.2 下载BenmarkSQL
注意:需要java环境,不低于1.8.0
[root@centos79 ~]# yum install git
[root@centos79 ~]# git clone https://github.com/obpilot/benchmarksql-5.0.git
[root@centos79 ~]# git clone https://github.com/obpilot/benchmarksql-5.0.git
Cloning into 'benchmarksql-5.0'...
remote: Enumerating objects: 110, done.
remote: Counting objects: 100% (110/110), done.
remote: Compressing objects: 100% (90/90), done.
remote: Total 110 (delta 14), reused 105 (delta 12), pack-reused 0
Receiving objects: 100% (110/110), 5.58 MiB | 89.00 KiB/s, done.
Resolving deltas: 100% (14/14), done.
📣 2.OceanBase4.2 集群
✨ 2.1 集群状态
1.启动 OceanBase 数据库
[root@centos79 ~]# su - admin
[admin@centos79 ~]$ obd cluster start obtest
obclient -h192.168.3.20 -P2881 -uroot -p’gxmxiv4fV6uKhJfgDktn’ -Doceanbase -A
2.查看集群状态
[admin@centos79 ~]$ obd cluster display obtest
Get local repositories and plugins ok
Open ssh connection ok
Cluster status check ok
Connect to observer 192.168.3.20:2881 ok
Wait for observer init ok
+------------------------------------------------+
| observer |
+--------------+---------+------+-------+--------+
| ip | version | port | zone | status |
+--------------+---------+------+-------+--------+
| 192.168.3.20 | 4.2.2.0 | 2881 | zone1 | ACTIVE |
+--------------+---------+------+-------+--------+
obclient -h192.168.3.20 -P2881 -uroot -p'gxmxiv4fV6uKhJfgDktn' -Doceanbase -AConnect to obproxy ok
+------------------------------------------------+
| obproxy |
+--------------+------+-----------------+--------+
| ip | port | prometheus_port | status |
+--------------+------+-----------------+--------+
| 192.168.3.20 | 2883 | 2884 | active |
+--------------+------+-----------------+--------+
obclient -h192.168.3.20 -P2883 -uroot -p'gxmxiv4fV6uKhJfgDktn' -Doceanbase -A Trace ID: bb89c746-e33d-11ee-97f5-000c29377d62
If you want to view detailed obd logs, please run: obd display-trace bb89c746-e33d-11ee-97f5-000c29377d62
✨ 2.2 测试用户
–登陆租户
obclient -uroot@mq_t1 -h127.1 -P2883 -p123456 -A
obclient [(none)]> use oceanbase
–创建测试用户及数据库
obclient [oceanbase]> create database tpcc;
obclient [oceanbase]> create user tpcc identified by ‘123456’;
obclient [oceanbase]> grant all on . to tpcc;
–重新登陆
[admin@centos79 ~]$ obclient -utpcc@mq_t1 -h127.1 -P2883 -p123456 -A
obclient [(none)]> use tpcc
📣 3.配置文件修改
这个配置文件在/root/benchmarksql-5.0/run/目录下,编辑后的内容如下:
cat > /root/benchmarksql-5.0/run/props.ob <<“EOF”
db=oracle
driver=com.alipay.oceanbase.obproxy.mysql.jdbc.Driver
conn=jdbc:oceanbase://192.168.3.20:2883/tpcc?useUnicode=true&characterEncoding=utf-8
user=tpcc@mq_t1#obcluster
password=123456
warehouses=2
loadWorkers=1
terminals=10
runTxnsPerTerminal=0
runMins=1
limitTxnsPerMin=0
terminalWarehouseFixed=true
newOrderWeight=45
paymentWeight=43
orderStatusWeight=4
deliveryWeight=4
stockLevelWeight=4
resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS
osCollectorScript=./misc/os_collector_linux.py
osCollectorInterval=1
EOF
📣 4.生成数据
1.修改字段类型
sql文件在benchmarksql-5.0-master/run/sql.oceanbase中,
看了一些建表语句,使用了varchar2类型,ob为mysql模式,需要修改:
[root@centos79 ~]# find / -name sql.oceanbase
/root/benchmarksql-5.0/run/sql.oceanbase
[root@centos79 ~]# cd /root/benchmarksql-5.0/run/sql.oceanbase
[root@centos79 sql.oceanbase]# ll
-rwxr-xr-x. 1 root root 190 Mar 16 19:17 indexCreates.sql
-rwxr-xr-x. 1 root root 3719 Mar 16 19:17 tableCreates3.sql
-rwxr-xr-x. 1 root root 3593 Mar 16 19:17 tableCreates.sql
[root@centos79 sql.oceanbase]# cp tableCreates.sql tableCreates_bak.sql
[root@centos79 sql.oceanbase]# sed -i ‘s/varchar2/varchar/g’ tableCreates_bak.sql
2.运行创建表语句
[root@centos79 ~]# cd /root/benchmarksql-5.0/run
[root@centos79 run]# ./runSQL.sh props.ob sql.oceanbase/tableCreates_bak.sql
这里出了点小问题,这个脚本报找不到funcs.sh文件,应该是环境变量的问题,不过通过更改脚本中funcs.sh路径为绝对路径也可以解决这个问题:
编辑一下runSQL.sh文件,更改内容如下:#!/usr/bin/env bash# ----
# Check command line usage
# ----
if [ $# -ne 2 ] ; thenecho "usage: $(basename $0) PROPS_FILE SQL_FILE" >&2exit 2
fi# ----
# Load common functions
# ----
source /root/benchmarksql-5.0/run/funcs.sh $1SHARDING = 'NONE';
–加载数据
[root@centos79 run]# ./runLoader.sh props.ob
装载前防止有大事物,需要调整事务超时参数:
obclient [oceanbase]> show variables like ‘%timeout%’;
±--------------------±-----------------+
| Variable_name | Value |
±--------------------±-----------------+
| connect_timeout | 10 |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| ob_pl_block_timeout | 3216672000000000 |
| ob_query_timeout | 10000000 |
| ob_trx_idle_timeout | 86400000000 |
| ob_trx_lock_timeout | -1 |
| ob_trx_timeout | 86400000000 |
| wait_timeout | 28800 |
±--------------------±-----------------+
obclient [oceanbase]> set global ob_trx_timeout=864000000000;
obclient [oceanbase]> set global ob_query_timeout=864000000000;
说明:
1.运行脚本,装载数据,输出显示装载成功
2.运行脚本报错,记得删除中文描述即可
[root@centos79 run]# ./runLoader.sh props.ob
📣 5.创建索引
[root@centos79 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;
📣 6.TPCC测试
[root@centos79 run]# ./runBenchmark.sh props.ob
📣 7.TOP SQL分析
✨ 7.1 查询TOP
obclient [tpcc]> show variables like ‘%enable_sql_audit%’;
±--------------------±------+
| Variable_name | Value |
±--------------------±------+
| ob_enable_sql_audit | ON |
±--------------------±------+
SELECT sql_id, count(*),round(avg(elapsed_time)) avg_elapsed_time,
round(avg(execute_time)) avg_exec_time,
s.svr_ip,
s.svr_port,
s.tenant_id,
s.plan_id
FROM oceanbase.GV$OB_SQL_AUDIT s
WHERE 1=1
and user_name=‘tpcc’
and request_time >= time_to_usec(DATE_SUB(current_timestamp, INTERVAL 200 MINUTE) )
GROUP BY sql_id
order by avg_elapsed_time desc limit 10;
✨ 7.2 执行计划分析
select distinct query_sql from oceanbase.GV$OB_SQL_AUDIT where sql_id='7229213613983BC5FDA15AD11EC70D01';+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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 = 1 AND s_i_id = 97744 FOR UPDATE |
| 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 = 10652 FOR UPDATE |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.068 sec)实际执行计划SELECT SVR_IP, plan_depth, plan_line_id,operator,name,rows,cost,property from GV$OB_PLAN_CACHE_PLAN_EXPLAIN
where tenant_id=1002 AND SVR_IP = '192.168.3.20'
AND svr_port=2882 AND plan_id=681\G;*************************** 1. row ***************************ip: 127.0.0.1plan_depth: 0plan_line_id: 0operator: PHY_TABLE_SCANname: bmsql_stockrows: 9cost: 248249property: table_rows:86530, physical_range_rows:200159, logical_range_rows:86530, index_back_rows:0, output_rows:8, est_method:local_storage, avaiable_index_name[bmsql_stock], estimation info[table_id:1100611139453798, (table_type:1, version:0-1-1, logical_rc:0, physical_rc:0), (table_type:7, version:1-1643245354224215-1643245354224215, logical_rc:0, physical_rc:96654), (table_type:0, version:1643245354224215-1643245354224215-9223372036854775807, logical_rc:86530, physical_rc:103505)]1 row in set (0.013 sec)ERROR: No query specified 解释执行计划*************************** 1. row ***************************Query Plan: ============================================|ID|OPERATOR |NAME |EST. ROWS|COST |--------------------------------------------|0 |TABLE SCAN|bmsql_stock|9 |248250|============================================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([bmsql_stock.s_w_id = 2], [bmsql_stock.s_i_id = 10652]),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.016 sec)ERROR: No query specified![ ](/Users/mac/Library/Application Support/typora-user-images/image-20240316002639580.png)
📣 8.报错分析
1.TPCC测试以下报错处理
20:17:55,307 [main] ERROR jTPCC : Term-00, Invalid number of terminals! Usage: 15MB / 178MB
props.ob文件里设置的需要满足:
1.文件的所有注释和多余空格删除,否则可能报错
2.0<Terminals num<=10* Warehouses num
生成数据拨错处理
./runSQL.sh props.ob sql.oceanbase/tableCreates_bak.sql
You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near ‘“tpcc_group”’ at line 1
原因为OB4.2版本影响导致语法的错误
create tablegroup “tpcc_group” 变更为:
create tablegroup tpcc_group";
📣 9.总结
通过本文的学习,可以帮助大家掌握 OceanBase 的执行计划查看方法,包括 explain 命令和查看实际执行计划。