首批通过分布式安全可靠测评,为关键业务系统打造
收集统计信息报错 5001,message="syntax error, unexpected SNAPSHOT" 的原因和解决方法
更新时间:2025-06-12 03:21
问题现象
无论是自动统计信息收集任务还是手动收集分区级统计信息,分区表数据量大的表的统计信息总是收集失败并报错 snapshot xxx。

observer.log 中有类似如下错误信息。
observer.log:[2025-03-14 11:10:03.373760] WDIAG [SQL] stmt_query (ob_sql.cpp:227) [92531][T1002_L0_G0][T1002][xxxxx-xxxxx-xxxxx-xxxxx] [lt=43][errcode=-5001] fail to handle text query(stmt=SELECT /*+ NO_REWRITE USE_PLAN_CACHE(NONE) DBMS_STATS FULL(order_main) OPT_PARAM('ROWSETS_MAX_ROWS', 8) USE_PX, PARALLEL(128)*/ COUNT(1), MAX(`id`), MIN(`id`), COUNT(`id`), APPROX_COUNT_DISTINCT(`id`), AVG(SYS_OP_OPNSIZE(`id`)), APPROX_COUNT_DISTINCT_SYNOPSIS(`id`), 1 FROM `retail_fas`.`order_main` PARTITION (`p0`) SAMPLE (50.000000) as of snapshot 1741921803371932001 , ret=-5001)
observer.log:[2025-03-14 11:10:03.373791] WDIAG [SERVER] do_query (ob_inner_sql_connection.cpp:784) [92531][T1002_L0_G0][T1002][xxxxx-xxxxx-xxxxx-xxxxx] [lt=24][errcode=-5001] executor execute failed(ret=-5001)
observer.log:[2025-03-14 11:10:03.373818] WDIAG [SERVER] query (ob_inner_sql_connection.cpp:943) [92531][T1002_L0_G0][T1002][xxxxx-xxxxx-xxxxx-xxxxx] [lt=61][errcode=-5001] execute failed(ret=-5001, tenant_id=1002, executor={ObIExecutor:, sql:"SELECT /*+ NO_REWRITE USE_PLAN_CACHE(NONE) DBMS_STATS FULL(order_main) OPT_PARAM('ROWSETS_MAX_ROWS', 8) USE_PX, PARALLEL(128)*/ COUNT(1), MAX(`id`), MIN(`id`), COUNT(`id`), APPROX_COUNT_DISTINCT(`id`), AVG(SYS_OP_OPNSIZE(`id`)), APPROX_COUNT_DISTINCT_SYNOPSIS(`id`), 1 FROM `retail_fas`.`order_main` PARTITION (`p0`) SAMPLE (50.000000) as of snapshot 1741921803371932001 "}, retry_cnt=0, local_sys_schema_version=1740366885882512, local_tenant_schema_version=1741916496788000)
observer.log:[2025-03-14 11:10:03.373849] WDIAG [SERVER] after_func (ob_query_retry_ctrl.cpp:1045) [92531][T1002_L0_G0][T1002][xxxxx-xxxxx-xxxxx-xxxxx] [lt=69][errcode=-5001] [RETRY] check if need retry(v={force_local_retry:true, stmt_retry_times:0, local_retry_times:0, err_:-5001, err_:"OB_ERR_PARSE_SQL", retry_type:0, client_ret:-5001}, need_retry=false)
问题原因
OceanBase 产品缺陷 BUG。
影响版本
OceanBase 数据库 V4.2.5(oceanbase-4.2.5.0-100000082024102022)~ V4.2.5 BP2 Hotfix2(oceanbase-4.2.5.2-102020022025031414)版本。
解决方法
升级至问题已修复版本。目前已修复的版本包括 OceanBase 数据库 V4.2.5 BP2 Hotfix3(oceanbase-4.2.5.2-102030052025032518)及之后版本。
规避方式
使用 GLOBAL 方式收集 granularity=>GLOBAL。
call DBMS_STATS.GATHER_TABLE_STATS('xxxx','order_main',granularity=>'GLOBAL',degree=>64);