Filter Queries

Found 59 queries.

  • 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.

#1. BOOLEAN base table and foreign table columns with a CHECK constraint that involves olnly this column

INFORMATION_SCHEMA+system catalog base tables

Find base table and foreign table columns with the Boolean type that has a CHECK constraint that involves only this column. Avoid unnecessary CHECK constraints. The Boolean type contains only two values and there is nothing to check. By creating a check that determines that possible values in the column are TRUE and FALSE, one duplicates the attribute constraint (column has a type). This is a form of duplication.

Problem detection License: MIT (opens in new tab)

#2. CHECK constraints with the cardinality bigger than one that involve the same set of columns

system catalog base tables only

CHECK constraints with the cardinality bigger than one that involve the same set of columns. Make sure that there is no duplication.

General License: MIT (opens in new tab)

#3. Domain CHECK constraints with the same name

INFORMATION_SCHEMA only

Find domain check constraint names that are used more than once (within the same schema or in different schemas). Different things should have different names. However, here different constraints have the same name. Also make sure that this is not a sign of duplication of domains.

Problem detection License: MIT (opens in new tab)

#4. Domains with the same name in different schemas

INFORMATION_SCHEMA only

Domains are like words that can be used to construct generalized claims about the real world (table predicates). Better not to duplicate the words in the dictionary.

Problem detection License: MIT (opens in new tab)

#5. Do not clone tables

INFORMATION_SCHEMA only

Find cases where a base table has been split horizontally into multiple smaller base tables based on the distinct values in one of the columns of the original table. Each such newly created table has the name, a part of which is a data value from the original tables. Find base tables that have the same columns (column name, column order, data type) and the difference between the tables are the numbers in the table names (table1, table2, etc.).

Problem detection License: MIT (opens in new tab)

#6. Double checking of the maximum character length

INFORMATION_SCHEMA+system catalog base tables

This query identifies superfluous CHECK constraints where a programmatic length check duplicates a declarative, data type-based length limit. For instance, a CHECK constraint like char_length(column) <= 100 on a column already defined as VARCHAR(100) is redundant.

Problem detection License: MIT (opens in new tab)

#7. Duplicate CHECK constraints that are connected directly to a table

INFORMATION_SCHEMA only

The same table should not have multiple CHECK constraints with exactly the same Boolean expression. Do remember that the same task can be solved in SQL usually in multiple different ways. Thus, the exact copies are not the only possible duplication.

Problem detection License: MIT (opens in new tab)

#8. Duplicate CHECK constraints that are connected to a domain

INFORMATION_SCHEMA only

The same domain should not have multiple CHECK constraints with exactly the same Boolean expression. Do remember that the same task can be solved in SQL usually in multiple different ways. Thus, the exact copies are not the only possible duplication.

Problem detection License: MIT (opens in new tab)

#9. Duplicate DEFAULT values of base table columns

INFORMATION_SCHEMA only

Find base table columns that have both default value determined through a domain and default value that is directly attached to the column. Do not duplicate specifications of default values to avoid confusion and surprises. If column and domain both have a default value, then in case of inserting data the default value that is associated directly with the column is used.

Problem detection License: MIT (opens in new tab)

#10. Duplicate domains

INFORMATION_SCHEMA only

Find domains that have the same properties (base type, character length, not null + check constraints, default value, collation). There should not be multiple domains that have the same properties. Do remember that the same task can be solved in SQL usually in multiple different ways. Therefore, the domains may have syntactically different check constraints that solve the same task. Thus, the exact copies are not the only possible duplication.

Problem detection License: MIT (opens in new tab)

#11. Duplicate enumerated types

INFORMATION_SCHEMA+system catalog base tables

Find enumerated types with exactly the same values. There should not be multiple types that have the same values.

Problem detection License: MIT (opens in new tab)

#12. Duplicate foreign key constraints

system catalog base tables only

Find duplicate foreign key constraints, which involve the same columns and refer to the same set of columns.

Problem detection License: MIT (opens in new tab)

#13. Duplicate independent (i.e., not created based on a table) composite types

system catalog base tables only

Find composite types with the same attributes (regardless of the order of attributes). Make sure that there is no duplication.

Problem detection License: MIT (opens in new tab)

#14. Duplicate keys

system catalog base tables only

Find completely overlapping key (primary key, unique, and exclude where all operators are =) constraints. This is a form of duplication. It leads to the creation of multiple indexes to the same set of columns.

Problem detection License: MIT (opens in new tab)

#15. Duplicate materialized views

system catalog base tables only

Find materialized views with exactly the same subquery. There should not be multiple materialized views with the same subquery. Do remember that the same task can be solved in SQL usually in multiple different ways. Thus, the exact copies are not the only possible duplication.

Problem detection License: MIT (opens in new tab)

#16. Duplicate NOT NULL constraints

INFORMATION_SCHEMA+system catalog base tables

Find columns that have NOT NULL constraint through a domain and also directly. Do not duplicate NOT NULL constraints in orde to avoid confusion and surprises.

Problem detection License: MIT (opens in new tab)

#17. Duplicate removal of duplicates in derived tables

INFORMATION_SCHEMA+system catalog base tables

Find derived tables (views and materialized views) that contain both DISTINCT and GROUP BY. Make sure that the means for removing duplicate rows from the query result are not duplicated.

Problem detection License: MIT (opens in new tab)

#18. Duplicate rules

system catalog base tables only

Find multiple rules with the same definition (event, condition, action) on the same table. Do remember that the same task can be solved in SQL usually in multiple different ways. Thus, the exact copies are not the only possible duplication.

Problem detection License: MIT (opens in new tab)

#19. Duplicate specification of character classes

INFORMATION_SCHEMA+system catalog base tables

