Filter Queries

Found 1096 queries.

Page 40 of 55
  • All the queries about database objects contain a subcondition to exclude from the result information about the system catalog.
  • Although the statements use SQL constructs (common table expressions; NOT in subqueries) that could cause performance problems in case of large datasets, it shouldn't be a problem in case of the relatively small amount of data in the system catalog of a database.

#781. Recursive relationships with the same source and target

system catalog base tables only

Find incorrectly implemented adjacency lists.

Problem detection License: MIT (opens in new tab)

#782. Recursive rules that directly modify their home table

system catalog base tables only

Do not cause potentially infinite loops. Recursive rules would fire itself over and over again. Although the system is able to detect these after executing a data modification statement it is better to avoid creating these altogether.

Problem detection License: MIT (opens in new tab)

#783. Recursive triggers potentially causing infinite loops

INFORMATION_SCHEMA+system catalog base tables

This query identifies recursive triggers, which occur when a trigger's execution performs an operation (such as an UPDATE on the same table) that immediately causes the same trigger to fire again. This creates a potential infinite loop of execution. While PostgreSQL implements a stack depth limit to detect and terminate such runaway processes to prevent a complete system crash, relying on this fail-safe is poor engineering practice. These triggers consume significant system resources before failure and invariably result in aborted transactions. They should be refactored to avoid self-invocation.

Problem detection License: MIT (opens in new tab)

#784. Redundant and unconditional SELECT ... FOR UPDATE preceding UPDATE or DELETE on the same table

INFORMATION_SCHEMA+system catalog base tables

This query identifies performance and concurrency bottlenecks in user-defined routines caused by executing a standalone SELECT ... FOR [NO KEY] UPDATE or PERFORM ... FOR [NO KEY] UPDATE statement on a table prior to modifying the exact same table with an UPDATE or DELETE statement.

In PostgreSQL, UPDATE and DELETE statements automatically acquire the appropriate row-level write lock (FOR NO KEY UPDATE for non-key updates, or FOR UPDATE for key-column updates and deletes) on target rows that satisfy the WHERE predicate. Executing a separate, preceding SELECT/PERFORM ... FOR [NO KEY] UPDATE on the same table (without an ORDER BY clause for deterministic multi-row deadlock prevention) is redundant—incurring an unnecessary extra scan and lock operation—and degrades concurrency when the initial lock predicate is less restrictive than the subsequent modification (for instance, locking a row solely by its primary key before verifying its status or optimistic lock version). If the subsequent UPDATE or DELETE affects zero rows due to a version mismatch or invalid state, the transaction still retains the write lock acquired by the preliminary query, unnecessarily blocking concurrent transactions.

Problem detection License: MIT (opens in new tab)

#785. Redundant CHECK constraints (logical subsumption or equivalence) (empty strings)

INFORMATION_SCHEMA+system catalog base tables

This query identifies superfluous CHECK constraints by detecting logical subsumption. It targets columns where a generic validation ensuring the trimmed string is not empty (e.g., trim(column) <> '') is rendered redundant by a more specific constraint that enforces a minimum length on the trimmed string (e.g., char_length(trim(column)) > 0). Since a string with a positive length is inherently not empty, the generic check adds no functional value and should be removed to simplify the schema.

Problem detection License: MIT (opens in new tab)

#786. Redundant CHECK constraints (logical subsumption or equivalence) (empty strings and strings that consist of whitespace characters)

INFORMATION_SCHEMA+system catalog base tables

This query identifies redundant CHECK constraints by detecting cases of logical equivalence or subsumption on a single column. For instance, a constraint like description !~ '^[[:space:]]*$' logically subsumes a less comprehensive constraint such as description <> '', rendering the latter superfluous. Eliminating such duplication is a best practice that improves schema clarity, reduces maintenance overhead, and removes logical noise.

Problem detection License: MIT (opens in new tab)

#787. Redundant CHECK constraints (logical subsumption or equivalence) (empty strings and strings that consist of whitespace characters) (2)

INFORMATION_SCHEMA+system catalog base tables

This query identifies superfluous CHECK constraints by detecting logical subsumption. It targets columns where a general non-blankness constraint is made redundant by a more specific, format-validating constraint. For instance, if an e_mail column is validated by a format constraint from Set1 (e.g., e_mail LIKE '%@%'), that constraint implicitly ensures the string is not blank. Therefore, any co-existing constraint from Set2 (e.g., e_mail !~ '^[[:space:]]*$') is logically unnecessary and can be removed to reduce schema complexity.

