PostgreSQL Source Code  git master
list.c File Reference
#include "postgres.h"
#include "nodes/pg_list.h"
#include "port/pg_bitutils.h"
#include "utils/memdebug.h"
#include "utils/memutils.h"
Include dependency graph for list.c:

Go to the source code of this file.

Macros

#define LIST_HEADER_OVERHEAD   ((int) ((offsetof(List, initial_elements) - 1) / sizeof(ListCell) + 1))
 
#define IsPointerList(l)   ((l) == NIL || IsA((l), List))
 
#define IsIntegerList(l)   ((l) == NIL || IsA((l), IntList))
 
#define IsOidList(l)   ((l) == NIL || IsA((l), OidList))
 
#define check_list_invariants(l)   ((void) 0)
 

Functions

static Listnew_list (NodeTag type, int min_size)
 
static void enlarge_list (List *list, int min_size)
 
Listlist_make1_impl (NodeTag t, ListCell datum1)
 
Listlist_make2_impl (NodeTag t, ListCell datum1, ListCell datum2)
 
Listlist_make3_impl (NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3)
 
Listlist_make4_impl (NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3, ListCell datum4)
 
Listlist_make5_impl (NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3, ListCell datum4, ListCell datum5)
 
static void new_head_cell (List *list)
 
static void new_tail_cell (List *list)
 
Listlappend (List *list, void *datum)
 
Listlappend_int (List *list, int datum)
 
Listlappend_oid (List *list, Oid datum)
 
static ListCellinsert_new_cell (List *list, int pos)
 
Listlist_insert_nth (List *list, int pos, void *datum)
 
Listlist_insert_nth_int (List *list, int pos, int datum)
 
Listlist_insert_nth_oid (List *list, int pos, Oid datum)
 
Listlcons (void *datum, List *list)
 
Listlcons_int (int datum, List *list)
 
Listlcons_oid (Oid datum, List *list)
 
Listlist_concat (List *list1, const List *list2)
 
Listlist_concat_copy (const List *list1, const List *list2)
 
Listlist_truncate (List *list, int new_size)
 
bool list_member (const List *list, const void *datum)
 
bool list_member_ptr (const List *list, const void *datum)
 
bool list_member_int (const List *list, int datum)
 
bool list_member_oid (const List *list, Oid datum)
 
Listlist_delete_nth_cell (List *list, int n)
 
Listlist_delete_cell (List *list, ListCell *cell)
 
Listlist_delete (List *list, void *datum)
 
Listlist_delete_ptr (List *list, void *datum)
 
Listlist_delete_int (List *list, int datum)
 
Listlist_delete_oid (List *list, Oid datum)
 
Listlist_delete_first (List *list)
 
Listlist_delete_last (List *list)
 
Listlist_union (const List *list1, const List *list2)
 
Listlist_union_ptr (const List *list1, const List *list2)
 
Listlist_union_int (const List *list1, const List *list2)
 
Listlist_union_oid (const List *list1, const List *list2)
 
Listlist_intersection (const List *list1, const List *list2)
 
Listlist_intersection_int (const List *list1, const List *list2)
 
Listlist_difference (const List *list1, const List *list2)
 
Listlist_difference_ptr (const List *list1, const List *list2)
 
Listlist_difference_int (const List *list1, const List *list2)
 
Listlist_difference_oid (const List *list1, const List *list2)
 
Listlist_append_unique (List *list, void *datum)
 
Listlist_append_unique_ptr (List *list, void *datum)
 
Listlist_append_unique_int (List *list, int datum)
 
Listlist_append_unique_oid (List *list, Oid datum)
 
Listlist_concat_unique (List *list1, const List *list2)
 
Listlist_concat_unique_ptr (List *list1, const List *list2)
 
Listlist_concat_unique_int (List *list1, const List *list2)
 
Listlist_concat_unique_oid (List *list1, const List *list2)
 
void list_deduplicate_oid (List *list)
 
static void list_free_private (List *list, bool deep)
 
void list_free (List *list)
 
void list_free_deep (List *list)
 
Listlist_copy (const List *oldlist)
 
Listlist_copy_tail (const List *oldlist, int nskip)
 
Listlist_copy_deep (const List *oldlist)
 
void list_sort (List *list, list_sort_comparator cmp)
 
int list_int_cmp (const ListCell *p1, const ListCell *p2)
 
int list_oid_cmp (const ListCell *p1, const ListCell *p2)
 

Macro Definition Documentation

◆ check_list_invariants

◆ IsIntegerList

#define IsIntegerList (   l)    ((l) == NIL || IsA((l), IntList))

◆ IsOidList

#define IsOidList (   l)    ((l) == NIL || IsA((l), OidList))

◆ IsPointerList

◆ LIST_HEADER_OVERHEAD

#define LIST_HEADER_OVERHEAD   ((int) ((offsetof(List, initial_elements) - 1) / sizeof(ListCell) + 1))

Definition at line 47 of file list.c.

Referenced by new_list().

Function Documentation

◆ enlarge_list()

static void enlarge_list ( List list,
int  min_size 
)
static

Definition at line 152 of file list.c.

References Assert, List::elements, GetMemoryChunkContext(), List::initial_elements, List::length, Max, List::max_length, MemoryContextAlloc(), pfree(), pg_nextpower2_32(), repalloc(), and VALGRIND_MAKE_MEM_NOACCESS.

Referenced by insert_new_cell(), list_concat(), new_head_cell(), and new_tail_cell().

153 {
154  int new_max_len;
155 
156  Assert(min_size > list->max_length); /* else we shouldn't be here */
157 
158 #ifndef DEBUG_LIST_MEMORY_USAGE
159 
160  /*
161  * As above, we prefer power-of-two total allocations; but here we need
162  * not account for list header overhead.
163  */
164 
165  /* clamp the minimum value to 16, a semi-arbitrary small power of 2 */
166  new_max_len = pg_nextpower2_32(Max(16, min_size));
167 
168 #else
169  /* As above, don't allocate anything extra */
170  new_max_len = min_size;
171 #endif
172 
173  if (list->elements == list->initial_elements)
174  {
175  /*
176  * Replace original in-line allocation with a separate palloc block.
177  * Ensure it is in the same memory context as the List header. (The
178  * previous List implementation did not offer any guarantees about
179  * keeping all list cells in the same context, but it seems reasonable
180  * to create such a guarantee now.)
181  */
182  list->elements = (ListCell *)
184  new_max_len * sizeof(ListCell));
185  memcpy(list->elements, list->initial_elements,
186  list->length * sizeof(ListCell));
187 
188  /*
189  * We must not move the list header, so it's unsafe to try to reclaim
190  * the initial_elements[] space via repalloc. In debugging builds,
191  * however, we can clear that space and/or mark it inaccessible.
192  * (wipe_mem includes VALGRIND_MAKE_MEM_NOACCESS.)
193  */
194 #ifdef CLOBBER_FREED_MEMORY
195  wipe_mem(list->initial_elements,
196  list->max_length * sizeof(ListCell));
197 #else
199  list->max_length * sizeof(ListCell));
200 #endif
201  }
202  else
203  {
204 #ifndef DEBUG_LIST_MEMORY_USAGE
205  /* Normally, let repalloc deal with enlargement */
206  list->elements = (ListCell *) repalloc(list->elements,
207  new_max_len * sizeof(ListCell));
208 #else
209  /*
210  * repalloc() might enlarge the space in-place, which we don't want
211  * for debugging purposes, so forcibly move the data somewhere else.
212  */
213  ListCell *newelements;
214 
215  newelements = (ListCell *)
217  new_max_len * sizeof(ListCell));
218  memcpy(newelements, list->elements,
219  list->length * sizeof(ListCell));
220  pfree(list->elements);
221  list->elements = newelements;
222 #endif
223  }
224 
225  list->max_length = new_max_len;
226 }
#define VALGRIND_MAKE_MEM_NOACCESS(addr, size)
Definition: memdebug.h:27
void pfree(void *pointer)
Definition: mcxt.c:1169
static uint32 pg_nextpower2_32(uint32 num)
Definition: pg_bitutils.h:146
union ListCell ListCell
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
#define Max(x, y)
Definition: c.h:980
#define Assert(condition)
Definition: c.h:804
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1182
int length
Definition: pg_list.h:53
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
ListCell initial_elements[FLEXIBLE_ARRAY_MEMBER]
Definition: pg_list.h:57
static MemoryContext GetMemoryChunkContext(void *pointer)
Definition: memutils.h:114

◆ insert_new_cell()

static ListCell* insert_new_cell ( List list,
int  pos 
)
static

Definition at line 394 of file list.c.

References Assert, List::elements, enlarge_list(), List::length, and List::max_length.

Referenced by list_insert_nth(), list_insert_nth_int(), and list_insert_nth_oid().

395 {
396  Assert(pos >= 0 && pos <= list->length);
397 
398  /* Enlarge array if necessary */
399  if (list->length >= list->max_length)
400  enlarge_list(list, list->length + 1);
401  /* Now shove the existing data over */
402  if (pos < list->length)
403  memmove(&list->elements[pos + 1], &list->elements[pos],
404  (list->length - pos) * sizeof(ListCell));
405  list->length++;
406 
407  return &list->elements[pos];
408 }
static void enlarge_list(List *list, int min_size)
Definition: list.c:152
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:804
int length
Definition: pg_list.h:53

◆ lappend()

List* lappend ( List list,
void *  datum 
)

Definition at line 336 of file list.c.

References Assert, check_list_invariants, IsPointerList, sort-test::list, llast, new_list(), new_tail_cell(), NIL, and T_List.

