MCPcopy Create free account
hub / github.com/apache/cloudberry / do_setval

Function do_setval

src/backend/commands/sequence.c:1069–1183  ·  view source on GitHub ↗

* Main internal procedure that handles 2 & 3 arg forms of SETVAL. * * Note that the 3 arg version (which sets the is_called flag) is * only for use in pg_dump, and setting the is_called flag may not * work if multiple users are attached to the database and referencing * the sequence (unlikely if pg_dump is restoring it). * * It is necessary to have the 3 arg version so that pg_dump can * r

Source from the content-addressed store, hash-verified

1067 * sequence.
1068 */
1069static void
1070do_setval(Oid relid, int64 next, bool iscalled)
1071{
1072 SeqTable elm;
1073 Relation seqrel;
1074 Buffer buf;
1075 HeapTupleData seqdatatuple;
1076 Form_pg_sequence_data seq;
1077 HeapTuple pgstuple;
1078 Form_pg_sequence pgsform;
1079 int64 maxv,
1080 minv;
1081
1082 if (Gp_role == GP_ROLE_EXECUTE)
1083 {
1084 ereport(ERROR,
1085 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1086 errmsg("setval() not supported in this context")));
1087 }
1088
1089 /* open and lock sequence */
1090 init_sequence(relid, &elm, &seqrel);
1091
1092 if (pg_class_aclcheck(elm->key.relid, GetUserId(), ACL_UPDATE) != ACLCHECK_OK)
1093 ereport(ERROR,
1094 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1095 errmsg("permission denied for sequence %s",
1096 RelationGetRelationName(seqrel))));
1097
1098 pgstuple = SearchSysCache1(SEQRELID, ObjectIdGetDatum(relid));
1099 if (!HeapTupleIsValid(pgstuple))
1100 elog(ERROR, "cache lookup failed for sequence %u", relid);
1101 pgsform = (Form_pg_sequence) GETSTRUCT(pgstuple);
1102 maxv = pgsform->seqmax;
1103 minv = pgsform->seqmin;
1104 ReleaseSysCache(pgstuple);
1105
1106 /* read-only transactions may only modify temp sequences */
1107 if (!seqrel->rd_islocaltemp)
1108 PreventCommandIfReadOnly("setval()");
1109
1110 /*
1111 * Forbid this during parallel operation because, to make it work, the
1112 * cooperating backends would need to share the backend-local cached
1113 * sequence information. Currently, we don't support that.
1114 */
1115 PreventCommandIfParallelMode("setval()");
1116
1117 /* lock page' buffer and read tuple */
1118 seq = read_seq_tuple(seqrel, &buf, &seqdatatuple);
1119
1120 if ((next < minv) || (next > maxv))
1121 {
1122 char bufv[100],
1123 bufm[100],
1124 bufx[100];
1125
1126 snprintf(bufv, sizeof(bufv), INT64_FORMAT, next);

Callers 2

setval_oidFunction · 0.85
setval3_oidFunction · 0.85

Calls 15

init_sequenceFunction · 0.85
pg_class_aclcheckFunction · 0.85
GetUserIdFunction · 0.85
SearchSysCache1Function · 0.85
ObjectIdGetDatumFunction · 0.85
ReleaseSysCacheFunction · 0.85
PreventCommandIfReadOnlyFunction · 0.85
read_seq_tupleFunction · 0.85
GetTopTransactionIdFunction · 0.85
MarkBufferDirtyFunction · 0.85
XLogBeginInsertFunction · 0.85

Tested by

no test coverage detected