Header And Logo

PostgreSQL
| The world's most advanced open source database.

Defines | Functions

list.c File Reference

#include "postgres.h"
#include "nodes/pg_list.h"
Include dependency graph for list.c:

Go to the source code of this file.

Defines

#define PG_LIST_INCLUDE_DEFINITIONS
#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)

Functions

static Listnew_list (NodeTag type)
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 ListCelladd_new_cell (List *list, ListCell *prev_cell)
ListCelllappend_cell (List *list, ListCell *prev, void *datum)
ListCelllappend_cell_int (List *list, ListCell *prev, int datum)
ListCelllappend_cell_oid (List *list, ListCell *prev, Oid datum)
Listlcons (void *datum, List *list)
Listlcons_int (int datum, List *list)
Listlcons_oid (Oid datum, List *list)
Listlist_concat (List *list1, List *list2)
Listlist_truncate (List *list, int new_size)
static ListCelllist_nth_cell (const List *list, int n)
void * list_nth (const List *list, int n)
int list_nth_int (const List *list, int n)
Oid list_nth_oid (const List *list, int n)
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_cell (List *list, ListCell *cell, ListCell *prev)
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_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_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, List *list2)
Listlist_concat_unique_ptr (List *list1, List *list2)
Listlist_concat_unique_int (List *list1, List *list2)
Listlist_concat_unique_oid (List *list1, List *list2)
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)
int length (const List *list)

Define Documentation

#define check_list_invariants (   l  ) 
#define IsIntegerList (   l  )     ((l) == NIL || IsA((l), IntList))
#define IsOidList (   l  )     ((l) == NIL || IsA((l), OidList))
#define IsPointerList (   l  )     ((l) == NIL || IsA((l), List))
#define PG_LIST_INCLUDE_DEFINITIONS

Definition at line 19 of file list.c.


Function Documentation

static ListCell* add_new_cell ( List list,
ListCell prev_cell 
) [static]

Definition at line 188 of file list.c.

References List::length, ListCell::next, palloc(), and List::tail.

Referenced by lappend_cell(), lappend_cell_int(), and lappend_cell_oid().

{
    ListCell   *new_cell;

    new_cell = (ListCell *) palloc(sizeof(*new_cell));
    /* new_cell->data is left undefined! */
    new_cell->next = prev_cell->next;
    prev_cell->next = new_cell;

    if (list->tail == prev_cell)
        list->tail = new_cell;

    list->length++;

    return new_cell;
}

List* lappend ( List list,
void *  datum 
)

Definition at line 131 of file list.c.

References Assert, check_list_invariants, IsPointerList, lfirst, new_list(), new_tail_cell(), NIL, T_List, and List::tail.

