PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/bufmask.h"
#include "access/htup_details.h"
#include "access/multixact.h"
#include "access/relation.h"
#include "access/table.h"
#include "access/transam.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "access/xloginsert.h"
#include "access/xlogutils.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_sequence.h"
#include "catalog/pg_type.h"
#include "catalog/storage_xlog.h"
#include "commands/defrem.h"
#include "commands/sequence.h"
#include "commands/tablecmds.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "parser/parse_type.h"
#include "storage/lmgr.h"
#include "storage/proc.h"
#include "storage/smgr.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/resowner.h"
#include "utils/syscache.h"
#include "utils/varlena.h"
Go to the source code of this file.
Data Structures | |
struct | sequence_magic |
struct | SeqTableData |
Macros | |
#define | SEQ_LOG_VALS 32 |
#define | SEQ_MAGIC 0x1717 |
Typedefs | |
typedef struct sequence_magic | sequence_magic |
typedef struct SeqTableData | SeqTableData |
typedef SeqTableData * | SeqTable |
Variables | |
static HTAB * | seqhashtab = NULL |
static SeqTableData * | last_used_seq = NULL |
#define SEQ_LOG_VALS 32 |
Definition at line 57 of file sequence.c.
#define SEQ_MAGIC 0x1717 |
Definition at line 62 of file sequence.c.
typedef SeqTableData* SeqTable |
Definition at line 88 of file sequence.c.
typedef struct SeqTableData SeqTableData |
typedef struct sequence_magic sequence_magic |
ObjectAddress AlterSequence | ( | ParseState * | pstate, |
AlterSeqStmt * | stmt | ||
) |
Definition at line 436 of file sequence.c.
References Assert(), buf, SeqTableData::cached, CatalogTupleUpdate(), elog(), ereport, errmsg(), ERROR, fill_seq_with_data(), GETSTRUCT, GetTopTransactionId(), heap_copytuple(), HeapTupleIsValid, init_params(), init_sequence(), InvalidMultiXactId, InvalidObjectAddress, InvalidOid, InvalidTransactionId, InvokeObjectPostAlterHook, SeqTableData::last, NoLock, NOTICE, ObjectAddressSet, ObjectIdGetDatum(), process_owned_by(), RangeVarCallbackOwnsRelation(), RangeVarGetRelidExtended(), RelationData::rd_rel, read_seq_tuple(), relation_close(), RelationNeedsWAL, RelationSetNewRelfilenumber(), RowExclusiveLock, RVR_MISSING_OK, SearchSysCacheCopy1, SEQRELID, ShareRowExclusiveLock, stmt, HeapTupleData::t_self, table_close(), table_open(), and UnlockReleaseBuffer().
Referenced by ProcessUtilitySlow().
|
static |
Definition at line 1105 of file sequence.c.
References HASHCTL::entrysize, HASH_BLOBS, hash_create(), HASH_ELEM, HASHCTL::keysize, and seqhashtab.
Referenced by init_sequence().
Datum currval_oid | ( | PG_FUNCTION_ARGS | ) |
Definition at line 858 of file sequence.c.
References ACL_SELECT, ACL_USAGE, ACLCHECK_OK, ereport, errcode(), errmsg(), ERROR, GetUserId(), init_sequence(), SeqTableData::last, SeqTableData::last_valid, NoLock, pg_class_aclcheck(), PG_GETARG_OID, PG_RETURN_INT64, relation_close(), RelationGetRelationName, and SeqTableData::relid.
ObjectAddress DefineSequence | ( | ParseState * | pstate, |
CreateSeqStmt * | seq | ||
) |
Definition at line 120 of file sequence.c.
References AccessExclusiveLock, Assert(), BoolGetDatum(), CatalogTupleInsert(), checkMembershipInCurrentExtension(), DefineRelation(), ereport, errcode(), errmsg(), fill_seq_with_data(), CreateSeqStmt::for_identity, FormData_pg_sequence, heap_form_tuple(), heap_freetuple(), i, CreateSeqStmt::if_not_exists, init_params(), Int64GetDatum(), Int64GetDatumFast, InvalidObjectAddress, InvalidOid, ColumnDef::is_not_null, lappend(), FormData_pg_sequence_data::last_value, makeColumnDef(), makeNode, NIL, NoLock, NOTICE, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), OidIsValid, ONCOMMIT_NOOP, CreateSeqStmt::options, CreateSeqStmt::ownerId, process_owned_by(), RangeVarGetAndCheckCreationNamespace(), RelationGetDescr, RangeVar::relname, RowExclusiveLock, SEQ_COL_CALLED, SEQ_COL_FIRSTCOL, SEQ_COL_LASTCOL, SEQ_COL_LASTVAL, SEQ_COL_LOG, CreateSeqStmt::sequence, stmt, table_close(), table_open(), and value.
Referenced by ProcessUtilitySlow().
void DeleteSequenceTuple | ( | Oid | relid | ) |
Definition at line 562 of file sequence.c.
References CatalogTupleDelete(), elog(), ERROR, HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), SEQRELID, HeapTupleData::t_self, table_close(), and table_open().
Referenced by doDeletion().
Definition at line 937 of file sequence.c.
References ACL_UPDATE, ACLCHECK_OK, buf, BufferGetPage(), SeqTableData::cached, elog(), END_CRIT_SECTION, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, GetTopTransactionId(), GetUserId(), HeapTupleIsValid, init_sequence(), FormData_pg_sequence_data::is_called, SeqTableData::last, SeqTableData::last_valid, FormData_pg_sequence_data::last_value, xl_seq_rec::locator, FormData_pg_sequence_data::log_cnt, MarkBufferDirty(), next, NoLock, ObjectIdGetDatum(), PageSetLSN(), pg_class_aclcheck(), PreventCommandIfParallelMode(), PreventCommandIfReadOnly(), RelationData::rd_islocaltemp, RelationData::rd_locator, read_seq_tuple(), REGBUF_WILL_INIT, relation_close(), RelationGetRelationName, RelationNeedsWAL, ReleaseSysCache(), SeqTableData::relid, SearchSysCache1(), SEQRELID, START_CRIT_SECTION, HeapTupleData::t_data, HeapTupleData::t_len, UnlockReleaseBuffer(), XLOG_SEQ_LOG, XLogBeginInsert(), XLogInsert(), XLogRegisterBuffer(), and XLogRegisterData().
Referenced by setval3_oid(), and setval_oid().
|
static |
Definition at line 358 of file sequence.c.
References Assert(), BMR_REL, buf, BufferGetBlockNumber(), BufferGetPage(), BufferGetPageSize(), EB_LOCK_FIRST, EB_SKIP_EXTENSION_LOCK, elog(), END_CRIT_SECTION, ERROR, ExtendBufferedRel(), FirstCommandId, FirstOffsetNumber, FrozenTransactionId, GetTopTransactionId(), HEAP_XMAX_INVALID, HeapTupleHeaderSetCmin, HeapTupleHeaderSetXmax, HeapTupleHeaderSetXmin, HeapTupleHeaderSetXminFrozen, INIT_FORKNUM, InvalidOffsetNumber, InvalidTransactionId, ItemPointerSet(), xl_seq_rec::locator, sequence_magic::magic, MarkBufferDirty(), PageAddItem, PageGetSpecialPointer(), PageInit(), PageSetLSN(), RelationData::rd_locator, REGBUF_WILL_INIT, RelationNeedsWAL, SEQ_MAGIC, START_CRIT_SECTION, HeapTupleHeaderData::t_ctid, HeapTupleData::t_data, HeapTupleHeaderData::t_infomask, HeapTupleData::t_len, UnlockReleaseBuffer(), XLOG_SEQ_LOG, XLogBeginInsert(), XLogInsert(), XLogRegisterBuffer(), and XLogRegisterData().
Referenced by fill_seq_with_data().
Definition at line 337 of file sequence.c.
References fill_seq_fork_with_data(), FlushRelationBuffers(), INIT_FORKNUM, InvalidBackendId, log_smgrcreate(), MAIN_FORKNUM, RelationData::rd_locator, RelationData::rd_rel, smgrclose(), smgrcreate(), and smgropen().
Referenced by AlterSequence(), DefineSequence(), ResetSequence(), and SequenceChangePersistence().
|
static |
Definition at line 1255 of file sequence.c.
References DefElem::arg, Assert(), BoolIsValid, boolVal, defGetInt64(), defGetQualifiedName(), defGetTypeName(), DefElem::defname, elog(), ereport, errcode(), errmsg(), ERROR, errorConflictingDefElem(), format_type_be(), FormData_pg_sequence_data::is_called, FormData_pg_sequence_data::last_value, lfirst, DefElem::location, FormData_pg_sequence_data::log_cnt, NIL, parser_errposition(), PG_INT16_MAX, PG_INT16_MIN, PG_INT32_MAX, PG_INT32_MIN, PG_INT64_MAX, PG_INT64_MIN, and typenameTypeId().
Referenced by AlterSequence(), and DefineSequence().
Definition at line 1121 of file sequence.c.
References SeqTableData::cached, create_seq_hashtable(), ereport, errcode(), errmsg(), ERROR, SeqTableData::filenumber, HASH_ENTER, hash_search(), InvalidLocalTransactionId, InvalidRelFileNumber, SeqTableData::last, SeqTableData::last_valid, lock_and_open_sequence(), SeqTableData::lxid, RelationData::rd_rel, RelationGetRelationName, and seqhashtab.
Referenced by AlterSequence(), currval_oid(), do_setval(), nextval_internal(), pg_sequence_last_value(), ResetSequence(), and SequenceChangePersistence().
Datum lastval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 889 of file sequence.c.
References ACL_SELECT, ACL_USAGE, ACLCHECK_OK, Assert(), ereport, errcode(), errmsg(), ERROR, GetUserId(), SeqTableData::last, last_used_seq, SeqTableData::last_valid, lock_and_open_sequence(), NoLock, ObjectIdGetDatum(), pg_class_aclcheck(), PG_RETURN_INT64, relation_close(), RelationGetRelationName, SeqTableData::relid, RELOID, and SearchSysCacheExists1.
Definition at line 1077 of file sequence.c.
References CurrentResourceOwner, LockRelationOid(), SeqTableData::lxid, PGPROC::lxid, MyProc, NoLock, relation_open(), SeqTableData::relid, RowExclusiveLock, and TopTransactionResourceOwner.
Referenced by init_sequence(), and lastval().
Datum nextval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 585 of file sequence.c.
References makeRangeVarFromNameList(), nextval_internal(), NoLock, PG_GETARG_TEXT_PP, PG_RETURN_INT64, RangeVarGetRelid, and textToQualifiedNameList().
Definition at line 615 of file sequence.c.
References ACL_UPDATE, ACL_USAGE, ACLCHECK_OK, Assert(), buf, BufferGetPage(), SeqTableData::cached, elog(), END_CRIT_SECTION, ereport, errcode(), errmsg(), ERROR, GetRedoRecPtr(), GETSTRUCT, GetTopTransactionId(), GetUserId(), HeapTupleIsValid, SeqTableData::increment, init_sequence(), FormData_pg_sequence_data::is_called, SeqTableData::last, last_used_seq, SeqTableData::last_valid, FormData_pg_sequence_data::last_value, xl_seq_rec::locator, FormData_pg_sequence_data::log_cnt, MarkBufferDirty(), next, NoLock, ObjectIdGetDatum(), PageGetLSN(), PageSetLSN(), pg_class_aclcheck(), PreventCommandIfParallelMode(), PreventCommandIfReadOnly(), RelationData::rd_islocaltemp, RelationData::rd_locator, read_seq_tuple(), REGBUF_WILL_INIT, relation_close(), RelationGetRelationName, RelationNeedsWAL, ReleaseSysCache(), SeqTableData::relid, SearchSysCache1(), SEQ_LOG_VALS, SEQRELID, START_CRIT_SECTION, HeapTupleData::t_data, HeapTupleData::t_len, UnlockReleaseBuffer(), XLOG_SEQ_LOG, XLogBeginInsert(), XLogInsert(), XLogRegisterBuffer(), and XLogRegisterData().
Referenced by ExecEvalNextValueExpr(), nextval(), and nextval_oid().
Datum nextval_oid | ( | PG_FUNCTION_ARGS | ) |
Definition at line 607 of file sequence.c.
References nextval_internal(), PG_GETARG_OID, and PG_RETURN_INT64.
Datum pg_sequence_last_value | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1780 of file sequence.c.
References ACL_SELECT, ACL_USAGE, ACLCHECK_OK, buf, ereport, errcode(), errmsg(), ERROR, GetUserId(), init_sequence(), FormData_pg_sequence_data::is_called, FormData_pg_sequence_data::last_value, NoLock, pg_class_aclcheck(), PG_GETARG_OID, PG_RETURN_INT64, PG_RETURN_NULL, read_seq_tuple(), relation_close(), RelationGetRelationName, and UnlockReleaseBuffer().
Datum pg_sequence_parameters | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1736 of file sequence.c.
References ACL_SELECT, ACL_UPDATE, ACL_USAGE, ACLCHECK_OK, BoolGetDatum(), elog(), ereport, errcode(), errmsg(), ERROR, get_call_result_type(), get_rel_name(), GETSTRUCT, GetUserId(), heap_form_tuple(), HeapTupleGetDatum(), HeapTupleIsValid, Int64GetDatum(), ObjectIdGetDatum(), pg_class_aclcheck(), PG_GETARG_OID, ReleaseSysCache(), SearchSysCache1(), SEQRELID, TYPEFUNC_COMPOSITE, and values.
Definition at line 1588 of file sequence.c.
References AccessShareLock, Assert(), attnum, ObjectAddress::classId, deleteDependencyRecordsForClass(), DEPENDENCY_AUTO, DEPENDENCY_INTERNAL, ereport, errcode(), errdetail(), errdetail_relkind_not_supported(), errhint(), errmsg(), ERROR, get_attnum(), get_rel_name(), InvalidAttrNumber, linitial, list_copy_head(), list_length(), llast, makeRangeVarFromNameList(), NoLock, ObjectAddress::objectId, ObjectAddress::objectSubId, RelationData::rd_rel, recordDependencyOn(), relation_close(), relation_openrv(), RelationGetNamespace, RelationGetRelationName, RelationGetRelid, relname, sequenceIsOwned(), and strVal.
Referenced by AlterSequence(), and DefineSequence().
|
static |
Definition at line 1188 of file sequence.c.
References Assert(), buf, BUFFER_LOCK_EXCLUSIVE, BufferGetPage(), elog(), ERROR, FirstOffsetNumber, GETSTRUCT, HEAP_XMAX_COMMITTED, HEAP_XMAX_INVALID, HEAP_XMAX_IS_MULTI, HeapTupleHeaderGetRawXmax, HeapTupleHeaderSetXmax, InvalidTransactionId, ItemIdGetLength, ItemIdIsNormal, LockBuffer(), sequence_magic::magic, MarkBufferDirtyHint(), PageGetItem(), PageGetItemId(), PageGetSpecialPointer(), ReadBuffer(), RelationGetRelationName, SEQ_MAGIC, HeapTupleData::t_data, HeapTupleHeaderData::t_infomask, and HeapTupleData::t_len.
Referenced by AlterSequence(), do_setval(), nextval_internal(), pg_sequence_last_value(), ResetSequence(), and SequenceChangePersistence().
void ResetSequence | ( | Oid | seq_relid | ) |
Definition at line 261 of file sequence.c.
References Assert(), buf, SeqTableData::cached, elog(), ERROR, fill_seq_with_data(), GETSTRUCT, heap_copytuple(), HeapTupleIsValid, init_sequence(), InvalidMultiXactId, InvalidTransactionId, FormData_pg_sequence_data::is_called, SeqTableData::last, FormData_pg_sequence_data::last_value, FormData_pg_sequence_data::log_cnt, NoLock, ObjectIdGetDatum(), RelationData::rd_rel, read_seq_tuple(), relation_close(), RelationSetNewRelfilenumber(), ReleaseSysCache(), SearchSysCache1(), SEQRELID, and UnlockReleaseBuffer().
Referenced by ExecuteTruncateGuts().
void ResetSequenceCaches | ( | void | ) |
Definition at line 1869 of file sequence.c.
References hash_destroy(), last_used_seq, and seqhashtab.
Referenced by DiscardAll(), and DiscardCommand().
void seq_mask | ( | char * | page, |
BlockNumber | blkno | ||
) |
Definition at line 1884 of file sequence.c.
References mask_page_lsn_and_checksum(), and mask_unused_space().
void seq_redo | ( | XLogReaderState * | record | ) |
Definition at line 1816 of file sequence.c.
References BufferGetPage(), BufferGetPageSize(), elog(), XLogReaderState::EndRecPtr, FirstOffsetNumber, InvalidOffsetNumber, sequence_magic::magic, MarkBufferDirty(), PageAddItem, PageGetSpecialPointer(), PageInit(), PageSetLSN(), palloc(), PANIC, pfree(), SEQ_MAGIC, UnlockReleaseBuffer(), XLOG_SEQ_LOG, XLogInitBufferForRedo(), XLogRecGetData, XLogRecGetDataLen, XLogRecGetInfo, and XLR_INFO_MASK.
Definition at line 1702 of file sequence.c.
References elog(), ERROR, GETSTRUCT, HeapTupleIsValid, INT64_FORMAT, lappend(), makeBoolean(), makeDefElem(), makeFloat(), NIL, ObjectIdGetDatum(), options, psprintf(), ReleaseSysCache(), SearchSysCache1(), and SEQRELID.
Referenced by transformTableLikeClause().
void SequenceChangePersistence | ( | Oid | relid, |
char | newrelpersistence | ||
) |
Definition at line 540 of file sequence.c.
References buf, fill_seq_with_data(), GetTopTransactionId(), init_sequence(), NoLock, read_seq_tuple(), relation_close(), RelationNeedsWAL, RelationSetNewRelfilenumber(), and UnlockReleaseBuffer().
Referenced by ATRewriteTables().
Datum setval3_oid | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1056 of file sequence.c.
References do_setval(), next, PG_GETARG_BOOL, PG_GETARG_INT64, PG_GETARG_OID, and PG_RETURN_INT64.
Datum setval_oid | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1041 of file sequence.c.
References do_setval(), next, PG_GETARG_INT64, PG_GETARG_OID, and PG_RETURN_INT64.
|
static |
Definition at line 96 of file sequence.c.
Referenced by lastval(), nextval_internal(), and ResetSequenceCaches().
|
static |
Definition at line 90 of file sequence.c.
Referenced by create_seq_hashtable(), init_sequence(), and ResetSequenceCaches().