---
title: slow query-V3.1.5-OceanBase 数据库文档-分布式数据库使用文档
description: 分布式数据库OceanBase 社区版文档中心，提供关于slow query的相关内容，方便用户更好的应用分布式数据库OceanBaseOceanBase 数据库
image: https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*OSPzQ6GUQF4AAAAAQHAAAAgAeiGDAQ/original
---
[OceanBase AI 数据大会](https://www.oceanbase.com/conference2026 "OceanBase AI 数据大会")文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*P8CuR4UJ_FkAAAAAAAAAAAAADiGDAQ/original) OceanBase 数据库分布式版 - V 3.1.5 社区版

# slow query

更新时间：2026-05-27 10:21:39

[编辑](https://github.com/oceanbase/oceanbase-doc/edit/V3.1.5/zh-CN/100.users-guide/900.performance-tuning-guide/200.performance-related-tools/300.log-information/300.slow_query.md)  

## slow query 的作用

在 Query 执行期间，如果编译加执行的耗时超过一定的阈值（由 trace_log_slow_query_watermark 配置项控制），则将会认为这个 Query 是一个慢查询（ slow query），并且会将该慢查询的 trace_log 强制打印到日志中。trace_log 中详细记录了每个阶段的执行耗时，对于分析慢查询的产生原因有很大的帮助。

## Slow query 的检测方法

```test
[2021-10-19 16:47:18.947121] TRACE [TRACE]obmp_base.cpp:134
[105909][0][YA92464589051-0005CEB0A443493C-0-0] [lt=8] [dc=0]
[slow query](TRACE=begin_ts=1634633228637094 2021-10-19 08:47:08.637094|
[process_begin] u=0 in_queue_time:16, receive_ts:1634633228939375, enqueue_ts:1634633228939377|
[start_sql] u=1 addr:{ip:"xxx.xxx.xxx.xxx", port:41995}|
[query_begin] u=1 trace_id:YA92464589051-0005CEB0A443493C-0-0|
[before_processor_run] u=5 |
[session] u=4 sid:3221502589, tenant_id:1|
[parse_begin] u=24 stmt:"select * from t where sleep(10)", stmt_len:31|
[cache_get_plan_begin] u=1 |
[cache_get_plan_end] u=25 |
[transform_with_outline_begin] u=2 |
[pc_fast_parse_start] u=67 |
[pc_fast_parse_end] u=5 |
[transform_with_outline_end] u=8 |
[resolve_begin] u=29 |
[analyze_precalc_expr_begin] u=210 |
[analyze_precalc_expr_end] u=9 |
[resolve_end] u=24 |
[transform_begin] u=106 |
[transform_end] u=319 |
[optimize_begin] u=4 |
[tl_calc_by_range_end] u=163 |
[tl_calc_part_id_end] u=0 |
[get_location_cache_begin] u=1 |
[renew_loc_by_sql_begin] u=16 |
[parse_begin] u=353 stmt:"SELECT * FROM __all_tenant_meta_table WHERE tenant_id = 1 AND table_id = 1099511677777 AND partition_id = 0 ORDER BY tenant_id, table_id, partition_id, svr_ip, svr_port", stmt_len:168|
[cache_get_plan_begin] u=2 |
[cache_get_plan_end] u=23 |
[transform_with_outline_begin] u=0 |
[pc_fast_parse_start] u=69 |
[pc_fast_parse_end] u=6 |
[transform_with_outline_end] u=6 |
[resolve_begin] u=28 |
[analyze_precalc_expr_begin] u=251 |
[analyze_precalc_expr_end] u=9 |
[resolve_end] u=18 |
[transform_begin] u=60 |
[transform_end] u=438 |
[optimize_begin] u=2 |
[tl_calc_by_range_end] u=136 |
[tl_calc_part_id_end] u=1 |
[get_location_cache_begin] u=0 |
[get_location_cache_end] u=19 |
[storage_estimation_begin] u=258 |
[storage_estimation_end] u=66 |
[optimize_end] u=212 |
[cg_begin] u=1 |
[cg_end] u=139 |
[plan_id] u=167 plan_id:7441|
[start_trans] u=15 trans_id:{hash:11136244619746343644, inc:85875, addr:{ip:"xxx.xxx.xxx.xxx", port:43300}, t:1634633228942267}|
[start_trans] u=0 trans_id:{hash:11136244619746343644, inc:85875, addr:{ip:"xxx.xxx.xxx.xxx", port:43300}, t:1634633228942267}, timeout:1634633238939375, start_time:1634633228940765|
[do_open_plan_begin] u=1 plan_id:7441|
[sql_start_stmt_begin] u=0 |
[sql_start_stmt_end] u=4 |
[exec_plan_begin] u=1 |
[exec_plan_end] u=2 |
[sql_start_participant_begin] u=0 |
[sql_start_participant_end] u=0 |
[do_open_plan_end] u=0 |
[storage_table_scan_begin] u=10 |
[storage_table_scan_end] u=20 |
[get_row] u=13 |
[close_plan_begin] u=28 |
[revert_scan_iter] u=4 |
[get_trans_result] u=0 ret:0, trans_id:{hash:11136244619746343644, inc:85875, addr:{ip:"xxx.xxx.xxx.xxx", port:43300}, t:1634633228942267}|
[end_participant_begin] u=1 |
[get_trans_result] u=1 ret:0, trans_id:{hash:11136244619746343644, inc:85875, addr:{ip:"xxx.xxx.xxx.xxx", port:43300}, t:1634633228942267}|
[end_participant] u=0 ret:0|
[end_participant_end] u=0 |
[start_end_stmt] u=0 |
[end_stmt] u=1 |
[close_plan_end] u=0 |
[affected_rows] u=0 affected_rows:-1|
[store_found_rows] u=1 found_rows:0, return_rows:2|
[auto_end_plan_begin] u=0 |
[end_trans] u=3 ret:0|
[auto_end_plan_end] u=1 |
[result_set_close] u=0 ret:0, arg1:0, arg2:0, arg3:-4008, async:false|
[renew_loc_by_sql_end] u=394 ret:0, table_id:1099511677777, partition_id:0|
[get_location_cache_end] u=16 |
[parse_begin] u=548 stmt:"SELECT partition_id, object_type, row_cnt as row_count, avg_row_len as avg_row_size, macro_blk_cnt as macro_block_num, micro_blk_cnt as micro_block_num, last_analyzed FROM __all_table_stat_v2  WHERE TENANT_ID = 1 AND TABLE_ID=1099511677777", stmt_len:239|
[cache_get_plan_begin] u=1 |
[cache_get_plan_end] u=18 |
[transform_with_outline_begin] u=1 |
[pc_fast_parse_start] u=53 |
[pc_fast_parse_end] u=7 |
[transform_with_outline_end] u=5 |
[resolve_begin] u=40 |
[analyze_precalc_expr_begin] u=149 |
[analyze_precalc_expr_end] u=18 |
[resolve_end] u=18 |
[transform_begin] u=45 |
[transform_end] u=251 |
[optimize_begin] u=1 |
[tl_calc_by_range_end] u=151 |
[tl_calc_part_id_end] u=0 |
[get_location_cache_begin] u=0 |
[renew_loc_by_sql_begin] u=7 |
[parse_begin] u=644 stmt:"SELECT * FROM __all_root_table WHERE tenant_id = 1 AND table_id = 1099511628104 AND partition_id = 0 ORDER BY tenant_id, table_id, partition_id, svr_ip, svr_port", stmt_len:161|
[cache_get_plan_begin] u=2 |
[tl_calc_by_range_end] u=35 |
[tl_calc_part_id_end] u=0 |
[pc_choose_plan] u=4 |
[check_priv] u=1 |
[cache_get_plan_end] u=0 |
[plan_id] u=1 plan_id:3514|
[start_trans] u=14 trans_id:{hash:7268543862466884666, inc:85881, addr:{ip:"xxx.xxx.xxx.xxx", port:43300}, t:1634633228944356}|
[start_trans] u=0 trans_id:{hash:7268543862466884666, inc:85881, addr:{ip:"xxx.xxx.xxx.xxx", port:43300}, t:1634633228944356}, timeout:1634633238939373, start_time:1634633228945153|
[do_open_plan_begin] u=1 plan_id:3514|
[sql_start_stmt_begin] u=0 |
[sql_start_stmt_end] u=4 |
[exec_plan_begin] u=0 |
[exec_plan_end] u=2 |
[sql_start_participant_begin] u=0 |
[sql_start_participant_end] u=1 |
[do_open_plan_end] u=0 |
[storage_table_scan_begin] u=10 |
[storage_table_scan_end] u=24 |
[close_plan_begin] u=44 |
[revert_scan_iter] u=2 |
[get_trans_result] u=1 ret:0, trans_id:{hash:7268543862466884666, inc:85881, addr:{ip:"xxx.xxx.xxx.xxx", port:43300}, t:1634633228944356}|
[end_participant_begin] u=1 |
[get_trans_result] u=1 ret:0, trans_id:{hash:7268543862466884666, inc:85881, addr:{ip:"xxx.xxx.xxx.xxx", port:43300}, t:1634633228944356}|
[end_participant] u=0 ret:0|
[end_participant_end] u=0 |
[start_end_stmt] u=0 |
[end_stmt] u=1 |
[close_plan_end] u=0 |
[affected_rows] u=0 affected_rows:-1|
[store_found_rows] u=1 found_rows:0, return_rows:2|
[auto_end_plan_begin] u=0 |
[end_trans] u=2 ret:0|
[auto_end_plan_end] u=2 |
[result_set_close] u=0 ret:0, arg1:0, arg2:0, arg3:-4008, async:false|
[renew_loc_by_sql_end] u=146 ret:0, table_id:1099511628104, partition_id:0|
[get_location_cache_end] u=21 |
[optimize_end] u=254 |
[cg_begin] u=1 |
[cg_end] u=78 |
[plan_id] u=123 plan_id:7442|
[start_trans] u=6 |
[start_trans] u=0 |
[do_open_plan_begin] u=0 |
[sql_start_stmt_begin] u=1 |
[sql_start_stmt_end] u=4 |
[exec_plan_begin] u=0 |
[exec_plan_end] u=2 |
[sql_start_participant_begin] u=0 |
[sql_start_participant_end] u=20 |
[do_open_plan_end] u=1 |
[storage_table_scan_begin] u=8 |
[storage_table_scan_end] u=17 |
[close_plan_begin] u=27 |
[revert_scan_iter] u=3 |
[get_trans_result] u=0 |
[end_participant_begin] u=1 |
[get_trans_result] u=0 |
[end_participant] u=0 ret:0|
[end_participant_end] u=1 |
[start_end_stmt] u=0 |
[end_stmt] u=0 |
[close_plan_end] u=1 |
[affected_rows] u=0 |
[store_found_rows] u=0 |
[auto_end_plan_begin] u=0 |
[end_trans] u=3 |
[auto_end_plan_end] u=6 |
[result_set_close] u=0 |
[optimize_end] u=263 |
[cg_begin] u=1 |
[cg_end] u=64 |
[plan_id] u=120 |
[exec_begin] u=1 |
[start_trans] u=5 |
[start_trans] u=0 |
[do_open_plan_begin] u=0 |
[sql_start_stmt_begin] u=1 |
[sql_start_stmt_end] u=13 |
[exec_plan_begin] u=0 |
[exec_plan_end] u=2 |
[sql_start_participant_begin] u=0 |
[sql_start_participant_end] u=1 |
[do_open_plan_end] u=0 |
[close_plan_begin] u=9989583 |
[end_participant_begin] u=7 |
[get_trans_result] u=2 |
[end_participant] u=0 |
[end_participant_end] u=1 |
[start_end_stmt] u=0 |
[end_stmt] u=2 |
[process_end] u=236 |
total_timeu=9996941 DROPPED_EVENTS=8)

```

**字段说明**：

| slow query 执行阶段 | 描述 |
| --- | --- |
| process_begin | 开始处理 |
| start_sql | 开始处理 SQL |
| query_begin | 开始查询 |
| before_processor_run | 处理器运行之前 |
| session | 获取 sesssion |
| parse_begin | 开始 parser |
| cache_get_plan_begin | 开始从计划缓存中获取计划 |
| cache_get_plan_end | 结束从计划缓存中获取计划 |
| transform_with_outline_begin | 根据 outline 重写 SQL 开始 |
| pc_fast_parse_start | 开始 fast parser |
| pc_fast_parse_end | 结束 fast parser |
| transform_with_outline_end | 结束 outline 转换 |
| resolve_begin | 开始 resolver |
| analyze_precalc_expr_begin | 开始预计算表达式 |
| analyze_precalc_expr_end | 结束预计算表达式 |
| resolve_end | 结束 resolver |
| transform_begin | 开始重写 |
| transform_end | 结束重写 |
| optimize_begin | 开始优化 |
| tl_calc_by_range_end | 根据 range 计算 table location 结束 |
| tl_calc_part_id_end | 根据 table location 计算 partition id 结束 |
| get_location_cache_begin | 开始获取本地缓存 |
| renew_loc_by_sql_begin | 开始通过执行 SQL 进行本地 table location 缓存的更新 |
| get_location_cache_end | 结束获取本地 table location 缓存 |
| storage_estimation_begin | 开始计算存储 |
| storage_estimation_end | 结束计算存储 |
| optimize_end | 结束优化 |
| cg_begin | code generation 开始 |
| cg_end | code generation 结束 |
| plan_id | 计划 ID |
| start_trans | 开始事务 |
| do_open_plan_begin | 开始打开执行计划 |
| sql_start_stmt_begin | 开始执行 SQL 对象 |
| sql_start_stmt_end | 结束执行 SQL 对象 |
| exec_plan_begin | 开始执行计划 |
| exec_plan_end | 结束执行计划 |
| sql_start_participant_begin | SQL 层开始开启副本 |
| sql_start_participant_end | SQL 层结束开启副本 |
| do_open_plan_end | 结束开启执行计划 |
| storage_table_scan_begin | 开始存储表扫描 |
| storage_table_scan_end | 结束存储表扫描 |
| get_row | 获取行 |
| close_plan_begin | 开始关闭计划 |
| revert_scan_iter | 重置扫描项 |
| get_trans_result | 获取事务结果集 |
| end_participant_begin | 关闭副本开始 |
| end_participant | 关闭副本 |
| end_participant_end | 关闭副本结束 |
| start_end_stmt | 开始结束 statement |
| end_stmt | 结束 statement |
| close_plan_end | 结束关闭计划 |
| affected_rows | 受影响的行 |
| store_found_rows | 存储发现的行 |
| auto_end_plan_begin | 开始自动关闭计划 |
| end_trans | 结束转换 |
| auto_end_plan_end | 结束自动关闭计划 |
| result_set_close | 关闭结果集 |
| renew_loc_by_sql_end | 结束通过执行 SQL 进行本地 table location 缓存的更新 |
| pc_choose_plan | plan cache 选择计划 |
| check_priv | 检查权限 |
| exec_begin | 开始执行 |
| process_end | 结束进程 |

> 注意
>
>  
>
> 当 trace log 中的 u=xxx 字段显示的间隔时长过长，请联系技术支持工程师协助排查。

 上一篇 下一篇 ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ) 咨询
