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/sequence.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 |
#define | PG_GET_SEQUENCE_DATA_COLS 2 |
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 PG_GET_SEQUENCE_DATA_COLS 2 |
#define SEQ_LOG_VALS 32 |
Definition at line 58 of file sequence.c.
#define SEQ_MAGIC 0x1717 |
Definition at line 63 of file sequence.c.
typedef SeqTableData* SeqTable |
Definition at line 89 of file sequence.c.
typedef struct SeqTableData SeqTableData |
typedef struct sequence_magic sequence_magic |
ObjectAddress AlterSequence | ( | ParseState * | pstate, |
AlterSeqStmt * | stmt | ||
) |
Definition at line 437 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(), RelationNeedsWAL, RelationSetNewRelfilenumber(), RowExclusiveLock, RVR_MISSING_OK, SearchSysCacheCopy1, sequence_close(), ShareRowExclusiveLock, stmt, HeapTupleData::t_self, table_close(), table_open(), and UnlockReleaseBuffer().
Referenced by ProcessUtilitySlow().
|
static |
Definition at line 1113 of file sequence.c.
References ctl, HASH_BLOBS, hash_create(), HASH_ELEM, and seqhashtab.
Referenced by init_sequence().
Datum currval_oid | ( | PG_FUNCTION_ARGS | ) |
Definition at line 866 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, RelationGetRelationName, SeqTableData::relid, and sequence_close().
ObjectAddress DefineSequence | ( | ParseState * | pstate, |
CreateSeqStmt * | seq | ||
) |
Definition at line 121 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, sequence_close(), sequence_open(), stmt, table_close(), table_open(), and value.
Referenced by ProcessUtilitySlow().
void DeleteSequenceTuple | ( | Oid | relid | ) |
Definition at line 570 of file sequence.c.
References CatalogTupleDelete(), elog, ERROR, HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), HeapTupleData::t_self, table_close(), and table_open().
Referenced by doDeletion().
Definition at line 945 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, RelationGetRelationName, RelationNeedsWAL, ReleaseSysCache(), SeqTableData::relid, SearchSysCache1(), sequence_close(), 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 359 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 338 of file sequence.c.
References fill_seq_fork_with_data(), FlushRelationBuffers(), INIT_FORKNUM, INVALID_PROC_NUMBER, 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 1257 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 1129 of file sequence.c.
References SeqTableData::cached, create_seq_hashtable(), SeqTableData::filenumber, HASH_ENTER, hash_search(), InvalidLocalTransactionId, InvalidRelFileNumber, SeqTableData::last, SeqTableData::last_valid, lock_and_open_sequence(), SeqTableData::lxid, RelationData::rd_rel, and seqhashtab.
Referenced by AlterSequence(), currval_oid(), do_setval(), nextval_internal(), pg_get_sequence_data(), pg_sequence_last_value(), ResetSequence(), and SequenceChangePersistence().
Datum lastval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 897 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, RelationGetRelationName, SeqTableData::relid, SearchSysCacheExists1, and sequence_close().
Definition at line 1085 of file sequence.c.
References CurrentResourceOwner, LockRelationOid(), SeqTableData::lxid, PGPROC::lxid, MyProc, NoLock, SeqTableData::relid, RowExclusiveLock, sequence_open(), TopTransactionResourceOwner, and PGPROC::vxid.
Referenced by init_sequence(), and lastval().
Datum nextval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 593 of file sequence.c.
References makeRangeVarFromNameList(), nextval_internal(), NoLock, PG_GETARG_TEXT_PP, PG_RETURN_INT64, RangeVarGetRelid, and textToQualifiedNameList().
Definition at line 623 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, RelationGetRelationName, RelationNeedsWAL, ReleaseSysCache(), SeqTableData::relid, SearchSysCache1(), SEQ_LOG_VALS, sequence_close(), 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 615 of file sequence.c.
References nextval_internal(), PG_GETARG_OID, and PG_RETURN_INT64.
Datum pg_get_sequence_data | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1787 of file sequence.c.
References ACL_SELECT, ACLCHECK_OK, BlessTupleDesc(), BoolGetDatum(), buf, CreateTemplateTupleDesc(), GetUserId(), heap_form_tuple(), HeapTupleGetDatum(), init_sequence(), Int64GetDatum(), FormData_pg_sequence_data::is_called, FormData_pg_sequence_data::last_value, NoLock, pg_class_aclcheck(), PG_GET_SEQUENCE_DATA_COLS, PG_GETARG_OID, PG_RETURN_DATUM, read_seq_tuple(), RecoveryInProgress(), RELATION_IS_OTHER_TEMP, RelationIsPermanent, sequence_close(), TupleDescInitEntry(), UnlockReleaseBuffer(), and values.
Datum pg_sequence_last_value | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1845 of file sequence.c.
References ACL_SELECT, ACL_USAGE, ACLCHECK_OK, buf, 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(), RecoveryInProgress(), RELATION_IS_OTHER_TEMP, RelationIsPermanent, sequence_close(), and UnlockReleaseBuffer().
Datum pg_sequence_parameters | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1741 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(), TYPEFUNC_COMPOSITE, and values.
Definition at line 1593 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 1190 of file sequence.c.
References Assert, buf, BUFFER_LOCK_EXCLUSIVE, BufferGetPage(), elog, ERROR, FirstOffsetNumber, GETSTRUCT, 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_get_sequence_data(), pg_sequence_last_value(), ResetSequence(), and SequenceChangePersistence().
void ResetSequence | ( | Oid | seq_relid | ) |
Definition at line 262 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(), RelationSetNewRelfilenumber(), ReleaseSysCache(), SearchSysCache1(), sequence_close(), and UnlockReleaseBuffer().
Referenced by ExecuteTruncateGuts().
void ResetSequenceCaches | ( | void | ) |
Definition at line 1943 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 1958 of file sequence.c.
References mask_page_lsn_and_checksum(), and mask_unused_space().
void seq_redo | ( | XLogReaderState * | record | ) |
Definition at line 1890 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, and XLogRecGetInfo.
Definition at line 1707 of file sequence.c.
References elog, ERROR, GETSTRUCT, HeapTupleIsValid, INT64_FORMAT, lappend(), makeBoolean(), makeDefElem(), makeFloat(), NIL, ObjectIdGetDatum(), options, psprintf(), ReleaseSysCache(), and SearchSysCache1().
Referenced by transformTableLikeClause().
void SequenceChangePersistence | ( | Oid | relid, |
char | newrelpersistence | ||
) |
Definition at line 541 of file sequence.c.
References AccessExclusiveLock, buf, fill_seq_with_data(), GetTopTransactionId(), init_sequence(), LockRelationOid(), NoLock, read_seq_tuple(), RelationNeedsWAL, RelationSetNewRelfilenumber(), sequence_close(), and UnlockReleaseBuffer().
Referenced by ATRewriteTables().
Datum setval3_oid | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1064 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 1049 of file sequence.c.
References do_setval(), next, PG_GETARG_INT64, PG_GETARG_OID, and PG_RETURN_INT64.
|
static |
Definition at line 97 of file sequence.c.
Referenced by lastval(), nextval_internal(), and ResetSequenceCaches().
|
static |
Definition at line 91 of file sequence.c.
Referenced by create_seq_hashtable(), init_sequence(), and ResetSequenceCaches().