PostgreSQL 11 preview - 表达式索引柱状图buckets\STATISTICS\default_statistics_target可设置

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB 分布式版,标准版 2核8GB
简介:

标签

PostgreSQL , 表达式索引 , 柱状图 , buckets , 增强 , 11


背景

PostgreSQL 支持表达式索引,优化器支持CBO,对于普通字段,我们有默认统计信息bucket控制,也可以通过alter table alter column来设置bucket,提高或降低字段级的统计精度。

ALTER TABLE [ IF EXISTS ] [ ONLY ] name [ * ]  
    action [, ... ]  
  
    ALTER [ COLUMN ] column_name SET STATISTICS integer  

SET STATISTICS

This form sets the per-column statistics-gathering target for subsequent ANALYZE operations. The target can be set in the range 0 to 10000; alternatively, set it to -1 to revert to using the system default statistics target (default_statistics_target). For more information on the use of statistics by the PostgreSQL query planner, refer to Section 14.2.

SET STATISTICS acquires a SHARE UPDATE EXCLUSIVE lock.

但是对于表达式索引,它可能是多列,它可能内嵌表达式,因为表达式它没有列名,只有第几列(或表达式),怎么调整表达式索引的统计信息bucket数呢?

PostgreSQL 将这个设置功能放到了alter index中。

ALTER INDEX [ IF EXISTS ] name ALTER [ COLUMN ] column_number  
    SET STATISTICS integer  
  
ALTER [ COLUMN ] column_number SET STATISTICS integer  
This form sets the per-column statistics-gathering target for subsequent [ANALYZE](https://www.postgresql.org/docs/devel/static/sql-analyze.html) operations, though can be used only on index columns that are defined as an expression. Since expressions lack a unique name, we refer to them using the ordinal number of the index column. The target can be set in the range 0 to 10000; alternatively, set it to -1 to revert to using the system default statistics target ([default_statistics_target](https://www.postgresql.org/docs/devel/static/runtime-config-query.html#GUC-DEFAULT-STATISTICS-TARGET)). For more information on the use of statistics by the PostgreSQL query planner, refer to [Section 14.2](https://www.postgresql.org/docs/devel/static/planner-stats.html).  

例子

create table measured (x text, y text, z int, t int);

CREATE INDEX coord_idx ON measured (x, y, (z + t));  
  
-- 将(z + t)的统计信息柱状图设置为1000  
  
ALTER INDEX coord_idx ALTER COLUMN 3 SET STATISTICS 1000;  
  
-- psql 可以看到这个统计信息柱状图的设置值

postgres=# \d+ coord_idx
                Index "public.coord_idx"
 Column |  Type   | Definition | Storage  | Stats target 
--------+---------+------------+----------+--------------
 x      | text    | x          | extended | 
 y      | text    | y          | extended | 
 expr   | integer | (z + t)    | plain    | 1000
btree, for table "public.measured"
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
2天前
|
存储 关系型数据库 MySQL
Mysql索引总结(1)
Mysql索引总结(1)
24 0
|
2天前
|
SQL 存储 关系型数据库
MySQL索引及事务
MySQL索引及事务
24 2
|
2天前
|
SQL 存储 关系型数据库
必知的 MySQL 索引失效场景【包括实践验证】,别再踩坑了!(下)
必知的 MySQL 索引失效场景【包括实践验证】,别再踩坑了!
21 2
|
2天前
|
SQL 关系型数据库 MySQL
必知的 MySQL 索引失效场景【包括实践验证】,别再踩坑了!(上)
必知的 MySQL 索引失效场景【包括实践验证】,别再踩坑了!
18 2
|
2天前
|
NoSQL 关系型数据库 MySQL
B+树 和 跳表 的结构及区别,不同的用途【mysql的索引为什么使用B+树而不使用跳表?】
B+树 和 跳表 的结构及区别,不同的用途【mysql的索引为什么使用B+树而不使用跳表?】
18 2
|
2天前
|
存储 算法 关系型数据库
MySQL索引详解
MySQL索引详解
15 0
|
2天前
|
存储 SQL 关系型数据库
完蛋!😱 我被MySQL索引失效包围了!
完蛋!😱 我被MySQL索引失效包围了!
|
2天前
|
SQL 存储 关系型数据库
MySQL的3种索引合并优化⭐️or到底能不能用索引?
MySQL的3种索引合并优化⭐️or到底能不能用索引?
|
2天前
|
存储 SQL 关系型数据库
MySQL索引,看这一篇就够了!
MySQL索引,看这一篇就够了!
|
2天前
|
Java 关系型数据库 MySQL
MySQL 索引事务
MySQL 索引事务
13 0

相关产品

  • 云原生数据库 PolarDB