22
33-- enhanced version of https://github.com/ioguix/pgsql-bloat-estimation/blob/master/btree/btree_bloat.sql
44
5- -- WARNING: executed with a non-superuser role, the query inspect only index on tables you are granted to read.
5+ -- WARNING: executed with a non-superuser role, the query inspects only indexes on tables you are granted to read.
66-- WARNING: rows with is_na = 't' are known to have bad statistics ("name" type is not supported).
77-- This query is compatible with PostgreSQL 8.2+
88
@@ -26,9 +26,9 @@ with step1 as (
2626 /* per tuple header: add IndexAttributeBitMapData if some cols are null-able */
2727 case
2828 when max (coalesce(s .null_frac ,0 )) = 0 then 2 -- IndexTupleData size
29- else 2 + (( 32 + 8 - 1 ) / 8 ) -- IndexTupleData size + IndexAttributeBitMapData size ( max num filed per index + 8 - 1 /8)
29+ else 2 + (( 32 + 8 - 1 ) / 8 ) -- IndexTupleData size + IndexAttributeBitMapData size ( max num fields per index + 8 - 1 /8)
3030 end as index_tuple_hdr_bm,
31- /* data len: we remove null values save space using it fractionnal part from stats */
31+ /* data len: we remove null values save space using its fractional part from stats */
3232 sum ((1 - coalesce(s .null_frac , 0 )) * coalesce(s .avg_width , 1024 )) as nulldatawidth,
3333 max (case when a .atttypid = ' pg_catalog.name' ::regtype then 1 else 0 end) > 0 as is_na
3434 from pg_attribute as a
@@ -47,7 +47,7 @@ with step1 as (
4747 s .schemaname = i .nspname
4848 and (
4949 (s .tablename = i .tblname and s .attname = pg_catalog .pg_get_indexdef (a .attrelid , a .attnum , true)) -- stats from tbl
50- OR (s .tablename = i .idxname AND s .attname = a .attname ) -- stats from functionnal cols
50+ OR (s .tablename = i .idxname AND s .attname = a .attname ) -- stats from functional cols
5151 )
5252 join pg_type as t on a .atttypid = t .oid
5353 where a .attnum > 0
0 commit comments