PostgreSQL Source Code: src/include/catalog/heap.h File Reference (original) (raw)
Go to the source code of this file.
Macros | |
---|---|
#define | CHKATYPE_ANYARRAY 0x01 /* allow ANYARRAY */ |
#define | CHKATYPE_ANYRECORD 0x02 /* allow RECORD and RECORD[] */ |
#define | CHKATYPE_IS_PARTKEY 0x04 /* attname is part key # not column */ |
#define | CHKATYPE_IS_VIRTUAL 0x08 /* is virtual generated column */ |
Functions | |
---|---|
Relation | heap_create (const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, RelFileNumber relfilenumber, Oid accessmtd, TupleDesc tupDesc, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, bool allow_system_table_mods, TransactionId *relfrozenxid, MultiXactId *relminmxid, bool create_storage) |
Oid | heap_create_with_catalog (const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, Oid reltypeid, Oid reloftypeid, Oid ownerid, Oid accessmtd, TupleDesc tupdesc, List *cooked_constraints, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, OnCommitAction oncommit, Datum reloptions, bool use_user_acl, bool allow_system_table_mods, bool is_internal, Oid relrewrite, ObjectAddress *typaddress) |
void | heap_drop_with_catalog (Oid relid) |
void | heap_truncate (List *relids) |
void | heap_truncate_one_rel (Relation rel) |
void | heap_truncate_check_FKs (List *relations, bool tempTables) |
List * | heap_truncate_find_FKs (List *relationIds) |
void | InsertPgAttributeTuples (Relation pg_attribute_rel, TupleDesc tupdesc, Oid new_rel_oid, const FormExtraData_pg_attribute tupdesc_extra[], CatalogIndexState indstate) |
void | InsertPgClassTuple (Relation pg_class_desc, Relation new_rel_desc, Oid new_rel_oid, Datum relacl, Datum reloptions) |
List * | AddRelationNewConstraints (Relation rel, List *newColDefaults, List *newConstraints, bool allow_merge, bool is_local, bool is_internal, const char *queryString) |
List * | AddRelationNotNullConstraints (Relation rel, List *constraints, List *old_notnulls) |
void | RelationClearMissing (Relation rel) |
void | StoreAttrMissingVal (Relation rel, AttrNumber attnum, Datum missingval) |
void | SetAttrMissing (Oid relid, char *attname, char *value) |
Node * | cookDefault (ParseState *pstate, Node *raw_default, Oid atttypid, int32 atttypmod, const char *attname, char attgenerated) |
void | DeleteRelationTuple (Oid relid) |
void | DeleteAttributeTuples (Oid relid) |
void | DeleteSystemAttributeTuples (Oid relid) |
void | RemoveAttributeById (Oid relid, AttrNumber attnum) |
void | CopyStatistics (Oid fromrelid, Oid torelid) |
void | RemoveStatistics (Oid relid, AttrNumber attnum) |
const FormData_pg_attribute * | SystemAttributeDefinition (AttrNumber attno) |
const FormData_pg_attribute * | SystemAttributeByName (const char *attname) |
void | CheckAttributeNamesTypes (TupleDesc tupdesc, char relkind, int flags) |
void | CheckAttributeType (const char *attname, Oid atttypid, Oid attcollation, List *containing_rowtypes, int flags) |
void | StorePartitionKey (Relation rel, char strategy, int16 partnatts, AttrNumber *partattrs, List *partexprs, Oid *partopclass, Oid *partcollation) |
void | RemovePartitionKeyByRelId (Oid relid) |
void | StorePartitionBound (Relation rel, Relation parent, PartitionBoundSpec *bound) |
◆ CHKATYPE_ANYARRAY
#define CHKATYPE_ANYARRAY 0x01 /* allow ANYARRAY */
Definition at line 23 of file heap.h.
◆ CHKATYPE_ANYRECORD
#define CHKATYPE_ANYRECORD 0x02 /* allow RECORD and RECORD[] */
Definition at line 24 of file heap.h.
◆ CHKATYPE_IS_PARTKEY
#define CHKATYPE_IS_PARTKEY 0x04 /* attname is part key # not column */
Definition at line 25 of file heap.h.
◆ CHKATYPE_IS_VIRTUAL
#define CHKATYPE_IS_VIRTUAL 0x08 /* is virtual generated column */
Definition at line 26 of file heap.h.
◆ CookedConstraint
◆ RawColumnDefault
◆ AddRelationNewConstraints()
List * AddRelationNewConstraints | ( | Relation | rel, |
---|---|---|---|
List * | newColDefaults, | ||
List * | newConstraints, | ||
bool | allow_merge, | ||
bool | is_local, | ||
bool | is_internal, | ||
const char * | queryString | ||
) |
Definition at line 2375 of file heap.c.
2382{
2383 List *cookedConstraints = NIL;
2386 int numoldchecks;
2389 int numchecks;
2390 List *checknames;
2391 List *nnnames;
2394
2395
2396
2397
2399 oldconstr = tupleDesc->constr;
2400 if (oldconstr)
2401 numoldchecks = oldconstr->num_check;
2402 else
2403 numoldchecks = 0;
2404
2405
2406
2407
2408
2412 rel,
2414 NULL,
2415 false,
2416 true);
2418
2419
2420
2421
2423 {
2425 Oid defOid;
2426
2427 expr = cookDefault(pstate, colDef->raw_default,
2428 atp->atttypid, atp->atttypmod,
2430 atp->attgenerated);
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444 if (expr == NULL ||
2445 (!colDef->generated &&
2448 continue;
2449
2450 defOid = StoreAttrDefault(rel, colDef->attnum, expr, is_internal);
2451
2454 cooked->conoid = defOid;
2455 cooked->name = NULL;
2456 cooked->attnum = colDef->attnum;
2457 cooked->expr = expr;
2460 cooked->is_local = is_local;
2461 cooked->inhcount = is_local ? 0 : 1;
2463 cookedConstraints = lappend(cookedConstraints, cooked);
2464 }
2465
2466
2467
2468
2469 numchecks = numoldchecks;
2470 checknames = NIL;
2471 nnnames = NIL;
2473 {
2474 Oid constrOid;
2475
2477 {
2478 char *ccname;
2479
2480 if (cdef->raw_expr != NULL)
2481 {
2482 Assert(cdef->cooked_expr == NULL);
2483
2484
2485
2486
2487
2490 }
2491 else
2492 {
2493 Assert(cdef->cooked_expr != NULL);
2494
2495
2496
2497
2498
2500 }
2501
2502
2503
2504
2505 if (cdef->conname != NULL)
2506 {
2507 ccname = cdef->conname;
2508
2509
2511 {
2512 if (strcmp(chkname, ccname) == 0)
2515 errmsg("check constraint \"%s\" already exists",
2516 ccname)));
2517 }
2518
2519
2520 checknames = lappend(checknames, ccname);
2521
2522
2523
2524
2525
2526
2527
2529 allow_merge, is_local,
2530 cdef->is_enforced,
2531 cdef->initially_valid,
2532 cdef->is_no_inherit))
2533 continue;
2534 }
2535 else
2536 {
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2551 char *colname;
2552
2554
2555
2557
2561 true);
2562 else
2563 colname = NULL;
2564
2566 colname,
2567 "check",
2569 checknames);
2570
2571
2572 checknames = lappend(checknames, ccname);
2573 }
2574
2575
2576
2577
2578 constrOid =
2579 StoreRelCheck(rel, ccname, expr, cdef->is_enforced,
2580 cdef->initially_valid, is_local,
2581 is_local ? 0 : 1, cdef->is_no_inherit,
2582 is_internal);
2583
2584 numchecks++;
2585
2588 cooked->conoid = constrOid;
2589 cooked->name = ccname;
2591 cooked->expr = expr;
2592 cooked->is_enforced = cdef->is_enforced;
2594 cooked->is_local = is_local;
2595 cooked->inhcount = is_local ? 0 : 1;
2597 cookedConstraints = lappend(cookedConstraints, cooked);
2598 }
2600 {
2603 int16 inhcount = is_local ? 0 : 1;
2604 char *nnname;
2605
2606
2610 errcode(ERRCODE_UNDEFINED_COLUMN),
2611 errmsg("column \"%s\" of relation \"%s\" does not exist",
2615 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2616 errmsg("cannot add not-null constraint on system column \"%s\"",
2618
2619 Assert(cdef->initially_valid != cdef->skip_validation);
2620
2621
2622
2623
2624
2625
2626
2628 is_local, cdef->is_no_inherit,
2629 cdef->skip_validation))
2630 continue;
2631
2632
2633
2634
2635
2636 if (cdef->conname)
2637 {
2640 cdef->conname))
2643 errmsg("constraint \"%s\" for relation \"%s\" already exists",
2645 nnname = cdef->conname;
2646 }
2647 else
2650 "not_null",
2652 nnnames);
2653 nnnames = lappend(nnnames, nnname);
2654
2655 constrOid =
2657 cdef->initially_valid,
2658 is_local,
2659 inhcount,
2660 cdef->is_no_inherit);
2661
2664 nncooked->conoid = constrOid;
2665 nncooked->name = nnname;
2666 nncooked->attnum = colnum;
2667 nncooked->expr = NULL;
2670 nncooked->is_local = is_local;
2671 nncooked->inhcount = inhcount;
2673
2674 cookedConstraints = lappend(cookedConstraints, nncooked);
2675 }
2676 }
2677
2678
2679
2680
2681
2682
2683
2684
2686
2687 return cookedConstraints;
2688}
#define InvalidAttrNumber
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Assert(PointerIsAligned(start, uint64))
static Oid StoreRelCheck(Relation rel, const char *ccname, Node *expr, bool is_enforced, bool is_validated, bool is_local, int16 inhcount, bool is_no_inherit, bool is_internal)
static bool MergeWithExistingConstraint(Relation rel, const char *ccname, Node *expr, bool allow_merge, bool is_local, bool is_enforced, bool is_initially_valid, bool is_no_inherit)
static Oid StoreRelNotNull(Relation rel, const char *nnname, AttrNumber attnum, bool is_validated, bool is_local, int inhcount, bool is_no_inherit)
static void SetRelationNumChecks(Relation rel, int numchecks)
Node * cookDefault(ParseState *pstate, Node *raw_default, Oid atttypid, int32 atttypmod, const char *attname, char attgenerated)
static Node * cookConstraint(ParseState *pstate, Node *raw_constraint, char *relname)
List * lappend(List *list, void *datum)
List * list_union(const List *list1, const List *list2)
AttrNumber get_attnum(Oid relid, const char *attname)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
ParseState * make_parsestate(ParseState *parentParseState)
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
Oid StoreAttrDefault(Relation rel, AttrNumber attnum, Node *expr, bool is_internal)
FormData_pg_attribute * Form_pg_attribute
bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, const char *conname)
char * ChooseConstraintName(const char *name1, const char *name2, const char *label, Oid namespaceid, List *others)
bool AdjustNotNullInheritance(Oid relid, AttrNumber attnum, bool is_local, bool is_no_inherit, bool is_notvalid)
static int list_length(const List *l)
#define foreach_ptr(type, var, lst)
#define foreach_node(type, var, lst)
void * stringToNode(const char *str)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationGetNamespace(relation)
#define ERRCODE_DUPLICATE_OBJECT
const char * p_sourcetext
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
List * pull_var_clause(Node *node, int flags)
References AccessShareLock, addNSItemToQuery(), addRangeTableEntryForRelation(), AdjustNotNullInheritance(), Assert(), CookedConstraint::attnum, castNode, ChooseConstraintName(), CookedConstraint::conoid, TupleDescData::constr, CONSTR_CHECK, CONSTR_DEFAULT, CONSTR_NOTNULL, CONSTRAINT_RELATION, ConstraintNameIsUsed(), CookedConstraint::contype, cookConstraint(), cookDefault(), ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, CookedConstraint::expr, foreach_node, foreach_ptr, get_attname(), get_attnum(), CookedConstraint::inhcount, InvalidAttrNumber, CookedConstraint::is_enforced, CookedConstraint::is_local, CookedConstraint::is_no_inherit, IsA, lappend(), linitial, list_length(), list_union(), make_parsestate(), MergeWithExistingConstraint(), CookedConstraint::name, NameStr, NIL, TupleConstr::num_check, ParseState::p_sourcetext, palloc(), pull_var_clause(), RelationData::rd_att, RelationGetDescr, RelationGetNamespace, RelationGetRelationName, RelationGetRelid, SetRelationNumChecks(), CookedConstraint::skip_validation, StoreAttrDefault(), StoreRelCheck(), StoreRelNotNull(), stringToNode(), strVal, and TupleDescAttr().
Referenced by ATAddCheckNNConstraint(), ATExecAddColumn(), ATExecColumnDefault(), ATExecSetExpression(), ATExecSetNotNull(), and DefineRelation().
◆ AddRelationNotNullConstraints()
Definition at line 2884 of file heap.c.
2886{
2887 List *givennames;
2888 List *nnnames;
2890
2891
2892
2893
2894
2895
2896
2897 nnnames = NIL;
2898 givennames = NIL;
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914 for (int outerpos = 0; outerpos < list_length(constraints); outerpos++)
2915 {
2918 char *conname;
2919 int inhcount = 0;
2920
2922
2924
2929 errcode(ERRCODE_UNDEFINED_COLUMN),
2930 errmsg("column \"%s\" of relation \"%s\" does not exist",
2935 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2936 errmsg("cannot add not-null constraint on system column \"%s\"",
2938
2939
2940
2941
2942
2943
2944 for (int restpos = outerpos + 1; restpos < list_length(constraints);)
2945 {
2947
2951 {
2954 errcode(ERRCODE_SYNTAX_ERROR),
2955 errmsg("conflicting NO INHERIT declaration for not-null constraint on column \"%s\"",
2957
2958
2959
2960
2961
2963 {
2966 else if (strcmp(constr->conname, other->conname) != 0)
2968 errcode(ERRCODE_SYNTAX_ERROR),
2969 errmsg("conflicting not-null constraint names \"%s\" and \"%s\"",
2971 }
2972
2973
2975 }
2976 else
2977 restpos++;
2978 }
2979
2980
2981
2982
2983
2984
2985
2986
2987
2989 {
2990 if (old->attnum == attnum)
2991 {
2992
2993
2994
2995
2998 (errcode(ERRCODE_DATATYPE_MISMATCH),
2999 errmsg("cannot define not-null constraint on column \"%s\" with NO INHERIT",
3001 errdetail("The column has an inherited not-null constraint.")));
3002
3003 inhcount++;
3005 }
3006 }
3007
3008
3009
3010
3011
3012
3014 {
3016 {
3017 if (strcmp(thisname, constr->conname) == 0)
3020 errmsg("constraint \"%s\" for relation \"%s\" already exists",
3023 }
3024
3025 conname = constr->conname;
3026 givennames = lappend(givennames, conname);
3027 }
3028 else
3032 "not_null",
3034 nnnames);
3035 nnnames = lappend(nnnames, conname);
3036
3040
3042 }
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058 for (int outerpos = 0; outerpos < list_length(old_notnulls); outerpos++)
3059 {
3061 char *conname = NULL;
3062 int inhcount = 1;
3063
3067
3068
3069
3070
3071 if (conname == NULL)
3072 conname = cooked->name;
3073
3074 for (int restpos = outerpos + 1; restpos < list_length(old_notnulls);)
3075 {
3077
3081 {
3082 if (conname == NULL)
3083 conname = other->name;
3084
3085 inhcount++;
3087 }
3088 else
3089 restpos++;
3090 }
3091
3092
3093 if (conname != NULL)
3094 {
3096 {
3097 if (strcmp(thisname, conname) == 0)
3098 {
3099 conname = NULL;
3100 break;
3101 }
3102 }
3103 }
3104
3105
3106 if (conname == NULL)
3109 cooked->attnum, false),
3110 "not_null",
3112 nnnames);
3113 nnnames = lappend(nnnames, conname);
3114
3115
3117 false, inhcount, false);
3118
3120 }
3121
3122 return nncols;
3123}
int errdetail(const char *fmt,...)
List * list_delete_nth_cell(List *list, int n)
List * lappend_int(List *list, int datum)
char * pstrdup(const char *in)
#define foreach_delete_current(lst, var_or_cell)
static void * list_nth(const List *list, int n)
#define list_nth_node(type, list, n)
References Assert(), CookedConstraint::attnum, attnum, ChooseConstraintName(), Constraint::conname, CONSTR_NOTNULL, CookedConstraint::contype, Constraint::contype, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errdetail(), errmsg(), ERROR, foreach_delete_current, foreach_ptr, get_attname(), get_attnum(), InvalidAttrNumber, Constraint::is_no_inherit, Constraint::keys, lappend(), lappend_int(), linitial, list_delete_nth_cell(), list_length(), list_nth(), list_nth_node, CookedConstraint::name, NIL, pstrdup(), RelationGetNamespace, RelationGetRelationName, RelationGetRelid, StoreRelNotNull(), and strVal.
Referenced by DefineRelation().
◆ CheckAttributeNamesTypes()
void CheckAttributeNamesTypes | ( | TupleDesc | tupdesc, |
---|---|---|---|
char | relkind, | ||
int | flags | ||
) |
Definition at line 452 of file heap.c.
454{
455 int i;
456 int j;
457 int natts = tupdesc->natts;
458
459
462 (errcode(ERRCODE_TOO_MANY_COLUMNS),
463 errmsg("tables can have at most %d columns",
465
466
467
468
469
470
471
472 if (relkind != RELKIND_VIEW && relkind != RELKIND_COMPOSITE_TYPE)
473 {
474 for (i = 0; i < natts; i++)
475 {
477
480 (errcode(ERRCODE_DUPLICATE_COLUMN),
481 errmsg("column name \"%s\" conflicts with a system column name",
482 NameStr(attr->attname))));
483 }
484 }
485
486
487
488
489 for (i = 1; i < natts; i++)
490 {
492 {
496 (errcode(ERRCODE_DUPLICATE_COLUMN),
497 errmsg("column name \"%s\" specified more than once",
499 }
500 }
501
502
503
504
505 for (i = 0; i < natts; i++)
506 {
510 NIL,
512 }
513}
void CheckAttributeType(const char *attname, Oid atttypid, Oid attcollation, List *containing_rowtypes, int flags)
const FormData_pg_attribute * SystemAttributeByName(const char *attname)
#define CHKATYPE_IS_VIRTUAL
#define MaxHeapAttributeNumber
References attname, CheckAttributeType(), CHKATYPE_IS_VIRTUAL, ereport, errcode(), errmsg(), ERROR, i, j, MaxHeapAttributeNumber, NameStr, TupleDescData::natts, NIL, SystemAttributeByName(), and TupleDescAttr().
Referenced by addRangeTableEntryForFunction(), and heap_create_with_catalog().
◆ CheckAttributeType()
void CheckAttributeType | ( | const char * | attname, |
---|---|---|---|
Oid | atttypid, | ||
Oid | attcollation, | ||
List * | containing_rowtypes, | ||
int | flags | ||
) |
Definition at line 544 of file heap.c.
548{
549 char att_typtype = get_typtype(atttypid);
550 Oid att_typelem;
551
552
554
555 if (att_typtype == TYPTYPE_PSEUDO)
556 {
557
558
559
560
561
562
563
564
565
566
567 if (!((atttypid == ANYARRAYOID && (flags & CHKATYPE_ANYARRAY)) ||
570 {
573 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
574
575 errmsg("partition key column %s has pseudo-type %s",
577 else
579 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
580 errmsg("column \"%s\" has pseudo-type %s",
582 }
583 }
584 else if (att_typtype == TYPTYPE_DOMAIN)
585 {
586
587
588
589
590
591
594 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
595 errmsg("virtual generated column \"%s\" cannot have a domain type", attname));
596
597
598
599
601 containing_rowtypes,
602 flags);
603 }
604 else if (att_typtype == TYPTYPE_COMPOSITE)
605 {
606
607
608
611 int i;
612
613
614
615
616
617
618
621 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
622 errmsg("composite type %s cannot be made a member of itself",
624
625 containing_rowtypes = lappend_oid(containing_rowtypes, atttypid);
626
628
630
631 for (i = 0; i < tupdesc->natts; i++)
632 {
634
635 if (attr->attisdropped)
636 continue;
638 attr->atttypid, attr->attcollation,
639 containing_rowtypes,
641 }
642
644
646 }
647 else if (att_typtype == TYPTYPE_RANGE)
648 {
649
650
651
654 containing_rowtypes,
655 flags);
656 }
658 {
659
660
661
663 containing_rowtypes,
664 flags);
665 }
666
667
668
669
670
672 {
675 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
676
677 errmsg("no collation was derived for partition key column %s with collatable type %s",
679 errhint("Use the COLLATE clause to set the collation explicitly.")));
680 else
682 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
683 errmsg("no collation was derived for column \"%s\" with collatable type %s",
685 errhint("Use the COLLATE clause to set the collation explicitly.")));
686 }
687}
#define OidIsValid(objectId)
int errhint(const char *fmt,...)
char * format_type_be(Oid type_oid)
#define CHKATYPE_ANYRECORD
#define CHKATYPE_ANYARRAY
#define CHKATYPE_IS_PARTKEY
List * lappend_oid(List *list, Oid datum)
List * list_delete_last(List *list)
bool list_member_oid(const List *list, Oid datum)
Oid get_range_subtype(Oid rangeOid)
Oid get_element_type(Oid typid)
Oid get_range_collation(Oid rangeOid)
bool type_is_collatable(Oid typid)
Oid get_typ_typrelid(Oid typid)
char get_typtype(Oid typid)
Oid getBaseType(Oid typid)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
void check_stack_depth(void)
References AccessShareLock, attname, check_stack_depth(), CheckAttributeType(), CHKATYPE_ANYARRAY, CHKATYPE_ANYRECORD, CHKATYPE_IS_PARTKEY, CHKATYPE_IS_VIRTUAL, ereport, errcode(), errhint(), errmsg(), ERROR, format_type_be(), get_element_type(), get_range_collation(), get_range_subtype(), get_typ_typrelid(), get_typtype(), getBaseType(), i, lappend_oid(), list_delete_last(), list_member_oid(), NameStr, TupleDescData::natts, OidIsValid, relation_close(), relation_open(), RelationGetDescr, TupleDescAttr(), and type_is_collatable().
Referenced by ATExecAddColumn(), ATPrepAlterColumnType(), CheckAttributeNamesTypes(), CheckAttributeType(), ComputePartitionAttrs(), and ConstructTupleDescriptor().
◆ cookDefault()
Node * cookDefault | ( | ParseState * | pstate, |
---|---|---|---|
Node * | raw_default, | ||
Oid | atttypid, | ||
int32 | atttypmod, | ||
const char * | attname, | ||
char | attgenerated | ||
) |
Definition at line 3230 of file heap.c.
3236{
3238
3239 Assert(raw_default != NULL);
3240
3241
3242
3243
3245
3246 if (attgenerated)
3247 {
3248
3250
3251
3254 (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3255 errmsg("generation expression is not immutable")));
3256 }
3257 else
3258 {
3259
3260
3261
3262
3264 }
3265
3266
3267
3268
3269
3270
3272 {
3274
3276 atttypid, atttypmod,
3279 -1);
3280 if (expr == NULL)
3282 (errcode(ERRCODE_DATATYPE_MISMATCH),
3283 errmsg("column \"%s\" is of type %s"
3284 " but default expression is of type %s",
3288 errhint("You will need to rewrite or cast the expression.")));
3289 }
3290
3291
3292
3293
3295
3296 return expr;
3297}
bool contain_mutable_functions_after_planning(Expr *expr)
static void check_nested_generated(ParseState *pstate, Node *node)
Oid exprType(const Node *expr)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
void assign_expr_collations(ParseState *pstate, Node *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
@ EXPR_KIND_COLUMN_DEFAULT
@ EXPR_KIND_GENERATED_COLUMN
bool contain_var_clause(Node *node)
References Assert(), assign_expr_collations(), attname, check_nested_generated(), COERCE_IMPLICIT_CAST, coerce_to_target_type(), COERCION_ASSIGNMENT, contain_mutable_functions_after_planning(), contain_var_clause(), ereport, errcode(), errhint(), errmsg(), ERROR, EXPR_KIND_COLUMN_DEFAULT, EXPR_KIND_GENERATED_COLUMN, exprType(), format_type_be(), OidIsValid, and transformExpr().
Referenced by AddRelationNewConstraints(), AlterDomainDefault(), and DefineDomain().
◆ CopyStatistics()
void CopyStatistics | ( | Oid | fromrelid, |
---|---|---|---|
Oid | torelid | ||
) |
Definition at line 3345 of file heap.c.
3346{
3352
3354
3355
3357 Anum_pg_statistic_starelid,
3360
3362 true, NULL, 1, key);
3363
3365 {
3367
3368
3371
3372
3373 statform->starelid = torelid;
3374
3375
3376 if (indstate == NULL)
3378
3380
3382 }
3383
3385
3386 if (indstate != NULL)
3389}
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
HeapTuple heap_copytuple(HeapTuple tuple)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
void CatalogTupleInsertWithInfo(Relation heapRel, HeapTuple tup, CatalogIndexState indstate)
void CatalogCloseIndexes(CatalogIndexState indstate)
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
FormData_pg_statistic * Form_pg_statistic
static Datum ObjectIdGetDatum(Oid X)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
#define BTEqualStrategyNumber
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
References BTEqualStrategyNumber, CatalogCloseIndexes(), CatalogOpenIndexes(), CatalogTupleInsertWithInfo(), GETSTRUCT(), heap_copytuple(), heap_freetuple(), HeapTupleIsValid, sort-test::key, ObjectIdGetDatum(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by index_concurrently_swap().
◆ DeleteAttributeTuples()
void DeleteAttributeTuples | ( | Oid | relid | ) |
---|
Definition at line 1595 of file heap.c.
1596{
1601
1602
1604
1605
1607 Anum_pg_attribute_attrelid,
1610
1612 NULL, 1, key);
1613
1614
1617
1618
1621}
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
References BTEqualStrategyNumber, CatalogTupleDelete(), sort-test::key, ObjectIdGetDatum(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().
Referenced by heap_drop_with_catalog(), and index_drop().
◆ DeleteRelationTuple()
void DeleteRelationTuple | ( | Oid | relid | ) |
---|
Definition at line 1566 of file heap.c.
1567{
1570
1571
1573
1576 elog(ERROR, "cache lookup failed for relation %u", relid);
1577
1578
1580
1582
1584}
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
References CatalogTupleDelete(), elog, ERROR, HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), HeapTupleData::t_self, table_close(), and table_open().
Referenced by heap_drop_with_catalog(), and index_drop().
◆ DeleteSystemAttributeTuples()
void DeleteSystemAttributeTuples | ( | Oid | relid | ) |
---|
Definition at line 1632 of file heap.c.
1633{
1638
1639
1641
1642
1644 Anum_pg_attribute_attrelid,
1648 Anum_pg_attribute_attnum,
1651
1653 NULL, 2, key);
1654
1655
1658
1659
1662}
static Datum Int16GetDatum(int16 X)
#define BTLessEqualStrategyNumber
References BTEqualStrategyNumber, BTLessEqualStrategyNumber, CatalogTupleDelete(), Int16GetDatum(), sort-test::key, ObjectIdGetDatum(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().
◆ heap_create()
Relation heap_create | ( | const char * | relname, |
---|---|---|---|
Oid | relnamespace, | ||
Oid | reltablespace, | ||
Oid | relid, | ||
RelFileNumber | relfilenumber, | ||
Oid | accessmtd, | ||
TupleDesc | tupDesc, | ||
char | relkind, | ||
char | relpersistence, | ||
bool | shared_relation, | ||
bool | mapped_relation, | ||
bool | allow_system_table_mods, | ||
TransactionId * | relfrozenxid, | ||
MultiXactId * | relminmxid, | ||
bool | create_storage | ||
) |
Definition at line 285 of file heap.c.
300{
302
303
305
306
307
308
309
310
311
312
313
314
315 if (!allow_system_table_mods &&
320 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
321 errmsg("permission denied to create \"%s.%s\"",
323 errdetail("System catalog modifications are currently disallowed.")));
324
327
328
329
330
331
332 if (!RELKIND_HAS_TABLESPACE(relkind))
334
335
336 if (!RELKIND_HAS_STORAGE(relkind))
337 create_storage = false;
338 else
339 {
340
341
342
343
345 relfilenumber = relid;
346 }
347
348
349
350
351
352
353
354
355
356
359
360
361
362
364 relnamespace,
365 tupDesc,
366 relid,
367 accessmtd,
368 relfilenumber,
369 reltablespace,
370 shared_relation,
371 mapped_relation,
372 relpersistence,
373 relkind);
374
375
376
377
378
379
380
381
382 if (create_storage)
383 {
384 if (RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind))
386 relpersistence,
387 relfrozenxid, relminmxid);
388 else if (RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
390 else
392 }
393
394
395
396
397
398
399 if (!create_storage && reltablespace != InvalidOid)
401 reltablespace);
402
403
405
406 return rel;
407}
bool IsToastNamespace(Oid namespaceId)
bool IsCatalogNamespace(Oid namespaceId)
char * get_namespace_name(Oid nspid)
#define IsNormalProcessingMode()
#define InvalidMultiXactId
void recordDependencyOnTablespace(Oid classId, Oid objectId, Oid tablespace)
void pgstat_create_relation(Relation rel)
Relation RelationBuildLocalRelation(const char *relname, Oid relnamespace, TupleDesc tupDesc, Oid relid, Oid accessmtd, RelFileNumber relfilenumber, Oid reltablespace, bool shared_relation, bool mapped_relation, char relpersistence, char relkind)
#define RelFileNumberIsValid(relnumber)
SMgrRelation RelationCreateStorage(RelFileLocator rlocator, char relpersistence, bool register_delete)
RelFileLocator rd_locator
static void table_relation_set_new_filelocator(Relation rel, const RelFileLocator *newrlocator, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
#define InvalidTransactionId
References Assert(), ereport, errcode(), errdetail(), errmsg(), ERROR, get_namespace_name(), InvalidMultiXactId, InvalidOid, InvalidTransactionId, IsCatalogNamespace(), IsNormalProcessingMode, IsToastNamespace(), MyDatabaseTableSpace, OidIsValid, pgstat_create_relation(), RelationData::rd_locator, RelationData::rd_rel, recordDependencyOnTablespace(), RelationBuildLocalRelation(), RelationCreateStorage(), RelFileNumberIsValid, relname, and table_relation_set_new_filelocator().
Referenced by heap_create_with_catalog(), and index_create().
◆ heap_create_with_catalog()
Oid heap_create_with_catalog | ( | const char * | relname, |
---|---|---|---|
Oid | relnamespace, | ||
Oid | reltablespace, | ||
Oid | relid, | ||
Oid | reltypeid, | ||
Oid | reloftypeid, | ||
Oid | ownerid, | ||
Oid | accessmtd, | ||
TupleDesc | tupdesc, | ||
List * | cooked_constraints, | ||
char | relkind, | ||
char | relpersistence, | ||
bool | shared_relation, | ||
bool | mapped_relation, | ||
OnCommitAction | oncommit, | ||
Datum | reloptions, | ||
bool | use_user_acl, | ||
bool | allow_system_table_mods, | ||
bool | is_internal, | ||
Oid | relrewrite, | ||
ObjectAddress * | typaddress | ||
) |
Definition at line 1112 of file heap.c.
1133{
1136 Acl *relacl;
1137 Oid existing_relid;
1138 Oid old_type_oid;
1139 Oid new_type_oid;
1140
1141
1145
1147
1148
1149
1150
1152
1153
1154
1155
1156
1157
1160
1161
1162
1163
1164
1168 (errcode(ERRCODE_DUPLICATE_TABLE),
1169 errmsg("relation \"%s\" already exists", relname)));
1170
1171
1172
1173
1174
1175
1176
1177 old_type_oid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
1181 {
1186 errhint("A relation has an associated type of the same name, "
1187 "so you must use a name that doesn't conflict "
1188 "with any existing type.")));
1189 }
1190
1191
1192
1193
1194 if (shared_relation && reltablespace != GLOBALTABLESPACE_OID)
1195 elog(ERROR, "shared relations must be placed in pg_global tablespace");
1196
1197
1198
1199
1200
1201
1202
1204 {
1205
1207 {
1208
1209
1210
1211
1212 Assert(relkind != RELKIND_INDEX);
1213 Assert(relkind != RELKIND_PARTITIONED_INDEX);
1214
1215 if (relkind == RELKIND_TOASTVALUE)
1216 {
1217
1219 {
1222
1225 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1226 errmsg("toast relfilenumber value not set when in binary upgrade mode")));
1227
1230 }
1231 }
1232 else
1233 {
1236 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1237 errmsg("pg_class heap OID value not set when in binary upgrade mode")));
1238
1241
1242 if (RELKIND_HAS_STORAGE(relkind))
1243 {
1246 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1247 errmsg("relfilenumber value not set when in binary upgrade mode")));
1248
1251 }
1252 }
1253 }
1254
1257 relpersistence);
1258 }
1259
1260
1261
1262
1263
1264
1266
1267
1268
1269
1270 if (use_user_acl)
1271 {
1272 switch (relkind)
1273 {
1274 case RELKIND_RELATION:
1275 case RELKIND_VIEW:
1276 case RELKIND_MATVIEW:
1277 case RELKIND_FOREIGN_TABLE:
1278 case RELKIND_PARTITIONED_TABLE:
1280 relnamespace);
1281 break;
1282 case RELKIND_SEQUENCE:
1284 relnamespace);
1285 break;
1286 default:
1287 relacl = NULL;
1288 break;
1289 }
1290 }
1291 else
1292 relacl = NULL;
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1304 relnamespace,
1305 reltablespace,
1306 relid,
1307 relfilenumber,
1308 accessmtd,
1309 tupdesc,
1310 relkind,
1311 relpersistence,
1312 shared_relation,
1313 mapped_relation,
1314 allow_system_table_mods,
1315 &relfrozenxid,
1316 &relminmxid,
1317 true);
1318
1320
1321 new_rel_desc->rd_rel->relrewrite = relrewrite;
1322
1323
1324
1325
1326
1327
1328 if (!(relkind == RELKIND_SEQUENCE ||
1329 relkind == RELKIND_TOASTVALUE ||
1330 relkind == RELKIND_INDEX ||
1331 relkind == RELKIND_PARTITIONED_INDEX))
1332 {
1333 Oid new_array_oid;
1335 char *relarrayname;
1336
1337
1338
1339
1340
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1353 relnamespace,
1354 relid,
1355 relkind,
1356 ownerid,
1357 reltypeid,
1358 new_array_oid);
1359 new_type_oid = new_type_addr.objectId;
1360 if (typaddress)
1361 *typaddress = new_type_addr;
1362
1363
1365
1366 TypeCreate(new_array_oid,
1367 relarrayname,
1368 relnamespace,
1369 InvalidOid,
1370 0,
1371 ownerid,
1372 -1,
1373 TYPTYPE_BASE,
1374 TYPCATEGORY_ARRAY,
1375 false,
1377 F_ARRAY_IN,
1378 F_ARRAY_OUT,
1379 F_ARRAY_RECV,
1380 F_ARRAY_SEND,
1381 InvalidOid,
1382 InvalidOid,
1383 F_ARRAY_TYPANALYZE,
1384 F_ARRAY_SUBSCRIPT_HANDLER,
1385 new_type_oid,
1386 true,
1387 InvalidOid,
1388 InvalidOid,
1389 NULL,
1390 NULL,
1391 false,
1392 TYPALIGN_DOUBLE,
1393 TYPSTORAGE_EXTENDED,
1394 -1,
1395 0,
1396 false,
1397 InvalidOid);
1398
1399 pfree(relarrayname);
1400 }
1401 else
1402 {
1403
1405 Assert(typaddress == NULL);
1406
1408 }
1409
1410
1411
1412
1413
1414
1415
1416
1418 new_rel_desc,
1419 relid,
1420 new_type_oid,
1421 reloftypeid,
1422 ownerid,
1423 relkind,
1424 relfrozenxid,
1425 relminmxid,
1427 reloptions);
1428
1429
1430
1431
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449 if (relkind != RELKIND_COMPOSITE_TYPE &&
1450 relkind != RELKIND_TOASTVALUE &&
1452 {
1454 referenced;
1456
1458
1460
1462
1464
1466
1467 ObjectAddressSet(referenced, NamespaceRelationId, relnamespace);
1469
1470 if (reloftypeid)
1471 {
1474 }
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484 if ((RELKIND_HAS_TABLE_AM(relkind) && relkind != RELKIND_TOASTVALUE) ||
1485 (relkind == RELKIND_PARTITIONED_TABLE && OidIsValid(accessmtd)))
1486 {
1487 ObjectAddressSet(referenced, AccessMethodRelationId, accessmtd);
1489 }
1490
1493 }
1494
1495
1497
1498
1499
1500
1501
1502
1503
1504
1505 StoreConstraints(new_rel_desc, cooked_constraints, is_internal);
1506
1507
1508
1509
1512
1513
1514
1515
1516
1517 table_close(new_rel_desc, NoLock);
1519
1520 return relid;
1521}
void recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, Acl *acl)
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
TransactionId MultiXactId
RelFileNumber GetNewRelFileNumber(Oid reltablespace, Relation pg_class, char relpersistence)
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
ObjectAddresses * new_object_addresses(void)
void free_object_addresses(ObjectAddresses *addrs)
static void StoreConstraints(Relation rel, List *cooked_constraints, bool is_internal)
static void AddNewAttributeTuples(Oid new_rel_oid, TupleDesc tupdesc, char relkind)
RelFileNumber binary_upgrade_next_heap_pg_class_relfilenumber
static void AddNewRelationTuple(Relation pg_class_desc, Relation new_rel_desc, Oid new_rel_oid, Oid new_type_oid, Oid reloftype, Oid relowner, char relkind, TransactionId relfrozenxid, TransactionId relminmxid, Datum relacl, Datum reloptions)
RelFileNumber binary_upgrade_next_toast_pg_class_relfilenumber
static ObjectAddress AddNewRelationType(const char *typeName, Oid typeNamespace, Oid new_rel_oid, char new_rel_kind, Oid ownerid, Oid new_row_type, Oid new_array_type)
void CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind, int flags)
Oid binary_upgrade_next_toast_pg_class_oid
Oid binary_upgrade_next_heap_pg_class_oid
Relation heap_create(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, RelFileNumber relfilenumber, Oid accessmtd, TupleDesc tupDesc, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, bool allow_system_table_mods, TransactionId *relfrozenxid, MultiXactId *relminmxid, bool create_storage)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
#define AccessExclusiveLock
Oid get_relname_relid(const char *relname, Oid relnamespace)
void pfree(void *pointer)
#define IsBootstrapProcessingMode()
#define InvokeObjectPostCreateHookArg(classId, objectId, subId, is_internal)
#define ObjectAddressSet(addr, class_id, object_id)
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
ObjectAddress TypeCreate(Oid newTypeOid, const char *typeName, Oid typeNamespace, Oid relationOid, char relationKind, Oid ownerId, int16 internalSize, char typeType, char typeCategory, bool typePreferred, char typDelim, Oid inputProcedure, Oid outputProcedure, Oid receiveProcedure, Oid sendProcedure, Oid typmodinProcedure, Oid typmodoutProcedure, Oid analyzeProcedure, Oid subscriptProcedure, Oid elementType, bool isImplicitArray, Oid arrayType, Oid baseType, const char *defaultTypeValue, char *defaultTypeBin, bool passedByValue, char alignment, char storage, int32 typeMod, int32 typNDims, bool typeNotNull, Oid typeCollation)
bool moveArrayTypeName(Oid typeOid, const char *typeName, Oid typeNamespace)
char * makeArrayTypeName(const char *typeName, Oid typeNamespace)
static Datum PointerGetDatum(const void *X)
static Datum CStringGetDatum(const char *X)
#define InvalidRelFileNumber
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
void register_on_commit_action(Oid relid, OnCommitAction action)
Oid AssignTypeArrayOid(void)
References AccessExclusiveLock, add_exact_object_address(), AddNewAttributeTuples(), AddNewRelationTuple(), AddNewRelationType(), Assert(), AssignTypeArrayOid(), binary_upgrade_next_heap_pg_class_oid, binary_upgrade_next_heap_pg_class_relfilenumber, binary_upgrade_next_toast_pg_class_oid, binary_upgrade_next_toast_pg_class_relfilenumber, CheckAttributeNamesTypes(), CHKATYPE_ANYARRAY, CStringGetDatum(), DEFAULT_TYPDELIM, DEPENDENCY_NORMAL, elog, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errhint(), errmsg(), ERROR, free_object_addresses(), get_relname_relid(), get_user_default_acl(), GetNewRelFileNumber(), GetSysCacheOid2, heap_create(), InvalidOid, InvalidRelFileNumber, InvokeObjectPostCreateHookArg, IsBinaryUpgrade, IsBootstrapProcessingMode, IsNormalProcessingMode, LockRelationOid(), makeArrayTypeName(), moveArrayTypeName(), new_object_addresses(), NoLock, OBJECT_SEQUENCE, OBJECT_TABLE, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), OidIsValid, ONCOMMIT_NOOP, pfree(), PointerGetDatum(), RelationData::rd_att, RelationData::rd_rel, record_object_address_dependencies(), recordDependencyOnCurrentExtension(), recordDependencyOnNewAcl(), recordDependencyOnOwner(), register_on_commit_action(), RelationGetRelid, RelFileNumberIsValid, relname, RowExclusiveLock, StoreConstraints(), table_close(), table_open(), and TypeCreate().
Referenced by create_toast_table(), DefineRelation(), and make_new_heap().
◆ heap_drop_with_catalog()
void heap_drop_with_catalog | ( | Oid | relid | ) |
---|
Definition at line 1774 of file heap.c.
1775{
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1793 elog(ERROR, "cache lookup failed for relation %u", relid);
1795 {
1796
1797
1798
1799
1800
1803
1804
1805
1806
1807
1809 if (OidIsValid(defaultPartOid) && relid != defaultPartOid)
1811 }
1812
1814
1815
1816
1817
1819
1820
1821
1822
1823
1824
1826
1827
1828
1829
1830
1831
1832
1834
1835
1836
1837
1838 if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1839 {
1842
1844
1847 elog(ERROR, "cache lookup failed for foreign table %u", relid);
1848
1850
1853 }
1854
1855
1856
1857
1858 if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1860
1861
1862
1863
1864
1865 if (relid == defaultPartOid)
1867
1868
1869
1870
1871 if (RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
1873
1874
1876
1877
1878
1879
1880
1881
1883
1884
1885
1886
1888
1889
1890
1891
1893
1894
1895
1896
1897
1898
1899
1900
1902
1903
1904
1905
1907
1908
1909
1910
1912
1913
1914
1915
1917
1918
1919
1920
1922
1924 {
1925
1926
1927
1928
1929
1930 if (OidIsValid(defaultPartOid) && relid != defaultPartOid)
1932
1933
1934
1935
1936
1938
1939 }
1940}
void DeleteRelationTuple(Oid relid)
void DeleteAttributeTuples(Oid relid)
void RemoveStatistics(Oid relid, AttrNumber attnum)
static void RelationRemoveInheritance(Oid relid)
void RemovePartitionKeyByRelId(Oid relid)
void CacheInvalidateRelcacheByRelid(Oid relid)
void update_default_partition_oid(Oid parentId, Oid defaultPartId)
Oid get_default_partition_oid(Oid parentId)
Oid get_partition_parent(Oid relid, bool even_if_detached)
FormData_pg_class * Form_pg_class
void RemoveSubscriptionRel(Oid subid, Oid relid)
void pgstat_drop_relation(Relation rel)
void CheckTableForSerializableConflictIn(Relation relation)
void RelationForgetRelation(Oid rid)
void RelationDropStorage(Relation rel)
void CheckTableNotInUse(Relation rel, const char *stmt)
void remove_on_commit_action(Oid relid)
References AccessExclusiveLock, CacheInvalidateRelcacheByRelid(), CatalogTupleDelete(), CheckTableForSerializableConflictIn(), CheckTableNotInUse(), DeleteAttributeTuples(), DeleteRelationTuple(), elog, ERROR, get_default_partition_oid(), get_partition_parent(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, LockRelationOid(), NoLock, ObjectIdGetDatum(), OidIsValid, pgstat_drop_relation(), RelationData::rd_rel, relation_close(), relation_open(), RelationDropStorage(), RelationForgetRelation(), RelationRemoveInheritance(), ReleaseSysCache(), remove_on_commit_action(), RemovePartitionKeyByRelId(), RemoveStatistics(), RemoveSubscriptionRel(), RowExclusiveLock, SearchSysCache1(), HeapTupleData::t_self, table_close(), table_open(), and update_default_partition_oid().
Referenced by doDeletion().
◆ heap_truncate()
void heap_truncate | ( | List * | relids | ) |
---|
Definition at line 3493 of file heap.c.
3494{
3497
3498
3499 foreach(cell, relids)
3500 {
3503
3505 relations = lappend(relations, rel);
3506 }
3507
3508
3510
3511
3512 foreach(cell, relations)
3513 {
3515
3516
3518
3519
3521 }
3522}
void heap_truncate_check_FKs(List *relations, bool tempTables)
void heap_truncate_one_rel(Relation rel)
References AccessExclusiveLock, heap_truncate_check_FKs(), heap_truncate_one_rel(), lappend(), lfirst, lfirst_oid, NIL, NoLock, table_close(), and table_open().
Referenced by PreCommit_on_commit_actions().
◆ heap_truncate_check_FKs()
void heap_truncate_check_FKs | ( | List * | relations, |
---|---|---|---|
bool | tempTables | ||
) |
Definition at line 3578 of file heap.c.
3579{
3581 List *dependents;
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592 foreach(cell, relations)
3593 {
3595
3596 if (rel->rd_rel->relhastriggers ||
3597 rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
3599 }
3600
3601
3602
3603
3604 if (oids == NIL)
3605 return;
3606
3607
3608
3609
3610
3612 if (dependents == NIL)
3613 return;
3614
3615
3616
3617
3618
3619
3620
3621
3622 foreach(cell, oids)
3623 {
3626
3628
3629 foreach(cell2, dependents)
3630 {
3632
3634 {
3637
3638 if (tempTables)
3640 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3641 errmsg("unsupported ON COMMIT and foreign key combination"),
3642 errdetail("Table \"%s\" references \"%s\", but they do not have the same ON COMMIT setting.",
3644 else
3646 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3647 errmsg("cannot truncate a table referenced in a foreign key constraint"),
3648 errdetail("Table \"%s\" references \"%s\".",
3650 errhint("Truncate table \"%s\" at the same time, "
3651 "or use TRUNCATE ... CASCADE.",
3652 relname2)));
3653 }
3654 }
3655 }
3656}
List * heap_truncate_find_FKs(List *relationIds)
char * get_rel_name(Oid relid)
#define list_make1_oid(x1)
References ereport, errcode(), errdetail(), errhint(), errmsg(), ERROR, get_rel_name(), heap_truncate_find_FKs(), lappend_oid(), lfirst, lfirst_oid, list_make1_oid, list_member_oid(), NIL, RelationData::rd_rel, RelationGetRelid, and relname.
Referenced by ExecuteTruncateGuts(), and heap_truncate().
◆ heap_truncate_find_FKs()
List * heap_truncate_find_FKs | ( | List * | relationIds | ) |
---|
Definition at line 3673 of file heap.c.
3674{
3677 List *parent_cons;
3683 bool restart;
3684
3686
3687
3688
3689
3690
3692
3693restart:
3694 restart = false;
3695 parent_cons = NIL;
3696
3698 NULL, 0, NULL);
3699
3701 {
3703
3704
3705 if (con->contype != CONSTRAINT_FOREIGN)
3706 continue;
3707
3708
3710 continue;
3711
3712
3713
3714
3715
3716
3717
3720 parent_cons = lappend_oid(parent_cons, con->conparentid);
3721
3722
3723
3724
3725
3727 result = lappend_oid(result, con->conrelid);
3728 }
3729
3731
3732
3733
3734
3735
3736
3737
3738
3739 foreach(cell, parent_cons)
3740 {
3742
3744 Anum_pg_constraint_oid,
3747
3749 true, NULL, 1, &key);
3750
3753 {
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3770 con->conparentid);
3772 {
3773 oids = lappend_oid(oids, con->confrelid);
3774 restart = true;
3775 }
3776 }
3777
3779 }
3780
3782 if (restart)
3783 goto restart;
3784
3787
3788
3791
3792 return result;
3793}
void list_sort(List *list, list_sort_comparator cmp)
List * list_copy(const List *oldlist)
List * list_append_unique_oid(List *list, Oid datum)
void list_deduplicate_oid(List *list)
int list_oid_cmp(const ListCell *p1, const ListCell *p2)
void list_free(List *list)
FormData_pg_constraint * Form_pg_constraint
References AccessShareLock, BTEqualStrategyNumber, GETSTRUCT(), HeapTupleIsValid, InvalidOid, sort-test::key, lappend_oid(), lfirst_oid, list_append_unique_oid(), list_copy(), list_deduplicate_oid(), list_free(), list_member_oid(), list_oid_cmp(), list_sort(), NIL, ObjectIdGetDatum(), OidIsValid, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by ExecuteTruncateGuts(), and heap_truncate_check_FKs().
◆ heap_truncate_one_rel()
void heap_truncate_one_rel | ( | Relation | rel | ) |
---|
◆ InsertPgAttributeTuples()
Definition at line 708 of file heap.c.
713{
716 int nslots;
717 int natts = 0;
718 int slotCount = 0;
719 bool close_index = false;
720
722
723
727 for (int i = 0; i < nslots; i++)
729
730 while (natts < tupdesc->natts)
731 {
734
736
737 memset(slot[slotCount]->tts_isnull, false,
738 slot[slotCount]->tts_tupleDescriptor->natts * sizeof(bool));
739
742 else
744
745 slot[slotCount]->tts_values[Anum_pg_attribute_attname - 1] = NameGetDatum(&attrs->attname);
747 slot[slotCount]->tts_values[Anum_pg_attribute_attlen - 1] = Int16GetDatum(attrs->attlen);
748 slot[slotCount]->tts_values[Anum_pg_attribute_attnum - 1] = Int16GetDatum(attrs->attnum);
749 slot[slotCount]->tts_values[Anum_pg_attribute_atttypmod - 1] = Int32GetDatum(attrs->atttypmod);
750 slot[slotCount]->tts_values[Anum_pg_attribute_attndims - 1] = Int16GetDatum(attrs->attndims);
751 slot[slotCount]->tts_values[Anum_pg_attribute_attbyval - 1] = BoolGetDatum(attrs->attbyval);
752 slot[slotCount]->tts_values[Anum_pg_attribute_attalign - 1] = CharGetDatum(attrs->attalign);
753 slot[slotCount]->tts_values[Anum_pg_attribute_attstorage - 1] = CharGetDatum(attrs->attstorage);
754 slot[slotCount]->tts_values[Anum_pg_attribute_attcompression - 1] = CharGetDatum(attrs->attcompression);
755 slot[slotCount]->tts_values[Anum_pg_attribute_attnotnull - 1] = BoolGetDatum(attrs->attnotnull);
756 slot[slotCount]->tts_values[Anum_pg_attribute_atthasdef - 1] = BoolGetDatum(attrs->atthasdef);
757 slot[slotCount]->tts_values[Anum_pg_attribute_atthasmissing - 1] = BoolGetDatum(attrs->atthasmissing);
758 slot[slotCount]->tts_values[Anum_pg_attribute_attidentity - 1] = CharGetDatum(attrs->attidentity);
759 slot[slotCount]->tts_values[Anum_pg_attribute_attgenerated - 1] = CharGetDatum(attrs->attgenerated);
760 slot[slotCount]->tts_values[Anum_pg_attribute_attisdropped - 1] = BoolGetDatum(attrs->attisdropped);
761 slot[slotCount]->tts_values[Anum_pg_attribute_attislocal - 1] = BoolGetDatum(attrs->attislocal);
762 slot[slotCount]->tts_values[Anum_pg_attribute_attinhcount - 1] = Int16GetDatum(attrs->attinhcount);
763 slot[slotCount]->tts_values[Anum_pg_attribute_attcollation - 1] = ObjectIdGetDatum(attrs->attcollation);
764 if (attrs_extra)
765 {
768
771 }
772 else
773 {
774 slot[slotCount]->tts_isnull[Anum_pg_attribute_attstattarget - 1] = true;
775 slot[slotCount]->tts_isnull[Anum_pg_attribute_attoptions - 1] = true;
776 }
777
778
779
780
781 slot[slotCount]->tts_isnull[Anum_pg_attribute_attacl - 1] = true;
782 slot[slotCount]->tts_isnull[Anum_pg_attribute_attfdwoptions - 1] = true;
783 slot[slotCount]->tts_isnull[Anum_pg_attribute_attmissingval - 1] = true;
784
786 slotCount++;
787
788
789
790
791
792 if (slotCount == nslots || natts == tupdesc->natts - 1)
793 {
794
795 if (!indstate)
796 {
798 close_index = true;
799 }
800
801
803 indstate);
804 slotCount = 0;
805 }
806
807 natts++;
808 }
809
810 if (close_index)
812 for (int i = 0; i < nslots; i++)
815}
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
const TupleTableSlotOps TTSOpsHeapTuple
void CatalogTuplesMultiInsertWithInfo(Relation heapRel, TupleTableSlot **slot, int ntuples, CatalogIndexState indstate)
#define MAX_CATALOG_MULTI_INSERT_BYTES
static Datum BoolGetDatum(bool X)
static Datum NameGetDatum(const NameData *X)
static Datum Int32GetDatum(int32 X)
static Datum CharGetDatum(char X)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
References FormExtraData_pg_attribute::attoptions, FormExtraData_pg_attribute::attstattarget, BoolGetDatum(), CatalogCloseIndexes(), CatalogOpenIndexes(), CatalogTuplesMultiInsertWithInfo(), CharGetDatum(), ExecClearTuple(), ExecDropSingleTupleTableSlot(), ExecStoreVirtualTuple(), FormData_pg_attribute, i, Int16GetDatum(), Int32GetDatum(), InvalidOid, NullableDatum::isnull, MakeSingleTupleTableSlot(), MAX_CATALOG_MULTI_INSERT_BYTES, Min, NameGetDatum(), TupleDescData::natts, ObjectIdGetDatum(), palloc(), pfree(), RelationGetDescr, TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, TTSOpsHeapTuple, TupleDescAttr(), and NullableDatum::value.
Referenced by AddNewAttributeTuples(), AppendAttributeTuples(), and ATExecAddColumn().
◆ InsertPgClassTuple()
Definition at line 901 of file heap.c.
906{
909 bool nulls[Natts_pg_class];
911
912
914 memset(nulls, false, sizeof(nulls));
915
927 values[Anum_pg_class_relallvisible - 1] = Int32GetDatum(rd_rel->relallvisible);
928 values[Anum_pg_class_relallfrozen - 1] = Int32GetDatum(rd_rel->relallfrozen);
930 values[Anum_pg_class_relhasindex - 1] = BoolGetDatum(rd_rel->relhasindex);
931 values[Anum_pg_class_relisshared - 1] = BoolGetDatum(rd_rel->relisshared);
932 values[Anum_pg_class_relpersistence - 1] = CharGetDatum(rd_rel->relpersistence);
936 values[Anum_pg_class_relhasrules - 1] = BoolGetDatum(rd_rel->relhasrules);
937 values[Anum_pg_class_relhastriggers - 1] = BoolGetDatum(rd_rel->relhastriggers);
938 values[Anum_pg_class_relrowsecurity - 1] = BoolGetDatum(rd_rel->relrowsecurity);
939 values[Anum_pg_class_relforcerowsecurity - 1] = BoolGetDatum(rd_rel->relforcerowsecurity);
940 values[Anum_pg_class_relhassubclass - 1] = BoolGetDatum(rd_rel->relhassubclass);
941 values[Anum_pg_class_relispopulated - 1] = BoolGetDatum(rd_rel->relispopulated);
942 values[Anum_pg_class_relreplident - 1] = CharGetDatum(rd_rel->relreplident);
943 values[Anum_pg_class_relispartition - 1] = BoolGetDatum(rd_rel->relispartition);
947 if (relacl != (Datum) 0)
948 values[Anum_pg_class_relacl - 1] = relacl;
949 else
950 nulls[Anum_pg_class_relacl - 1] = true;
951 if (reloptions != (Datum) 0)
952 values[Anum_pg_class_reloptions - 1] = reloptions;
953 else
954 nulls[Anum_pg_class_reloptions - 1] = true;
955
956
957 nulls[Anum_pg_class_relpartbound - 1] = true;
958
960
961
963
965}
static Datum values[MAXATTR]
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
static Datum Float4GetDatum(float4 X)
static Datum TransactionIdGetDatum(TransactionId X)
static Datum MultiXactIdGetDatum(MultiXactId X)
References BoolGetDatum(), CatalogTupleInsert(), CharGetDatum(), Float4GetDatum(), heap_form_tuple(), heap_freetuple(), Int16GetDatum(), Int32GetDatum(), MultiXactIdGetDatum(), NameGetDatum(), ObjectIdGetDatum(), RelationData::rd_rel, RelationGetDescr, TransactionIdGetDatum(), and values.
Referenced by AddNewRelationTuple(), and index_create().
◆ RelationClearMissing()
void RelationClearMissing | ( | Relation | rel | ) |
---|
Definition at line 1954 of file heap.c.
1955{
1960 Datum repl_val[Natts_pg_attribute];
1961 bool repl_null[Natts_pg_attribute];
1962 bool repl_repl[Natts_pg_attribute];
1965 newtuple;
1966
1967 memset(repl_val, 0, sizeof(repl_val));
1968 memset(repl_null, false, sizeof(repl_null));
1969 memset(repl_repl, false, sizeof(repl_repl));
1970
1971 repl_val[Anum_pg_attribute_atthasmissing - 1] = BoolGetDatum(false);
1972 repl_null[Anum_pg_attribute_attmissingval - 1] = true;
1973
1974 repl_repl[Anum_pg_attribute_atthasmissing - 1] = true;
1975 repl_repl[Anum_pg_attribute_attmissingval - 1] = true;
1976
1977
1978
1980
1981
1983 {
1988 elog(ERROR, "cache lookup failed for attribute %d of relation %u",
1990
1992
1993
1994 if (attrtuple->atthasmissing)
1995 {
1997 repl_val, repl_null, repl_repl);
1998
2000
2002 }
2003
2005 }
2006
2007
2008
2009
2010
2012}
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
#define RelationGetNumberOfAttributes(relation)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
References attnum, BoolGetDatum(), CatalogTupleUpdate(), elog, ERROR, GETSTRUCT(), heap_freetuple(), heap_modify_tuple(), HeapTupleIsValid, Int16GetDatum(), ObjectIdGetDatum(), RelationGetDescr, RelationGetNumberOfAttributes, RelationGetRelid, ReleaseSysCache(), RowExclusiveLock, SearchSysCache2(), HeapTupleData::t_self, table_close(), and table_open().
Referenced by ATExecAlterColumnType(), ATExecSetExpression(), and finish_heap_swap().
◆ RemoveAttributeById()
Definition at line 1673 of file heap.c.
1674{
1680 Datum valuesAtt[Natts_pg_attribute] = {0};
1681 bool nullsAtt[Natts_pg_attribute] = {0};
1682 bool replacesAtt[Natts_pg_attribute] = {0};
1683
1684
1685
1686
1687
1688
1689
1691
1693
1698 elog(ERROR, "cache lookup failed for attribute %d of relation %u",
1701
1702
1703 attStruct->attisdropped = true;
1704
1705
1706
1707
1708
1709
1710
1711
1712
1714
1715
1716 attStruct->attnotnull = false;
1717
1718
1719 attStruct->attgenerated = '\0';
1720
1721
1722
1723
1724 snprintf(newattname, sizeof(newattname),
1725 "........pg.dropped.%d........", attnum);
1726 namestrcpy(&(attStruct->attname), newattname);
1727
1728
1729 attStruct->atthasmissing = false;
1730 nullsAtt[Anum_pg_attribute_attmissingval - 1] = true;
1731 replacesAtt[Anum_pg_attribute_attmissingval - 1] = true;
1732
1733
1734
1735
1736
1737 nullsAtt[Anum_pg_attribute_attstattarget - 1] = true;
1738 replacesAtt[Anum_pg_attribute_attstattarget - 1] = true;
1739 nullsAtt[Anum_pg_attribute_attacl - 1] = true;
1740 replacesAtt[Anum_pg_attribute_attacl - 1] = true;
1741 nullsAtt[Anum_pg_attribute_attoptions - 1] = true;
1742 replacesAtt[Anum_pg_attribute_attoptions - 1] = true;
1743 nullsAtt[Anum_pg_attribute_attfdwoptions - 1] = true;
1744 replacesAtt[Anum_pg_attribute_attfdwoptions - 1] = true;
1745
1747 valuesAtt, nullsAtt, replacesAtt);
1748
1750
1751
1752
1753
1754
1755
1756
1758
1760
1762}
void namestrcpy(Name name, const char *str)
#define SearchSysCacheCopy2(cacheId, key1, key2)
References AccessExclusiveLock, attnum, CatalogTupleUpdate(), elog, ERROR, GETSTRUCT(), heap_modify_tuple(), HeapTupleIsValid, Int16GetDatum(), InvalidOid, NAMEDATALEN, namestrcpy(), NoLock, ObjectIdGetDatum(), relation_close(), relation_open(), RelationGetDescr, RemoveStatistics(), RowExclusiveLock, SearchSysCacheCopy2, snprintf, HeapTupleData::t_self, table_close(), and table_open().
Referenced by doDeletion().
◆ RemovePartitionKeyByRelId()
void RemovePartitionKeyByRelId | ( | Oid | relid | ) |
---|
Definition at line 3925 of file heap.c.
3926{
3929
3931
3934 elog(ERROR, "cache lookup failed for partition key of relation %u",
3935 relid);
3936
3938
3941}
References CatalogTupleDelete(), elog, ERROR, HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), HeapTupleData::t_self, table_close(), and table_open().
Referenced by heap_drop_with_catalog().
◆ RemoveStatistics()
Definition at line 3398 of file heap.c.
3399{
3403 int nkeys;
3405
3407
3409 Anum_pg_statistic_starelid,
3412
3414 nkeys = 1;
3415 else
3416 {
3418 Anum_pg_statistic_staattnum,
3421 nkeys = 2;
3422 }
3423
3424 scan = systable_beginscan(pgstatistic, StatisticRelidAttnumInhIndexId, true,
3425 NULL, nkeys, key);
3426
3427
3430
3432
3434}
References attnum, BTEqualStrategyNumber, CatalogTupleDelete(), HeapTupleIsValid, Int16GetDatum(), sort-test::key, ObjectIdGetDatum(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().
Referenced by ATExecAlterColumnType(), ATExecSetExpression(), heap_drop_with_catalog(), index_drop(), and RemoveAttributeById().
◆ SetAttrMissing()
void SetAttrMissing | ( | Oid | relid, |
---|---|---|---|
char * | attname, | ||
char * | value | ||
) |
Definition at line 2076 of file heap.c.
2077{
2078 Datum valuesAtt[Natts_pg_attribute] = {0};
2079 bool nullsAtt[Natts_pg_attribute] = {0};
2080 bool replacesAtt[Natts_pg_attribute] = {0};
2081 Datum missingval;
2084 tablerel;
2086 newtup;
2087
2088
2090
2091
2092 if (tablerel->rd_rel->relkind != RELKIND_RELATION)
2093 {
2095 return;
2096 }
2097
2098
2102 elog(ERROR, "cache lookup failed for attribute %s of relation %u",
2105
2106
2111
2112
2113 valuesAtt[Anum_pg_attribute_atthasmissing - 1] = BoolGetDatum(true);
2114 replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
2115 valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
2116 replacesAtt[Anum_pg_attribute_attmissingval - 1] = true;
2117
2119 valuesAtt, nullsAtt, replacesAtt);
2121
2122
2126}
#define OidFunctionCall3(functionId, arg1, arg2, arg3)
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
References AccessExclusiveLock, attname, BoolGetDatum(), CatalogTupleUpdate(), CStringGetDatum(), elog, ERROR, GETSTRUCT(), heap_modify_tuple(), HeapTupleIsValid, Int32GetDatum(), ObjectIdGetDatum(), OidFunctionCall3, RelationData::rd_rel, RelationGetDescr, ReleaseSysCache(), RowExclusiveLock, SearchSysCacheAttName(), HeapTupleData::t_self, table_close(), table_open(), and value.
Referenced by binary_upgrade_set_missing_value().
◆ StoreAttrMissingVal()
Definition at line 2020 of file heap.c.
2021{
2022 Datum valuesAtt[Natts_pg_attribute] = {0};
2023 bool nullsAtt[Natts_pg_attribute] = {0};
2024 bool replacesAtt[Natts_pg_attribute] = {0};
2028 newtup;
2029
2030
2031 Assert(rel->rd_rel->relkind == RELKIND_RELATION);
2032
2033
2035
2040 elog(ERROR, "cache lookup failed for attribute %d of relation %u",
2043
2044
2046 1,
2047 attStruct->atttypid,
2048 attStruct->attlen,
2049 attStruct->attbyval,
2050 attStruct->attalign));
2051
2052
2053 valuesAtt[Anum_pg_attribute_atthasmissing - 1] = BoolGetDatum(true);
2054 replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
2055
2056 valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
2057 replacesAtt[Anum_pg_attribute_attmissingval - 1] = true;
2058
2060 valuesAtt, nullsAtt, replacesAtt);
2062
2063
2066}
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
References Assert(), attnum, BoolGetDatum(), CatalogTupleUpdate(), construct_array(), elog, ERROR, GETSTRUCT(), heap_modify_tuple(), HeapTupleIsValid, Int16GetDatum(), ObjectIdGetDatum(), PointerGetDatum(), RelationData::rd_rel, RelationGetDescr, RelationGetRelid, ReleaseSysCache(), RowExclusiveLock, SearchSysCache2(), HeapTupleData::t_self, table_close(), and table_open().
Referenced by ATExecAddColumn().
◆ StorePartitionBound()
Definition at line 3956 of file heap.c.
3957{
3960 newtuple;
3961 Datum new_val[Natts_pg_class];
3962 bool new_null[Natts_pg_class],
3963 new_repl[Natts_pg_class];
3964 Oid defaultPartOid;
3965
3966
3971 elog(ERROR, "cache lookup failed for relation %u",
3973
3974#ifdef USE_ASSERT_CHECKING
3975 {
3977 bool isnull;
3978
3980 Assert(!classForm->relispartition);
3981 (void) SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relpartbound,
3982 &isnull);
3984 }
3985#endif
3986
3987
3988 memset(new_val, 0, sizeof(new_val));
3989 memset(new_null, false, sizeof(new_null));
3990 memset(new_repl, false, sizeof(new_repl));
3992 new_null[Anum_pg_class_relpartbound - 1] = false;
3993 new_repl[Anum_pg_class_relpartbound - 1] = true;
3995 new_val, new_null, new_repl);
3996
3998
3999
4000
4001
4002
4003 if (rel->rd_rel->relkind == RELKIND_RELATION && rel->rd_rel->relhassubclass)
4005
4009
4010
4011
4012
4013
4017
4018
4020
4021
4022
4023
4024
4025
4026
4027 defaultPartOid =
4031
4033}
#define CStringGetTextDatum(s)
void CacheInvalidateRelcache(Relation relation)
char * nodeToString(const void *obj)
PartitionDesc RelationGetPartitionDesc(Relation rel, bool omit_detached)
Oid get_default_oid_from_partdesc(PartitionDesc partdesc)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
#define SearchSysCacheCopy1(cacheId, key1)
void CommandCounterIncrement(void)
References Assert(), CacheInvalidateRelcache(), CacheInvalidateRelcacheByRelid(), CatalogTupleUpdate(), CommandCounterIncrement(), CStringGetTextDatum, elog, ERROR, get_default_oid_from_partdesc(), GETSTRUCT(), heap_freetuple(), heap_modify_tuple(), HeapTupleIsValid, PartitionBoundSpec::is_default, nodeToString(), ObjectIdGetDatum(), OidIsValid, RelationData::rd_rel, RelationGetDescr, RelationGetPartitionDesc(), RelationGetRelid, RowExclusiveLock, SearchSysCacheCopy1, SysCacheGetAttr(), HeapTupleData::t_self, table_close(), table_open(), and update_default_partition_oid().
Referenced by ATExecAttachPartition(), and DefineRelation().
◆ StorePartitionKey()
Definition at line 3800 of file heap.c.
3807{
3808 int i;
3812 Datum partexprDatum;
3813 Relation pg_partitioned_table;
3815 Datum values[Natts_pg_partitioned_table];
3816 bool nulls[Natts_pg_partitioned_table] = {0};
3820
3821 Assert(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
3822
3823
3825 partopclass_vec = buildoidvector(partopclass, partnatts);
3826 partcollation_vec = buildoidvector(partcollation, partnatts);
3827
3828
3829 if (partexprs)
3830 {
3831 char *exprString;
3832
3835 pfree(exprString);
3836 }
3837 else
3838 partexprDatum = (Datum) 0;
3839
3841
3842
3843 if (!partexprDatum)
3844 nulls[Anum_pg_partitioned_table_partexprs - 1] = true;
3845
3847 values[Anum_pg_partitioned_table_partstrat - 1] = CharGetDatum(strategy);
3848 values[Anum_pg_partitioned_table_partnatts - 1] = Int16GetDatum(partnatts);
3850 values[Anum_pg_partitioned_table_partattrs - 1] = PointerGetDatum(partattrs_vec);
3851 values[Anum_pg_partitioned_table_partclass - 1] = PointerGetDatum(partopclass_vec);
3852 values[Anum_pg_partitioned_table_partcollation - 1] = PointerGetDatum(partcollation_vec);
3853 values[Anum_pg_partitioned_table_partexprs - 1] = partexprDatum;
3854
3856
3859
3860
3863
3864
3865 for (i = 0; i < partnatts; i++)
3866 {
3867 ObjectAddressSet(referenced, OperatorClassRelationId, partopclass[i]);
3869
3870
3872 partcollation[i] != DEFAULT_COLLATION_OID)
3873 {
3874 ObjectAddressSet(referenced, CollationRelationId, partcollation[i]);
3876 }
3877 }
3878
3881
3882
3883
3884
3885
3886
3887
3888 for (i = 0; i < partnatts; i++)
3889 {
3890 if (partattrs[i] == 0)
3891 continue;
3892
3896 }
3897
3898
3899
3900
3901
3902
3903
3904 if (partexprs)
3906 (Node *) partexprs,
3910 true );
3911
3912
3913
3914
3915
3916
3918}
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)
int2vector * buildint2vector(const int16 *int2s, int n)
#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)
oidvector * buildoidvector(const Oid *oids, int n)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
References add_exact_object_address(), Assert(), buildint2vector(), buildoidvector(), CacheInvalidateRelcache(), CatalogTupleInsert(), CharGetDatum(), CStringGetTextDatum, DEPENDENCY_INTERNAL, DEPENDENCY_NORMAL, free_object_addresses(), heap_form_tuple(), i, Int16GetDatum(), InvalidOid, new_object_addresses(), nodeToString(), ObjectAddressSet, ObjectAddressSubSet, ObjectIdGetDatum(), OidIsValid, pfree(), PointerGetDatum(), RelationData::rd_rel, record_object_address_dependencies(), recordDependencyOn(), recordDependencyOnSingleRelExpr(), RelationGetDescr, RelationGetRelid, RowExclusiveLock, table_close(), table_open(), and values.
Referenced by DefineRelation().
◆ SystemAttributeByName()
◆ SystemAttributeDefinition()
Definition at line 236 of file heap.c.
237{
239 elog(ERROR, "invalid system attribute number %d", attno);
240 return SysAtt[-attno - 1];
241}
References elog, ERROR, lengthof, and SysAtt.
Referenced by attnumAttName(), attnumTypeId(), build_index_tlist(), scanNSItemForColumn(), SPI_fname(), SPI_gettype(), SPI_gettypeid(), SPI_getvalue(), and transformIndexConstraint().