Referenced by _SPI_make_plan_non_temp(), _SPI_prepare_oneshot_plan(), _SPI_prepare_plan(), _SPI_save_plan(), accumulate_append_subpath(), AcquireRewriteLocks(), add_dummy_return(), add_eq_member(), add_join_clause_to_rels(), add_lateral_info(), add_placeholders_to_base_rels(), add_placeholders_to_joinrel(), add_to_flat_tlist(), add_unique_group_var(), add_vars_to_targetlist(), addArc(), addFamilyMember(), addKey(), addKeyToQueue(), addRangeTableEntry(), addRangeTableEntryForCTE(), addRangeTableEntryForFunction(), addRangeTableEntryForJoin(), addRangeTableEntryForRelation(), addRangeTableEntryForSubquery(), addRangeTableEntryForValues(), AddRelationNewConstraints(), addRTEtoQuery(), addTargetToGroupList(), addTargetToSortList(), adjust_inherited_tlist(), AlterTSDictionary(), analyzeCTETargetList(), applyLockingClause(), ApplyRetrieveRule(), assign_param_for_placeholdervar(), assign_param_for_var(), Async_Notify(), ATAddCheckConstraint(), ATAddForeignKeyConstraint(), ATExecAddColumn(), ATExecAlterColumnType(), ATExecDropInherit(), ATGetQueueEntry(), ATPostAlterTypeParse(), ATPrepAlterColumnType(), ATPrepCmd(), btcostestimate(), build_aggregate_fnexprs(), build_coercion_expression(), build_index_pathkeys(), build_index_paths(), build_index_tlist(), build_join_rel(), build_joinrel_tlist(), build_physical_tlist(), build_relation_tlist(), build_subplan(), BuildEventTriggerCache(), buildRelationAliases(), cached_scansel(), calc_joinrel_size_estimate(), check_partial_indexes(), check_selective_binary_conversion(), check_sql_fn_retval(), checkInsertTargets(), checkSharedDependencies(), checkWellFormedRecursionWalker(), choose_bitmap_and(), ChooseIndexColumnNames(), classifyConditions(), coerce_record_to_complex(), compute_common_attribute(), compute_semi_anti_join_factors(), ComputeIndexAttrs(), convert_ANY_sublink_to_join(), convert_EXISTS_to_ANY(), convert_subquery_pathkeys(), ConvertTriggerToFK(), create_append_plan(), create_bitmap_scan_plan(), create_bitmap_subplan(), create_index_paths(), create_indexscan_plan(), create_join_clause(), create_merge_append_plan(), create_nestloop_path(), create_nestloop_plan(), create_unique_path(), create_unique_plan(), CreateLockFile(), database_to_xmlschema_internal(), deconstruct_recurse(), DefineRelation(), DefineSequence(), DefineTSDictionary(), DefineVirtualRelation(), deparseParam(), deparseVar(), deserialize_deflist(), determineRecursiveColTypes(), distribute_qual_to_rels(), distribute_restrictinfo_to_rels(), drop_indexable_join_clauses(), eval_const_expressions_mutator(), EvalPlanQualStart(), examine_parameter_list(), Exec_ListenCommit(), ExecAllocTableSlot(), ExecBuildProjectionInfo(), ExecEvalXml(), ExecGetTriggerResultRel(), ExecInitExpr(), ExecInitHashJoin(), ExecInitLockRows(), ExecInitModifyTable(), ExecInitNode(), ExecInitSubPlan(), ExecuteGrantStmt(), ExecuteTruncate(), expand_indexqual_conditions(), expand_inherited_rtentry(), expand_targetlist(), expandRelAttrs(), ExpandRowReference(), expandRTE(), expandTupleDesc(), ExportSnapshot(), expression_tree_mutator(), extract_actual_clauses(), extract_actual_join_clauses(), extract_lateral_references(), extractRemainingColumns(), file_fdw_validator(), find_duplicate_ors(), find_list_position(), find_mergeclauses_for_pathkeys(), find_minmax_aggs_walker(), find_placeholder_info(), find_window_functions_walker(), findTargetlistEntrySQL99(), fireRIRrules(), fireRules(), fix_indexorderby_references(), fix_indexqual_references(), flatten_join_alias_vars_mutator(), flatten_join_using_qual(), flatten_simple_union_all(), func_get_detail(), generate_append_tlist(), generate_bitmap_or_paths(), generate_implied_equalities_for_column(), generate_join_implied_equalities_broken(), generate_join_implied_equalities_normal(), generate_setop_tlist(), generate_subquery_params(), generate_subquery_vars(), generateClonedIndexStmt(), get_actual_clauses(), get_agg_expr(), get_all_actual_clauses(), get_appendrel_parampathinfo(), get_baserel_parampathinfo(), get_column_info_for_window(), get_database_list(), get_eclass_for_sort_expr(), get_ext_ver_info(), get_ext_ver_list(), get_file_fdw_attribute_options(), get_func_expr(), get_index_paths(), get_insert_query_def(), get_join_index_paths(), get_joinrel_parampathinfo(), get_op_btree_interpretation(), get_relation_constraints(), get_sortgrouplist_exprs(), get_switched_clauses(), get_tlist_exprs(), getState(), gistFindPath(), gistfixsplit(), gistplacetopage(), hash_inner_and_outer(), heap_truncate(), index_check_primary_key(), inheritance_planner(), init_execution_state(), init_sql_fcache(), InitPlan(), intorel_startup(), join_is_removable(), 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(), load_hba(), load_ident(), log_incomplete_deletion(), log_incomplete_split(), make_canonical_pathkey(), make_inh_translation_list(), make_inner_pathkeys_for_merge(), make_modifytable(), make_pathkeys_for_sortclauses(), make_rel_from_joinlist(), make_restrictinfo_from_bitmapqual(), make_restrictinfos_from_actual_clauses(), make_row_comparison_op(), make_setop_translation_list(), make_sub_restrictinfos(), make_subplanTargetList(), make_windowInputTargetList(), makeDependencyGraphWalker(), match_join_clauses_to_index(), match_pathkeys_to_index(), matchLocks(), merge_clump(), MergeAttributes(), mergeStates(), negate_clause(), network_prefix_quals(), next_field_expand(), nodeRead(), order_qual_clauses(), parse_hba_line(), ParseFuncOrColumn(), perform_base_backup(), pg_plan_queries(), postgresAddForeignUpdateTargets(), postgresGetForeignPaths(), postgresGetForeignPlan(), prefix_quals(), prepare_sort_from_pathkeys(), preprocess_groupclause(), preprocess_rowmarks(), preprocess_targetlist(), process_duplicate_ors(), process_equivalence(), process_pipe_input(), process_sublinks_mutator(), process_subquery_nestloop_params(), ProcessStartupPacket(), pull_ands(), pull_ors(), pull_up_sublinks_jointree_recurse(), pull_up_sublinks_qual_recurse(), pull_up_union_leaf_queries(), pull_var_clause_walker(), pull_vars_walker(), push_ancestor_plan(), pushIncompleteSplit(), QueryRewrite(), queue_listen(), range_table_mutator(), record_plan_function_dependency(), reduce_outer_joins_pass1(), register_label_provider(), relation_excluded_by_constraints(), relation_has_unique_index_for(), RelationCacheInvalidate(), RememberFsyncRequest(), remove_rel_from_joinlist(), reorder_function_arguments(), replace_nestloop_params_mutator(), replace_outer_agg(), resetSpGistScanOpaque(), RewriteQuery(), rewriteTargetListIU(), rewriteTargetListUD(), rewriteTargetView(), rewriteValuesRTE(), schema_to_xmlschema_internal(), SearchCatCacheList(), select_active_windows(), select_mergejoin_clauses(), select_outer_pathkeys_for_merge(), sepgsql_set_client_label(), set_append_rel_pathlist(), set_cheapest(), set_deparse_for_query(), set_dummy_tlist_references(), set_plan_references(), set_plan_refs(), set_rtable_names(), set_simple_column_names(), set_subquery_pathlist(), set_upper_references(), set_using_names(), show_plan_tlist(), show_sort_keys_common(), simplify_and_arguments(), simplify_or_arguments(), SplitDirectoriesString(), SplitIdentifierString(), SS_make_initplan_from_plan(), SS_process_ctes(), StandbyAcquireAccessExclusiveLock(), stringToQualifiedNameList(), subquery_planner(), textToQualifiedNameList(), tokenize_file(), tokenize_inc_file(), transformAExprIn(), transformAggregateCall(), transformAlterTableStmt(), transformArrayExpr(), transformArraySubscripts(), transformAssignmentIndirection(), transformCaseExpr(), transformCoalesceExpr(), transformColumnDefinition(), transformCreateSchemaStmt(), transformCreateStmt(), transformDistinctClause(), transformDistinctOnClause(), transformExpressionList(), transformFKConstraints(), transformFkeyGetPrimaryKey(), transformFromClause(), transformFromClauseItem(), transformFuncCall(), transformGenericOptions(), transformGroupClause(), transformIndexConstraint(), transformIndexConstraints(), transformIndirection(), transformInsertRow(), transformInsertStmt(), transformMinMaxExpr(), transformOfType(), transformRowExpr(), transformRuleStmt(), transformSetOperationStmt(), transformSetOperationTree(), transformSubLink(), transformTableConstraint(), transformTableLikeClause(), transformTargetList(), transformValuesClause(), transformWindowDefinitions(), transformWindowFuncCall(), transformWithClause(), transformXmlExpr(), untransformRelOptions(), and xmlelement().