Referenced by _SPI_make_plan_non_temp(), _SPI_prepare_oneshot_plan(), _SPI_prepare_plan(), _SPI_save_plan(), accumulate_append_subpath(), AcquireRewriteLocks(), add_column_to_pathtarget(), add_dummy_return(), add_eq_member(), add_join_clause_to_rels(), add_join_rel(), add_local_reloption(), add_merged_range_bounds(), add_part_relids(), add_paths_to_append_rel(), add_placeholders_to_base_rels(), add_placeholders_to_joinrel(), add_row_identity_var(), add_rte_to_flat_rtable(), add_security_quals(), add_to_flat_tlist(), add_unique_group_var(), add_vars_to_targetlist(), add_with_check_options(), addArc(), AddEventToPendingNotifies(), addFamilyMember(), addFkRecurseReferencing(), addKey(), addKeyToQueue(), addNSItemToQuery(), addRangeTableEntry(), addRangeTableEntryForCTE(), addRangeTableEntryForENR(), addRangeTableEntryForFunction(), addRangeTableEntryForJoin(), addRangeTableEntryForRelation(), addRangeTableEntryForSubquery(), addRangeTableEntryForTableFunc(), addRangeTableEntryForValues(), AddRelationNewConstraints(), addTargetToGroupList(), addTargetToSortList(), AlterPublicationTables(), AlterTableMoveAll(), AlterTSDictionary(), analyzeCTE(), analyzeCTETargetList(), apply_child_basequals(), apply_handle_truncate(), apply_scanjoin_target_to_paths(), applyLockingClause(), ApplyRetrieveRule(), array_subscript_transform(), assign_param_for_placeholdervar(), assign_param_for_var(), ATAddCheckConstraint(), ATExecAddColumn(), ATExecValidateConstraint(), ATGetQueueEntry(), ATParseTransformCmd(), ATPostAlterTypeCleanup(), ATPostAlterTypeParse(), ATPrepAlterColumnType(), ATPrepCmd(), btcostestimate(), build_aggregate_finalfn_expr(), build_aggregate_transfn_expr(), build_coercion_expression(), build_index_pathkeys(), build_index_paths(), build_index_tlist(), build_join_rel(), build_joinrel_tlist(), build_partition_pathkeys(), build_path_tlist(), build_physical_tlist(), build_remote_returning(), build_subplan(), BuildEventTriggerCache(), BuildOnConflictExcludedTargetlist(), buildRelationAliases(), cached_scansel(), calc_joinrel_size_estimate(), can_minmax_aggs(), check_index_predicates(), check_selective_binary_conversion(), check_sql_fn_retval(), check_tuple_attribute(), checkInsertTargets(), checkSharedDependencies(), checkWellFormedRecursionWalker(), choose_bitmap_and(), ChooseIndexColumnNames(), classifyConditions(), clauselist_apply_dependencies(), CloneFkReferenced(), CloneFkReferencing(), CloneRowTriggersToPartition(), coerce_fn_result_column(), coerce_record_to_complex(), compute_common_attribute(), compute_semi_anti_join_factors(), compute_semijoin_info(), ComputeIndexAttrs(), ComputePartitionAttrs(), consider_groupingsets_paths(), consider_new_or_clause(), convert_ANY_sublink_to_join(), convert_EXISTS_to_ANY(), convert_subquery_pathkeys(), CopyMultiInsertInfoFlush(), CopyMultiInsertInfoSetupBuffer(), cost_incremental_sort(), create_append_plan(), create_bitmap_scan_plan(), create_bitmap_subplan(), create_ctas_nodata(), create_customscan_plan(), create_degenerate_grouping_paths(), create_estate_for_relation(), create_groupingsets_plan(), create_hashjoin_plan(), create_index_paths(), create_indexscan_plan(), create_join_clause(), create_list_bounds(), create_merge_append_plan(), create_nestloop_path(), create_partitionwise_grouping_paths(), create_tidrangescan_plan(), create_tidscan_plan(), create_unique_plan(), CreateStatistics(), database_to_xmlschema_internal(), deconstruct_recurse(), DefineRelation(), DefineSequence(), DefineTSDictionary(), DefineView(), DefineVirtualRelation(), deparseParam(), deparseVar(), deserialize_deflist(), determineRecursiveColTypes(), distribute_qual_to_rels(), distribute_restrictinfo_to_rels(), distribute_row_identity_vars(), do_pg_start_backup(), DoCopy(), estimate_multivariate_ndistinct(), estimate_num_groups(), eval_const_expressions_mutator(), EvalPlanQualStart(), EventTriggerAlterTableEnd(), EventTriggerCollectAlterDefPrivs(), EventTriggerCollectAlterOpFam(), EventTriggerCollectAlterTableSubcmd(), EventTriggerCollectAlterTSConfig(), EventTriggerCollectCreateOpClass(), EventTriggerCollectGrant(), EventTriggerCollectSimpleCommand(), Exec_ListenCommit(), ExecAllocTableSlot(), ExecEvalXmlExpr(), ExecGetTriggerResultRel(), ExecInitExprList(), ExecInitExprRec(), ExecInitInsertProjection(), ExecInitLockRows(), ExecInitModifyTable(), ExecInitNode(), ExecInitPartitionInfo(), ExecInitResultRelation(), ExecInitSubPlan(), ExecPrepareExprList(), ExecSerializePlan(), ExecuteGrantStmt(), ExecuteTruncate(), ExecuteTruncateGuts(), expand_grouping_sets(), expand_groupingset_node(), expand_inherited_rtentry(), expand_insert_targetlist(), expand_single_inheritance_child(), expand_vacuum_rel(), expandNSItemAttrs(), expandNSItemVars(), ExpandRowReference(), expandRTE(), expandTableLikeClause(), expandTupleDesc(), ExplainNode(), ExportSnapshot(), expression_tree_mutator(), extract_actual_clauses(), extract_actual_join_clauses(), extract_jsp_path_expr_nodes(), extract_lateral_references(), extract_nonindex_conditions(), extract_or_clause(), extract_rollup_sets(), extractRemainingColumns(), fetch_statentries_for_relation(), fetch_table_list(), fetch_upper_rel(), file_fdw_validator(), fill_hba_line(), find_duplicate_ors(), find_hash_columns(), find_indexpath_quals(), find_list_position(), find_mergeclauses_for_outer_pathkeys(), find_partition_scheme(), find_placeholder_info(), find_window_functions_walker(), findTargetlistEntrySQL99(), fireRIRrules(), fireRules(), fix_indexorderby_references(), fix_indexqual_references(), flatten_grouping_sets(), flatten_join_alias_vars_mutator(), flatten_simple_union_all(), fmgr_sql_validator(), foreign_grouping_ok(), foreign_join_ok(), format_operator_parts(), format_procedure_parts(), func_get_detail(), gen_partprune_steps_internal(), gen_prune_step_combine(), gen_prune_step_op(), gen_prune_steps_from_opexps(), generate_append_tlist(), generate_base_implied_equalities_const(), generate_bitmap_or_paths(), generate_implied_equalities_for_column(), generate_join_implied_equalities_broken(), generate_join_implied_equalities_normal(), generate_matching_part_pairs(), generate_orderedappend_paths(), generate_partitionwise_join_paths(), generate_setop_tlist(), generate_subquery_params(), generate_subquery_vars(), generate_union_paths(), generateClonedExtStatsStmt(), generateClonedIndexStmt(), generateSerialExtraStmts(), get_actual_clauses(), get_all_vacuum_rels(), get_appendrel_parampathinfo(), get_baserel_parampathinfo(), get_database_list(), get_eclass_for_sort_expr(), get_ext_ver_info(), get_ext_ver_list(), get_file_fdw_attribute_options(), get_foreign_key_join_selectivity(), get_func_expr(), get_index_clause_from_support(), get_index_paths(), get_insert_query_def(), get_join_index_paths(), get_joinrel_parampathinfo(), get_matching_part_pairs(), get_op_btree_interpretation(), get_policies_for_relation(), get_qual_for_hash(), get_qual_for_list(), get_qual_for_range(), get_quals_from_indexclauses(), get_range_nulltest(), get_relation_constraints(), get_relation_foreign_keys(), get_relation_statistics(), get_rels_with_domain(), get_required_extension(), get_sortgrouplist_exprs(), get_steps_using_prefix_recurse(), get_subscription_list(), get_switched_clauses(), get_tables_to_cluster(), get_tlist_exprs(), get_update_query_targetlist_def(), get_useful_ecs_for_relation(), get_useful_pathkeys_for_relation(), get_windowfunc_expr(), GetAfterTriggersTableData(), getObjectIdentityParts(), getState(), GetSubscriptionNotReadyRelations(), GetSubscriptionRelations(), gistFindPath(), gistfixsplit(), gistplacetopage(), grouping_planner(), hash_inner_and_outer(), heap_truncate(), identify_current_nestloop_params(), identify_opfamily_groups(), index_concurrently_create_copy(), infer_arbiter_indexes(), init_execution_state(), init_sql_fcache(), InitPlan(), innerrel_is_unique(), interpret_AS_clause(), interpret_function_parameter_list(), intorel_startup(), is_innerrel_unique_for(), join_is_removable(), jsonb_ops__extract_nodes(), jsonb_path_ops__extract_nodes(), jsonb_subscript_transform(), JsonValueListAppend(), list_append_unique(), list_append_unique_ptr(), list_concat_unique(), list_concat_unique_ptr(), list_difference(), list_difference_ptr(), list_intersection(), list_union(), list_union_ptr(), llvm_compile_module(), load_hba(), load_ident(), LoadPublications(), logicalrep_workers_find(), make_canonical_pathkey(), make_copy_attnamelist(), make_group_input_target(), make_inh_translation_list(), make_inner_pathkeys_for_merge(), make_modifytable(), make_partial_grouping_target(), make_partition_op_expr(), make_partition_pruneinfo(), make_partitionedrel_pruneinfo(), make_path_rowexpr(), make_pathkeys_for_sortclauses(), make_pathtarget_from_tlist(), make_rel_from_joinlist(), make_row_comparison_op(), make_setop_translation_list(), make_sort_input_target(), make_sub_restrictinfos(), make_tlist_from_pathtarget(), make_window_input_target(), makeDependencyGraphWalker(), match_clause_to_index(), match_clause_to_partition_key(), match_foreign_keys_to_quals(), match_join_clauses_to_index(), match_network_subset(), match_pathkeys_to_index(), match_pattern_prefix(), matchLocks(), merge_clump(), merge_list_bounds(), merge_publications(), MergeAttributes(), negate_clause(), next_field_expand(), nodeRead(), OpenTableList(), order_qual_clauses(), paraminfo_get_equal_hashops(), parse_hba_line(), parseCheckAggregates(), ParseFuncOrColumn(), PartConstraintImpliedByRelConstraint(), perform_base_backup(), pg_get_object_address(), pg_logical_slot_get_changes_guts(), pg_plan_queries(), pg_rewrite_query(), plan_union_children(), populate_typ_list(), postgresGetForeignPaths(), postgresGetForeignPlan(), postgresImportForeignSchema(), prep_domain_constraints(), prepare_sort_from_pathkeys(), preprocess_aggref(), preprocess_groupclause(), preprocess_grouping_sets(), preprocess_rowmarks(), preprocess_targetlist(), process_duplicate_ors(), process_equivalence(), process_pipe_input(), process_sublinks_mutator(), process_subquery_nestloop_params(), process_syncing_tables_for_apply(), ProcessStartupPacket(), pull_ands(), pull_ors(), pull_up_simple_values(), pull_up_sublinks_jointree_recurse(), pull_up_sublinks_qual_recurse(), pull_up_union_leaf_queries(), pull_var_clause_walker(), pull_vars_walker(), query_tree_mutator(), QueryRewrite(), queue_listen(), range_table_mutator(), read_tablespace_map(), rebuild_fdw_scan_tlist(), RebuildConstraintComment(), record_plan_function_dependency(), record_plan_type_dependency(), reduce_outer_joins_pass1(), register_ENR(), register_label_provider(), register_reloptions_validator(), ReindexRelationConcurrently(), relation_excluded_by_constraints(), relation_has_unique_index_for(), RelationCacheInvalidate(), RelationGetDummyIndexExpressions(), RelationGetFKeyList(), remap_to_groupclause_idx(), RememberConstraintForRebuilding(), RememberIndexForRebuilding(), RememberStatisticsForRebuilding(), RememberSyncRequest(), remove_rel_from_joinlist(), remove_useless_groupby_columns(), RemoveInheritance(), reorder_function_arguments(), reparameterize_path(), reparameterize_path_by_child(), reparameterize_pathlist_by_child(), replace_empty_jointree(), replace_nestloop_param_placeholdervar(), replace_nestloop_param_var(), replace_outer_agg(), replace_outer_grouping(), resolve_unique_index_expr(), RewriteQuery(), rewriteSearchAndCycle(), rewriteTargetListIU(), rewriteTargetView(), rewriteValuesRTE(), schema_to_xmlschema_internal(), SearchCatCacheList(), select_active_windows(), select_mergejoin_clauses(), select_outer_pathkeys_for_merge(), sepgsql_set_client_label(), sequence_options(), set_append_rel_pathlist(), set_cheapest(), set_deparse_for_query(), set_dummy_tlist_references(), set_joinrel_partition_key_exprs(), set_plan_references(), set_plan_refs(), set_rtable_names(), set_simple_column_names(), set_subquery_pathlist(), set_upper_references(), set_using_names(), show_eval_params(), show_grouping_set_keys(), show_incremental_sort_group_info(), show_modifytable_info(), show_plan_tlist(), show_sort_group_keys(), show_tablesample(), simplify_and_arguments(), simplify_or_arguments(), split_pathtarget_at_srfs(), split_pathtarget_walker(), SplitDirectoriesString(), SplitGUCList(), SplitIdentifierString(), SS_make_initplan_from_plan(), SS_process_ctes(), StandbyAcquireAccessExclusiveLock(), statext_is_compatible_clause_internal(), statext_mcv_clauselist_selectivity(), StreamServerPort(), stringToQualifiedNameList(), subquery_planner(), table_slot_create(), textarray_to_stringlist(), textarray_to_strvaluelist(), textToQualifiedNameList(), TidExprListCreate(), TidRangeQualFromRestrictInfoList(), tokenize_file(), tokenize_inc_file(), transformAExprIn(), transformAggregateCall(), transformAlterTableStmt(), transformArrayExpr(), transformAssignmentIndirection(), transformBoolExpr(), transformCallStmt(), transformCaseExpr(), transformCoalesceExpr(), transformColumnDefinition(), transformCreateSchemaStmt(), transformCreateStmt(), transformDistinctClause(), transformDistinctOnClause(), transformExpressionList(), transformFKConstraints(), transformFkeyGetPrimaryKey(), transformFromClause(), transformFromClauseItem(), transformFuncCall(), transformGenericOptions(), transformGroupClause(), transformGroupClauseExpr(), transformGroupingFunc(), transformGroupingSet(), transformIndexConstraint(), transformIndexConstraints(), transformIndirection(), transformInsertRow(), transformInsertStmt(), transformJoinUsingClause(), transformMinMaxExpr(), transformMultiAssignRef(), transformOfType(), transformPartitionBound(), transformPartitionRangeBounds(), transformPartitionSpec(), transformPLAssignStmt(), transformRangeFunction(), transformRangeTableFunc(), transformRangeTableSample(), transformRowExpr(), transformRuleStmt(), transformSetOperationStmt(), transformSetOperationTree(), transformSubLink(), transformTableConstraint(), transformTableLikeClause(), transformTargetList(), transformValuesClause(), transformWindowDefinitions(), transformWindowFuncCall(), transformWithClause(), transformXmlExpr(), trim_mergeclauses_for_inner_pathkeys(), untransformRelOptions(), UpdateLogicalMappings(), WaitForLockersMultiple(), and xmlelement().

