Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INDEXES_WITH_NULL_VALUES] Enhance support for partitioned tables/indexes #66

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions sql/indexes_with_null_values.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@

-- Finds indexes that can contain null values.
select
x.indrelid::regclass::text as table_name,
x.indexrelid::regclass::text as index_name,
i.indrelid::regclass::text as table_name,
i.indexrelid::regclass::text as index_name,
string_agg(a.attname, ', ') as nullable_fields, /* in fact, there will always be only one column */
pg_relation_size(x.indexrelid) as index_size
pg_relation_size(i.indexrelid) as index_size
from
pg_catalog.pg_index x
inner join pg_catalog.pg_stat_all_indexes psai on psai.indexrelid = x.indexrelid
inner join pg_catalog.pg_attribute a on a.attrelid = x.indrelid and a.attnum = any(x.indkey)
pg_catalog.pg_index i
inner join pg_catalog.pg_class ic on ic.oid = i.indexrelid
inner join pg_catalog.pg_namespace nsp on nsp.oid = ic.relnamespace
inner join pg_catalog.pg_attribute a on a.attrelid = i.indrelid and a.attnum = any(i.indkey)
where
not x.indisunique and
not i.indisunique and
not a.attnotnull and
psai.schemaname = :schema_name_param::text and
array_position(x.indkey, a.attnum) = 0 and /* only for first segment */
(x.indpred is null or (position(lower(a.attname) in lower(pg_get_expr(x.indpred, x.indrelid))) = 0))
group by x.indrelid, x.indexrelid, x.indpred
not ic.relispartition and
nsp.nspname = :schema_name_param::text and
array_position(i.indkey, a.attnum) = 0 and /* only for first segment */
(i.indpred is null or (position(lower(a.attname) in lower(pg_get_expr(i.indpred, i.indrelid))) = 0))
group by i.indrelid, i.indexrelid, i.indpred
order by table_name, index_name;
Loading