{
    Assert(IsPointerList(list));

    if (list == NIL)
        list = new_list(T_List);
    else
        new_tail_cell(list);

    lfirst(list->tail) = datum;
    check_list_invariants(list);
    return list;
}

ListCell* lappend_cell ( List list,
ListCell prev,
void *  datum 
)

Definition at line 212 of file list.c.

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

Referenced by add_path(), and merge_clump().

{
    ListCell   *new_cell;

    Assert(IsPointerList(list));

    new_cell = add_new_cell(list, prev);
    lfirst(new_cell) = datum;
    check_list_invariants(list);
    return new_cell;
}

ListCell* lappend_cell_int ( List list,
ListCell prev,
int  datum 
)

Definition at line 225 of file list.c.

References add_new_cell(), Assert, check_list_invariants, IsIntegerList, and lfirst_int.

{
    ListCell   *new_cell;

    Assert(IsIntegerList(list));

    new_cell = add_new_cell(list, prev);
    lfirst_int(new_cell) = datum;
    check_list_invariants(list);
    return new_cell;
}

ListCell* lappend_cell_oid ( List list,
ListCell prev,
Oid  datum 
)

Definition at line 238 of file list.c.

References add_new_cell(), Assert, check_list_invariants, IsOidList, and lfirst_oid.

Referenced by insert_ordered_oid(), and insert_ordered_unique_oid().

{
    ListCell   *new_cell;

    Assert(IsOidList(list));

    new_cell = add_new_cell(list, prev);
    lfirst_oid(new_cell) = datum;
    check_list_invariants(list);
    return new_cell;
}

List* lappend_int ( List list,
int  datum 
)
List* lappend_oid ( List list,
Oid  datum 
)

Definition at line 167 of file list.c.

References Assert, check_list_invariants, IsOidList, lfirst_oid, new_list(), new_tail_cell(), NIL, T_OidList, and List::tail.

Referenced by addRangeTableEntryForFunction(), adjust_rowcompare_for_index(), AfterTriggerSetState(), analyzeCTETargetList(), ApplyExtensionUpdates(), assign_collations_walker(), ATExecAlterColumnType(), check_functional_grouping(), CommuteRowCompareExpr(), convert_EXISTS_to_ANY(), create_empty_extension(), create_unique_path(), CreateExtension(), do_autovacuum(), EventTriggerCommonSetup(), ExecAlterDefaultPrivilegesStmt(), ExecInitHashJoin(), ExecInsertIndexTuples(), ExecuteGrantStmt(), ExecuteTruncate(), extract_query_dependencies_walker(), find_all_inheritors(), find_inheritance_children(), find_typed_table_dependencies(), fix_expr_common(), get_mergejoin_opfamilies(), get_rel_oids(), getOwnedSequences(), getRelationsInNamespace(), heap_truncate_check_FKs(), list_append_unique_oid(), list_concat_unique_oid(), list_difference_oid(), list_union_oid(), make_row_comparison_op(), MergeAttributes(), nodeRead(), objectNamesToOids(), objectsInSchemaToOids(), PreCommit_on_commit_actions(), query_to_oid_list(), recomputeNamespacePath(), reindex_relation(), ReindexDatabase(), roleNamesToIds(), set_plan_references(), transformSetOperationTree(), transformValuesClause(), and typeInheritsFrom().