337 {
338  Assert(IsPointerList(list));
339 
340  if (list == NIL)
341  list = new_list(T_List, 1);
342  else
343  new_tail_cell(list);
344 
345  llast(list) = datum;
346  check_list_invariants(list);
347  return list;
348 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
#define llast(l)
Definition: pg_list.h:194
static void new_tail_cell(List *list)
Definition: list.c:320
#define IsPointerList(l)
Definition: list.c:54
Definition: nodes.h:305
#define Assert(condition)
Definition: c.h:804
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ lappend_int()

List* lappend_int ( List list,
int  datum 
)

Definition at line 354 of file list.c.

References Assert, check_list_invariants, IsIntegerList, sort-test::list, llast_int, new_list(), new_tail_cell(), NIL, and T_IntList.

Referenced by add_merged_range_bounds(), addRangeTableEntryForCTE(), addRangeTableEntryForENR(), addRangeTableEntryForFunction(), addRangeTableEntryForSubquery(), adjust_inherited_attnums(), adjust_partition_colnos(), analyzeCTETargetList(), ATRewriteTable(), build_merged_partition_bounds(), build_subplan(), check_ungrouped_columns_walker(), checkInsertTargets(), convert_EXISTS_to_ANY(), CopyGetAttnums(), deparseAnalyzeSql(), deparseExplicitTargetList(), deparseTargetList(), ExecBuildAggTrans(), ExecBuildGroupingEqual(), ExecBuildParamSetEqual(), ExecInitExprRec(), ExecInitQual(), ExecInitSubscriptingRef(), expand_indexqual_rowcompare(), extract_update_targetlist_colnos(), extractRemainingColumns(), fetch_statentries_for_relation(), finalize_grouping_exprs_walker(), find_all_inheritors(), find_compatible_agg(), fix_expr_common(), gen_partprune_steps_internal(), generate_subquery_params(), grouping_planner(), list_append_unique_int(), list_concat_unique_int(), list_difference_int(), list_intersection_int(), list_union_int(), match_pathkeys_to_index(), merge_list_bounds(), nodeRead(), postgresBeginForeignInsert(), postgresPlanForeignModify(), rel_is_distinct_for(), remap_to_groupclause_idx(), reorder_grouping_sets(), rewriteSearchAndCycle(), set_plan_refs(), set_schema_sent_in_streamed_txn(), split_pathtarget_at_srfs(), SS_process_ctes(), TerminateOtherDBBackends(), transformDistinctOnClause(), transformFromClauseItem(), transformGroupClauseList(), transformInsertStmt(), transformRangeTableFunc(), transformSetOperationTree(), transformValuesClause(), and translate_sub_tlist().

355 {
356  Assert(IsIntegerList(list));
357 
358  if (list == NIL)
359  list = new_list(T_IntList, 1);
360  else
361  new_tail_cell(list);
362 
363  llast_int(list) = datum;
364  check_list_invariants(list);
365  return list;
366 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
#define IsIntegerList(l)
Definition: list.c:55
static void new_tail_cell(List *list)
Definition: list.c:320
#define Assert(condition)
Definition: c.h:804
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88
#define llast_int(l)
Definition: pg_list.h:195

◆ lappend_oid()

List* lappend_oid ( List list,
Oid  datum 
)

Definition at line 372 of file list.c.

References Assert, check_list_invariants, IsOidList, sort-test::list, llast_oid, new_list(), new_tail_cell(), NIL, and T_OidList.

Referenced by add_rte_to_flat_rtable(), addRangeTableEntryForCTE(), addRangeTableEntryForENR(), addRangeTableEntryForFunction(), addRangeTableEntryForSubquery(), AfterTriggerSetState(), AlterTableMoveAll(), analyzeCTETargetList(), apply_handle_truncate(), ApplyExtensionUpdates(), assign_collations_walker(), assign_param_for_placeholdervar(), assign_param_for_var(), assign_special_exec_param(), binary_upgrade_create_empty_extension(), check_functional_grouping(), CheckAttributeType(), CloneFkReferenced(), CloneFkReferencing(), compute_semijoin_info(), convert_EXISTS_to_ANY(), create_hashjoin_plan(), create_indexscan_plan(), CreateExtensionInternal(), CreateFunction(), CreateTrigger(), DefineRelation(), do_autovacuum(), EventTriggerCommonSetup(), ExecAlterDefaultPrivilegesStmt(), ExecInitPartitionInfo(), ExecInsertIndexTuples(), ExecuteGrantStmt(), ExecuteTruncate(), ExecuteTruncateGuts(), expand_indexqual_rowcompare(), extract_query_dependencies_walker(), ExtractExtensionList(), find_all_inheritors(), find_inheritance_children_extended(), find_typed_table_dependencies(), fireRIRrules(), fix_expr_common(), generate_new_exec_param(), get_index_ref_constraints(), get_mergejoin_opfamilies(), get_partition_ancestors_worker(), get_steps_using_prefix_recurse(), GetAllTablesPublicationRelations(), GetAllTablesPublications(), getAutoExtensionsOfObject(), getOwnedSequences_internal(), GetParentedForeignKeyRefs(), GetPublicationRelations(), GetRelationPublications(), getRelationsInNamespace(), heap_truncate_check_FKs(), heap_truncate_find_FKs(), index_concurrently_swap(), infer_arbiter_indexes(), inline_function(), interpret_function_parameter_list(), list_append_unique_oid(), list_concat_unique_oid(), list_difference_oid(), list_union_oid(), LockViewRecurse(), logicalrep_read_truncate(), make_row_comparison_op(), nodeRead(), objectNamesToOids(), objectsInSchemaToOids(), oid_array_to_list(), OpenTableList(), paraminfo_get_equal_hashops(), pgstat_recv_inquiry(), PreCommit_on_commit_actions(), query_to_oid_list(), recomputeNamespacePath(), ReindexMultipleTables(), ReindexPartitions(), ReindexRelationConcurrently(), rel_is_distinct_for(), relation_is_updatable(), RelationGetIndexList(), RelationGetStatExtList(), RememberConstraintForRebuilding(), RememberIndexForRebuilding(), RememberStatisticsForRebuilding(), remove_dbtablespaces(), replace_outer_agg(), replace_outer_grouping(), RestoreReindexState(), rewriteSearchAndCycle(), roleSpecsToIds(), transformAggregateCall(), transformInsertStmt(), transformRangeTableFunc(), transformSetOperationTree(), transformValuesClause(), TryReuseForeignKey(), and typeInheritsFrom().

373 {
374  Assert(IsOidList(list));
375 
376  if (list == NIL)
377  list = new_list(T_OidList, 1);
378  else
379  new_tail_cell(list);
380 
381  llast_oid(list) = datum;
382  check_list_invariants(list);
383  return list;
384 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
#define llast_oid(l)
Definition: pg_list.h:196
static void new_tail_cell(List *list)
Definition: list.c:320
#define IsOidList(l)
Definition: list.c:56
#define Assert(condition)
Definition: c.h:804
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ lcons()

List* lcons ( void *  datum,
List list 
)

Definition at line 468 of file list.c.

References Assert, check_list_invariants, IsPointerList, linitial, sort-test::list, new_head_cell(), new_list(), NIL, and T_List.

Referenced by build_minmax_path(), checkWellFormedRecursionWalker(), consider_groupingsets_paths(), CreateExprContextInternal(), CreateLockFile(), ExecInitModifyTable(), expandTableLikeClause(), ExplainNode(), ExplainSubPlans(), extract_rollup_sets(), find_expr_references_walker(), find_update_path(), generate_orderedappend_paths(), generateSerialExtraStmts(), get_name_for_var_field(), get_object_address_rv(), get_query_def(), get_relation_info(), gistEmptyAllBuffers(), gistFindPath(), gistGetNodeBuffer(), gistPushItupToNodeBuffer(), hashagg_spill_finish(), load_domaintype_info(), makeDependencyGraphWalker(), pg_get_object_address(), plan_union_children(), PLy_subtransaction_enter(), PrepareClientEncoding(), push_child_plan(), pushOperator(), PushOverrideSearchPath(), pushStop(), pushValue_internal(), readTimeLineHistory(), register_on_commit_action(), RelationBuildRowSecurity(), RelationCacheInvalidate(), reorder_grouping_sets(), RewriteQuery(), rewriteSearchAndCycle(), rewriteTargetView(), sepgsql_avc_compute(), set_cheapest(), SharedFileSetInit(), show_agg_keys(), show_group_keys(), sort_inner_and_outer(), transformCaseExpr(), and UpdateRangeTableOfViewParse().

469 {
470  Assert(IsPointerList(list));
471 
472  if (list == NIL)
473  list = new_list(T_List, 1);
474  else
475  new_head_cell(list);
476 
477  linitial(list) = datum;
478  check_list_invariants(list);
479  return list;
480 }
#define NIL
Definition: pg_list.h:65
static void new_head_cell(List *list)
Definition: list.c:302
#define check_list_invariants(l)
Definition: list.c:77
#define linitial(l)
Definition: pg_list.h:174
#define IsPointerList(l)
Definition: list.c:54
Definition: nodes.h:305
#define Assert(condition)
Definition: c.h:804
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ lcons_int()

List* lcons_int ( int  datum,
List list 
)

Definition at line 486 of file list.c.

References Assert, check_list_invariants, IsIntegerList, linitial_int, sort-test::list, new_head_cell(), new_list(), NIL, and T_IntList.

Referenced by ExecInitAgg(), ExplainBeginOutput(), ExplainOpenGroup(), ExplainOpenSetAsideGroup(), and ExplainRestoreGroup().

487 {
488  Assert(IsIntegerList(list));
489 
490  if (list == NIL)
491  list = new_list(T_IntList, 1);
492  else
493  new_head_cell(list);
494 
495  linitial_int(list) = datum;
496  check_list_invariants(list);
497  return list;
498 }
#define NIL
Definition: pg_list.h:65
static void new_head_cell(List *list)
Definition: list.c:302
#define check_list_invariants(l)
Definition: list.c:77
#define IsIntegerList(l)
Definition: list.c:55
#define linitial_int(l)
Definition: pg_list.h:175
#define Assert(condition)
Definition: c.h:804
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ lcons_oid()

List* lcons_oid ( Oid  datum,
List list 
)

Definition at line 504 of file list.c.

References Assert, check_list_invariants, IsOidList, linitial_oid, sort-test::list, new_head_cell(), new_list(), NIL, and T_OidList.

Referenced by CreateSchemaCommand(), pg_partition_ancestors(), PushOverrideSearchPath(), recomputeNamespacePath(), and ReindexMultipleTables().

505 {
506  Assert(IsOidList(list));
507 
508  if (list == NIL)
509  list = new_list(T_OidList, 1);
510  else
511  new_head_cell(list);
512 
513  linitial_oid(list) = datum;
514  check_list_invariants(list);
515  return list;
516 }
#define NIL
Definition: pg_list.h:65
static void new_head_cell(List *list)
Definition: list.c:302
#define check_list_invariants(l)
Definition: list.c:77
#define IsOidList(l)
Definition: list.c:56
#define Assert(condition)
Definition: c.h:804
#define linitial_oid(l)
Definition: pg_list.h:176
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ list_append_unique()

List* list_append_unique ( List list,
void *  datum 
)

Definition at line 1195 of file list.c.

References lappend(), sort-test::list, and list_member().

Referenced by add_security_quals(), and add_with_check_options().

1196 {
1197  if (list_member(list, datum))
1198  return list;
1199  else
1200  return lappend(list, datum);
1201 }
bool list_member(const List *list, const void *datum)
Definition: list.c:628
List * lappend(List *list, void *datum)
Definition: list.c:336

◆ list_append_unique_int()

List* list_append_unique_int ( List list,
int  datum 
)

Definition at line 1220 of file list.c.

References lappend_int(), sort-test::list, and list_member_int().

1221 {
1222  if (list_member_int(list, datum))
1223  return list;
1224  else
1225  return lappend_int(list, datum);
1226 }
bool list_member_int(const List *list, int datum)
Definition: list.c:669
List * lappend_int(List *list, int datum)
Definition: list.c:354

◆ list_append_unique_oid()

List* list_append_unique_oid ( List list,
Oid  datum 
)

Definition at line 1232 of file list.c.

References lappend_oid(), sort-test::list, and list_member_oid().

Referenced by ATExecAlterConstrRecurse(), btvalidate(), hashvalidate(), heap_truncate_find_FKs(), map_sql_typecoll_to_xmlschema_types(), and roles_is_member_of().

1233 {
1234  if (list_member_oid(list, datum))
1235  return list;
1236  else
1237  return lappend_oid(list, datum);
1238 }
List * lappend_oid(List *list, Oid datum)
Definition: list.c:372
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:689

◆ list_append_unique_ptr()

List* list_append_unique_ptr ( List list,
void *  datum 
)

Definition at line 1208 of file list.c.

References lappend(), sort-test::list, and list_member_ptr().

Referenced by get_useful_ecs_for_relation(), postgresGetForeignPaths(), subbuild_joinrel_joinlist(), and subbuild_joinrel_restrictlist().

1209 {
1210  if (list_member_ptr(list, datum))
1211  return list;
1212  else
1213  return lappend(list, datum);
1214 }
List * lappend(List *list, void *datum)
Definition: list.c:336
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:649

◆ list_concat()

List* list_concat ( List list1,
const List list2 
)

Definition at line 530 of file list.c.

References Assert, check_list_invariants, List::elements, enlarge_list(), List::length, list_copy(), List::max_length, NIL, and List::type.

Referenced by accumulate_append_subpath(), add_predicate_to_index_quals(), addRangeTableEntryForJoin(), addRangeTableEntryForTableFunc(), ATExecAttachPartition(), ATParseTransformCmd(), ATPostAlterTypeParse(), AtSubCommit_Notify(), build_joinrel_restrictlist(), build_paths_for_OR(), check_index_predicates(), choose_bitmap_and(), clean_up_removed_plan_level(), consider_groupingsets_paths(), ConstraintImpliedByRelConstraint(), convert_EXISTS_sublink_to_join(), cost_index(), create_append_path(), create_append_plan(), create_bitmap_subplan(), create_index_paths(), create_join_plan(), create_merge_append_plan(), deconstruct_recurse(), DefineRelation(), deparseDirectDeleteSql(), deparseDirectUpdateSql(), deparseFromExprForRel(), estimate_path_cost_size(), expand_groupingset_node(), ExpandAllTables(), expandRTE(), extract_or_clause(), extract_rollup_sets(), fileBeginForeignScan(), fileGetOptions(), find_forced_null_vars(), find_indexpath_quals(), find_mergeclauses_for_outer_pathkeys(), find_nonnullable_vars_walker(), fireRIRrules(), flatten_grouping_sets(), foreign_grouping_ok(), foreign_join_ok(), gen_partprune_steps_internal(), gen_prune_steps_from_opexps(), generate_bitmap_or_paths(), generate_join_implied_equalities(), generate_join_implied_equalities_for_ecs(), generate_join_implied_equalities_normal(), generate_partition_qual(), get_baserel_parampathinfo(), get_batch_size_option(), get_foreign_key_join_selectivity(), get_from_clause_item(), get_index_paths(), get_join_index_paths(), get_joinrel_parampathinfo(), get_relation_constraints(), get_rels_with_domain(), get_steps_using_prefix_recurse(), GetPublicationRelations(), is_parallel_safe(), objectsInSchemaToOids(), process_equivalence(), process_sublinks_mutator(), ProcessUtilitySlow(), pull_ands(), pull_ors(), pull_up_simple_subquery(), pull_up_simple_union_all(), reduce_outer_joins_pass2(), reduce_unique_semijoins(), reorder_grouping_sets(), RewriteQuery(), rewriteRuleAction(), rewriteTargetListIU(), selectColorTrigrams(), set_joinrel_partition_key_exprs(), set_plan_refs(), split_pathtarget_at_srfs(), split_pathtarget_walker(), TidQualFromRestrictInfoList(), transformAExprIn(), transformAlterTableStmt(), transformCreateSchemaStmt(), transformCreateStmt(), transformExpressionList(), transformExtendedStatistics(), transformFromClause(), transformFromClauseItem(), transformIndexConstraints(), transformTargetList(), and vacuum().

531 {
532  int new_len;
533 
534  if (list1 == NIL)
535  return list_copy(list2);
536  if (list2 == NIL)
537  return list1;
538 
539  Assert(list1->type == list2->type);
540 
541  new_len = list1->length + list2->length;
542  /* Enlarge array if necessary */
543  if (new_len > list1->max_length)
544  enlarge_list(list1, new_len);
545 
546  /* Even if list1 == list2, using memcpy should be safe here */
547  memcpy(&list1->elements[list1->length], &list2->elements[0],
548  list2->length * sizeof(ListCell));
549  list1->length = new_len;
550 
551  check_list_invariants(list1);
552  return list1;
553 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
List * list_copy(const List *oldlist)
Definition: list.c:1418
static void enlarge_list(List *list, int min_size)
Definition: list.c:152
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:804
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52

◆ list_concat_copy()

List* list_concat_copy ( const List list1,
const List list2 
)

Definition at line 567 of file list.c.

References Assert, check_list_invariants, List::elements, List::length, list_copy(), new_list(), NIL, and List::type.

Referenced by add_function_defaults(), btadjustmembers(), build_paths_for_OR(), choose_bitmap_and(), create_scan_plan(), DefineIndex(), gen_partprune_steps(), generate_bitmap_or_paths(), get_parameterized_baserel_size(), hashadjustmembers(), make_pathkeys_for_window(), max_parallel_hazard_walker(), process_matched_tle(), set_joinrel_partition_key_exprs(), simplify_and_arguments(), and simplify_or_arguments().

568 {
569  List *result;
570  int new_len;
571 
572  if (list1 == NIL)
573  return list_copy(list2);
574  if (list2 == NIL)
575  return list_copy(list1);
576 
577  Assert(list1->type == list2->type);
578 
579  new_len = list1->length + list2->length;
580  result = new_list(list1->type, new_len);
581  memcpy(result->elements, list1->elements,
582  list1->length * sizeof(ListCell));
583  memcpy(result->elements + list1->length, list2->elements,
584  list2->length * sizeof(ListCell));
585 
586  check_list_invariants(result);
587  return result;
588 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
List * list_copy(const List *oldlist)
Definition: list.c:1418
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:804
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ list_concat_unique()

List* list_concat_unique ( List list1,
const List list2 
)

Definition at line 1252 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, and list_member().

Referenced by create_bitmap_subplan(), and select_active_windows().

1253 {
1254  ListCell *cell;
1255 
1256  Assert(IsPointerList(list1));
1257  Assert(IsPointerList(list2));
1258 
1259  foreach(cell, list2)
1260  {
1261  if (!list_member(list1, lfirst(cell)))
1262  list1 = lappend(list1, lfirst(cell));
1263  }
1264 
1265  check_list_invariants(list1);
1266  return list1;
1267 }
#define check_list_invariants(l)
Definition: list.c:77
bool list_member(const List *list, const void *datum)
Definition: list.c:628
#define IsPointerList(l)
Definition: list.c:54
List * lappend(List *list, void *datum)
Definition: list.c:336
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169

◆ list_concat_unique_int()

List* list_concat_unique_int ( List list1,
const List list2 
)

Definition at line 1295 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lappend_int(), lfirst_int, and list_member_int().

1296 {
1297  ListCell *cell;
1298 
1299  Assert(IsIntegerList(list1));
1300  Assert(IsIntegerList(list2));
1301 
1302  foreach(cell, list2)
1303  {
1304  if (!list_member_int(list1, lfirst_int(cell)))
1305  list1 = lappend_int(list1, lfirst_int(cell));
1306  }
1307 
1308  check_list_invariants(list1);
1309  return list1;
1310 }
#define check_list_invariants(l)
Definition: list.c:77
#define IsIntegerList(l)
Definition: list.c:55
#define lfirst_int(lc)
Definition: pg_list.h:170
bool list_member_int(const List *list, int datum)
Definition: list.c:669
List * lappend_int(List *list, int datum)
Definition: list.c:354
#define Assert(condition)
Definition: c.h:804

◆ list_concat_unique_oid()

List* list_concat_unique_oid ( List list1,
const List list2 
)

Definition at line 1316 of file list.c.

References Assert, check_list_invariants, IsOidList, lappend_oid(), lfirst_oid, and list_member_oid().

Referenced by GetRelationPublicationActions().

1317 {
1318  ListCell *cell;
1319 
1320  Assert(IsOidList(list1));
1321  Assert(IsOidList(list2));
1322 
1323  foreach(cell, list2)
1324  {
1325  if (!list_member_oid(list1, lfirst_oid(cell)))
1326  list1 = lappend_oid(list1, lfirst_oid(cell));
1327  }
1328 
1329  check_list_invariants(list1);
1330  return list1;
1331 }
#define check_list_invariants(l)
Definition: list.c:77
List * lappend_oid(List *list, Oid datum)
Definition: list.c:372
#define IsOidList(l)
Definition: list.c:56
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:689
#define Assert(condition)
Definition: c.h:804
#define lfirst_oid(lc)
Definition: pg_list.h:171

◆ list_concat_unique_ptr()

List* list_concat_unique_ptr ( List list1,
const List list2 
)

Definition at line 1274 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, and list_member_ptr().

1275 {
1276  ListCell *cell;
1277 
1278  Assert(IsPointerList(list1));
1279  Assert(IsPointerList(list2));
1280 
1281  foreach(cell, list2)
1282  {
1283  if (!list_member_ptr(list1, lfirst(cell)))
1284  list1 = lappend(list1, lfirst(cell));
1285  }
1286 
1287  check_list_invariants(list1);
1288  return list1;
1289 }
#define check_list_invariants(l)
Definition: list.c:77
#define IsPointerList(l)
Definition: list.c:54
List * lappend(List *list, void *datum)
Definition: list.c:336
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:649
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169

◆ list_copy()

List* list_copy ( const List oldlist)

Definition at line 1418 of file list.c.

References check_list_invariants, List::elements, List::length, new_list(), NIL, and List::type.

Referenced by accumulate_append_subpath(), addRangeTableEntryForCTE(), arrayconst_startup_fn(), arrayexpr_startup_fn(), build_subplan(), check_index_predicates(), consider_groupingsets_paths(), ConstraintImpliedByRelConstraint(), copy_pathtarget(), copyObjectImpl(), CopyOverrideSearchPath(), create_append_plan(), create_merge_append_plan(), does_not_exist_skipping(), EventTriggerCollectGrant(), ExecuteTruncateGuts(), expand_indexqual_rowcompare(), expression_tree_mutator(), fetch_search_path(), generate_mergejoin_paths(), get_eclass_for_sort_expr(), get_foreign_key_join_selectivity(), get_object_address_attrdef(), get_object_address_attribute(), get_object_address_opf_member(), get_object_address_relobject(), get_query_def(), get_required_extension(), get_steps_using_prefix_recurse(), get_switched_clauses(), get_useful_pathkeys_for_relation(), GetOverrideSearchPath(), heap_truncate_find_FKs(), list_concat(), list_concat_copy(), list_difference(), list_difference_int(), list_difference_oid(), list_difference_ptr(), list_union(), list_union_int(), list_union_oid(), list_union_ptr(), merge_publications(), owningrel_does_not_exist_skipping(), process_owned_by(), PushOverrideSearchPath(), recomputeNamespacePath(), RelationGetIndexList(), RelationGetStatExtList(), remove_rel_from_query(), reorder_grouping_sets(), roles_is_member_of(), select_active_windows(), select_outer_pathkeys_for_merge(), set_joinrel_partition_key_exprs(), set_using_names(), SetReindexPending(), simplify_and_arguments(), simplify_or_arguments(), sort_inner_and_outer(), transformPLAssignStmt(), transformWithClause(), and truncate_useless_pathkeys().

1419 {
1420  List *newlist;
1421 
1422  if (oldlist == NIL)
1423  return NIL;
1424 
1425  newlist = new_list(oldlist->type, oldlist->length);
1426  memcpy(newlist->elements, oldlist->elements,
1427  newlist->length * sizeof(ListCell));
1428 
1429  check_list_invariants(newlist);
1430  return newlist;
1431 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
ListCell * elements
Definition: pg_list.h:55
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ list_copy_deep()

List* list_copy_deep ( const List oldlist)

Definition at line 1463 of file list.c.

References Assert, check_list_invariants, copyObjectImpl(), List::elements, i, IsA, List::length, lfirst, new_list(), NIL, and List::type.

Referenced by copyObjectImpl().

1464 {
1465  List *newlist;
1466 
1467  if (oldlist == NIL)
1468  return NIL;
1469 
1470  /* This is only sensible for pointer Lists */
1471  Assert(IsA(oldlist, List));
1472 
1473  newlist = new_list(oldlist->type, oldlist->length);
1474  for (int i = 0; i < newlist->length; i++)
1475  lfirst(&newlist->elements[i]) =
1476  copyObjectImpl(lfirst(&oldlist->elements[i]));
1477 
1478  check_list_invariants(newlist);
1479  return newlist;
1480 }
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:590
#define check_list_invariants(l)
Definition: list.c:77
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52
int i
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88
void * copyObjectImpl(const void *from)
Definition: copyfuncs.c:4958

◆ list_copy_tail()

List* list_copy_tail ( const List oldlist,
int  nskip 
)

Definition at line 1437 of file list.c.

References check_list_invariants, List::elements, List::length, new_list(), NIL, and List::type.

Referenced by accumulate_append_subpath(), add_function_defaults(), addRangeTableEntryForJoin(), addRangeTableEntryForTableFunc(), does_not_exist_skipping(), expandRTE(), func_get_detail(), get_name_for_var_field(), get_object_address_opcf(), ParseFuncOrColumn(), push_ancestor_plan(), and transformAggregateCall().

1438 {
1439  List *newlist;
1440 
1441  if (nskip < 0)
1442  nskip = 0; /* would it be better to elog? */
1443 
1444  if (oldlist == NIL || nskip >= oldlist->length)
1445  return NIL;
1446 
1447  newlist = new_list(oldlist->type, oldlist->length - nskip);
1448  memcpy(newlist->elements, &oldlist->elements[nskip],
1449  newlist->length * sizeof(ListCell));
1450 
1451  check_list_invariants(newlist);
1452  return newlist;
1453 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
ListCell * elements
Definition: pg_list.h:55
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ list_deduplicate_oid()

void list_deduplicate_oid ( List list)

Definition at line 1340 of file list.c.

References Assert, check_list_invariants, List::elements, i, IsOidList, List::length, list_length(), and ListCell::oid_value.

Referenced by heap_truncate_find_FKs().

1341 {
1342  int len;
1343 
1344  Assert(IsOidList(list));
1345  len = list_length(list);
1346  if (len > 1)
1347  {
1348  ListCell *elements = list->elements;
1349  int i = 0;
1350 
1351  for (int j = 1; j < len; j++)
1352  {
1353  if (elements[i].oid_value != elements[j].oid_value)
1354  elements[++i].oid_value = elements[j].oid_value;
1355  }
1356  list->length = i + 1;
1357  }
1358  check_list_invariants(list);
1359 }
#define check_list_invariants(l)
Definition: list.c:77
ListCell * elements
Definition: pg_list.h:55
#define IsOidList(l)
Definition: list.c:56
#define Assert(condition)
Definition: c.h:804
static int list_length(const List *l)
Definition: pg_list.h:149
int length
Definition: pg_list.h:53
Oid oid_value
Definition: pg_list.h:47
int i

◆ list_delete()

List* list_delete ( List list,
void *  datum 
)

Definition at line 792 of file list.c.

References Assert, check_list_invariants, equal(), IsPointerList, lfirst, sort-test::list, and list_delete_cell().

Referenced by postgresGetForeignPlan(), and unregister_ENR().

793 {
794  ListCell *cell;
795 
796  Assert(IsPointerList(list));
797  check_list_invariants(list);
798 
799  foreach(cell, list)
800  {
801  if (equal(lfirst(cell), datum))
802  return list_delete_cell(list, cell);
803  }
804 
805  /* Didn't find a match: return the list unmodified */
806  return list;
807 }
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3113
#define check_list_invariants(l)
Definition: list.c:77
#define IsPointerList(l)
Definition: list.c:54
List * list_delete_cell(List *list, ListCell *cell)
Definition: list.c:782
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169

◆ list_delete_cell()

List* list_delete_cell ( List list,
ListCell cell 
)

Definition at line 782 of file list.c.

References List::elements, and list_delete_nth_cell().

Referenced by list_delete(), list_delete_int(), list_delete_oid(), list_delete_ptr(), remove_useless_joins(), and transformGenericOptions().

783 {
784  return list_delete_nth_cell(list, cell - list->elements);
785 }
ListCell * elements
Definition: pg_list.h:55
List * list_delete_nth_cell(List *list, int n)
Definition: list.c:711

◆ list_delete_first()

◆ list_delete_int()

List* list_delete_int ( List list,
int  datum 
)

Definition at line 830 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lfirst_int, sort-test::list, and list_delete_cell().

Referenced by reorder_grouping_sets().

831 {
832  ListCell *cell;
833 
834  Assert(IsIntegerList(list));
835  check_list_invariants(list);
836 
837  foreach(cell, list)
838  {
839  if (lfirst_int(cell) == datum)
840  return list_delete_cell(list, cell);
841  }
842 
843  /* Didn't find a match: return the list unmodified */
844  return list;
845 }
#define check_list_invariants(l)
Definition: list.c:77
#define IsIntegerList(l)
Definition: list.c:55
#define lfirst_int(lc)
Definition: pg_list.h:170
List * list_delete_cell(List *list, ListCell *cell)
Definition: list.c:782
#define Assert(condition)
Definition: c.h:804

◆ list_delete_last()

List* list_delete_last ( List list)

Definition at line 892 of file list.c.

References check_list_invariants, list_free(), list_length(), list_truncate(), and NIL.

Referenced by CheckAttributeType(), fireRIRrules(), inline_function(), LockViewRecurse(), relation_is_updatable(), RewriteQuery(), transformMultiAssignRef(), and transformOnConflictClause().

893 {
894  check_list_invariants(list);
895 
896  if (list == NIL)
897  return NIL; /* would an error be better? */
898 
899  /* list_truncate won't free list if it goes to empty, but this should */
900  if (list_length(list) <= 1)
901  {
902  list_free(list);
903  return NIL;
904  }
905 
906  return list_truncate(list, list_length(list) - 1);
907 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
List * list_truncate(List *list, int new_size)
Definition: list.c:600
static int list_length(const List *l)
Definition: pg_list.h:149
void list_free(List *list)
Definition: list.c:1391

◆ list_delete_nth_cell()

List* list_delete_nth_cell ( List list,
int  n 
)

Definition at line 711 of file list.c.

References Assert, check_list_invariants, List::elements, GetMemoryChunkContext(), List::initial_elements, List::length, sort-test::list, list_free(), List::max_length, MemoryContextAlloc(), NIL, pfree(), and VALGRIND_MAKE_MEM_NOACCESS.

Referenced by generateSerialExtraStmts(), list_delete_cell(), list_delete_first(), MergeAttributes(), process_equivalence(), reconsider_full_join_clause(), and sort_inner_and_outer().

712 {
713  check_list_invariants(list);
714 
715  Assert(n >= 0 && n < list->length);
716 
717  /*
718  * If we're about to delete the last node from the list, free the whole
719  * list instead and return NIL, which is the only valid representation of
720  * a zero-length list.
721  */
722  if (list->length == 1)
723  {
724  list_free(list);
725  return NIL;
726  }
727 
728  /*
729  * Otherwise, we normally just collapse out the removed element. But for
730  * debugging purposes, move the whole list contents someplace else.
731  *
732  * (Note that we *must* keep the contents in the same memory context.)
733  */
734 #ifndef DEBUG_LIST_MEMORY_USAGE
735  memmove(&list->elements[n], &list->elements[n + 1],
736  (list->length - 1 - n) * sizeof(ListCell));
737  list->length--;
738 #else
739  {
740  ListCell *newelems;
741  int newmaxlen = list->length - 1;
742 
743  newelems = (ListCell *)
745  newmaxlen * sizeof(ListCell));
746  memcpy(newelems, list->elements, n * sizeof(ListCell));
747  memcpy(&newelems[n], &list->elements[n + 1],
748  (list->length - 1 - n) * sizeof(ListCell));
749  if (list->elements != list->initial_elements)
750  pfree(list->elements);
751  else
752  {
753  /*
754  * As in enlarge_list(), clear the initial_elements[] space and/or
755  * mark it inaccessible.
756  */
757 #ifdef CLOBBER_FREED_MEMORY
758  wipe_mem(list->initial_elements,
759  list->max_length * sizeof(ListCell));
760 #else
762  list->max_length * sizeof(ListCell));
763 #endif
764  }
765  list->elements = newelems;
766  list->max_length = newmaxlen;
767  list->length--;
768  check_list_invariants(list);
769  }
770 #endif
771 
772  return list;
773 }
#define NIL
Definition: pg_list.h:65
#define VALGRIND_MAKE_MEM_NOACCESS(addr, size)
Definition: memdebug.h:27
#define check_list_invariants(l)
Definition: list.c:77
void pfree(void *pointer)
Definition: mcxt.c:1169
union ListCell ListCell
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:804
int length
Definition: pg_list.h:53
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
void list_free(List *list)
Definition: list.c:1391
ListCell initial_elements[FLEXIBLE_ARRAY_MEMBER]
Definition: pg_list.h:57
static MemoryContext GetMemoryChunkContext(void *pointer)
Definition: memutils.h:114

◆ list_delete_oid()

List* list_delete_oid ( List list,
Oid  datum 
)

Definition at line 849 of file list.c.

References Assert, check_list_invariants, IsOidList, lfirst_oid, sort-test::list, and list_delete_cell().

Referenced by RemoveReindexPending().

850 {
851  ListCell *cell;
852 
853  Assert(IsOidList(list));
854  check_list_invariants(list);
855 
856  foreach(cell, list)
857  {
858  if (lfirst_oid(cell) == datum)
859  return list_delete_cell(list, cell);
860  }
861 
862  /* Didn't find a match: return the list unmodified */
863  return list;
864 }
#define check_list_invariants(l)
Definition: list.c:77
List * list_delete_cell(List *list, ListCell *cell)
Definition: list.c:782
#define IsOidList(l)
Definition: list.c:56
#define Assert(condition)
Definition: c.h:804
#define lfirst_oid(lc)
Definition: pg_list.h:171

◆ list_delete_ptr()

List* list_delete_ptr ( List list,
void *  datum 
)

Definition at line 811 of file list.c.

References Assert, check_list_invariants, IsPointerList, lfirst, sort-test::list, and list_delete_cell().

Referenced by FreeExprContext(), and remove_join_clause_from_rels().

812 {
813  ListCell *cell;
814 
815  Assert(IsPointerList(list));
816  check_list_invariants(list);
817 
818  foreach(cell, list)
819  {
820  if (lfirst(cell) == datum)
821  return list_delete_cell(list, cell);
822  }
823 
824  /* Didn't find a match: return the list unmodified */
825  return list;
826 }
#define check_list_invariants(l)
Definition: list.c:77
#define IsPointerList(l)
Definition: list.c:54
List * list_delete_cell(List *list, ListCell *cell)
Definition: list.c:782
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169

◆ list_difference()

List* list_difference ( const List list1,
const List list2 
)

Definition at line 1091 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, list_copy(), list_member(), and NIL.

Referenced by create_hashjoin_plan(), create_mergejoin_plan(), create_tidscan_plan(), infer_arbiter_indexes(), and process_duplicate_ors().

1092 {
1093  const ListCell *cell;
1094  List *result = NIL;
1095 
1096  Assert(IsPointerList(list1));
1097  Assert(IsPointerList(list2));
1098 
1099  if (list2 == NIL)
1100  return list_copy(list1);
1101 
1102  foreach(cell, list1)
1103  {
1104  if (!list_member(list2, lfirst(cell)))
1105  result = lappend(result, lfirst(cell));
1106  }
1107 
1108  check_list_invariants(result);
1109  return result;
1110 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
List * list_copy(const List *oldlist)
Definition: list.c:1418
bool list_member(const List *list, const void *datum)
Definition: list.c:628
#define IsPointerList(l)
Definition: list.c:54
List * lappend(List *list, void *datum)
Definition: list.c:336
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
Definition: pg_list.h:50

◆ list_difference_int()

List* list_difference_int ( const List list1,
const List list2 
)

Definition at line 1142 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lappend_int(), lfirst_int, list_copy(), list_member_int(), and NIL.

Referenced by reorder_grouping_sets().

1143 {
1144  const ListCell *cell;
1145  List *result = NIL;
1146 
1147  Assert(IsIntegerList(list1));
1148  Assert(IsIntegerList(list2));
1149 
1150  if (list2 == NIL)
1151  return list_copy(list1);
1152 
1153  foreach(cell, list1)
1154  {
1155  if (!list_member_int(list2, lfirst_int(cell)))
1156  result = lappend_int(result, lfirst_int(cell));
1157  }
1158 
1159  check_list_invariants(result);
1160  return result;
1161 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
List * list_copy(const List *oldlist)
Definition: list.c:1418
#define IsIntegerList(l)
Definition: list.c:55
#define lfirst_int(lc)
Definition: pg_list.h:170
bool list_member_int(const List *list, int datum)
Definition: list.c:669
List * lappend_int(List *list, int datum)
Definition: list.c:354
#define Assert(condition)
Definition: c.h:804
Definition: pg_list.h:50

◆ list_difference_oid()

List* list_difference_oid ( const List list1,
const List list2 
)

Definition at line 1167 of file list.c.

References Assert, check_list_invariants, IsOidList, lappend_oid(), lfirst_oid, list_copy(), list_member_oid(), and NIL.

1168 {
1169  const ListCell *cell;
1170  List *result = NIL;
1171 
1172  Assert(IsOidList(list1));
1173  Assert(IsOidList(list2));
1174 
1175  if (list2 == NIL)
1176  return list_copy(list1);
1177 
1178  foreach(cell, list1)
1179  {
1180  if (!list_member_oid(list2, lfirst_oid(cell)))
1181  result = lappend_oid(result, lfirst_oid(cell));
1182  }
1183 
1184  check_list_invariants(result);
1185  return result;
1186 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
List * list_copy(const List *oldlist)
Definition: list.c:1418
List * lappend_oid(List *list, Oid datum)
Definition: list.c:372
#define IsOidList(l)
Definition: list.c:56
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:689
#define Assert(condition)
Definition: c.h:804
Definition: pg_list.h:50
#define lfirst_oid(lc)
Definition: pg_list.h:171

◆ list_difference_ptr()

List* list_difference_ptr ( const List list1,
const List list2 
)

Definition at line 1117 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, list_copy(), list_member_ptr(), and NIL.

Referenced by create_bitmap_scan_plan(), and ExecuteTruncateGuts().

1118 {
1119  const ListCell *cell;
1120  List *result = NIL;
1121 
1122  Assert(IsPointerList(list1));
1123  Assert(IsPointerList(list2));
1124 
1125  if (list2 == NIL)
1126  return list_copy(list1);
1127 
1128  foreach(cell, list1)
1129  {
1130  if (!list_member_ptr(list2, lfirst(cell)))
1131  result = lappend(result, lfirst(cell));
1132  }
1133 
1134  check_list_invariants(result);
1135  return result;
1136 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
List * list_copy(const List *oldlist)
Definition: list.c:1418
#define IsPointerList(l)
Definition: list.c:54
List * lappend(List *list, void *datum)
Definition: list.c:336
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:649
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
Definition: pg_list.h:50

◆ list_free()

void list_free ( List list)

Definition at line 1391 of file list.c.

References list_free_private().

Referenced by AfterTriggerSetState(), AlterIndexNamespaces(), arrayconst_cleanup_fn(), arrayexpr_cleanup_fn(), ATCheckPartitionsNotInUse(), AtEOSubXact_Namespace(), AtEOXact_Namespace(), ATExecChangeOwner(), ATExecDropNotNull(), ATExecSetTableSpace(), build_base_rel_tlists(), build_remote_returning(), calc_joinrel_size_estimate(), calculate_indexes_size(), calculate_toast_table_size(), check_datestyle(), check_log_destination(), check_search_path(), check_temp_tablespaces(), check_wal_consistency_checking(), choose_bitmap_and(), compute_semi_anti_join_factors(), CopyFrom(), CopyMultiInsertBufferFlush(), CopyMultiInsertInfoCleanup(), CreateExtensionInternal(), CreateTrigger(), current_schema(), current_schemas(), DefineIndex(), DefineRelation(), distribute_qual_to_rels(), DropSubscription(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerSQLDrop(), EventTriggerTableRewrite(), ExecInitPartitionInfo(), ExecInsert(), ExecOpenIndices(), ExecRefreshMatView(), ExecResetTupleTable(), ExecSimpleRelationInsert(), ExecSimpleRelationUpdate(), ExecUpdate(), extract_lateral_references(), ExtractExtensionList(), find_all_inheritors(), find_compatible_agg(), find_computable_ec_member(), find_hash_columns(), find_placeholders_in_expr(), fix_placeholder_input_needed_levels(), generate_base_implied_equalities_no_const(), generate_partitionwise_join_paths(), get_rel_sync_entry(), get_relation_info(), get_relation_statistics(), get_steps_using_prefix_recurse(), hashagg_reset_spill_state(), heap_truncate_find_FKs(), index_concurrently_swap(), index_get_partition(), index_unchanged_by_update(), infer_arbiter_indexes(), list_delete_last(), list_delete_nth_cell(), make_group_input_target(), make_partial_grouping_target(), make_pathkeys_for_window(), make_sort_input_target(), make_window_input_target(), max_parallel_hazard_walker(), merge_list_bounds(), merge_range_bounds(), OpenTableList(), paraminfo_get_equal_hashops(), parse_hba_auth_opt(), pg_partition_root(), pgstat_report_anl_ancestors(), pgstat_write_statsfiles(), plpgsql_extra_checks_check_hook(), pop_ancestor_plan(), PopOverrideSearchPath(), PostmasterMain(), PrepareTempTablespaces(), preprocess_targetlist(), process_implied_equality(), ProcessUtilitySlow(), qual_is_pushdown_safe(), recomputeNamespacePath(), refresh_by_match_merge(), rel_sync_cache_relation_cb(), RelationCacheInvalidate(), RelationDestroyRelation(), RelationGetIdentityKeyBitmap(), RelationGetIndexAttrBitmap(), RelationGetIndexList(), RelationGetPrimaryKeyIndex(), RelationGetReplicaIndex(), RelationGetStatExtList(), relationHasPrimaryKey(), remove_dbtablespaces(), reorder_grouping_sets(), reparameterize_pathlist_by_child(), roles_is_member_of(), sepgsql_dml_privileges(), simplify_and_arguments(), simplify_or_arguments(), statext_mcv_clauselist_selectivity(), stringToQualifiedNameList(), textToQualifiedNameList(), toast_open_indexes(), transformFkeyCheckAttrs(), transformFkeyGetPrimaryKey(), transformTableLikeClause(), transformValuesClause(), triggered_change_notification(), typeInheritsFrom(), vac_open_indexes(), and WaitForLockers().

1392 {
1393  list_free_private(list, false);
1394 }
static void list_free_private(List *list, bool deep)
Definition: list.c:1365

◆ list_free_deep()

void list_free_deep ( List list)

Definition at line 1405 of file list.c.

References Assert, IsPointerList, and list_free_private().

Referenced by AfterTriggerFreeQuery(), checkSharedDependencies(), DetachPartitionFinalize(), Exec_UnlistenAllCommit(), FreeSubscription(), get_rel_sync_entry(), gettype(), gistbufferinginserttuples(), load_libraries(), lookup_proof_cache(), PostmasterMain(), process_syncing_tables_for_apply(), RelationDestroyRelation(), RelationGetFKeyList(), rescanLatestTimeLine(), StartReplication(), verify_heapam(), WaitForLockersMultiple(), XLogReadDetermineTimeline(), and XLogSendPhysical().

1406 {
1407  /*
1408  * A "deep" free operation only makes sense on a list of pointers.
1409  */
1410  Assert(IsPointerList(list));
1411  list_free_private(list, true);
1412 }
#define IsPointerList(l)
Definition: list.c:54
#define Assert(condition)
Definition: c.h:804
static void list_free_private(List *list, bool deep)
Definition: list.c:1365

◆ list_free_private()

static void list_free_private ( List list,
bool  deep 
)
static

Definition at line 1365 of file list.c.

References check_list_invariants, List::elements, i, List::initial_elements, List::length, lfirst, NIL, and pfree().

Referenced by list_free(), and list_free_deep().

1366 {
1367  if (list == NIL)
1368  return; /* nothing to do */
1369 
1370  check_list_invariants(list);
1371 
1372  if (deep)
1373  {
1374  for (int i = 0; i < list->length; i++)
1375  pfree(lfirst(&list->elements[i]));
1376  }
1377  if (list->elements != list->initial_elements)
1378  pfree(list->elements);
1379  pfree(list);
1380 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
void pfree(void *pointer)
Definition: mcxt.c:1169
ListCell * elements
Definition: pg_list.h:55
#define lfirst(lc)
Definition: pg_list.h:169
int length
Definition: pg_list.h:53
int i
ListCell initial_elements[FLEXIBLE_ARRAY_MEMBER]
Definition: pg_list.h:57

◆ list_insert_nth()

List* list_insert_nth ( List list,
int  pos,
void *  datum 
)

Definition at line 415 of file list.c.

References Assert, check_list_invariants, insert_new_cell(), IsPointerList, lfirst, sort-test::list, list_make1, and NIL.

Referenced by add_partial_path(), add_path(), and merge_clump().

416 {
417  if (list == NIL)
418  {
419  Assert(pos == 0);
420  return list_make1(datum);
421  }
422  Assert(IsPointerList(list));
423  lfirst(insert_new_cell(list, pos)) = datum;
424  check_list_invariants(list);
425  return list;
426 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
static ListCell * insert_new_cell(List *list, int pos)
Definition: list.c:394
#define list_make1(x1)
Definition: pg_list.h:206
#define IsPointerList(l)
Definition: list.c:54
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169

◆ list_insert_nth_int()

List* list_insert_nth_int ( List list,
int  pos,
int  datum 
)

Definition at line 429 of file list.c.

References Assert, check_list_invariants, insert_new_cell(), IsIntegerList, lfirst_int, sort-test::list, list_make1_int, and NIL.

430 {
431  if (list == NIL)
432  {
433  Assert(pos == 0);
434  return list_make1_int(datum);
435  }
436  Assert(IsIntegerList(list));
437  lfirst_int(insert_new_cell(list, pos)) = datum;
438  check_list_invariants(list);
439  return list;
440 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
static ListCell * insert_new_cell(List *list, int pos)
Definition: list.c:394
#define IsIntegerList(l)
Definition: list.c:55
#define lfirst_int(lc)
Definition: pg_list.h:170
#define list_make1_int(x1)
Definition: pg_list.h:221
#define Assert(condition)
Definition: c.h:804

◆ list_insert_nth_oid()

List* list_insert_nth_oid ( List list,
int  pos,
Oid  datum 
)

Definition at line 443 of file list.c.

References Assert, check_list_invariants, insert_new_cell(), IsOidList, lfirst_oid, sort-test::list, list_make1_oid, and NIL.

444 {
445  if (list == NIL)
446  {
447  Assert(pos == 0);
448  return list_make1_oid(datum);
449  }
450  Assert(IsOidList(list));
451  lfirst_oid(insert_new_cell(list, pos)) = datum;
452  check_list_invariants(list);
453  return list;
454 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
static ListCell * insert_new_cell(List *list, int pos)
Definition: list.c:394
#define list_make1_oid(x1)
Definition: pg_list.h:236
#define IsOidList(l)
Definition: list.c:56
#define Assert(condition)
Definition: c.h:804
#define lfirst_oid(lc)
Definition: pg_list.h:171

◆ list_int_cmp()

int list_int_cmp ( const ListCell p1,
const ListCell p2 
)

Definition at line 1513 of file list.c.

References lfirst_int.

Referenced by expand_grouping_sets().

1514 {
1515  int v1 = lfirst_int(p1);
1516  int v2 = lfirst_int(p2);
1517 
1518  if (v1 < v2)
1519  return -1;
1520  if (v1 > v2)
1521  return 1;
1522  return 0;
1523 }
#define lfirst_int(lc)
Definition: pg_list.h:170

◆ list_intersection()

List* list_intersection ( const List list1,
const List list2 
)

Definition at line 1033 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, list_member(), and NIL.

Referenced by find_nonnullable_vars_walker(), and reduce_outer_joins_pass2().

1034 {
1035  List *result;
1036  const ListCell *cell;
1037 
1038  if (list1 == NIL || list2 == NIL)
1039  return NIL;
1040 
1041  Assert(IsPointerList(list1));
1042  Assert(IsPointerList(list2));
1043 
1044  result = NIL;
1045  foreach(cell, list1)
1046  {
1047  if (list_member(list2, lfirst(cell)))
1048  result = lappend(result, lfirst(cell));
1049  }
1050 
1051  check_list_invariants(result);
1052  return result;
1053 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
bool list_member(const List *list, const void *datum)
Definition: list.c:628
#define IsPointerList(l)
Definition: list.c:54
List * lappend(List *list, void *datum)
Definition: list.c:336
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
Definition: pg_list.h:50

◆ list_intersection_int()

List* list_intersection_int ( const List list1,
const List list2 
)

Definition at line 1059 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lappend_int(), lfirst_int, list_member_int(), and NIL.

Referenced by parseCheckAggregates().

1060 {
1061  List *result;
1062  const ListCell *cell;
1063 
1064  if (list1 == NIL || list2 == NIL)
1065  return NIL;
1066 
1067  Assert(IsIntegerList(list1));
1068  Assert(IsIntegerList(list2));
1069 
1070  result = NIL;
1071  foreach(cell, list1)
1072  {
1073  if (list_member_int(list2, lfirst_int(cell)))
1074  result = lappend_int(result, lfirst_int(cell));
1075  }
1076 
1077  check_list_invariants(result);
1078  return result;
1079 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:77
#define IsIntegerList(l)
Definition: list.c:55
#define lfirst_int(lc)
Definition: pg_list.h:170
bool list_member_int(const List *list, int datum)
Definition: list.c:669
List * lappend_int(List *list, int datum)
Definition: list.c:354
#define Assert(condition)
Definition: c.h:804
Definition: pg_list.h:50

◆ list_make1_impl()

List* list_make1_impl ( NodeTag  t,
ListCell  datum1 
)

Definition at line 233 of file list.c.

References check_list_invariants, List::elements, sort-test::list, and new_list().

234 {
235  List *list = new_list(t, 1);
236 
237  list->elements[0] = datum1;
238  check_list_invariants(list);
239  return list;
240 }
#define check_list_invariants(l)
Definition: list.c:77
ListCell * elements
Definition: pg_list.h:55
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ list_make2_impl()

List* list_make2_impl ( NodeTag  t,
ListCell  datum1,
ListCell  datum2 
)

Definition at line 243 of file list.c.

References check_list_invariants, List::elements, sort-test::list, and new_list().

244 {
245  List *list = new_list(t, 2);
246 
247  list->elements[0] = datum1;
248  list->elements[1] = datum2;
249  check_list_invariants(list);
250  return list;
251 }
#define check_list_invariants(l)
Definition: list.c:77
ListCell * elements
Definition: pg_list.h:55
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ list_make3_impl()

List* list_make3_impl ( NodeTag  t,
ListCell  datum1,
ListCell  datum2,
ListCell  datum3 
)

Definition at line 254 of file list.c.

References check_list_invariants, List::elements, sort-test::list, and new_list().

256 {
257  List *list = new_list(t, 3);
258 
259  list->elements[0] = datum1;
260  list->elements[1] = datum2;
261  list->elements[2] = datum3;
262  check_list_invariants(list);
263  return list;
264 }
#define check_list_invariants(l)
Definition: list.c:77
ListCell * elements
Definition: pg_list.h:55
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ list_make4_impl()

List* list_make4_impl ( NodeTag  t,
ListCell  datum1,
ListCell  datum2,
ListCell  datum3,
ListCell  datum4 
)

Definition at line 267 of file list.c.

References check_list_invariants, List::elements, sort-test::list, and new_list().

269 {
270  List *list = new_list(t, 4);
271 
272  list->elements[0] = datum1;
273  list->elements[1] = datum2;
274  list->elements[2] = datum3;
275  list->elements[3] = datum4;
276  check_list_invariants(list);
277  return list;
278 }
#define check_list_invariants(l)
Definition: list.c:77
ListCell * elements
Definition: pg_list.h:55
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ list_make5_impl()

List* list_make5_impl ( NodeTag  t,
ListCell  datum1,
ListCell  datum2,
ListCell  datum3,
ListCell  datum4,
ListCell  datum5 
)

Definition at line 281 of file list.c.

References check_list_invariants, List::elements, sort-test::list, and new_list().

283 {
284  List *list = new_list(t, 5);
285 
286  list->elements[0] = datum1;
287  list->elements[1] = datum2;
288  list->elements[2] = datum3;
289  list->elements[3] = datum4;
290  list->elements[4] = datum5;
291  check_list_invariants(list);
292  return list;
293 }
#define check_list_invariants(l)
Definition: list.c:77
ListCell * elements
Definition: pg_list.h:55
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:88

◆ list_member()

bool list_member ( const List list,
const void *  datum 
)

Definition at line 628 of file list.c.

References Assert, check_list_invariants, equal(), IsPointerList, and lfirst.

Referenced by add_new_column_to_pathtarget(), analyzeCTE(), build_minmax_path(), create_bitmap_scan_plan(), ec_member_matches_foreign(), find_window_functions_walker(), group_by_has_partkey(), infer_arbiter_indexes(), list_append_unique(), list_concat_unique(), list_difference(), list_intersection(), list_union(), process_duplicate_ors(), split_pathtarget_at_srfs(), and split_pathtarget_walker().

629 {
630  const ListCell *cell;
631 
632  Assert(IsPointerList(list));
633  check_list_invariants(list);
634 
635  foreach(cell, list)
636  {
637  if (equal(lfirst(cell), datum))
638  return true;
639  }
640 
641  return false;
642 }
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3113
#define check_list_invariants(l)
Definition: list.c:77
#define IsPointerList(l)
Definition: list.c:54
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169

◆ list_member_int()

bool list_member_int ( const List list,
int  datum 
)

Definition at line 669 of file list.c.

References Assert, check_list_invariants, IsIntegerList, and lfirst_int.

Referenced by BeginCopyFrom(), BeginCopyTo(), check_ungrouped_columns_walker(), contain_exec_param_walker(), CopyGetAttnums(), estimate_num_groups(), ExecRelationIsTargetRelation(), init_returning_filter(), list_append_unique_int(), list_concat_unique_int(), list_difference_int(), list_intersection_int(), list_union_int(), max_parallel_hazard_walker(), parseCheckAggregates(), reorder_grouping_sets(), and transformDistinctOnClause().

670 {
671  const ListCell *cell;
672 
673  Assert(IsIntegerList(list));
674  check_list_invariants(list);
675 
676  foreach(cell, list)
677  {
678  if (lfirst_int(cell) == datum)
679  return true;
680  }
681 
682  return false;
683 }
#define check_list_invariants(l)
Definition: list.c:77
#define IsIntegerList(l)
Definition: list.c:55
#define lfirst_int(lc)
Definition: pg_list.h:170
#define Assert(condition)
Definition: c.h:804

◆ list_member_oid()

bool list_member_oid ( const List list,
Oid  datum 
)

Definition at line 689 of file list.c.

References Assert, check_list_invariants, IsOidList, and lfirst_oid.

Referenced by AfterTriggerSaveEvent(), AlterTableMoveAll(), apply_handle_truncate(), ATExecAddInherit(), ATExecAttachPartition(), BeginCopyTo(), CheckAttributeType(), CloneFkReferenced(), CloneFkReferencing(), CollationIsVisible(), ConversionIsVisible(), DefineRelation(), ec_member_matches_indexcol(), ExecAlterObjectDependsStmt(), ExecCheckIndexConstraints(), ExecInitPartitionInfo(), ExecInsertIndexTuples(), ExecuteTruncate(), fireRIRrules(), FunctionIsVisible(), get_rel_sync_entry(), get_transform_fromsql(), get_transform_tosql(), has_privs_of_role(), hashvalidate(), have_partkey_equi_join(), heap_truncate_check_FKs(), heap_truncate_find_FKs(), inline_function(), is_member_of_role(), is_member_of_role_nosuper(), list_append_unique_oid(), list_concat_unique_oid(), list_difference_oid(), list_union_oid(), LockViewRecurse_walker(), lookup_shippable(), OpclassIsVisible(), OpenTableList(), OperatorIsVisible(), OpfamilyIsVisible(), pgstat_db_requested(), pgstat_recv_inquiry(), PlanCacheRelCallback(), recomputeNamespacePath(), ReindexIsProcessingIndex(), relation_has_unique_index_for(), relation_is_updatable(), RelationIsVisible(), RememberConstraintForRebuilding(), RememberIndexForRebuilding(), RememberStatisticsForRebuilding(), StatisticsObjIsVisible(), TSConfigIsVisible(), TSDictionaryIsVisible(), TSParserIsVisible(), TSTemplateIsVisible(), typeInheritsFrom(), and TypeIsVisible().

690 {
691  const ListCell *cell;
692 
693  Assert(IsOidList(list));
694  check_list_invariants(list);
695 
696  foreach(cell, list)
697  {
698  if (lfirst_oid(cell) == datum)
699  return true;
700  }
701 
702  return false;
703 }
#define check_list_invariants(l)
Definition: list.c:77
#define IsOidList(l)
Definition: list.c:56
#define Assert(condition)
Definition: c.h:804
#define lfirst_oid(lc)
Definition: pg_list.h:171

◆ list_member_ptr()

bool list_member_ptr ( const List list,
const void *  datum 
)

Definition at line 649 of file list.c.

References Assert, check_list_invariants, IsPointerList, and lfirst.

Referenced by create_bitmap_scan_plan(), create_tidrangescan_plan(), create_tidscan_plan(), get_foreign_key_join_selectivity(), list_append_unique_ptr(), list_concat_unique_ptr(), list_difference_ptr(), list_union_ptr(), postgresGetForeignPlan(), preprocess_groupclause(), and remove_join_clause_from_rels().

650 {
651  const ListCell *cell;
652 
653  Assert(IsPointerList(list));
654  check_list_invariants(list);
655 
656  foreach(cell, list)
657  {
658  if (lfirst(cell) == datum)
659  return true;
660  }
661 
662  return false;
663 }
#define check_list_invariants(l)
Definition: list.c:77
#define IsPointerList(l)
Definition: list.c:54
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169

◆ list_oid_cmp()

int list_oid_cmp ( const ListCell p1,
const ListCell p2 
)

Definition at line 1529 of file list.c.

References lfirst_oid.

Referenced by heap_truncate_find_FKs(), RelationGetIndexList(), and RelationGetStatExtList().

1530 {
1531  Oid v1 = lfirst_oid(p1);
1532  Oid v2 = lfirst_oid(p2);
1533 
1534  if (v1 < v2)
1535  return -1;
1536  if (v1 > v2)
1537  return 1;
1538  return 0;
1539 }
unsigned int Oid
Definition: postgres_ext.h:31
#define lfirst_oid(lc)
Definition: pg_list.h:171

◆ list_sort()

void list_sort ( List list,
list_sort_comparator  cmp 
)

Definition at line 1496 of file list.c.

References check_list_invariants, List::elements, list_length(), and qsort.

Referenced by create_append_path(), expand_grouping_sets(), heap_truncate_find_FKs(), perform_base_backup(), RelationGetIndexList(), RelationGetStatExtList(), sort_policies_by_name(), and UpdateLogicalMappings().

1497 {
1498  typedef int (*qsort_comparator) (const void *a, const void *b);
1499  int len;
1500 
1501  check_list_invariants(list);
1502 
1503  /* Nothing to do if there's less than two elements */
1504  len = list_length(list);
1505  if (len > 1)
1506  qsort(list->elements, len, sizeof(ListCell), (qsort_comparator) cmp);
1507 }
#define check_list_invariants(l)
Definition: list.c:77
ListCell * elements
Definition: pg_list.h:55
static int list_length(const List *l)
Definition: pg_list.h:149
#define qsort(a, b, c, d)
Definition: port.h:504
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:747

◆ list_truncate()

List* list_truncate ( List list,
int  new_size 
)

Definition at line 600 of file list.c.

References List::length, sort-test::list, list_length(), and NIL.

Referenced by accumulate_append_subpath(), choose_bitmap_and(), create_append_plan(), create_merge_append_plan(), does_not_exist_skipping(), expand_indexqual_rowcompare(), ExpandIndirectionStar(), expandRTE(), generate_mergejoin_paths(), geqo_eval(), get_object_address_attrdef(), get_object_address_attribute(), get_object_address_opf_member(), get_object_address_relobject(), get_useful_pathkeys_for_relation(), list_delete_last(), owningrel_does_not_exist_skipping(), ParseFuncOrColumn(), process_owned_by(), transformAggregateCall(), transformFromClauseItem(), transformSetOperationStmt(), transformWholeRowRef(), and truncate_useless_pathkeys().

601 {
602  if (new_size <= 0)
603  return NIL; /* truncate to zero length */
604 
605  /* If asked to effectively extend the list, do nothing */
606  if (new_size < list_length(list))
607  list->length = new_size;
608 
609  /*
610  * Note: unlike the individual-list-cell deletion functions, we don't move
611  * the list cells to new storage, even in DEBUG_LIST_MEMORY_USAGE mode.
612  * This is because none of them can move in this operation, so just like
613  * in the old cons-cell-based implementation, this function doesn't
614  * invalidate any pointers to cells of the list. This is also the reason
615  * for not wiping the memory of the deleted cells: the old code didn't
616  * free them either. Perhaps later we'll tighten this up.
617  */
618 
619  return list;
620 }
#define NIL
Definition: pg_list.h:65
static int list_length(const List *l)
Definition: pg_list.h:149
int length
Definition: pg_list.h:53

◆ list_union()

List* list_union ( const List list1,
const List list2 
)

Definition at line 930 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, list_copy(), and list_member().

Referenced by AddRelationNewConstraints(), and process_duplicate_ors().

931 {
932  List *result;
933  const ListCell *cell;
934 
935  Assert(IsPointerList(list1));
936  Assert(IsPointerList(list2));
937 
938  result = list_copy(list1);
939  foreach(cell, list2)
940  {
941  if (!list_member(result, lfirst(cell)))
942  result = lappend(result, lfirst(cell));
943  }
944 
945  check_list_invariants(result);
946  return result;
947 }
#define check_list_invariants(l)
Definition: list.c:77
List * list_copy(const List *oldlist)
Definition: list.c:1418
bool list_member(const List *list, const void *datum)
Definition: list.c:628
#define IsPointerList(l)
Definition: list.c:54
List * lappend(List *list, void *datum)
Definition: list.c:336
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
Definition: pg_list.h:50

◆ list_union_int()

List* list_union_int ( const List list1,
const List list2 
)

Definition at line 977 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lappend_int(), lfirst_int, list_copy(), and list_member_int().

Referenced by expand_grouping_sets().

978 {
979  List *result;
980  const ListCell *cell;
981 
982  Assert(IsIntegerList(list1));
983  Assert(IsIntegerList(list2));
984 
985  result = list_copy(list1);
986  foreach(cell, list2)
987  {
988  if (!list_member_int(result, lfirst_int(cell)))
989  result = lappend_int(result, lfirst_int(cell));
990  }
991 
992  check_list_invariants(result);
993  return result;
994 }
#define check_list_invariants(l)
Definition: list.c:77
List * list_copy(const List *oldlist)
Definition: list.c:1418
#define IsIntegerList(l)
Definition: list.c:55
#define lfirst_int(lc)
Definition: pg_list.h:170
bool list_member_int(const List *list, int datum)
Definition: list.c:669
List * lappend_int(List *list, int datum)
Definition: list.c:354
#define Assert(condition)
Definition: c.h:804
Definition: pg_list.h:50

◆ list_union_oid()

List* list_union_oid ( const List list1,
const List list2 
)

Definition at line 1000 of file list.c.

References Assert, check_list_invariants, IsOidList, lappend_oid(), lfirst_oid, list_copy(), and list_member_oid().

1001 {
1002  List *result;
1003  const ListCell *cell;
1004 
1005  Assert(IsOidList(list1));
1006  Assert(IsOidList(list2));
1007 
1008  result = list_copy(list1);
1009  foreach(cell, list2)
1010  {
1011  if (!list_member_oid(result, lfirst_oid(cell)))
1012  result = lappend_oid(result, lfirst_oid(cell));
1013  }
1014 
1015  check_list_invariants(result);
1016  return result;
1017 }
#define check_list_invariants(l)
Definition: list.c:77
List * list_copy(const List *oldlist)
Definition: list.c:1418
List * lappend_oid(List *list, Oid datum)
Definition: list.c:372
#define IsOidList(l)
Definition: list.c:56
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:689
#define Assert(condition)
Definition: c.h:804
Definition: pg_list.h:50
#define lfirst_oid(lc)
Definition: pg_list.h:171

◆ list_union_ptr()

List* list_union_ptr ( const List list1,
const List list2 
)

Definition at line 954 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, list_copy(), and list_member_ptr().

955 {
956  List *result;
957  const ListCell *cell;
958 
959  Assert(IsPointerList(list1));
960  Assert(IsPointerList(list2));
961 
962  result = list_copy(list1);
963  foreach(cell, list2)
964  {
965  if (!list_member_ptr(result, lfirst(cell)))
966  result = lappend(result, lfirst(cell));
967  }
968 
969  check_list_invariants(result);
970  return result;
971 }
#define check_list_invariants(l)
Definition: list.c:77
List * list_copy(const List *oldlist)
Definition: list.c:1418
#define IsPointerList(l)
Definition: list.c:54
List * lappend(List *list, void *datum)
Definition: list.c:336
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:649
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
Definition: pg_list.h:50

◆ new_head_cell()

static void new_head_cell ( List list)
static

Definition at line 302 of file list.c.

References List::elements, enlarge_list(), List::length, and List::max_length.

Referenced by lcons(), lcons_int(), and lcons_oid().

303 {
304  /* Enlarge array if necessary */
305  if (list->length >= list->max_length)
306  enlarge_list(list, list->length + 1);
307  /* Now shove the existing data over */
308  memmove(&list->elements[1], &list->elements[0],
309  list->length * sizeof(ListCell));
310  list->length++;
311 }
static void enlarge_list(List *list, int min_size)
Definition: list.c:152
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
int length
Definition: pg_list.h:53

◆ new_list()

static List* new_list ( NodeTag  type,
int  min_size 
)
static

Definition at line 88 of file list.c.

References Assert, List::elements, List::initial_elements, List::length, LIST_HEADER_OVERHEAD, Max, List::max_length, offsetof, palloc(), pg_nextpower2_32(), List::type, and generate_unaccent_rules::type.

Referenced by lappend(), lappend_int(), lappend_oid(), lcons(), lcons_int(), lcons_oid(), list_concat_copy(), list_copy(), list_copy_deep(), list_copy_tail(), list_make1_impl(), list_make2_impl(), list_make3_impl(), list_make4_impl(), list_make5_impl(), pg_parse_query(), and pg_rewrite_query().

89 {
90  List *newlist;
91  int max_size;
92 
93  Assert(min_size > 0);
94 
95  /*
96  * We allocate all the requested cells, and possibly some more, as part of
97  * the same palloc request as the List header. This is a big win for the
98  * typical case of short fixed-length lists. It can lose if we allocate a
99  * moderately long list and then it gets extended; we'll be wasting more
100  * initial_elements[] space than if we'd made the header small. However,
101  * rounding up the request as we do in the normal code path provides some
102  * defense against small extensions.
103  */
104 
105 #ifndef DEBUG_LIST_MEMORY_USAGE
106 
107  /*
108  * Normally, we set up a list with some extra cells, to allow it to grow
109  * without a repalloc. Prefer cell counts chosen to make the total
110  * allocation a power-of-2, since palloc would round it up to that anyway.
111  * (That stops being true for very large allocations, but very long lists
112  * are infrequent, so it doesn't seem worth special logic for such cases.)
113  *
114  * The minimum allocation is 8 ListCell units, providing either 4 or 5
115  * available ListCells depending on the machine's word width. Counting
116  * palloc's overhead, this uses the same amount of space as a one-cell
117  * list did in the old implementation, and less space for any longer list.
118  *
119  * We needn't worry about integer overflow; no caller passes min_size
120  * that's more than twice the size of an existing list, so the size limits
121  * within palloc will ensure that we don't overflow here.
122  */
123  max_size = pg_nextpower2_32(Max(8, min_size + LIST_HEADER_OVERHEAD));
124  max_size -= LIST_HEADER_OVERHEAD;
125 #else
126 
127  /*
128  * For debugging, don't allow any extra space. This forces any cell
129  * addition to go through enlarge_list() and thus move the existing data.
130  */
131  max_size = min_size;
132 #endif
133 
134  newlist = (List *) palloc(offsetof(List, initial_elements) +
135  max_size * sizeof(ListCell));
136  newlist->type = type;
137  newlist->length = min_size;
138  newlist->max_length = max_size;
139  newlist->elements = newlist->initial_elements;
140 
141  return newlist;
142 }
#define LIST_HEADER_OVERHEAD
Definition: list.c:47
static uint32 pg_nextpower2_32(uint32 num)
Definition: pg_bitutils.h:146
union ListCell ListCell
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
#define Max(x, y)
Definition: c.h:980
#define Assert(condition)
Definition: c.h:804
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52
void * palloc(Size size)
Definition: mcxt.c:1062
ListCell initial_elements[FLEXIBLE_ARRAY_MEMBER]
Definition: pg_list.h:57
Definition: pg_list.h:50
#define offsetof(type, field)
Definition: c.h:727

◆ new_tail_cell()

static void new_tail_cell ( List list)
static

Definition at line 320 of file list.c.

References enlarge_list(), List::length, and List::max_length.

Referenced by lappend(), lappend_int(), and lappend_oid().

321 {
322  /* Enlarge array if necessary */
323  if (list->length >= list->max_length)
324  enlarge_list(list, list->length + 1);
325  list->length++;
326 }
static void enlarge_list(List *list, int min_size)
Definition: list.c:152
int max_length
Definition: pg_list.h:54
int length
Definition: pg_list.h:53