Example. Set1: {e_mail~'[[:alnum:]@]+'; position('@' in e_mail)>0; e_mail LIKE '%@%'} Set2: {e_mail~'\S'; e_mail!~'^[[:space:]]*$'; e_mail!~'^\s*$'} If column e_mail has a constraint from Set1, then it does not need a constraint from Set2.

Problem detection License: MIT (opens in new tab)

#788. Redundant DO INSTEAD NOTHING rules on naturally non-updatable views

INFORMATION_SCHEMA+system catalog base tables

This query identifies redundant rewrite rules within the database schema. It targets views that are inherently non-updatable (due to the presence of aggregates, joins, or set operations) but are nevertheless defined with a DO INSTEAD NOTHING rule. Since the PostgreSQL engine cannot perform DML operations on such views natively, the view is effectively read-only by definition. Consequently, the explicit rule serves no functional purpose in preventing data modification and represents superfluous schema metadata.

Problem detection License: MIT (opens in new tab)

#789. Redundant explicit locking in initially deferred constraint triggers

INFORMATION_SCHEMA+system catalog base tables

This query identifies INITIALLY DEFERRED constraint triggers that utilize explicit locking mechanisms (e.g., LOCK TABLE, SELECT ... FOR SHARE). Deferred constraints are evaluated at transaction commit time, by which point the database engine automatically manages the necessary data consistency states. Consequently, acquiring manual locks within these triggers is technically redundant. Furthermore, it introduces performance risks by enforcing serialization at the critical end-stage of the transaction, potentially increasing the likelihood of deadlocks and reducing system throughput.

Problem detection License: MIT (opens in new tab)

#790. Redundant indexes

system catalog base tables only

Find indexes that may be redundant. In addition to identical indexes it also considers indexes that cover the same columns and have the same properties except uniqueness. The query considers all types of indexes, including indexes that have been automatically created to support a constraint and function-based indexes.

Problem detection License: MIT (opens in new tab)

#791. Redundant indexes sharing an identical leading column

system catalog base tables only

This query identifies redundant, standard (non-expression, non-partial) indexes that share an identical leading column and operator class. In PostgreSQL B-tree indexes, queries filtering on a leading column can utilize any index where that column comes first (the leftmost prefix rule). Having multiple indexes starting with the exact same column and operator class—whether standalone or backing declarative constraints (such as PRIMARY KEY, UNIQUE, or exclusion constraints)—creates overlapping index coverage. This redundancy wastes disk space, consumes buffer cache memory, and introduces unnecessary write overhead on INSERT, UPDATE, and DELETE operations without providing additional query performance benefits.

Problem detection License: MIT (opens in new tab)

#792. Redundant leading or trailing wildcards in regular expressions

INFORMATION_SCHEMA+system catalog base tables