{
    Assert(IsOidList(list));

    if (list == NIL)
        list = new_list(T_OidList);
    else
        new_tail_cell(list);

    lfirst_oid(list->tail) = datum;
    check_list_invariants(list);
    return list;
}

List* lcons ( void *  datum,
List list 
)
List* lcons_int ( int  datum,
List list 
)

Definition at line 280 of file list.c.

References Assert, check_list_invariants, List::head, IsIntegerList, lfirst_int, new_head_cell(), new_list(), NIL, and T_IntList.

Referenced by ExplainBeginOutput(), ExplainOpenGroup(), and find_hash_columns().

{
    Assert(IsIntegerList(list));

    if (list == NIL)
        list = new_list(T_IntList);
    else
        new_head_cell(list);

    lfirst_int(list->head) = datum;
    check_list_invariants(list);
    return list;
}

List* lcons_oid ( Oid  datum,
List list 
)
int length ( const List list  ) 
List* list_append_unique ( List list,
void *  datum 
)

Definition at line 939 of file list.c.

References lappend(), and list_member().

{
    if (list_member(list, datum))
        return list;
    else
        return lappend(list, datum);
}

List* list_append_unique_int ( List list,
int  datum 
)

Definition at line 964 of file list.c.

References lappend_int(), and list_member_int().

{
    if (list_member_int(list, datum))
        return list;
    else
        return lappend_int(list, datum);
}

List* list_append_unique_oid ( List list,
Oid  datum 
)

Definition at line 976 of file list.c.

References lappend_oid(), and list_member_oid().

Referenced by is_admin_of_role(), map_sql_typecoll_to_xmlschema_types(), roles_has_privs_of(), and roles_is_member_of().

{
    if (list_member_oid(list, datum))
        return list;
    else
        return lappend_oid(list, datum);
}

List* list_append_unique_ptr ( List list,
void *  datum 
)

Definition at line 952 of file list.c.

References lappend(), and list_member_ptr().

Referenced by match_clause_to_index(), subbuild_joinrel_joinlist(), and subbuild_joinrel_restrictlist().

{
    if (list_member_ptr(list, datum))
        return list;
    else
        return lappend(list, datum);
}

List* list_concat ( List list1,
List list2 
)

Definition at line 324 of file list.c.

References Assert, check_list_invariants, elog, ERROR, List::head, List::length, ListCell::next, NIL, List::tail, and List::type.

Referenced by accumulate_append_subpath(), add_function_defaults(), add_predicate_to_quals(), addRangeTableEntryForJoin(), ATPostAlterTypeParse(), AtSubCommit_Notify(), build_joinrel_restrictlist(), build_paths_for_OR(), check_partial_indexes(), check_sql_fn_retval(), choose_bitmap_and(), convert_EXISTS_sublink_to_join(), cost_index(), create_bitmap_subplan(), create_index_paths(), create_join_plan(), create_or_index_quals(), create_scan_plan(), deconstruct_recurse(), DefineRelation(), expand_indexqual_conditions(), expand_inherited_rtentry(), ExpandAllTables(), fileBeginForeignScan(), fileGetOptions(), find_forced_null_vars(), find_indexpath_quals(), find_mergeclauses_for_pathkeys(), find_nonnullable_vars_walker(), fmgr_sql_validator(), generate_bitmap_or_paths(), generate_join_implied_equalities(), generate_join_implied_equalities_normal(), generate_union_plan(), get_baserel_parampathinfo(), get_index_paths(), get_join_index_paths(), get_joinrel_parampathinfo(), get_parameterized_baserel_size(), get_relation_constraints(), get_rels_with_domain(), gincostestimate(), inheritance_planner(), init_sql_fcache(), inline_set_returning_function(), make_pathkeys_for_window(), make_restrictinfo_from_bitmapqual(), mergeStates(), objectsInSchemaToOids(), process_equivalence(), process_matched_tle(), process_sublinks_mutator(), pull_ands(), pull_ors(), pull_up_simple_subquery(), pull_up_simple_union_all(), recurse_union_children(), reduce_outer_joins_pass2(), RewriteQuery(), rewriteRuleAction(), rewriteTargetListIU(), selectColorTrigrams(), set_plan_refs(), set_subqueryscan_references(), simplify_and_arguments(), simplify_or_arguments(), TidQualFromExpr(), transformAExprIn(), transformAlterTableStmt(), transformCreateSchemaStmt(), transformCreateStmt(), transformExpressionList(), transformFromClause(), transformFromClauseItem(), and transformTargetList().

{
    if (list1 == NIL)
        return list2;
    if (list2 == NIL)
        return list1;
    if (list1 == list2)
        elog(ERROR, "cannot list_concat() a list to itself");

    Assert(list1->type == list2->type);

    list1->length += list2->length;
    list1->tail->next = list2->head;
    list1->tail = list2->tail;

    check_list_invariants(list1);
    return list1;
}

List* list_concat_unique ( List list1,
List list2 
)

Definition at line 995 of file list.c.

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

Referenced by create_bitmap_subplan(), and make_restrictinfo_from_bitmapqual().

{
    ListCell   *cell;

    Assert(IsPointerList(list1));
    Assert(IsPointerList(list2));

    foreach(cell, list2)
    {
        if (!list_member(list1, lfirst(cell)))
            list1 = lappend(list1, lfirst(cell));
    }

    check_list_invariants(list1);
    return list1;
}

