Filter 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.
#241. Derived table names have prefix or suffix
system catalog base tables onlyThis query identifies views and materialized views that include a prefix or suffix in their names (such as v_ or _mv). In a well-designed database, derived tables should follow the exact same naming conventions as base tables, because they function identically from the application's perspective. Therefore, if base tables do not use type-based prefixes or suffixes, derived tables should not use them either.
#242. Derived table on top of another derived table
INFORMATION_SCHEMA+system catalog base tablesDo not build multiple levels of derived tables (views and materialized views) because it will hamper evolvability and understandability of the tables.
#243. Derived table presents the same data in the same way as a single base table
INFORMATION_SCHEMA+system catalog base tablesFind derived tables (views and materialized views) that present data from one base table without adding columns, renaming columns, changing the order of columns, removing columns, or restricting rows. Perhaps something is missing from the subquery of the derived table.
#244. Derived tables that have a column with the xid type
INFORMATION_SCHEMA+system catalog base tablesFind the derived tables (views and materialized views) that have a column with the xid type, i.e., these use the data from the hidden xmin column of a base table. If one uses optimistic approach for dealing with the concurrent data modifications, then xmin values should be presented by views and used in routines that modify or delete rows.
#245. Derived tables that present data in json or xml format
INFORMATION_SCHEMA+system catalog base tablesFind views and materialized views that present data in json or xml format. Instead of recording data in this format in base tables one could generate the data value on the fly based on data that has been recorded in base tables.
#246. Derived tables with embedded row locking
INFORMATION_SCHEMA+system catalog base tablesThis query identifies derived tables (views and materialized views) whose defining subqueries utilize explicit row locking clauses (e.g., FOR UPDATE, FOR SHARE). Embedding locking semantics within a view definition is considered an architectural anti-pattern. It couples data projection with transaction control, causing simple read operations against the view to unexpectedly acquire locks. This behavior degrades concurrency by blocking other readers and violates the principle that reading a data element should not implicitly block simultaneous access.
#247. Derived tables with multiple DISTINCT's
INFORMATION_SCHEMA+system catalog base tablesFind derived tables (views and materialized views) that contain more than one DISTINCT invocation. Make sure that the query is correctly written, including that it does not have unwanted formation of a Cartesian product.
#248. Derived tables with ranking
INFORMATION_SCHEMA+system catalog base tablesFind views and materialized views that use rank and dense_rank window functions.
#249. Derived tables with sorting
INFORMATION_SCHEMA+system catalog base tablesFind derived tables where the rows are ordered, i.e., there is ORDER BY clause at the end of the view. Different users may want to see the rows in different order. Thus, the DBMS may have to do extra and unnecessary work by firstly sorting based on one set of rows and after that based on other set of rows. Use sorting if you know that all the users want the rows in the same order and cannot/will not change the order in the application.
#250. Derived tables with string_agg
INFORMATION_SCHEMA+system catalog base tablesFind views and materialized views that use string_agg aggregate function.
#251. Derived table uses a function to get data from another table
INFORMATION_SCHEMA+system catalog base tablesFind views that use a function to get data from another table.
#252. Deterministic (immutable) functions that do not have input parameters
INFORMATION_SCHEMA+system catalog base tablesFind deterministic functions that do not have any input parameters. Make sure that it is correct because in general a deterministic function must calculate a value based on input.
#253. Deterministic (immutable) functions that do not return a value
INFORMATION_SCHEMA+system catalog base tablesFind deterministic (immutable) functions that do not return a value. This goes against the idea of deterministic functions.
#254. Different character maximum lengths that are used to define textual base table columns
INFORMATION_SCHEMA onlyFind the number of different character maximum lengths that are used to define textual base table columns as well as list all the different lengths. Show also the total number of columns with char/varchar type. Maximum character length constrains values in a column. Thus, in case there is a small number of used lengths, it raises a question as to whether the lengths have been optimally selected.
#255. Different data types that are used to define base table columns
INFORMATION_SCHEMA onlyFind the number of different data types that are used to define base table columns as well as list all the different types. Data type constrains values in a column. Thus, in case there is a small number of used types, it raises a question as to whether the types have been optimally selected.
#256. Different foreign key column names in case of referencing the same candidate key
system catalog base tables onlyFind the cases when the names of columns in different foreign keys that reference to the same candidate key are different. If different names reflect different roles, then it is legitimate. However, there could also be accidental differences that makes it more difficult to use the database.
#257. Different non-surrogate key default values
INFORMATION_SCHEMA onlyFind the different default values that implement something other than a surrogate key.
#258. Different prefixes of a candidate key column and a referencing foreign key column
system catalog base tables onlyThe naming must be consistent. Find foreign key constraints where the candidate key column and foreign key column names have different prefixes. Thus, for instance, one cannot use USING syntax for joining the tables.
#259. Different search paths of SECURITY DEFINER functions
INFORMATION_SCHEMA+system catalog base tablesFind the different search paths used in case of SECURITY DEFINER functions and the number of their occurrences. Make sure that these have been specified correctly and consistently and that they do not refer to any non-existent schemas.
#260. Different suffixes of a candidate key column and a referencing foreign key column
system catalog base tables onlyThis query identifies naming inconsistencies in foreign key relationships by comparing the suffixes of foreign key columns against their referenced candidate key columns. It flags pairs where the suffixes diverge (e.g., referencing user_id via a column named user_code or user_ref). Such discrepancies prevent the use of the simplified ANSI SQL USING syntax for joins, forcing the use of explicit ON clauses. The goal is to enforce a standardized suffix convention (typically _id) across the schema to improve maintainability and query readability.
| # | 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 |
|---|---|---|---|---|---|---|---|
| 241 | Derived table names have prefix or suffix | This query identifies views and materialized views that include a prefix or suffix in their names (such as v_ or _mv). In a well-designed database, derived tables should follow the exact same naming conventions as base tables, because they function identically from the application's perspective. Therefore, if base tables do not use type-based prefixes or suffixes, derived tables should not use them either. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 242 | Derived table on top of another derived table | Do not build multiple levels of derived tables (views and materialized views) because it will hamper evolvability and understandability of the tables. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 243 | Derived table presents the same data in the same way as a single base table | Find derived tables (views and materialized views) that present data from one base table without adding columns, renaming columns, changing the order of columns, removing columns, or restricting rows. Perhaps something is missing from the subquery of the derived table. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 244 | Derived tables that have a column with the xid type | Find the derived tables (views and materialized views) that have a column with the xid type, i.e., these use the data from the hidden xmin column of a base table. If one uses optimistic approach for dealing with the concurrent data modifications, then xmin values should be presented by views and used in routines that modify or delete rows. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 245 | Derived tables that present data in json or xml format | Find views and materialized views that present data in json or xml format. Instead of recording data in this format in base tables one could generate the data value on the fly based on data that has been recorded in base tables. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 246 | Derived tables with embedded row locking | This query identifies derived tables (views and materialized views) whose defining subqueries utilize explicit row locking clauses (e.g., FOR UPDATE, FOR SHARE). Embedding locking semantics within a view definition is considered an architectural anti-pattern. It couples data projection with transaction control, causing simple read operations against the view to unexpectedly acquire locks. This behavior degrades concurrency by blocking other readers and violates the principle that reading a data element should not implicitly block simultaneous access. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 247 | Derived tables with multiple DISTINCT's | Find derived tables (views and materialized views) that contain more than one DISTINCT invocation. Make sure that the query is correctly written, including that it does not have unwanted formation of a Cartesian product. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 248 | Derived tables with ranking | Find views and materialized views that use rank and dense_rank window functions. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 249 | Derived tables with sorting | Find derived tables where the rows are ordered, i.e., there is ORDER BY clause at the end of the view. Different users may want to see the rows in different order. Thus, the DBMS may have to do extra and unnecessary work by firstly sorting based on one set of rows and after that based on other set of rows. Use sorting if you know that all the users want the rows in the same order and cannot/will not change the order in the application. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 250 | Derived tables with string_agg | Find views and materialized views that use string_agg aggregate function. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 251 | Derived table uses a function to get data from another table | Find views that use a function to get data from another table. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 252 | Deterministic (immutable) functions that do not have input parameters | Find deterministic functions that do not have any input parameters. Make sure that it is correct because in general a deterministic function must calculate a value based on input. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 253 | Deterministic (immutable) functions that do not return a value | Find deterministic (immutable) functions that do not return a value. This goes against the idea of deterministic functions. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 254 | Different character maximum lengths that are used to define textual base table columns | Find the number of different character maximum lengths that are used to define textual base table columns as well as list all the different lengths. Show also the total number of columns with char/varchar type. Maximum character length constrains values in a column. Thus, in case there is a small number of used lengths, it raises a question as to whether the lengths have been optimally selected. | Sofware measure | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 255 | Different data types that are used to define base table columns | Find the number of different data types that are used to define base table columns as well as list all the different types. Data type constrains values in a column. Thus, in case there is a small number of used types, it raises a question as to whether the types have been optimally selected. | Sofware measure | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 256 | Different foreign key column names in case of referencing the same candidate key | Find the cases when the names of columns in different foreign keys that reference to the same candidate key are different. If different names reflect different roles, then it is legitimate. However, there could also be accidental differences that makes it more difficult to use the database. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 257 | Different non-surrogate key default values | Find the different default values that implement something other than a surrogate key. | General | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 258 | Different prefixes of a candidate key column and a referencing foreign key column | The naming must be consistent. Find foreign key constraints where the candidate key column and foreign key column names have different prefixes. Thus, for instance, one cannot use USING syntax for joining the tables. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 259 | Different search paths of SECURITY DEFINER functions | Find the different search paths used in case of SECURITY DEFINER functions and the number of their occurrences. Make sure that these have been specified correctly and consistently and that they do not refer to any non-existent schemas. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 260 | Different suffixes of a candidate key column and a referencing foreign key column | This query identifies naming inconsistencies in foreign key relationships by comparing the suffixes of foreign key columns against their referenced candidate key columns. It flags pairs where the suffixes diverge (e.g., referencing user_id via a column named user_code or user_ref). Such discrepancies prevent the use of the simplified ANSI SQL USING syntax for joins, forcing the use of explicit ON clauses. The goal is to enforce a standardized suffix convention (typically _id) across the schema to improve maintainability and query readability. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View |