-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
126 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ plugins { | |
} | ||
|
||
group 'com.mfvanek' | ||
version '0.0.3' | ||
version '0.0.4' | ||
|
||
sourceCompatibility = 11 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
select c.conrelid::regclass as table_name, | ||
string_agg(col.attname, ', ' order by u.attposition) as columns, | ||
c.conname as constraint_name | ||
from pg_constraint c | ||
from pg_catalog.pg_constraint c | ||
join lateral unnest(c.conkey) with ordinality as u(attnum, attposition) on true | ||
join pg_class t on (c.conrelid = t.oid) | ||
join pg_namespace nsp on nsp.oid = t.relnamespace | ||
join pg_attribute col on (col.attrelid = t.oid and col.attnum = u.attnum) | ||
where contype = 'f' | ||
join pg_catalog.pg_class t on (c.conrelid = t.oid) | ||
join pg_catalog.pg_namespace nsp on nsp.oid = t.relnamespace | ||
join pg_catalog.pg_attribute col on (col.attrelid = t.oid and col.attnum = u.attnum) | ||
where c.contype = 'f' | ||
and nsp.nspname = 'public'::text | ||
and not exists( | ||
select 1 | ||
from pg_index | ||
where indrelid = c.conrelid | ||
and (c.conkey::int[] <@ indkey::int[]) /*all columns of foreign key have to present in index*/ | ||
and array_position(indkey::int[], (c.conkey::int[])[1]) = 0 /*ordering of columns in foreign key and in index is the same*/ | ||
from pg_catalog.pg_index pi | ||
where pi.indrelid = c.conrelid | ||
and (c.conkey::int[] <@ pi.indkey::int[]) /*all columns of foreign key have to present in index*/ | ||
and array_position(pi.indkey::int[], (c.conkey::int[])[1]) = 0 /*ordering of columns in foreign key and in index is the same*/ | ||
) | ||
group by c.conrelid, c.conname, c.oid | ||
order by (c.conrelid::regclass)::text, columns; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
select a.indrelid::regclass as table_name, | ||
'idx=' || a.indexrelid::regclass || ', size=' || pg_relation_size(a.indexrelid) || '; idx=' || | ||
b.indexrelid::regclass || ', size=' || pg_relation_size(b.indexrelid) as intersected_indexes | ||
from ( | ||
select *, array_to_string(indkey, ' ') as cols | ||
from pg_index) as a | ||
join (select *, array_to_string(indkey, ' ') as cols from pg_index) as b | ||
from (select *, array_to_string(indkey, ' ') as cols from pg_catalog.pg_index) as a | ||
join (select *, array_to_string(indkey, ' ') as cols from pg_catalog.pg_index) as b | ||
on (a.indrelid = b.indrelid and a.indexrelid > b.indexrelid and ( | ||
(a.cols like b.cols || '%' and coalesce(substr(a.cols, length(b.cols) + 1, 1), ' ') = ' ') or | ||
(b.cols like a.cols || '%' and coalesce(substr(b.cols, length(a.cols) + 1, 1), ' ') = ' '))) | ||
join pg_catalog.pg_stat_all_indexes psai on a.indexrelid = psai.indexrelid | ||
where psai.schemaname = 'public'::text | ||
order by a.indrelid::regclass::text; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
select | ||
x.indrelid::regclass as table_name, | ||
select x.indrelid::regclass as table_name, | ||
x.indexrelid::regclass as index_name | ||
from pg_index x | ||
join pg_stat_all_indexes psai on x.indexrelid = psai.indexrelid and psai.schemaname = 'public'::text | ||
where x.indisvalid = false; | ||
from pg_catalog.pg_index x | ||
join pg_catalog.pg_stat_all_indexes psai on x.indexrelid = psai.indexrelid | ||
where psai.schemaname = 'public'::text | ||
and x.indisvalid = false; |
Oops, something went wrong.