List* list_concat_unique_int ( List list1,
List list2 
)

Definition at line 1038 of file list.c.

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

{
    ListCell   *cell;

    Assert(IsIntegerList(list1));
    Assert(IsIntegerList(list2));

    foreach(cell, list2)
    {
        if (!list_member_int(list1, lfirst_int(cell)))
            list1 = lappend_int(list1, lfirst_int(cell));
    }

    check_list_invariants(list1);
    return list1;
}

List* list_concat_unique_oid ( List list1,
List list2 
)

Definition at line 1059 of file list.c.

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

{
    ListCell   *cell;

    Assert(IsOidList(list1));
    Assert(IsOidList(list2));

    foreach(cell, list2)
    {
        if (!list_member_oid(list1, lfirst_oid(cell)))
            list1 = lappend_oid(list1, lfirst_oid(cell));
    }

    check_list_invariants(list1);
    return list1;
}

List* list_concat_unique_ptr ( List list1,
List list2 
)

Definition at line 1017 of file list.c.

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

Referenced by make_agg_subplan().

{
    ListCell   *cell;

    Assert(IsPointerList(list1));
    Assert(IsPointerList(list2));

    foreach(cell, list2)
    {
        if (!list_member_ptr(list1, lfirst(cell)))
            list1 = lappend(list1, lfirst(cell));
    }

    check_list_invariants(list1);
    return list1;
}

List* list_copy ( const List oldlist  ) 

Definition at line 1137 of file list.c.

References check_list_invariants, ListCell::data, List::head, List::length, new_list(), ListCell::next, NIL, palloc(), List::tail, and List::type.

Referenced by accumulate_append_subpath(), add_function_defaults(), adjust_rowcompare_for_index(), arrayconst_startup_fn(), arrayexpr_startup_fn(), build_minmax_path(), build_paths_for_OR(), build_subplan(), check_partial_indexes(), choose_bitmap_and(), copyObject(), CopyOverrideSearchPath(), cost_index(), create_scan_plan(), does_not_exist_skipping(), expression_tree_mutator(), fetch_search_path(), find_indexpath_quals(), generate_bitmap_or_paths(), get_eclass_for_sort_expr(), get_object_address_attribute(), get_object_address_relobject(), get_parameterized_baserel_size(), get_query_def(), get_switched_clauses(), GetOverrideSearchPath(), init_sql_fcache(), list_difference(), list_difference_int(), list_difference_oid(), list_difference_ptr(), list_union(), list_union_int(), list_union_oid(), list_union_ptr(), make_pathkeys_for_window(), make_restrictinfo_from_bitmapqual(), make_subplanTargetList(), match_unsorted_outer(), process_matched_tle(), process_owned_by(), PushOverrideSearchPath(), recomputeNamespacePath(), RelationGetIndexList(), RelationSetIndexList(), remove_rel_from_query(), roles_has_privs_of(), roles_is_member_of(), select_outer_pathkeys_for_merge(), set_plan_refs(), SetReindexPending(), simplify_and_arguments(), simplify_or_arguments(), sort_inner_and_outer(), transformWithClause(), and truncate_useless_pathkeys().

{
    List       *newlist;
    ListCell   *newlist_prev;
    ListCell   *oldlist_cur;

    if (oldlist == NIL)
        return NIL;

    newlist = new_list(oldlist->type);
    newlist->length = oldlist->length;

    /*
     * Copy over the data in the first cell; new_list() has already allocated
     * the head cell itself
     */
    newlist->head->data = oldlist->head->data;

    newlist_prev = newlist->head;
    oldlist_cur = oldlist->head->next;
    while (oldlist_cur)
    {
        ListCell   *newlist_cur;

        newlist_cur = (ListCell *) palloc(sizeof(*newlist_cur));
        newlist_cur->data = oldlist_cur->data;
        newlist_prev->next = newlist_cur;

        newlist_prev = newlist_cur;
        oldlist_cur = oldlist_cur->next;
    }

    newlist_prev->next = NULL;
    newlist->tail = newlist_prev;

    check_list_invariants(newlist);
    return newlist;
}

List* list_copy_tail ( const List oldlist,
int  nskip 
)

Definition at line 1180 of file list.c.

References check_list_invariants, ListCell::data, List::head, List::length, new_list(), ListCell::next, NIL, palloc(), List::tail, and List::type.

Referenced by addRangeTableEntryForJoin(), find_expr_references_walker(), get_name_for_var_field(), inheritance_planner(), and ParseFuncOrColumn().

