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 boolean values #31

Merged
merged 2 commits into from
Feb 6, 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: 24 additions & 0 deletions sql/indexes_with_boolean.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2019-2024. Ivan Vakhrushev and others.
* https://github.com/mfvanek/pg-index-health-sql
*
* Licensed under the Apache License 2.0
*/

-- Finds indexes that contains boolean values.
select
pi.indrelid::regclass::text as table_name,
pi.indexrelid::regclass::text as index_name,
col.attname as column_name,
col.attnotnull as column_not_null
from
pg_catalog.pg_index pi
join pg_catalog.pg_class pc on pc.oid = pi.indexrelid
join pg_catalog.pg_namespace pn on pn.oid = pc.relnamespace
join pg_catalog.pg_attribute col on col.attrelid = pi.indrelid and col.attnum = any(pi.indkey)
where pn.nspname = :schema_name_param::text
and not pi.indisunique
and pi.indisready
and pi.indisvalid
and col.atttypid = 'boolean'::regtype
order by table_name, index_name;