Bug 反馈
一个比较简单的语句:
SELECT order_id FROM fin_dws.dws_fin_east_multi_year_acv_lcy
WHERE data_source = 'EAST'
直接报错, Unknown column ‘order_id’ in ‘field list’
SELECT account_id,
acv_gsr_year AS gs_year,
contract_no,
lcy_total_acv AS acv2
FROM fin_dws.dws_fin2_global_acv_1d t
WHERE order_id NOT IN (
SELECT order_id FROM fin_dws.dws_fin_east_multi_year_acv_lcy
WHERE data_source = 'EAST'
)
AND acv_gsr_year IN (2023, 2024)
AND t.type = 'EAST'
LIMIT 10
执行计划如下:
id,estRows,actRows,task,access object,execution info,operator info,memory,disk
Projection_11,10.00,0,root,,"time:5.31s, loops:1, RU:11.888240, Concurrency:OFF","fin_dws.dws_fin2_global_acv_1d.account_id, fin_dws.dws_fin2_global_acv_1d.acv_gsr_year, fin_dws.dws_fin2_global_acv_1d.contract_no, fin_dws.dws_fin2_global_acv_1d.lcy_total_acv",9.14 KB,N/A
└─Limit_14,10.00,0,root,,"time:5.31s, loops:1","offset:0, count:10",N/A,N/A
└─HashJoin_15,10.00,0,root,,"time:5.31s, loops:1, build_hash_table:{total:11ms, fetch:9.77ms, build:1.23ms}, probe:{concurrency:16, total:1m9.7s, max:5.31s, probe:1m8.8s, fetch:899.3ms}",CARTESIAN anti semi join,438.4 KB,0 Bytes
├─TableReader_21(Build),12426.00,12426,root,,"time:10.1ms, loops:14, cop_task: {num: 7, max: 2.66ms, min: 1.23ms, avg: 1.55ms, p95: 2.66ms, tot_proc: 11µs, tot_wait: 1.73ms, rpc_num: 7, rpc_time: 10.7ms, copr_cache_hit_ratio: 1.00, build_task_duration: 6µs, max_distsql_concurrency: 1}",data:Selection_20,95.9 KB,N/A
│ └─Selection_20,12426.00,12426,cop[tikv],,"tikv_task:{proc max:20ms, min:0s, avg: 7.43ms, p80:12ms, p95:20ms, iters:39, tasks:7}, scan_detail: {get_snapshot_time: 1.38ms, rocksdb: {block: {}}}","eq(fin_dws.dws_fin_east_multi_year_acv_lcy.data_source, ""EAST"")",N/A,N/A
│ └─TableFullScan_19,12426.00,12426,cop[tikv],table:dws_fin_east_multi_year_acv_lcy,"tikv_task:{proc max:20ms, min:0s, avg: 7.43ms, p80:12ms, p95:20ms, iters:39, tasks:7}",keep order:false,N/A,N/A
└─TableReader_18(Probe),12.50,22239,root,,"time:62.8ms, loops:23, cop_task: {num: 18, max: 40.9ms, min: 502.5µs, avg: 8.66ms, p95: 40.9ms, tot_proc: 28.7µs, tot_wait: 4.89ms, rpc_num: 18, rpc_time: 155.3ms, copr_cache_hit_ratio: 1.00, build_task_duration: 17.5µs, max_distsql_concurrency: 3}",data:Selection_17,830.3 KB,N/A
└─Selection_17,12.50,22239,cop[tikv],,"tikv_task:{proc max:120ms, min:0s, avg: 35.6ms, p80:68ms, p95:120ms, iters:141, tasks:18}, scan_detail: {get_snapshot_time: 4.05ms, rocksdb: {block: {}}}","eq(fin_dws.dws_fin2_global_acv_1d.type, ""EAST""), or(eq(cast(fin_dws.dws_fin2_global_acv_1d.acv_gsr_year, double BINARY), 2023), eq(cast(fin_dws.dws_fin2_global_acv_1d.acv_gsr_year, double BINARY), 2024))",N/A,N/A
└─TableFullScan_16,73.55,70424,cop[tikv],table:t,"tikv_task:{proc max:112ms, min:0s, avg: 34.2ms, p80:64ms, p95:112ms, iters:141, tasks:18}",keep order:false,N/A,N/A
所以CARTESIAN anti semi join 这里出现了问题, 没有识别到.
换一个写法:
SELECT account_id,
acv_gsr_year AS gs_year,
contract_no,
lcy_total_acv AS acv2
FROM fin_dws.dws_fin2_global_acv_1d t
LEFT JOIN (
SELECT order_id FROM fin_dws.dws_fin_east_multi_year_acv_lcy
WHERE data_source = 'EAST'
) multi
ON t.order_id = multi.order_id
WHERE multi.order_id IS NULL
AND acv_gsr_year IN (2023, 2024)
AND t.type = 'EAST'
LIMIT 10
这样就不会出错.
表DDL文件:
dws_fin_east_multi_year_acv_lcy.ddl.sql (2.7 KB)
dws_fin2_global_acv_1d.ddl.sql (7.9 KB)
【 TiDB 版本】
7.5.1
【 Bug 的影响】
影响统计结果准确性.
【可能的问题复现步骤】
简单的SQL 可以复现:
-- NOT IN 子查询
WITH t1 AS (
SELECT 1 AS n
),
t2 AS (
SELECT 2 AS b
)
SELECT *
FROM t1
WHERE n NOT IN (SELECT n FROM t2);
以及In 子查询
WITH t1 AS (
SELECT 1 AS n
),
t2 AS (
SELECT 2 AS b
)
SELECT *
FROM t1
WHERE n IN (SELECT n FROM t2)
【看到的非预期行为】
语句可以顺利执行不报错, 产生意外结果.
【期望看到的行为】
语法错误
【相关组件及具体版本】
tidb
【其他背景信息或者截图】
如集群拓扑,系统和内核版本,应用 app 信息等;如果问题跟 SQL 有关,请提供 SQL 语句和相关表的 Schema 信息;如果节点日志存在关键报错,请提供相关节点的日志内容或文件;如果一些业务敏感信息不便提供,请留下联系方式,我们与您私下沟通。