From 4869ee7a9de7418689c75a9a75d9a18881dee25c Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Tue, 16 Aug 2022 11:03:44 +1000 Subject: [PATCH v1] list_is_empty - use the new function --- src/backend/catalog/objectaddress.c | 2 +- src/backend/catalog/pg_depend.c | 2 +- src/backend/commands/event_trigger.c | 8 ++++---- src/backend/commands/functioncmds.c | 4 ++-- src/backend/commands/publicationcmds.c | 6 +++--- src/backend/commands/statscmds.c | 4 ++-- src/backend/commands/subscriptioncmds.c | 2 +- src/backend/commands/tablecmds.c | 4 ++-- src/backend/commands/typecmds.c | 2 +- src/backend/executor/execPartition.c | 2 +- src/backend/libpq/auth.c | 4 ++-- src/backend/libpq/hba.c | 4 ++-- src/backend/optimizer/path/costsize.c | 2 +- src/backend/optimizer/plan/createplan.c | 2 +- src/backend/optimizer/plan/planner.c | 12 ++++++------ src/backend/partitioning/partprune.c | 2 +- src/backend/replication/logical/tablesync.c | 4 ++-- src/backend/replication/pgoutput/pgoutput.c | 2 +- src/backend/rewrite/rewriteDefine.c | 2 +- src/backend/statistics/mcv.c | 3 +-- src/backend/storage/lmgr/lmgr.c | 2 +- src/backend/utils/adt/ruleutils.c | 2 +- src/backend/utils/adt/selfuncs.c | 2 +- src/backend/utils/adt/tsquery.c | 2 +- 24 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index 6080ff8..58a9a25 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -2186,7 +2186,7 @@ pg_get_object_address(PG_FUNCTION_ARGS) else { name = textarray_to_strvaluelist(namearr); - if (list_length(name) < 1) + if (list_is_empty(name)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("name list length must be at least %d", 1))); diff --git a/src/backend/catalog/pg_depend.c b/src/backend/catalog/pg_depend.c index 89bbb5c..65b56bf 100644 --- a/src/backend/catalog/pg_depend.c +++ b/src/backend/catalog/pg_depend.c @@ -947,7 +947,7 @@ getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok) if (list_length(seqlist) > 1) elog(ERROR, "more than one owned sequence found"); - else if (list_length(seqlist) < 1) + else if (list_is_empty(seqlist)) { if (missing_ok) return InvalidOid; diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c index eef3e5d..24519af 100644 --- a/src/backend/commands/event_trigger.c +++ b/src/backend/commands/event_trigger.c @@ -1143,9 +1143,9 @@ trackDroppedObjectsNeeded(void) * true if any sql_drop, table_rewrite, ddl_command_end event trigger * exists */ - return list_length(EventCacheLookup(EVT_SQLDrop)) > 0 || - list_length(EventCacheLookup(EVT_TableRewrite)) > 0 || - list_length(EventCacheLookup(EVT_DDLCommandEnd)) > 0; + return !(list_is_empty(EventCacheLookup(EVT_SQLDrop)) && + list_is_empty(EventCacheLookup(EVT_TableRewrite)) && + list_is_empty(EventCacheLookup(EVT_DDLCommandEnd))); } /* @@ -1616,7 +1616,7 @@ EventTriggerAlterTableEnd(void) parent = currentEventTriggerState->currentCommand->parent; /* If no subcommands, don't collect */ - if (list_length(currentEventTriggerState->currentCommand->d.alterTable.subcmds) != 0) + if (!list_is_empty(currentEventTriggerState->currentCommand->d.alterTable.subcmds)) { MemoryContext oldcxt; diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index 59e3af6..7b88d08 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -419,7 +419,7 @@ interpret_function_parameter_list(ParseState *pstate, * Make sure no variables are referred to (this is probably dead * code now that add_missing_from is history). */ - if (list_length(pstate->p_rtable) != 0 || + if (!list_is_empty(pstate->p_rtable) || contain_var_clause(def)) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), @@ -1209,7 +1209,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt) returnsSet = false; } - if (list_length(trftypes_list) > 0) + if (!list_is_empty(trftypes_list)) { ListCell *lc; Datum *arr; diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c index 89a0055..3d77c6b 100644 --- a/src/backend/commands/publicationcmds.c +++ b/src/backend/commands/publicationcmds.c @@ -848,12 +848,12 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt) &schemaidlist); /* FOR ALL TABLES IN SCHEMA requires superuser */ - if (list_length(schemaidlist) > 0 && !superuser()) + if (!list_is_empty(schemaidlist) && !superuser()) ereport(ERROR, errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("must be superuser to create FOR ALL TABLES IN SCHEMA publication")); - if (list_length(relations) > 0) + if (!list_is_empty(relations)) { List *rels; @@ -871,7 +871,7 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt) CloseTableList(rels); } - if (list_length(schemaidlist) > 0) + if (!list_is_empty(schemaidlist)) { /* * Schema lock is held until the publication is created to prevent diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c index 7c62beb..da33403 100644 --- a/src/backend/commands/statscmds.c +++ b/src/backend/commands/statscmds.c @@ -339,7 +339,7 @@ CreateStatistics(CreateStatsStmt *stmt) if ((list_length(stmt->exprs) == 1) && (list_length(stxexprs) == 1)) { /* statistics kinds not specified */ - if (list_length(stmt->stat_types) > 0) + if (!list_is_empty(stmt->stat_types)) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("when building statistics on a single expression, statistics kinds may not be specified"))); @@ -391,7 +391,7 @@ CreateStatistics(CreateStatsStmt *stmt) * automatically. This allows calculating good estimates for stats that * consider per-clause estimates (e.g. functional dependencies). */ - build_expressions = (list_length(stxexprs) > 0); + build_expressions = !list_is_empty(stxexprs); /* * Check that at least two columns were specified in the statement, or diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index f73dfb6..199dc44 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -410,7 +410,7 @@ get_publications_str(List *publications, StringInfo dest, bool quote_literal) ListCell *lc; bool first = true; - Assert(list_length(publications) > 0); + Assert(!list_is_empty(publications)); foreach(lc, publications) { diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 70b94bb..5d07580 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -2097,7 +2097,7 @@ ExecuteTruncateGuts(List *explicit_rels, * Assemble an array of relids so we can write a single WAL record for the * whole action. */ - if (list_length(relids_logged) > 0) + if (!list_is_empty(relids_logged)) { xl_heap_truncate xlrec; int i = 0; @@ -16268,7 +16268,7 @@ ATPrepChangePersistence(Relation rel, bool toLogged) * UNLOGGED as UNLOGGED tables can't be published. */ if (!toLogged && - list_length(GetRelationPublications(RelationGetRelid(rel))) > 0) + !list_is_empty(GetRelationPublications(RelationGetRelid(rel)))) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("cannot change table \"%s\" to unlogged because it is part of a publication", diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index d0d87a1..f8c821d 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -3503,7 +3503,7 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, * Domains don't allow variables (this is probably dead code now that * add_missing_from is history, but let's be sure). */ - if (list_length(pstate->p_rtable) != 0 || + if (!list_is_empty(pstate->p_rtable) || contain_var_clause(expr)) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index eb49106..44250a9 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -685,7 +685,7 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, EState *estate, * list and searching for ancestry relationships to each index in the * ancestor table. */ - if (list_length(rootResultRelInfo->ri_onConflictArbiterIndexes) > 0) + if (!list_is_empty(rootResultRelInfo->ri_onConflictArbiterIndexes)) { List *childIdxs; diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index 290eb17..320791e 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -2915,14 +2915,14 @@ CheckRADIUSAuth(Port *port) Assert(offsetof(radius_packet, vector) == 4); /* Verify parameters */ - if (list_length(port->hba->radiusservers) < 1) + if (list_is_empty(port->hba->radiusservers)) { ereport(LOG, (errmsg("RADIUS server not specified"))); return STATUS_ERROR; } - if (list_length(port->hba->radiussecrets) < 1) + if (list_is_empty(port->hba->radiussecrets)) { ereport(LOG, (errmsg("RADIUS secret not specified"))); diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c index 857b9e5..ad55bdd 100644 --- a/src/backend/libpq/hba.c +++ b/src/backend/libpq/hba.c @@ -1564,7 +1564,7 @@ parse_hba_line(TokenizedAuthLine *tok_line, int elevel) MANDATORY_AUTH_ARG(parsedline->radiusservers, "radiusservers", "radius"); MANDATORY_AUTH_ARG(parsedline->radiussecrets, "radiussecrets", "radius"); - if (list_length(parsedline->radiusservers) < 1) + if (list_is_empty(parsedline->radiusservers)) { ereport(elevel, (errcode(ERRCODE_CONFIG_FILE_ERROR), @@ -1575,7 +1575,7 @@ parse_hba_line(TokenizedAuthLine *tok_line, int elevel) return NULL; } - if (list_length(parsedline->radiussecrets) < 1) + if (list_is_empty(parsedline->radiussecrets)) { ereport(elevel, (errcode(ERRCODE_CONFIG_FILE_ERROR), diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index fb28e64..527aa0f 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -1957,7 +1957,7 @@ compute_cpu_sort_cost(PlannerInfo *root, List *pathkeys, int nPresortedKeys, List *cache_varinfos = NIL; /* fallback if pathkeys is unknown */ - if (list_length(pathkeys) == 0) + if (list_is_empty(pathkeys)) { /* * If we'll use a bounded heap-sort keeping just K tuples in memory, diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index e37f293..a72ac35 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -2462,7 +2462,7 @@ create_groupingsets_plan(PlannerInfo *root, GroupingSetsPath *best_path) if (rollup->is_hashed) strat = AGG_HASHED; - else if (list_length(linitial(rollup->gsets)) == 0) + else if (list_is_empty(linitial(rollup->gsets))) strat = AGG_PLAIN; else strat = AGG_SORTED; diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 64632db..ccb164d 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -3097,7 +3097,7 @@ reorder_grouping_sets(List *groupingsets, List *sortclause) GroupingSetData *gs = makeNode(GroupingSetData); while (list_length(sortclause) > list_length(previous) && - list_length(new_elems) > 0) + !list_is_empty(new_elems)) { SortGroupClause *sc = list_nth(sortclause, list_length(previous)); int ref = sc->tleSortGroupRef; @@ -4120,7 +4120,7 @@ consider_groupingsets_paths(PlannerInfo *root, /* * If we have sorted input but nothing we can do with it, bail. */ - if (list_length(gd->rollups) == 0) + if (list_is_empty(gd->rollups)) return; /* @@ -6477,7 +6477,7 @@ add_paths_to_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel, group_clauses, orderAggPathkeys); - Assert(list_length(pathkey_orderings) > 0); + Assert(!list_is_empty(pathkey_orderings)); /* process all potentially interesting grouping reorderings */ foreach(lc2, pathkey_orderings) @@ -6650,7 +6650,7 @@ add_paths_to_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel, group_clauses, orderAggPathkeys); - Assert(list_length(pathkey_orderings) > 0); + Assert(!list_is_empty(pathkey_orderings)); /* process all potentially interesting grouping reorderings */ foreach(lc2, pathkey_orderings) @@ -6994,7 +6994,7 @@ create_partial_grouping_paths(PlannerInfo *root, group_clauses, orderAggPathkeys); - Assert(list_length(pathkey_orderings) > 0); + Assert(!list_is_empty(pathkey_orderings)); /* process all potentially interesting grouping reorderings */ foreach(lc2, pathkey_orderings) @@ -7145,7 +7145,7 @@ create_partial_grouping_paths(PlannerInfo *root, group_clauses, orderAggPathkeys); - Assert(list_length(pathkey_orderings) > 0); + Assert(!list_is_empty(pathkey_orderings)); /* process all potentially interesting grouping reorderings */ foreach(lc2, pathkey_orderings) diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index 9d3c05a..c98f054 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -2383,7 +2383,7 @@ get_steps_using_prefix(GeneratePruningStepsContext *context, context->rel->part_scheme->strategy == PARTITION_STRATEGY_HASH); /* Quick exit if there are no values to prefix with. */ - if (list_length(prefix) == 0) + if (list_is_empty(prefix)) { PartitionPruneStep *step; diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c index 6a01ffd..dbf4f67 100644 --- a/src/backend/replication/logical/tablesync.c +++ b/src/backend/replication/logical/tablesync.c @@ -1498,7 +1498,7 @@ FetchTableStates(bool *started_tx) * if table_state_not_ready was empty we still need to check again to * see if there are 0 tables. */ - has_subrels = (list_length(table_states_not_ready) > 0) || + has_subrels = !list_is_empty(table_states_not_ready) || HasSubscriptionRelations(MySubscription->oid); table_states_valid = true; @@ -1534,7 +1534,7 @@ AllTablesyncsReady(void) * Return false when there are no tables in subscription or not all tables * are in ready state; true otherwise. */ - return has_subrels && list_length(table_states_not_ready) == 0; + return has_subrels && list_is_empty(table_states_not_ready); } /* diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index a3c1ba8..9a4084e 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -450,7 +450,7 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt, errmsg("client sent proto_version=%d but we only support protocol %d or higher", data->protocol_version, LOGICALREP_PROTO_MIN_VERSION_NUM))); - if (list_length(data->publication_names) < 1) + if (list_is_empty(data->publication_names)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("publication_names parameter missing"))); diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c index a5a1fb8..963c781 100644 --- a/src/backend/rewrite/rewriteDefine.c +++ b/src/backend/rewrite/rewriteDefine.c @@ -313,7 +313,7 @@ DefineQueryRewrite(const char *rulename, * * So there cannot be INSTEAD NOTHING, ... */ - if (list_length(action) == 0) + if (list_is_empty(action)) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("INSTEAD NOTHING rules on SELECT are not implemented"), diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c index 6d9a098..64d4501 100644 --- a/src/backend/statistics/mcv.c +++ b/src/backend/statistics/mcv.c @@ -1609,8 +1609,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses, bool *matches; /* The bitmap may be partially built. */ - Assert(clauses != NIL); - Assert(list_length(clauses) >= 1); + Assert(!list_is_empty(clauses)); Assert(mcvlist != NULL); Assert(mcvlist->nitems > 0); Assert(mcvlist->nitems <= STATS_MCVLIST_MAX_ITEMS); diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c index 1543da6..e90d9ed 100644 --- a/src/backend/storage/lmgr/lmgr.c +++ b/src/backend/storage/lmgr/lmgr.c @@ -913,7 +913,7 @@ WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress) int done = 0; /* Done if no locks to wait for */ - if (list_length(locktags) == 0) + if (list_is_empty(locktags)) return; /* Collect the transactions we need to wait on */ diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index d575aa0..b052d86 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -8114,7 +8114,7 @@ get_parameter(Param *param, deparse_context *context) { deparse_namespace *dpns = lfirst(lc); - if (list_length(dpns->rtable_names) > 0) + if (!list_is_empty(dpns->rtable_names)) { should_qualify = true; break; diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index d35e560..003a1c4 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -3408,7 +3408,7 @@ estimate_num_groups_incremental(PlannerInfo *root, List *groupExprs, * for normal cases with GROUP BY or DISTINCT, but it is possible for * corner cases with set operations.) */ - if (groupExprs == NIL || (pgset && list_length(*pgset) < 1)) + if (groupExprs == NIL || (pgset && list_is_empty(*pgset))) return 1.0; /* diff --git a/src/backend/utils/adt/tsquery.c b/src/backend/utils/adt/tsquery.c index f54f298..330c088 100644 --- a/src/backend/utils/adt/tsquery.c +++ b/src/backend/utils/adt/tsquery.c @@ -829,7 +829,7 @@ parse_tsquery(char *buf, close_tsvector_parser(state.valstate); - if (list_length(state.polstr) == 0) + if (list_is_empty(state.polstr)) { ereport(NOTICE, (errmsg("text-search query doesn't contain lexemes: \"%s\"", -- 1.8.3.1