This query identifies regular expressions that contain superfluous .* constructs at the beginning or end of the pattern. In standard unanchored regular expression matching (as performed by PostgreSQL's ~ operator), the engine checks for the pattern's existence anywhere within the string by default. Therefore, a leading or trailing .* is typically redundant, as it explicitly instructs the engine to do what it would already be doing implicitly. Removing these unnecessary wildcards improves the readability and maintainability of the expression and can, in some cases, lead to better performance by reducing unnecessary backtracking.

Problem detection License: MIT (opens in new tab)

#793. Redundant sequence usage privileges (missing table insert rights)

INFORMATION_SCHEMA+system catalog base tables

This query identifies a logical mismatch in access control lists (ACLs). It flags cases where a role is granted USAGE privilege on a sequence (allowing the generation of values via nextval) but lacks the INSERT privilege on the table associated with that sequence. Since the primary purpose of such a sequence is to generate surrogate keys for new rows, possessing the right to generate IDs without the right to insert rows renders the sequence privilege functionally useless. This violates the principle of least privilege and should be revoked to minimize the attack surface.

Problem detection License: MIT (opens in new tab)

#794. Redundant trim() function in whitespace constraints

INFORMATION_SCHEMA only

This query identifies superfluous trim() function calls within CHECK constraints where the validation is performed by a regular expression that disallows whitespace-only strings. A constraint using the pattern column !~ '^[[:space:]]*$' already provides comprehensive validation against empty or whitespace-only strings by anchoring the check to the start (^) and end ($) of the string. The trim() function is a pre-processing step that does not alter the boolean outcome of this specific regex match, making the expression trim(column) !~ '^[[:space:]]*$' functionally equivalent to the simpler column !~ '^[[:space:]]*$'. Removing the unnecessary function call improves clarity and simplifies the constraint.

Problem detection License: MIT (opens in new tab)

#795. Reference to the numeric type is too imprecise, i.e., precision and scale are missing

INFORMATION_SCHEMA only

Find base table columns that have the DECIMAL/NUMERIC type, but do not have precision and scale specified. "Specifying: NUMERIC without any precision or scale creates a column in which numeric values of any precision and scale can be stored, up to the implementation limit on precision. A column of this kind will not coerce input values to any particular scale, whereas numeric columns with a declared scale will coerce input values to that scale."

Problem detection License: MIT (opens in new tab)

#796. Referential degree of a schema

INFORMATION_SCHEMA only

Referential degree of a schema is defined as the number of foreign keys in the database schema.

Sofware measure License: MIT (opens in new tab)

#797. Referential degree of tables

INFORMATION_SCHEMA only

This metric represents the number of foreign keys in a base table.

Sofware measure License: MIT (opens in new tab)

#798. Referential degree of tables (ver 2)

system catalog base tables only

Find how many base tables are referenced from a base table by using foreign keys.

Sofware measure License: MIT (opens in new tab)

#799. Registration/modification time is optional

INFORMATION_SCHEMA only

This query identifies columns intended to store registration or modification timestamps that are currently defined as optional (nullable). Since creation and update times are crucial for data auditing, these columns should typically have a NOT NULL constraint.

Problem detection License: MIT (opens in new tab)

#800. Regular expressions redundantly specifying a-zA-Z or A-Za-z character ranges

INFORMATION_SCHEMA+system catalog base tables

This query identifies database objects (table and domain CHECK constraints, trigger WHEN conditions, rules, views, materialized views, and user-defined routines) that contain regular expressions specifying both lowercase and uppercase ASCII letter ranges (a-zA-Z or A-Za-z) where the case-insensitive regular expression operator (~* or !~*) with a single range (a-z) can be used instead.

Writing a-zA-Z or A-Za-z is unnecessary and verbose in two situations:

  • The expression already uses a case-insensitive operator (~* or !~*), making the second letter range completely redundant.
  • The expression uses a case-sensitive operator (~ or !~), and the regular expression pattern contains no other case-sensitive letters outside of the a-zA-Z / A-Za-z range. In this case, switching to ~* (or !~*) with a-z makes the pattern shorter, easier to read, and less error-prone.


Regular expressions that use a case-sensitive operator (~ or !~) alongside other case-specific characters or character classes (for example, '^\$2[abxy]\$[0-9]{2}\$[./A-Za-z0-9]{53}$', where [abxy] must remain strictly lowercase) are excluded, because replacing ~ with ~* would alter the validation semantics of the rest of the pattern.

Problem detection License: MIT (opens in new tab)
# Name(sorted ascending, activate to sort descending) Goal(activate to sort ascending) Type(activate to sort ascending) Data source(activate to sort ascending) Last update(activate to sort ascending) License Actions
781 Recursive relationships with the same source and target Find incorrectly implemented adjacency lists. Problem detection system catalog base tables only MIT (opens in new tab) View
782 Recursive rules that directly modify their home table Do not cause potentially infinite loops. Recursive rules would fire itself over and over again. Although the system is able to detect these after executing a data modification statement it is better to avoid creating these altogether. Problem detection system catalog base tables only MIT (opens in new tab) View
783 Recursive triggers potentially causing infinite loops This query identifies recursive triggers, which occur when a trigger's execution performs an operation (such as an UPDATE on the same table) that immediately causes the same trigger to fire again. This creates a potential infinite loop of execution. While PostgreSQL implements a stack depth limit to detect and terminate such runaway processes to prevent a complete system crash, relying on this fail-safe is poor engineering practice. These triggers consume significant system resources before failure and invariably result in aborted transactions. They should be refactored to avoid self-invocation. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
784 Redundant and unconditional SELECT ... FOR UPDATE preceding UPDATE or DELETE on the same table This query identifies performance and concurrency bottlenecks in user-defined routines caused by executing a standalone SELECT ... FOR [NO KEY] UPDATE or PERFORM ... FOR [NO KEY] UPDATE statement on a table prior to modifying the exact same table with an UPDATE or DELETE statement.

In PostgreSQL, UPDATE and DELETE statements automatically acquire the appropriate row-level write lock (FOR NO KEY UPDATE for non-key updates, or FOR UPDATE for key-column updates and deletes) on target rows that satisfy the WHERE predicate. Executing a separate, preceding SELECT/PERFORM ... FOR [NO KEY] UPDATE on the same table (without an ORDER BY clause for deterministic multi-row deadlock prevention) is redundant—incurring an unnecessary extra scan and lock operation—and degrades concurrency when the initial lock predicate is less restrictive than the subsequent modification (for instance, locking a row solely by its primary key before verifying its status or optimistic lock version). If the subsequent UPDATE or DELETE affects zero rows due to a version mismatch or invalid state, the transaction still retains the write lock acquired by the preliminary query, unnecessarily blocking concurrent transactions.
Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
785 Redundant CHECK constraints (logical subsumption or equivalence) (empty strings) This query identifies superfluous CHECK constraints by detecting logical subsumption. It targets columns where a generic validation ensuring the trimmed string is not empty (e.g., trim(column) <> '') is rendered redundant by a more specific constraint that enforces a minimum length on the trimmed string (e.g., char_length(trim(column)) > 0). Since a string with a positive length is inherently not empty, the generic check adds no functional value and should be removed to simplify the schema. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
786 Redundant CHECK constraints (logical subsumption or equivalence) (empty strings and strings that consist of whitespace characters) This query identifies redundant CHECK constraints by detecting cases of logical equivalence or subsumption on a single column. For instance, a constraint like description !~ '^[[:space:]]*$' logically subsumes a less comprehensive constraint such as description <> '', rendering the latter superfluous. Eliminating such duplication is a best practice that improves schema clarity, reduces maintenance overhead, and removes logical noise. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
787 Redundant CHECK constraints (logical subsumption or equivalence) (empty strings and strings that consist of whitespace characters) (2) This query identifies superfluous CHECK constraints by detecting logical subsumption. It targets columns where a general non-blankness constraint is made redundant by a more specific, format-validating constraint. For instance, if an e_mail column is validated by a format constraint from Set1 (e.g., e_mail LIKE '%@%'), that constraint implicitly ensures the string is not blank. Therefore, any co-existing constraint from Set2 (e.g., e_mail !~ '^[[:space:]]*$') is logically unnecessary and can be removed to reduce schema complexity.

Example. Set1: {e_mail~'[[:alnum:]@]+'; position('@' in e_mail)>0; e_mail LIKE '%@%'} Set2: {e_mail~'\S'; e_mail!~'^[[:space:]]*$'; e_mail!~'^\s*$'} If column e_mail has a constraint from Set1, then it does not need a constraint from Set2.

Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
788 Redundant DO INSTEAD NOTHING rules on naturally non-updatable views This query identifies redundant rewrite rules within the database schema. It targets views that are inherently non-updatable (due to the presence of aggregates, joins, or set operations) but are nevertheless defined with a DO INSTEAD NOTHING rule. Since the PostgreSQL engine cannot perform DML operations on such views natively, the view is effectively read-only by definition. Consequently, the explicit rule serves no functional purpose in preventing data modification and represents superfluous schema metadata. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
789 Redundant explicit locking in initially deferred constraint triggers This query identifies INITIALLY DEFERRED constraint triggers that utilize explicit locking mechanisms (e.g., LOCK TABLE, SELECT ... FOR SHARE). Deferred constraints are evaluated at transaction commit time, by which point the database engine automatically manages the necessary data consistency states. Consequently, acquiring manual locks within these triggers is technically redundant. Furthermore, it introduces performance risks by enforcing serialization at the critical end-stage of the transaction, potentially increasing the likelihood of deadlocks and reducing system throughput. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
790 Redundant indexes Find indexes that may be redundant. In addition to identical indexes it also considers indexes that cover the same columns and have the same properties except uniqueness. The query considers all types of indexes, including indexes that have been automatically created to support a constraint and function-based indexes. Problem detection system catalog base tables only MIT (opens in new tab) View
791 Redundant indexes sharing an identical leading column This query identifies redundant, standard (non-expression, non-partial) indexes that share an identical leading column and operator class. In PostgreSQL B-tree indexes, queries filtering on a leading column can utilize any index where that column comes first (the leftmost prefix rule). Having multiple indexes starting with the exact same column and operator class—whether standalone or backing declarative constraints (such as PRIMARY KEY, UNIQUE, or exclusion constraints)—creates overlapping index coverage. This redundancy wastes disk space, consumes buffer cache memory, and introduces unnecessary write overhead on INSERT, UPDATE, and DELETE operations without providing additional query performance benefits. Problem detection system catalog base tables only MIT (opens in new tab) View
792 Redundant leading or trailing wildcards in regular expressions This query identifies regular expressions that contain superfluous .* constructs at the beginning or end of the pattern. In standard unanchored regular expression matching (as performed by PostgreSQL's ~ operator), the engine checks for the pattern's existence anywhere within the string by default. Therefore, a leading or trailing .* is typically redundant, as it explicitly instructs the engine to do what it would already be doing implicitly. Removing these unnecessary wildcards improves the readability and maintainability of the expression and can, in some cases, lead to better performance by reducing unnecessary backtracking. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
793 Redundant sequence usage privileges (missing table insert rights) This query identifies a logical mismatch in access control lists (ACLs). It flags cases where a role is granted USAGE privilege on a sequence (allowing the generation of values via nextval) but lacks the INSERT privilege on the table associated with that sequence. Since the primary purpose of such a sequence is to generate surrogate keys for new rows, possessing the right to generate IDs without the right to insert rows renders the sequence privilege functionally useless. This violates the principle of least privilege and should be revoked to minimize the attack surface. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
794 Redundant trim() function in whitespace constraints This query identifies superfluous trim() function calls within CHECK constraints where the validation is performed by a regular expression that disallows whitespace-only strings. A constraint using the pattern column !~ '^[[:space:]]*$' already provides comprehensive validation against empty or whitespace-only strings by anchoring the check to the start (^) and end ($) of the string. The trim() function is a pre-processing step that does not alter the boolean outcome of this specific regex match, making the expression trim(column) !~ '^[[:space:]]*$' functionally equivalent to the simpler column !~ '^[[:space:]]*$'. Removing the unnecessary function call improves clarity and simplifies the constraint. Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View
795 Reference to the numeric type is too imprecise, i.e., precision and scale are missing Find base table columns that have the DECIMAL/NUMERIC type, but do not have precision and scale specified. "Specifying: NUMERIC without any precision or scale creates a column in which numeric values of any precision and scale can be stored, up to the implementation limit on precision. A column of this kind will not coerce input values to any particular scale, whereas numeric columns with a declared scale will coerce input values to that scale." Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View
796 Referential degree of a schema Referential degree of a schema is defined as the number of foreign keys in the database schema. Sofware measure INFORMATION_SCHEMA only MIT (opens in new tab) View
797 Referential degree of tables This metric represents the number of foreign keys in a base table. Sofware measure INFORMATION_SCHEMA only MIT (opens in new tab) View
798 Referential degree of tables (ver 2) Find how many base tables are referenced from a base table by using foreign keys. Sofware measure system catalog base tables only MIT (opens in new tab) View
799 Registration/modification time is optional This query identifies columns intended to store registration or modification timestamps that are currently defined as optional (nullable). Since creation and update times are crucial for data auditing, these columns should typically have a NOT NULL constraint. Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View
800 Regular expressions redundantly specifying a-zA-Z or A-Za-z character ranges This query identifies database objects (table and domain CHECK constraints, trigger WHEN conditions, rules, views, materialized views, and user-defined routines) that contain regular expressions specifying both lowercase and uppercase ASCII letter ranges (a-zA-Z or A-Za-z) where the case-insensitive regular expression operator (~* or !~*) with a single range (a-z) can be used instead.

Writing a-zA-Z or A-Za-z is unnecessary and verbose in two situations:
  • The expression already uses a case-insensitive operator (~* or !~*), making the second letter range completely redundant.
  • The expression uses a case-sensitive operator (~ or !~), and the regular expression pattern contains no other case-sensitive letters outside of the a-zA-Z / A-Za-z range. In this case, switching to ~* (or !~*) with a-z makes the pattern shorter, easier to read, and less error-prone.


Regular expressions that use a case-sensitive operator (~ or !~) alongside other case-specific characters or character classes (for example, '^\$2[abxy]\$[0-9]{2}\$[./A-Za-z0-9]{53}$', where [abxy] must remain strictly lowercase) are excluded, because replacing ~ with ~* would alter the validation semantics of the rest of the pattern.

Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View