PostgreSQL10.0preview功能增強-自由定義統計資訊維度
標籤
PostgreSQL , 10.0 , 統計資訊 , 自由定義 , 自由分組統計資訊
背景
統計資訊是資料庫優化器用來計算SQL plan tree中每個NODE成本的依據,目前PostgreSQL的統計資訊是開源資料庫中最完備的。
包括繼承表、以及全域性的統計資訊,每個欄位的NULL值個數或百分比,平均欄位寬度,唯一值個數或百分比,高頻詞,高頻詞的百分比,柱狀圖,線性相關性,陣列欄位的高頻元素,高頻元素的百分比,陣列元素的柱狀圖。
View "pg_catalog.pg_stats"
Column | Type | Modifiers
------------------------+----------+-----------
schemaname | name |
tablename | name |
attname | name |
inherited | boolean |
null_frac | real |
avg_width | integer |
n_distinct | real |
most_common_vals | anyarray |
most_common_freqs | real[] |
histogram_bounds | anyarray |
correlation | real |
most_common_elems | anyarray |
most_common_elem_freqs | real[] |
elem_count_histogram | real[] |
實際上統計資訊已經非常完備了,10.0提出了一個更大膽的統計資訊,自定義統計資訊。
比如我們將多個欄位作為一個分組,生成分組的統計資訊。有什麼用呢?
例如select count(distinct a,b) from tbl, select count(*),a,b from tbl group by a,b;
以上SQL,如果有a,b分組的統計資訊,有多少唯一值,線性相關性如何。優化器就可以評估group by需要多少記憶體,結果集大概多大。
是的,現在PostgreSQL 10.0允許你定義欄位分組的統計資訊了。是不是很開森呢?
你甚至可以用它來做多個欄位組合的TOP N的評估呢。
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it`s a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
新增的系統表
pg_statistic_ext
新增的語法
CREATE STATISTICS
這個patch的討論,詳見郵件組,本文末尾URL。
PostgreSQL社群的作風非常嚴謹,一個patch可能在郵件組中討論幾個月甚至幾年,根據大家的意見反覆的修正,patch合併到master已經非常成熟,所以PostgreSQL的穩定性也是遠近聞名的。
參考
相關文章
- PostgreSQL10.0preview功能增強-國際化功能增強,支援ICU(InternationalComponentsforUnicode)SQLViewUnicode
- PostgreSQL10.0preview功能增強-增加ProcArrayGroupUpdate等待事件SQLView事件
- PostgreSQL10.0preview功能增強-OLAP增強向量聚集索引(列儲存擴充套件)SQLView索引套件
- PostgreSQL10.0preview功能增強-CLOGoldestXID跟蹤SQLViewGo
- PostgreSQL10.0preview功能增強-JSON內容全文檢索SQLViewJSON
- PostgreSQL10.0preview功能增強-後臺執行(pg_background)SQLView
- PostgreSQL10.0preview效能增強-hashindexmetapagecache、高併發增強SQLViewIndex
- Python巢狀定義函式增強reduce()函式功能Python巢狀函式
- PostgreSQL10.0preview功能增強-動態檢視pg_stat_activity新增資料庫管理程式資訊SQLView資料庫
- PostgreSQL10.0preview功能增強-觸發器函式內建中間表SQLView觸發器函式
- PostgreSQL10.0preview功能增強-兩段式索引(約束欄位+附加欄位)SQLView索引
- PostgreSQL10.0preview功能增強-邏輯訂閱端控制引數解說SQLView
- PostgreSQL10.0preview效能增強-分割槽表效能增強(plan階段加速)SQLView
- PostgreSQL10.0preview功能增強-序列隔離級別預加鎖閾值可控SQLView
- BI之SSAS完整實戰教程6 -- 設計維度、細化維度上:建立維度定義特性關係
- 資料庫的智慧之源-統計資訊之自定義多維統計資料庫
- PostgreSQL10.0preview效能增強-間接索引(secondaryindex)SQLView索引Index
- PostgreSQL10.0preview效能增強-支援64bitatomicSQLView
- PostgreSQL10.0preview效能增強-(多維分析)更快,更省記憶體hashedaggregationwithgroupingsetsSQLView記憶體Gse
- PostgreSQL10.0preview功能增強-客戶端ACL(pg_hba.conf動態檢視)SQLView客戶端
- PostgreSQL10.0preview功能增強-回滾範圍可精細控制(事務、語句級)SQLView
- PostgreSQL10.0preview功能增強-邏輯複製支援並行COPY初始化資料SQLView並行
- IEA:制定基於排放強度的氫定義
- PostgreSQL10.0preview效能增強-OLAP提速框架,FasterExpressionEvaluationFramework(含JIT)SQLView框架ASTExpressFramework
- Oracle12c功能增強 新特性之管理功能的增強Oracle
- PostgreSQL10.0preview功能增強-更強可靠性,過去式事務狀態可查(杜絕unknown事務)SQLView
- openGauss DSS功能增強
- oracle VM virtualbox安裝增強功能與設定全屏Oracle
- 震精-PostgreSQL10.0preview效能增強-WARM提升一倍效能SQLView
- .NET Framework 新功能和增強的功能Framework
- 功能強大的三維包裝設計工具
- Windows7安全增強功能Windows
- PostgreSQL10.0preview效能增強-pg_xactalign(cacheline對齊)SQLView
- SQLServer裡統計維護功能(autostats)SQLServer
- 功能強大!帶你走近Smartbi增強分析模組
- Oracle運維指令碼-收集統計資訊Oracle運維指令碼
- Oracle統計資訊的收集和維護Oracle
- ORACLE 12C RMAN 功能增強Oracle