Find regular expressions where within the same specification of a character class the character class alnum as well as 0-9, \d, A-Z, or a-z has been defined.

Problem detection License: MIT (opens in new tab)

#20. Duplicate stored generated base table columns

INFORMATION_SCHEMA only

Find base tables that have more than one stored generated column with the same expression. The support of generated columns was added to PostgreSQL 12. Do remember that the same task can be solved in SQL usually in multiple different ways. Thus, the exact copies are not the only possible duplication.

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
1 BOOLEAN base table and foreign table columns with a CHECK constraint that involves olnly this column Find base table and foreign table columns with the Boolean type that has a CHECK constraint that involves only this column. Avoid unnecessary CHECK constraints. The Boolean type contains only two values and there is nothing to check. By creating a check that determines that possible values in the column are TRUE and FALSE, one duplicates the attribute constraint (column has a type). This is a form of duplication. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View (opens in new tab)
2 CHECK constraints with the cardinality bigger than one that involve the same set of columns CHECK constraints with the cardinality bigger than one that involve the same set of columns. Make sure that there is no duplication. General system catalog base tables only MIT (opens in new tab) View (opens in new tab)
3 Domain CHECK constraints with the same name Find domain check constraint names that are used more than once (within the same schema or in different schemas). Different things should have different names. However, here different constraints have the same name. Also make sure that this is not a sign of duplication of domains. Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View (opens in new tab)
4 Domains with the same name in different schemas Domains are like words that can be used to construct generalized claims about the real world (table predicates). Better not to duplicate the words in the dictionary. Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View (opens in new tab)
5 Do not clone tables Find cases where a base table has been split horizontally into multiple smaller base tables based on the distinct values in one of the columns of the original table. Each such newly created table has the name, a part of which is a data value from the original tables. Find base tables that have the same columns (column name, column order, data type) and the difference between the tables are the numbers in the table names (table1, table2, etc.). Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View (opens in new tab)
6 Double checking of the maximum character length This query identifies superfluous CHECK constraints where a programmatic length check duplicates a declarative, data type-based length limit. For instance, a CHECK constraint like char_length(column) <= 100 on a column already defined as VARCHAR(100) is redundant. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View (opens in new tab)
7 Duplicate CHECK constraints that are connected directly to a table The same table should not have multiple CHECK constraints with exactly the same Boolean expression. Do remember that the same task can be solved in SQL usually in multiple different ways. Thus, the exact copies are not the only possible duplication. Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View (opens in new tab)
8 Duplicate CHECK constraints that are connected to a domain The same domain should not have multiple CHECK constraints with exactly the same Boolean expression. Do remember that the same task can be solved in SQL usually in multiple different ways. Thus, the exact copies are not the only possible duplication. Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View (opens in new tab)
9 Duplicate DEFAULT values of base table columns Find base table columns that have both default value determined through a domain and default value that is directly attached to the column. Do not duplicate specifications of default values to avoid confusion and surprises. If column and domain both have a default value, then in case of inserting data the default value that is associated directly with the column is used. Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View (opens in new tab)
10 Duplicate domains Find domains that have the same properties (base type, character length, not null + check constraints, default value, collation). There should not be multiple domains that have the same properties. Do remember that the same task can be solved in SQL usually in multiple different ways. Therefore, the domains may have syntactically different check constraints that solve the same task. Thus, the exact copies are not the only possible duplication. Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View (opens in new tab)
11 Duplicate enumerated types Find enumerated types with exactly the same values. There should not be multiple types that have the same values. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View (opens in new tab)
12 Duplicate foreign key constraints Find duplicate foreign key constraints, which involve the same columns and refer to the same set of columns. Problem detection system catalog base tables only MIT (opens in new tab) View (opens in new tab)
13 Duplicate independent (i.e., not created based on a table) composite types Find composite types with the same attributes (regardless of the order of attributes). Make sure that there is no duplication. Problem detection system catalog base tables only MIT (opens in new tab) View (opens in new tab)
14 Duplicate keys Find completely overlapping key (primary key, unique, and exclude where all operators are =) constraints. This is a form of duplication. It leads to the creation of multiple indexes to the same set of columns. Problem detection system catalog base tables only MIT (opens in new tab) View (opens in new tab)
15 Duplicate materialized views Find materialized views with exactly the same subquery. There should not be multiple materialized views with the same subquery. Do remember that the same task can be solved in SQL usually in multiple different ways. Thus, the exact copies are not the only possible duplication. Problem detection system catalog base tables only MIT (opens in new tab) View (opens in new tab)
16 Duplicate NOT NULL constraints Find columns that have NOT NULL constraint through a domain and also directly. Do not duplicate NOT NULL constraints in orde to avoid confusion and surprises. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View (opens in new tab)
17 Duplicate removal of duplicates in derived tables Find derived tables (views and materialized views) that contain both DISTINCT and GROUP BY. Make sure that the means for removing duplicate rows from the query result are not duplicated. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View (opens in new tab)
18 Duplicate rules Find multiple rules with the same definition (event, condition, action) on the same table. Do remember that the same task can be solved in SQL usually in multiple different ways. Thus, the exact copies are not the only possible duplication. Problem detection system catalog base tables only MIT (opens in new tab) View (opens in new tab)
19 Duplicate specification of character classes Find regular expressions where within the same specification of a character class the character class alnum as well as 0-9, \d, A-Z, or a-z has been defined. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View (opens in new tab)
20 Duplicate stored generated base table columns Find base tables that have more than one stored generated column with the same expression. The support of generated columns was added to PostgreSQL 12. Do remember that the same task can be solved in SQL usually in multiple different ways. Thus, the exact copies are not the only possible duplication. Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View (opens in new tab)