tidb产生过多执行计划

v7.4.0

tiup bench tpcc(500 warehouse) 初始化数据期间,发现dashbaord有查询慢SQL,里面有500多个执行计划。

select count ( ? ) from ( select `c` . `c_id` , `c` . `c_d_id` , `c` . `c_w_id` , `c` . `c_balance` `c1` , ( select sum ( `ol_amount` ) from `orders` , `order_line` where `ol_w_id` = `o_w_id` and `ol_d_id` = `o_d_id` and `ol_o_id` = `o_id` and `ol_delivery_d` is not ? and `o_w_id` = ? and `o_d_id` = `c` . `c_d_id` and `o_c_id` = `c` . `c_id` ) `sm` , ( select sum ( `h_amount` ) from history where `h_c_w_id` = ? and `h_c_d_id` = `c` . `c_d_id` and `h_c_id` = `c` . `c_id` ) `smh` from `customer` `c` where `c` . `c_w_id` = ? ) `t` where `c1` <> `sm` - `smh`

image

有对比这些产生不同 plan 的 SQL text 有什么差异吗,可以提供任意两个的 plan text。

SQL1:
select count ( ? ) from ( select c . c_id , c . c_d_id , c . c_w_id , c . c_balance c1 , ( select sum ( ol_amount ) from orders , order_line where ol_w_id = o_w_id and ol_d_id = o_d_id and ol_o_id = o_id and ol_delivery_d is not ? and o_w_id = ? and o_d_id = c . c_d_id and o_c_id = c . c_id ) sm , ( select sum ( h_amount ) from history where h_c_w_id = ? and h_c_d_id = c . c_d_id and h_c_id = c . c_id ) smh from customer c where c . c_w_id = ? ) t where c1 <> sm - smh

SQL2:
select count ( ? ) from ( select c . c_id , c . c_d_id , c . c_balance c1 , c_ytd_payment , ( select sum ( ol_amount ) from orders , order_line where ol_w_id = o_w_id and ol_d_id = o_d_id and ol_o_id = o_id and ol_delivery_d is not ? and o_w_id = ? and o_d_id = c . c_d_id and o_c_id = c . c_id ) sm from customer c where c . c_w_id = ? ) t1 where c1 + c_ytd_payment <> sm

我又重新初始化1000个warehous ,2个SQL的执行计划

可以从 slow query log 中取两条完整的对于这个 sql 的内容吗?
select count ( ? ) from ( select c . c_id , c . c_d_id , c . c_w_id , c . c_balance c1 , ( select sum ( ol_amount ) from orders , order_line where ol_w_id = o_w_id and ol_d_id = o_d_id and ol_o_id = o_id and ol_delivery_d is not ? and o_w_id = ? and o_d_id = c . c_d_id and o_c_id = c . c_id ) sm , ( select sum ( h_amount ) from history where h_c_w_id = ? and h_c_d_id = c . c_d_id and h_c_id = c . c_id ) smh from customer c where c . c_w_id = ? ) t where c1 <> sm - smh

tidb_slow_query.log.gz (23.6 MB)

同一条SQL 有 500多个执行计划?看着有点吓人

Plandigest 不一样分了两种情况,一种是算子确实不一致,另外一种算子是一致但是 plandigest 不一致,这个需要再找一下 rootcause。


是sql的问题吗

indexjoin probe side 使用谓词条件和 join key 一起过滤数据,就这里的 indexrangescan 的算子,处理的时候没有对这个谓词条件进行替换成?,所以就产生了不同的 plandigest。感谢反馈,下个版本应该会带上 fix。


2 个赞

Tracking issue: https://github.com/pingcap/tidb/issues/47634

:call_me_hand: 666

:call_me_hand: :call_me_hand: :call_me_hand:这都能遇到

此话题已在最后回复的 60 天后被自动关闭。不再允许新回复。