Skip to content

Commit 34c1fd3

Browse files
authored
Add index size to the output (#88)
* Add check to find usage of varchar(32/36) instead of uuid for PK * Fix linter * Add index size to the output
1 parent 52e0892 commit 34c1fd3

12 files changed

+14
-13
lines changed

sql/btree_indexes_on_array_columns.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ select
1414
i.indrelid::regclass::text as table_name,
1515
i.indexrelid::regclass::text as index_name,
1616
col.attnotnull as column_not_null,
17-
quote_ident(col.attname::text) as column_name,
17+
quote_ident(col.attname) as column_name,
1818
pg_relation_size(i.indexrelid) as index_size
1919
from pg_catalog.pg_index i
2020
inner join pg_catalog.pg_class ic on ic.oid = i.indexrelid

sql/columns_not_following_naming_convention.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
select
1515
t.oid::regclass::text as table_name,
1616
col.attnotnull as column_not_null,
17-
quote_ident(col.attname::text) as column_name
17+
quote_ident(col.attname) as column_name
1818
from
1919
pg_catalog.pg_class t
2020
inner join pg_catalog.pg_namespace nsp on nsp.oid = t.relnamespace

sql/columns_with_json_type.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
select
1313
t.oid::regclass::text as table_name,
1414
col.attnotnull as column_not_null,
15-
quote_ident(col.attname::text) as column_name
15+
quote_ident(col.attname) as column_name
1616
from
1717
pg_catalog.pg_class t
1818
inner join pg_catalog.pg_namespace nsp on nsp.oid = t.relnamespace

sql/columns_with_serial_types.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ with
1515
col.attrelid::regclass::text as table_name,
1616
col.attnotnull as column_not_null,
1717
nsp.nspname as schema_name,
18-
quote_ident(col.attname::text) as column_name,
18+
quote_ident(col.attname) as column_name,
1919
case col.atttypid
2020
when 'int'::regtype then 'serial'
2121
when 'int8'::regtype then 'bigserial'

sql/columns_without_description.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
select
1111
pc.oid::regclass::text as table_name,
1212
col.attnotnull as column_not_null,
13-
quote_ident(col.attname::text) as column_name
13+
quote_ident(col.attname) as column_name
1414
from
1515
pg_catalog.pg_class pc
1616
inner join pg_catalog.pg_namespace nsp on nsp.oid = pc.relnamespace

sql/duplicated_foreign_keys.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ with
1414
c.conrelid as table_oid,
1515
c.confrelid as foreign_table_oid,
1616
u.attposition,
17-
col.attname,
1817
col.attnotnull,
18+
quote_ident(col.attname) as column_name,
1919
quote_ident(c.conname) as constraint_name
2020
from
2121
pg_catalog.pg_constraint c
@@ -33,7 +33,7 @@ with
3333
constraint_name,
3434
table_oid,
3535
foreign_table_oid,
36-
array_agg(attname::text || ',' || attnotnull::text order by attposition) as columns
36+
array_agg(column_name || ',' || attnotnull::text order by attposition) as columns
3737
from fk_with_attributes
3838
group by constraint_name, table_oid, foreign_table_oid
3939
)

sql/foreign_keys_without_index.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
select
1111
c.conrelid::regclass::text as table_name,
1212
quote_ident(c.conname) as constraint_name,
13-
array_agg(col.attname::text || ',' || col.attnotnull::text order by u.attposition) as columns
13+
array_agg(quote_ident(col.attname) || ',' || col.attnotnull::text order by u.attposition) as columns
1414
from
1515
pg_catalog.pg_constraint c
1616
inner join lateral unnest(c.conkey) with ordinality u(attnum, attposition) on true

sql/indexes_with_boolean.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ select
1010
pi.indrelid::regclass::text as table_name,
1111
pi.indexrelid::regclass::text as index_name,
1212
col.attnotnull as column_not_null,
13-
quote_ident(col.attname::text) as column_name,
13+
quote_ident(col.attname) as column_name,
1414
pg_relation_size(pi.indexrelid) as index_size
1515
from
1616
pg_catalog.pg_index pi

sql/indexes_with_null_values.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
select
1010
i.indrelid::regclass::text as table_name,
1111
i.indexrelid::regclass::text as index_name,
12-
string_agg(a.attname, ', ') as nullable_fields, /* in fact, there will always be only one column */
12+
string_agg(quote_ident(a.attname), ', ') as nullable_fields, /* in fact, there will always be only one column */
1313
pg_relation_size(i.indexrelid) as index_size
1414
from
1515
pg_catalog.pg_index i

sql/primary_keys_with_serial_types.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ with
2424
col.attrelid::regclass::text as table_name,
2525
col.attnotnull as column_not_null,
2626
s.seqrelid::regclass::text as sequence_name,
27-
quote_ident(col.attname::text) as column_name,
27+
quote_ident(col.attname) as column_name,
2828
case col.atttypid
2929
when 'int'::regtype then 'serial'
3030
when 'int8'::regtype then 'bigserial'

sql/primary_keys_with_varchar.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
-- Finds primary keys with columns of varchar(32/36/38) type.
9-
-- Usually this columns should use built-in uuid type.
9+
-- Usually these columns should use built-in uuid type.
1010
--
1111
-- See https://www.postgresql.org/docs/17/datatype-uuid.html
1212
-- b9b1f6f5-7f90-4b68-a389-f0ad8bb5784b - with dashes - 36 characters
@@ -15,6 +15,7 @@
1515
select
1616
pc.oid::regclass::text as table_name,
1717
i.indexrelid::regclass as index_name,
18+
pg_relation_size(i.indexrelid) as index_size,
1819
array_agg(quote_ident(a.attname) || ',' || a.attnotnull::text order by a.attnum) as columns
1920
from
2021
pg_catalog.pg_class pc

sql/tables_with_zero_or_one_column.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
select
1515
pc.oid::regclass::text as table_name,
1616
pg_table_size(pc.oid) as table_size,
17-
coalesce(array_agg(a.attname::text || ',' || a.attnotnull::text order by a.attnum) filter (where a.attname is not null), '{}') as columns
17+
coalesce(array_agg(quote_ident(a.attname) || ',' || a.attnotnull::text order by a.attnum) filter (where a.attname is not null), '{}') as columns
1818
from
1919
pg_catalog.pg_class pc
2020
inner join pg_catalog.pg_namespace nsp on nsp.oid = pc.relnamespace

0 commit comments

Comments
 (0)