【 TiDB 使用环境】测试
【 TiDB 版本】 8.1.0
【复现路径】做过哪些操作出现的问题
【遇到的问题:问题现象及影响】
mysql> explain analyze format=true_card_cost select * from customer where C_ADDRESS=‘abc’ order by C_PHONE limit 100;
±-----------------------------±----------±------------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------±--------±----------±---------------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------±-------------------------------------------±----------±-----+
| id | estRows | estCost | costFormula | actRows | task | access object | execution info | operator info | memory | disk |
±-----------------------------±----------±------------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------±--------±----------±---------------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------±-------------------------------------------±----------±-----+
| TopN_8 | 1.43 | 3728257.14 | (((((cpu(150000filters(1)tikv_cpu_factor(49.9))) + (scan(150000logrowsize(242.69)tikv_scan_factor(40.7)))) + ((exprCPU(00tikv_cpu_factor(49.9))) + (orderCPU(0log(100)tikv_cpu_factor(49.9)))) + (topMem(100216tikv_mem_factor(0.2)))) + (net(0rowsize(216)tidb_kv_net_factor(3.96))))/15.00) + ((exprCPU(00tidb_cpu_factor(49.9))) + (orderCPU(0log(100)tidb_cpu_factor(49.9)))) + (topMem(100216tidb_mem_factor(0.2))) | 0 | root | | time:345.2ms, loops:1 | tpch.customer.c_phone, offset:0, count:100 | 0 Bytes | N/A |
| └─TableReader_16 | 1.43 | 3723937.14 | ((((cpu(150000filters(1)tikv_cpu_factor(49.9))) + (scan(150000logrowsize(242.69)tikv_scan_factor(40.7)))) + ((exprCPU(00tikv_cpu_factor(49.9))) + (orderCPU(0log(100)tikv_cpu_factor(49.9)))) + (topMem(100216tikv_mem_factor(0.2)))) + (net(0rowsize(216)tidb_kv_net_factor(3.96))))/15.00 | 0 | root | | time:345.1ms, loops:2, cop_task: {num: 1, max: 344.8ms, proc_keys: 150000, tot_proc: 343ms, rpc_num: 1, rpc_time: 344.8ms, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15} | data:TopN_15 | 277 Bytes | N/A |
| └─TopN_15 | 1.43 | 55859057.06 | ((cpu(150000filters(1)tikv_cpu_factor(49.9))) + (scan(150000logrowsize(242.69)tikv_scan_factor(40.7)))) + ((exprCPU(00tikv_cpu_factor(49.9))) + (orderCPU(0log(100)tikv_cpu_factor(49.9)))) + (topMem(100216tikv_mem_factor(0.2))) | 0 | cop[tikv] | | tikv_task:{time:343ms, loops:147}, scan_detail: {total_process_keys: 150000, total_process_keys_size: 30533765, total_keys: 150001, get_snapshot_time: 87.9µs, rocksdb: {key_skipped_count: 150000, block: {cache_hit_count: 501}}} | tpch.customer.c_phone, offset:0, count:100 | N/A | N/A |
| └─Selection_14 | 1.43 | 55854737.06 | (cpu(150000*filters(1)tikv_cpu_factor(49.9))) + (scan(150000logrowsize(242.69)tikv_scan_factor(40.7))) | 0 | cop[tikv] | | tikv_task:{time:343ms, loops:147} | eq(tpch.customer.c_address, “abc”) | N/A | N/A |
| └─TableFullScan_13 | 211936.00 | 48369737.06 | scan(150000logrowsize(242.69)*tikv_scan_factor(40.7)) | 150000 | cop[tikv] | table:customer | tikv_task:{time:338ms, loops:147} | keep order:false | N/A | N/A |
±-----------------------------±----------±------------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------±--------±----------±---------------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------±-------------------------------------------±----------±-----+
5 rows in set, 3 warnings (0.37 sec)
我就想咨询一下tidb 的explain analyze format=true_card_cost中显示的代价是基于真实基数计算得来的,还是说基于预估的,以及我想知道一条 SQL 的完整代价该如何获悉呢?如果只看第一行的话,最上层的算子为何要比下层算子代价还可能低。其实主要是想知道在基数准确的时候,代价模型的精准程度。
【资源配置】进入到 TiDB Dashboard -集群信息 (Cluster Info) -主机(Hosts) 截图此页面
【附件:截图/日志/监控】
诶,我猜测是不是 estCost 还是基于预估基数计算的,然后 costFomula 是基于真实基数列出公式,但是需要自己推算出来,然后第一行就是整体代价?
估算代价都是基于统计信息算的吧,不可能基于真实数据来计算,我接触过的数据库大家都是这么做的
都是估计的吧
一般是因为子算子存在并行,在上层算子计算时候会除以并行度,所以看起来上层算子cost更低。
另外这个true_card_cost应该是基于实际值计算出来的,不是估算值。