Postgres-更新性能降低

时间:2020-05-19 09:30:29

标签: postgresql

有人可以帮助您确定为什么下面的过去需要2个小时而不是6个小时而不增加体积的原因吗?

with P as 
(SELECT DISTINCT CD.CASE_DETAIL_ID, SVL.SERVICE_LEVEL_ID\n       
FROM report_fct CD LEFT JOIN SERVICE_LEVEL SVL ON SVL.ORDER_TYPE_CD =   CD.ORDER_TYPE_CD\n                                                            
AND SVL.SOURCE_ID = CD.SOURCE_ID\n                                                  AND SVL.AREA_ID = CD.HQ_AREA_ID\n                                                   AND SVL.CATEGORY_ID = CD.CATEGORY_ID\n                                              AND SVL.STATE_CD = CD.CUST_STATE\n       
WHERE CD.LINE_OF_BIZ = 'CLOTH'\n       
AND CD.HQ_AREA_ID is NOT NULL\n       
AND CD.SOURCE_ID is NOT NULL\n       
AND CD.CATEGORY_ID is NOT NULL\n       
AND CD.CUST_STATE is NOT NULL)\n
update report_fct rpt\n
set service_level_id = P.service_level_id\n
from P\n
where rpt.case_detail_id = P.case_detail_id;"}


CREATE TABLE report_fct 
...
..
case_detail_id bigint NOT NULL,
...



CREATE INDEX report_fct _ix1
ON report_fct USING btree
(case_detail_id)
TABLESPACE pg_default;


CREATE INDEX report_fct _ix2
    ON report_fct  USING btree
    (insert_dt)
TABLESPACE pg_default;

我有一个疑问是统计信息是否可以在此表上倾斜,从而导致性能下降。

relname       inserts      updates  deletes live_tuples dead_tupes  last autovacuum last autoanalyze
report_fct  262746347   5387849450  0           2473523    3573914  5/19/20 3:38    5/19/20 1:13


EXPLAIN:
"Update on report_fct rpt  (cost=24847.47..27881.35 rows=415 width=3772)"
"  CTE p"
"    ->  Unique  (cost=24844.02..24847.05 rows=405 width=16)"
"          ->  Sort  (cost=24844.02..24845.03 rows=405 width=16)"
"                Sort Key: cd.case_detail_id, svl.service_level_id"
"                ->  Nested Loop Left Join  (cost=0.41..24826.48 rows=405 width=16)"
"                      ->  Seq Scan on report_fct cd  (cost=0.00..21915.21 rows=405 width=44)"
"                            Filter: ((hq_area_id IS NOT NULL) AND (source_id IS NOT NULL) AND (category_id IS NOT NULL) AND (cust_state IS NOT NULL) AND ((line_of_biz)::text = 'CLOTH'::text))"
"                      ->  Index Scan using service_level_unq on service_level svl  (cost=0.41..7.18 rows=1 width=45)"
"                            Index Cond: ((area_id = cd.hq_area_id) AND ((order_type_cd)::text = (cd.order_type_cd)::text) AND (source_id = cd.source_id) AND (state_cd = (cd.cust_state)::bpchar) AND (category_id = cd.category_id))"
"  ->  Nested Loop  (cost=0.41..3034.30 rows=415 width=3772)"
"        ->  CTE Scan on p  (cost=0.00..8.10 rows=405 width=56)"
"        ->  Index Scan using report_fct_ix1 on report_fct rpt  (cost=0.41..7.46 rows=1 width=3724)"
"              Index Cond: (case_detail_id = p.case_detail_id)"



0 个答案:

没有答案