lightdb/postgresql中的统计信息详解

和oracle,lightdb也支持单列和多列统计信息,见14.2. Statistics Used by the Planner (light-pg.com)

默认情况下,analyze收集的统计信息是针对单列的,多个列之间通常没有依赖关系,在多个where里面,这容易导致基数计算失真。

planner使用statistics的方式,在sql执行的plan步骤,Chapter 70. How the Planner Uses Statistics (light-pg.com)

创建扩展统计信息  CREATE STATISTICS (light-pg.com),它只是创建元数据,并不在执行DDL的时候计算,仍然是由analyze(支持字段级别统计信息收集,典型的是OLAP gp下的场景,适合于大宽表)负责收集(anlayze.c会调用extended_stats.c中的具体实现,如ComputeExtStatisticsRows函数、BuildRelationExtStatistics函数)。目前主要支持mcv,dependencies以及ndistinct。

查看mcv统计信息的直方图,9.30. Statistics Information Functions (light-pg.com)

51.51. pg_statistic_ext (light-pg.com)

51.52. pg_statistic_ext_data (light-pg.com)

51.90. pg_stats_ext (light-pg.com)

ALTER TABLE (light-pg.com) 设置字段级别的default_statistics_target。 

posted @ 2023-04-25 14:20  zhjh256  阅读(22)  评论(0编辑  收藏  举报