{
    List       *newlist;
    ListCell   *newlist_prev;
    ListCell   *oldlist_cur;

    if (nskip < 0)
        nskip = 0;              /* would it be better to elog? */

    if (oldlist == NIL || nskip >= oldlist->length)
        return NIL;

    newlist = new_list(oldlist->type);
    newlist->length = oldlist->length - nskip;

    /*
     * Skip over the unwanted elements.
     */
    oldlist_cur = oldlist->head;
    while (nskip-- > 0)
        oldlist_cur = oldlist_cur->next;

    /*
     * Copy over the data in the first remaining cell; new_list() has already
     * allocated the head cell itself
     */
    newlist->head->data = oldlist_cur->data;

    newlist_prev = newlist->head;
    oldlist_cur = oldlist_cur->next;
    while (oldlist_cur)
    {
        ListCell   *newlist_cur;

        newlist_cur = (ListCell *) palloc(sizeof(*newlist_cur));
        newlist_cur->data = oldlist_cur->data;
        newlist_prev->next = newlist_cur;

        newlist_prev = newlist_cur;
        oldlist_cur = oldlist_cur->next;
    }

    newlist_prev->next = NULL;
    newlist->tail = newlist_prev;

    check_list_invariants(newlist);
    return newlist;
}

List* list_delete ( List list,
void *  datum 
)

Definition at line 570 of file list.c.

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

{
    ListCell   *cell;
    ListCell   *prev;

    Assert(IsPointerList(list));
    check_list_invariants(list);

    prev = NULL;
    foreach(cell, list)
    {
        if (equal(lfirst(cell), datum))
            return list_delete_cell(list, cell, prev);

        prev = cell;
    }

    /* Didn't find a match: return the list unmodified */
    return list;
}

List* list_delete_cell ( List list,
ListCell cell,
ListCell prev 
)

Definition at line 531 of file list.c.

References Assert, check_list_invariants, List::head, List::length, list_free(), list_head(), lnext, ListCell::next, NULL, pfree(), and List::tail.

Referenced by add_path(), addKey(), AlterTSDictionary(), AtEOSubXact_on_commit_actions(), AtEOXact_on_commit_actions(), choose_bitmap_and(), create_nestloop_plan(), Exec_UnlistenCommit(), fileGetOptions(), list_delete(), list_delete_first(), list_delete_int(), list_delete_oid(), list_delete_ptr(), merge_clump(), MergeAttributes(), reconsider_outer_join_clauses(), RememberFsyncRequest(), select_active_windows(), sepgsql_avc_reclaim(), sepgsql_subxact_callback(), SetClientEncoding(), StandbyReleaseAllLocks(), StandbyReleaseLocks(), StandbyReleaseOldLocks(), and transformGenericOptions().

{
    check_list_invariants(list);
    Assert(prev != NULL ? lnext(prev) == cell : list_head(list) == cell);

    /*
     * If we're about to delete the last node from the list, free the whole
     * list instead and return NIL, which is the only valid representation of
     * a zero-length list.
     */
    if (list->length == 1)
    {
        list_free(list);
        return NIL;
    }

    /*
     * Otherwise, adjust the necessary list links, deallocate the particular
     * node we have just removed, and return the list we were given.
     */
    list->length--;

    if (prev)
        prev->next = cell->next;
    else
        list->head = cell->next;

    if (list->tail == cell)
        list->tail = prev;

    pfree(cell);
    return list;
}

List* list_delete_first ( List list  ) 
List* list_delete_int ( List list,
int  datum 
)

Definition at line 616 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lfirst_int, and list_delete_cell().

{
    ListCell   *cell;
    ListCell   *prev;

    Assert(IsIntegerList(list));
    check_list_invariants(list);

    prev = NULL;
    foreach(cell, list)
    {
        if (lfirst_int(cell) == datum)
            return list_delete_cell(list, cell, prev);

        prev = cell;
    }

    /* Didn't find a match: return the list unmodified */
    return list;
}

List* list_delete_oid ( List list,
Oid  datum 
)

Definition at line 639 of file list.c.

References Assert, check_list_invariants, IsOidList, lfirst_oid, and list_delete_cell().

Referenced by RemoveReindexPending().

{
    ListCell   *cell;
    ListCell   *prev;

    Assert(IsOidList(list));
    check_list_invariants(list);

    prev = NULL;
    foreach(cell, list)
    {
        if (lfirst_oid(cell) == datum)
            return list_delete_cell(list, cell, prev);

        prev = cell;
    }

    /* Didn't find a match: return the list unmodified */
    return list;
}

List* list_delete_ptr ( List list,
void *  datum 
)
List* list_difference ( const List list1,
const List list2 
)

Definition at line 835 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(), and process_duplicate_ors().

{
    const ListCell *cell;
    List       *result = NIL;

    Assert(IsPointerList(list1));
    Assert(IsPointerList(list2));

    if (list2 == NIL)
        return list_copy(list1);

    foreach(cell, list1)
    {
        if (!list_member(list2, lfirst(cell)))
            result = lappend(result, lfirst(cell));
    }

    check_list_invariants(result);
    return result;
}

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

Definition at line 886 of file list.c.

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

{
    const ListCell *cell;
    List       *result = NIL;

    Assert(IsIntegerList(list1));
    Assert(IsIntegerList(list2));

    if (list2 == NIL)
        return list_copy(list1);

    foreach(cell, list1)
    {
        if (!list_member_int(list2, lfirst_int(cell)))
            result = lappend_int(result, lfirst_int(cell));
    }

    check_list_invariants(result);
    return result;
}

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

Definition at line 911 of file list.c.

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

