GaussDB分区表查询性能异常
分区索引失效,顺序扫描导致的SQL性能慢 分区表无法进行分区剪枝导致的SQL性能慢 SQL计划选择非最优导致的SQL性能慢
查询索引类型和状态
gaussdb=# select c.relname, i.indisusable, c.relkind from pg_class c join pg_index i on c.oid=i.indexrelidjoin pg_class r on i.indrelid=r.oid where r.relname='t1';relname | indisusable | relkind--------------------+-------------+---------t1_c1_idx | t | it1_c2_tableoid_idx | f | I
gaussdb=# \d t1Table "public.t1"Column | Type | Modifiers--------+---------+-----------c1 | integer |c2 | integer |Indexes:"t1_c1_idx" btree (c1) LOCAL TABLESPACE pg_default"t1_c2_tableoid_idx" btree (c2) TABLESPACE pg_default UNUSABLEPartition By RANGE(c1)Number of partitions: 2 (View pg_partition to check each partition range.)
查询索引分区状态
gaussdb=# select p.relname,p.indisusable from pg_partition p join pg_class c on p.parentid=c.oid where c.relname='t1_c1_idx';relname | indisusable-----------+-------------p1_c1_idx | tp2_c1_idx | f(2 rows)
重建异常的索引/索引分区
ALTER INDEX t1_c2_tableoid_idx REBUILD;ALTER INDEX t1_c1_idx REBUILD PARTITION p2_c1_idx;判断是否触发了分区剪枝
gaussdb=# explain select * from t1 where c1 < 100;QUERY PLAN-----------------------------------------------------------------------Partition Iterator (cost=0.00..27.86 rows=716 width=8)Iterations: 1-> Partitioned Seq Scan on t1 (cost=0.00..27.86 rows=716 width=8)Filter: (c1 < 100)Selected Partitions: 1(5 rows)
gaussdb=# explain select * from t1;QUERY PLAN------------------------------------------------------------------------Partition Iterator (cost=0.00..31.49 rows=2149 width=8)Iterations: 2-> Partitioned Seq Scan on t1 (cost=0.00..31.49 rows=2149 width=8)Selected Partitions: 1..2(4 rows)
gaussdb=# prepare p1 as select * from t1 where c1 < $1;gaussdb=# explain execute p1(100);QUERY PLAN--------------------------------------------------------------------------------------------Partition Iterator (cost=9.80..28.75 rows=716 width=8)Iterations: PART-> Partitioned Bitmap Heap Scan on t1 (cost=9.80..28.75 rows=716 width=8)Recheck Cond: (c1 < $1)Selected Partitions: PART-> Partitioned Bitmap Index Scan on t1_c1_idx (cost=0.00..9.62 rows=716 width=0)Index Cond: (c1 < $1)Selected Partitions: PART(8 rows)
支持分区剪枝的场景
不支持分区剪枝的场景
业务改写适配分区剪枝
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




