From 49ee4b9c2bc661da70ae4b765802687b0a2112eb Mon Sep 17 00:00:00 2001 From: Ivan Vakhrushev Date: Sun, 5 Jan 2025 21:03:54 +0400 Subject: [PATCH] New year 2025 update (#69) * Update copyright * Update linter --- .github/workflows/linter.yml | 2 +- .gitignore | 1 + README.md | 6 +++--- sql/bloated_indexes.sql | 4 ++-- sql/bloated_tables.sql | 2 +- sql/btree_indexes_on_array_columns.sql | 4 ++-- sql/columns_with_json_type.sql | 2 +- sql/columns_with_serial_types.sql | 2 +- sql/columns_without_description.sql | 2 +- sql/duplicated_foreign_keys.sql | 2 +- sql/duplicated_indexes.sql | 2 +- sql/ext/slowest_queries_by_total_execution_time.sql | 2 +- sql/ext/slowest_queries_by_total_execution_time_13.sql | 2 +- sql/foreign_keys_with_unmatched_column_type.sql | 2 +- sql/foreign_keys_without_index.sql | 2 +- sql/functions_without_description.sql | 2 +- sql/indexes_with_boolean.sql | 2 +- sql/indexes_with_null_values.sql | 2 +- sql/intersected_foreign_keys.sql | 2 +- sql/intersected_indexes.sql | 4 ++-- sql/invalid_indexes.sql | 2 +- sql/not_valid_constraints.sql | 2 +- sql/possible_object_name_overflow.sql | 2 +- sql/primary_keys_with_serial_types.sql | 2 +- sql/sequence_overflow.sql | 2 +- sql/tables_not_linked_to_others.sql | 8 ++++---- sql/tables_with_missing_indexes.sql | 2 +- sql/tables_without_description.sql | 2 +- sql/tables_without_primary_key.sql | 2 +- sql/unused_indexes.sql | 3 ++- 30 files changed, 39 insertions(+), 37 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index c05e851..fc04f4a 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -18,7 +18,7 @@ jobs: fetch-depth: 0 - name: Lint Code Base - uses: super-linter/super-linter/slim@v7.1.0 + uses: super-linter/super-linter/slim@v7.2.1 env: VALIDATE_ALL_CODEBASE: false VALIDATE_SQLFLUFF: true diff --git a/.gitignore b/.gitignore index 485dee6..bc933ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +/.sqlfluff diff --git a/README.md b/README.md index 0587caa..56ac6a7 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ docker run \ -e USE_FIND_ALGORITHM=true \ -e VALIDATE_SQLFLUFF=true \ -v $(pwd):/tmp/lint \ - ghcr.io/super-linter/super-linter:slim-v7.1.0 + ghcr.io/super-linter/super-linter:slim-v7.2.1 ``` #### Windows @@ -75,7 +75,7 @@ docker run ^ -e USE_FIND_ALGORITHM=true ^ -e VALIDATE_SQLFLUFF=true ^ -v "%cd%":/tmp/lint ^ - ghcr.io/super-linter/super-linter:slim-v7.1.0 + ghcr.io/super-linter/super-linter:slim-v7.2.1 ``` ```shell @@ -83,5 +83,5 @@ docker run --rm ^ -v "%cd%\.github\linters\.sqlfluff":/sql/.sqlfluff:ro ^ -v "%cd%":/sql ^ -e SQLFLUFF_CONFIG=/sql/.sqlfluff ^ - sqlfluff/sqlfluff:3.1.1 lint /sql + sqlfluff/sqlfluff:3.2.5 lint /sql ``` diff --git a/sql/bloated_indexes.sql b/sql/bloated_indexes.sql index 657e4b5..612c003 100644 --- a/sql/bloated_indexes.sql +++ b/sql/bloated_indexes.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 @@ -35,7 +35,7 @@ with inner join pg_catalog.pg_class pc on pc.oid = pi.indexrelid inner join pg_catalog.pg_namespace nsp on nsp.oid = pc.relnamespace where - pc.relam = (select oid from pg_catalog.pg_am where amname = 'btree') and + pc.relam = (select am.oid from pg_catalog.pg_am am where am.amname = 'btree') and pc.relpages > 0 and nsp.nspname = :schema_name_param::text ), diff --git a/sql/bloated_tables.sql b/sql/bloated_tables.sql index dd707b9..e5a00c2 100644 --- a/sql/bloated_tables.sql +++ b/sql/bloated_tables.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/btree_indexes_on_array_columns.sql b/sql/btree_indexes_on_array_columns.sql index 3cbd42b..fc010e7 100644 --- a/sql/btree_indexes_on_array_columns.sql +++ b/sql/btree_indexes_on_array_columns.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 @@ -19,7 +19,7 @@ select from 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_am a on a.oid = ic.relam and a.amname = 'btree' + inner join pg_catalog.pg_am am on am.oid = ic.relam and am.amname = 'btree' inner join pg_catalog.pg_attribute col on col.attrelid = i.indrelid and col.attnum = any((string_to_array(i.indkey::text, ' ')::int2[])[:i.indnkeyatts]) inner join pg_catalog.pg_type typ on typ.oid = col.atttypid where diff --git a/sql/columns_with_json_type.sql b/sql/columns_with_json_type.sql index c19c001..60f87a2 100644 --- a/sql/columns_with_json_type.sql +++ b/sql/columns_with_json_type.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/columns_with_serial_types.sql b/sql/columns_with_serial_types.sql index 7a09a08..7273ef4 100644 --- a/sql/columns_with_serial_types.sql +++ b/sql/columns_with_serial_types.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/columns_without_description.sql b/sql/columns_without_description.sql index 3d941ba..41396a8 100644 --- a/sql/columns_without_description.sql +++ b/sql/columns_without_description.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/duplicated_foreign_keys.sql b/sql/duplicated_foreign_keys.sql index 49c969b..466c167 100644 --- a/sql/duplicated_foreign_keys.sql +++ b/sql/duplicated_foreign_keys.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/duplicated_indexes.sql b/sql/duplicated_indexes.sql index f14ea1c..a7848ac 100644 --- a/sql/duplicated_indexes.sql +++ b/sql/duplicated_indexes.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/ext/slowest_queries_by_total_execution_time.sql b/sql/ext/slowest_queries_by_total_execution_time.sql index ca53d37..52b97d5 100644 --- a/sql/ext/slowest_queries_by_total_execution_time.sql +++ b/sql/ext/slowest_queries_by_total_execution_time.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/ext/slowest_queries_by_total_execution_time_13.sql b/sql/ext/slowest_queries_by_total_execution_time_13.sql index d8ae986..ff3cdd5 100644 --- a/sql/ext/slowest_queries_by_total_execution_time_13.sql +++ b/sql/ext/slowest_queries_by_total_execution_time_13.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/foreign_keys_with_unmatched_column_type.sql b/sql/foreign_keys_with_unmatched_column_type.sql index 880fdac..934ac5b 100644 --- a/sql/foreign_keys_with_unmatched_column_type.sql +++ b/sql/foreign_keys_with_unmatched_column_type.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/foreign_keys_without_index.sql b/sql/foreign_keys_without_index.sql index c5cf659..3550566 100644 --- a/sql/foreign_keys_without_index.sql +++ b/sql/foreign_keys_without_index.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/functions_without_description.sql b/sql/functions_without_description.sql index febab21..fc94c69 100644 --- a/sql/functions_without_description.sql +++ b/sql/functions_without_description.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/indexes_with_boolean.sql b/sql/indexes_with_boolean.sql index 95601b8..4dace59 100644 --- a/sql/indexes_with_boolean.sql +++ b/sql/indexes_with_boolean.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/indexes_with_null_values.sql b/sql/indexes_with_null_values.sql index 6dabb56..6eda176 100644 --- a/sql/indexes_with_null_values.sql +++ b/sql/indexes_with_null_values.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/intersected_foreign_keys.sql b/sql/intersected_foreign_keys.sql index 05ec97c..6726a29 100644 --- a/sql/intersected_foreign_keys.sql +++ b/sql/intersected_foreign_keys.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/intersected_indexes.sql b/sql/intersected_indexes.sql index ebd1947..ee0615f 100644 --- a/sql/intersected_indexes.sql +++ b/sql/intersected_indexes.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 @@ -8,7 +8,7 @@ -- Finds indexes with overlapping sets of columns. -- For example, (A) and (A+B) and (A+B+C). -- Some of these indexes can usually be safely deleted. --- noqa: disable=ST09,ST05 +-- noqa: disable=ST09,ST05,RF02 with index_info as ( select diff --git a/sql/invalid_indexes.sql b/sql/invalid_indexes.sql index 6cc49e6..ec674f2 100644 --- a/sql/invalid_indexes.sql +++ b/sql/invalid_indexes.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/not_valid_constraints.sql b/sql/not_valid_constraints.sql index 68fc1b8..a518d16 100644 --- a/sql/not_valid_constraints.sql +++ b/sql/not_valid_constraints.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/possible_object_name_overflow.sql b/sql/possible_object_name_overflow.sql index 19e3420..0b24872 100644 --- a/sql/possible_object_name_overflow.sql +++ b/sql/possible_object_name_overflow.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/primary_keys_with_serial_types.sql b/sql/primary_keys_with_serial_types.sql index 718b2bf..e0f19f6 100644 --- a/sql/primary_keys_with_serial_types.sql +++ b/sql/primary_keys_with_serial_types.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/sequence_overflow.sql b/sql/sequence_overflow.sql index ec618ee..ba90279 100644 --- a/sql/sequence_overflow.sql +++ b/sql/sequence_overflow.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/tables_not_linked_to_others.sql b/sql/tables_not_linked_to_others.sql index e265b3d..fc85b3b 100644 --- a/sql/tables_not_linked_to_others.sql +++ b/sql/tables_not_linked_to_others.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 @@ -22,7 +22,7 @@ with ), fkeys as ( - select c.conrelid + select c.conrelid as fk_oid from pg_catalog.pg_constraint c inner join nsp on nsp.oid = c.connamespace @@ -31,7 +31,7 @@ with union - select c.confrelid + select c.confrelid as fk_oid from pg_catalog.pg_constraint c inner join nsp on nsp.oid = c.connamespace @@ -48,5 +48,5 @@ from where pc.relkind in ('r', 'p') and not pc.relispartition and - pc.oid not in (select * from fkeys) + pc.oid not in (select f.fk_oid from fkeys f) order by table_name; diff --git a/sql/tables_with_missing_indexes.sql b/sql/tables_with_missing_indexes.sql index fa02b2a..0f7c894 100644 --- a/sql/tables_with_missing_indexes.sql +++ b/sql/tables_with_missing_indexes.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/tables_without_description.sql b/sql/tables_without_description.sql index 0662e5c..93ffdeb 100644 --- a/sql/tables_without_description.sql +++ b/sql/tables_without_description.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/tables_without_primary_key.sql b/sql/tables_without_primary_key.sql index c52e76d..220f7cb 100644 --- a/sql/tables_without_primary_key.sql +++ b/sql/tables_without_primary_key.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 diff --git a/sql/unused_indexes.sql b/sql/unused_indexes.sql index e05c951..faca737 100644 --- a/sql/unused_indexes.sql +++ b/sql/unused_indexes.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * Copyright (c) 2019-2025. Ivan Vakhrushev and others. * https://github.com/mfvanek/pg-index-health-sql * * Licensed under the Apache License 2.0 @@ -8,6 +8,7 @@ -- Finds potentially unused indexes. -- This sql query have to be executed on all hosts in the cluster. -- The final result can be obtained as an intersection of results from all hosts. +-- noqa: disable=RF02 with foreign_key_indexes as ( select i.indexrelid