{
    const ListCell *cell;
    List       *result = NIL;

    Assert(IsOidList(list1));
    Assert(IsOidList(list2));

    if (list2 == NIL)
        return list_copy(list1);

    foreach(cell, list1)
    {
        if (!list_member_oid(list2, lfirst_oid(cell)))
            result = lappend_oid(result, lfirst_oid(cell));
    }

    check_list_invariants(result);
    return result;
}

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

Definition at line 861 of file list.c.

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

Referenced by cost_index(), and create_bitmap_scan_plan().

{
    const ListCell *cell;
    List       *result = NIL;

    Assert(IsPointerList(list1));
    Assert(IsPointerList(list2));

    if (list2 == NIL)
        return list_copy(list1);

    foreach(cell, list1)
    {
        if (!list_member_ptr(list2, lfirst(cell)))
            result = lappend(result, lfirst(cell));
    }

    check_list_invariants(result);
    return result;
}

void list_free ( List list  ) 

Definition at line 1110 of file list.c.

References list_free_private().

Referenced by AfterTriggerSetState(), AlterIndexNamespaces(), arrayconst_cleanup_fn(), arrayexpr_cleanup_fn(), AtEOSubXact_cleanup(), AtEOSubXact_Namespace(), AtEOXact_cleanup(), AtEOXact_Namespace(), ATExecChangeOwner(), ATExecDropNotNull(), build_base_rel_tlists(), calc_joinrel_size_estimate(), calculate_indexes_size(), check_datestyle(), check_log_destination(), check_search_path(), check_synchronous_standby_names(), check_temp_tablespaces(), choose_bitmap_and(), compute_semi_anti_join_factors(), CopyFrom(), CopyFromInsertBatch(), CreateExtension(), current_schema(), current_schemas(), distribute_qual_to_rels(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerSQLDrop(), ExecInsert(), ExecOpenIndices(), ExecResetTupleTable(), ExecUpdate(), extract_lateral_references(), find_all_inheritors(), find_expr_references_walker(), fix_placeholder_input_needed_levels(), flatten_tlist(), freeScanStack(), generate_base_implied_equalities_no_const(), get_relation_info(), is_admin_of_role(), list_delete_cell(), load_libraries(), make_pathkeys_for_window(), make_subplanTargetList(), make_windowInputTargetList(), mark_placeholders_in_expr(), OverrideSearchPathMatchesCurrent(), pop_ancestor_plan(), PopOverrideSearchPath(), PostmasterMain(), prepare_sort_from_pathkeys(), PrepareTempTablespaces(), preprocess_targetlist(), qual_is_pushdown_safe(), recomputeNamespacePath(), RelationCacheInvalidate(), RelationDestroyRelation(), RelationGetIndexAttrBitmap(), RelationGetOidIndex(), relationHasPrimaryKey(), RelationSetIndexList(), roles_has_privs_of(), roles_is_member_of(), sepgsql_dml_privileges(), stringToQualifiedNameList(), SyncRepGetStandbyPriority(), textToQualifiedNameList(), TidQualFromExpr(), transformFkeyCheckAttrs(), transformFkeyGetPrimaryKey(), transformValuesClause(), triggered_change_notification(), typeInheritsFrom(), and vac_open_indexes().

{
    list_free_private(list, false);
}

void list_free_deep ( List list  ) 

Definition at line 1124 of file list.c.

References Assert, IsPointerList, and list_free_private().

Referenced by checkSharedDependencies(), Exec_UnlistenAllCommit(), get_btree_test_op(), gistbufferinginserttuples(), PostmasterMain(), rescanLatestTimeLine(), StartReplication(), and XLogSend().

{
    /*
     * A "deep" free operation only makes sense on a list of pointers.
     */
    Assert(IsPointerList(list));
    list_free_private(list, true);
}

static void list_free_private ( List list,
bool  deep 
) [static]

Definition at line 1080 of file list.c.

References check_list_invariants, lfirst, list_head(), lnext, NULL, and pfree().

Referenced by list_free(), and list_free_deep().

{
    ListCell   *cell;

    check_list_invariants(list);

    cell = list_head(list);
    while (cell != NULL)
    {
        ListCell   *tmp = cell;

        cell = lnext(cell);
        if (deep)
            pfree(lfirst(tmp));
        pfree(tmp);
    }

    if (list)
        pfree(list);
}

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

Definition at line 803 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().

{
    List       *result;
    const ListCell *cell;

    if (list1 == NIL || list2 == NIL)
        return NIL;

    Assert(IsPointerList(list1));
    Assert(IsPointerList(list2));

    result = NIL;
    foreach(cell, list1)
    {
        if (list_member(list2, lfirst(cell)))
            result = lappend(result, lfirst(cell));
    }

    check_list_invariants(result);
    return result;
}

bool list_member ( const List list,
const void *  datum 
)
bool list_member_int ( const List list,
int  datum 
)
bool list_member_oid ( const List list,
Oid  datum 
)
bool list_member_ptr ( const List list,
const void *  datum 
)
void* list_nth ( const List list,
int  n 
)
static ListCell* list_nth_cell ( const List list,
int  n 
) [static]

Definition at line 389 of file list.c.

References Assert, check_list_invariants, List::head, List::length, length(), ListCell::next, NIL, and List::tail.

Referenced by list_nth(), list_nth_int(), and list_nth_oid().

{
    ListCell   *match;

    Assert(list != NIL);
    Assert(n >= 0);
    Assert(n < list->length);
    check_list_invariants(list);

    /* Does the caller actually mean to fetch the tail? */
    if (n == list->length - 1)
        return list->tail;

    for (match = list->head; n-- > 0; match = match->next)
        ;

    return match;
}

int list_nth_int ( const List list,
int  n 
)

Definition at line 424 of file list.c.

References Assert, IsIntegerList, lfirst_int, and list_nth_cell().

Referenced by create_ctescan_plan(), get_rte_attribute_type(), and set_cte_pathlist().

{
    Assert(IsIntegerList(list));
    return lfirst_int(list_nth_cell(list, n));
}

Oid list_nth_oid ( const List list,
int  n 
)

Definition at line 435 of file list.c.

References Assert, IsOidList, lfirst_oid, and list_nth_cell().

Referenced by get_rte_attribute_type().

{
    Assert(IsOidList(list));
    return lfirst_oid(list_nth_cell(list, n));
}

List* list_truncate ( List list,
int  new_size 
)

Definition at line 353 of file list.c.

References Assert, check_list_invariants, List::length, list_length(), ListCell::next, and List::tail.

Referenced by adjust_rowcompare_for_index(), does_not_exist_skipping(), ExpandIndirectionStar(), geqo_eval(), get_object_address_attribute(), get_object_address_relobject(), match_unsorted_outer(), ParseFuncOrColumn(), process_owned_by(), transformFromClauseItem(), transformSetOperationStmt(), and truncate_useless_pathkeys().

{
    ListCell   *cell;
    int         n;

    if (new_size <= 0)
        return NIL;             /* truncate to zero length */

    /* If asked to effectively extend the list, do nothing */
    if (new_size >= list_length(list))
        return list;

    n = 1;
    foreach(cell, list)
    {
        if (n == new_size)
        {
            cell->next = NULL;
            list->tail = cell;
            list->length = new_size;
            check_list_invariants(list);
            return list;
        }
        n++;
    }

    /* keep the compiler quiet; never reached */
    Assert(false);
    return list;
}

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

Definition at line 700 of file list.c.

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

Referenced by AddRelationNewConstraints(), and process_duplicate_ors().

{
    List       *result;
    const ListCell *cell;

    Assert(IsPointerList(list1));
    Assert(IsPointerList(list2));

    result = list_copy(list1);
    foreach(cell, list2)
    {
        if (!list_member(result, lfirst(cell)))
            result = lappend(result, lfirst(cell));
    }

    check_list_invariants(result);
    return result;
}

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

Definition at line 747 of file list.c.

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

{
    List       *result;
    const ListCell *cell;

    Assert(IsIntegerList(list1));
    Assert(IsIntegerList(list2));

    result = list_copy(list1);
    foreach(cell, list2)
    {
        if (!list_member_int(result, lfirst_int(cell)))
            result = lappend_int(result, lfirst_int(cell));
    }

    check_list_invariants(result);
    return result;
}

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

Definition at line 770 of file list.c.

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

{
    List       *result;
    const ListCell *cell;

    Assert(IsOidList(list1));
    Assert(IsOidList(list2));

    result = list_copy(list1);
    foreach(cell, list2)
    {
        if (!list_member_oid(result, lfirst_oid(cell)))
            result = lappend_oid(result, lfirst_oid(cell));
    }

    check_list_invariants(result);
    return result;
}

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

Definition at line 724 of file list.c.

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

{
    List       *result;
    const ListCell *cell;

    Assert(IsPointerList(list1));
    Assert(IsPointerList(list2));

    result = list_copy(list1);
    foreach(cell, list2)
    {
        if (!list_member_ptr(result, lfirst(cell)))
            result = lappend(result, lfirst(cell));
    }

    check_list_invariants(result);
    return result;
}

static void new_head_cell ( List list  )  [static]

Definition at line 92 of file list.c.

References List::head, List::length, ListCell::next, and palloc().

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

{
    ListCell   *new_head;

    new_head = (ListCell *) palloc(sizeof(*new_head));
    new_head->next = list->head;

    list->head = new_head;
    list->length++;
}

static List* new_list ( NodeTag  type  )  [static]

Definition at line 66 of file list.c.

References List::head, List::length, ListCell::next, palloc(), List::tail, and List::type.

Referenced by lappend(), lappend_int(), lappend_oid(), lcons(), lcons_int(), lcons_oid(), list_copy(), list_copy_tail(), and pg_parse_query().

{
    List       *new_list;
    ListCell   *new_head;

    new_head = (ListCell *) palloc(sizeof(*new_head));
    new_head->next = NULL;
    /* new_head->data is left undefined! */

    new_list = (List *) palloc(sizeof(*new_list));
    new_list->type = type;
    new_list->length = 1;
    new_list->head = new_head;
    new_list->tail = new_head;

    return new_list;
}

static void new_tail_cell ( List list  )  [static]

Definition at line 111 of file list.c.

References List::length, ListCell::next, palloc(), and List::tail.

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

{
    ListCell   *new_tail;

    new_tail = (ListCell *) palloc(sizeof(*new_tail));
    new_tail->next = NULL;

    list->tail->next = new_tail;
    list->tail = new_tail;
    list->length++;
}