diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:15:05 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:15:05 +0000 |
commit | 46651ce6fe013220ed397add242004d764fc0153 (patch) | |
tree | 6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/include/commands | |
parent | Initial commit. (diff) | |
download | postgresql-14-46651ce6fe013220ed397add242004d764fc0153.tar.xz postgresql-14-46651ce6fe013220ed397add242004d764fc0153.zip |
Adding upstream version 14.5.upstream/14.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
36 files changed, 2524 insertions, 0 deletions
diff --git a/src/include/commands/alter.h b/src/include/commands/alter.h new file mode 100644 index 0000000..7b12e9a --- /dev/null +++ b/src/include/commands/alter.h @@ -0,0 +1,35 @@ +/*------------------------------------------------------------------------- + * + * alter.h + * prototypes for commands/alter.c + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/alter.h + * + *------------------------------------------------------------------------- + */ +#ifndef ALTER_H +#define ALTER_H + +#include "catalog/dependency.h" +#include "catalog/objectaddress.h" +#include "nodes/parsenodes.h" +#include "utils/relcache.h" + +extern ObjectAddress ExecRenameStmt(RenameStmt *stmt); + +extern ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, + ObjectAddress *refAddress); +extern ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, + ObjectAddress *oldSchemaAddr); +extern Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, + ObjectAddresses *objsMoved); + +extern ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt); +extern void AlterObjectOwner_internal(Relation catalog, Oid objectId, + Oid new_ownerId); + +#endif /* ALTER_H */ diff --git a/src/include/commands/async.h b/src/include/commands/async.h new file mode 100644 index 0000000..85bfb24 --- /dev/null +++ b/src/include/commands/async.h @@ -0,0 +1,54 @@ +/*------------------------------------------------------------------------- + * + * async.h + * Asynchronous notification: NOTIFY, LISTEN, UNLISTEN + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/async.h + * + *------------------------------------------------------------------------- + */ +#ifndef ASYNC_H +#define ASYNC_H + +#include <signal.h> + +/* + * The number of SLRU page buffers we use for the notification queue. + */ +#define NUM_NOTIFY_BUFFERS 8 + +extern bool Trace_notify; +extern volatile sig_atomic_t notifyInterruptPending; + +extern Size AsyncShmemSize(void); +extern void AsyncShmemInit(void); + +extern void NotifyMyFrontEnd(const char *channel, + const char *payload, + int32 srcPid); + +/* notify-related SQL statements */ +extern void Async_Notify(const char *channel, const char *payload); +extern void Async_Listen(const char *channel); +extern void Async_Unlisten(const char *channel); +extern void Async_UnlistenAll(void); + +/* perform (or cancel) outbound notify processing at transaction commit */ +extern void PreCommit_Notify(void); +extern void AtCommit_Notify(void); +extern void AtAbort_Notify(void); +extern void AtSubCommit_Notify(void); +extern void AtSubAbort_Notify(void); +extern void AtPrepare_Notify(void); +extern void ProcessCompletedNotifies(void); + +/* signal handler for inbound notifies (PROCSIG_NOTIFY_INTERRUPT) */ +extern void HandleNotifyInterrupt(void); + +/* process interrupts */ +extern void ProcessNotifyInterrupt(bool flush); + +#endif /* ASYNC_H */ diff --git a/src/include/commands/cluster.h b/src/include/commands/cluster.h new file mode 100644 index 0000000..a941f2a --- /dev/null +++ b/src/include/commands/cluster.h @@ -0,0 +1,49 @@ +/*------------------------------------------------------------------------- + * + * cluster.h + * header file for postgres cluster command stuff + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994-5, Regents of the University of California + * + * src/include/commands/cluster.h + * + *------------------------------------------------------------------------- + */ +#ifndef CLUSTER_H +#define CLUSTER_H + +#include "nodes/parsenodes.h" +#include "parser/parse_node.h" +#include "storage/lock.h" +#include "utils/relcache.h" + + +/* flag bits for ClusterParams->flags */ +#define CLUOPT_RECHECK 0x01 /* recheck relation state */ +#define CLUOPT_VERBOSE 0x02 /* print progress info */ + +/* options for CLUSTER */ +typedef struct ClusterParams +{ + bits32 options; /* bitmask of CLUOPT_* */ +} ClusterParams; + +extern void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel); +extern void cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params); +extern void check_index_is_clusterable(Relation OldHeap, Oid indexOid, + bool recheck, LOCKMODE lockmode); +extern void mark_index_clustered(Relation rel, Oid indexOid, bool is_internal); + +extern Oid make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, char relpersistence, + LOCKMODE lockmode); +extern void finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, + bool is_system_catalog, + bool swap_toast_by_content, + bool check_constraints, + bool is_internal, + TransactionId frozenXid, + MultiXactId minMulti, + char newrelpersistence); + +#endif /* CLUSTER_H */ diff --git a/src/include/commands/collationcmds.h b/src/include/commands/collationcmds.h new file mode 100644 index 0000000..e49a5db --- /dev/null +++ b/src/include/commands/collationcmds.h @@ -0,0 +1,25 @@ +/*------------------------------------------------------------------------- + * + * collationcmds.h + * prototypes for collationcmds.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/collationcmds.h + * + *------------------------------------------------------------------------- + */ + +#ifndef COLLATIONCMDS_H +#define COLLATIONCMDS_H + +#include "catalog/objectaddress.h" +#include "parser/parse_node.h" + +extern ObjectAddress DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_exists); +extern void IsThereCollationInNamespace(const char *collname, Oid nspOid); +extern ObjectAddress AlterCollation(AlterCollationStmt *stmt); + +#endif /* COLLATIONCMDS_H */ diff --git a/src/include/commands/comment.h b/src/include/commands/comment.h new file mode 100644 index 0000000..3a5f725 --- /dev/null +++ b/src/include/commands/comment.h @@ -0,0 +1,45 @@ +/* + * src/include/commands/comment.h + * + *------------------------------------------------------------------------- + * + * comment.h + * + * Prototypes for functions in commands/comment.c + * + * Copyright (c) 1999-2021, PostgreSQL Global Development Group + * + *------------------------------------------------------------------------- + */ + +#ifndef COMMENT_H +#define COMMENT_H + +#include "catalog/objectaddress.h" +#include "nodes/parsenodes.h" + +/*------------------------------------------------------------------ + * Function Prototypes -- + * + * The following prototypes define the public functions of the comment + * related routines. CommentObject() implements the SQL "COMMENT ON" + * command. DeleteComments() deletes all comments for an object. + * CreateComments creates (or deletes, if comment is NULL) a comment + * for a specific key. There are versions of these two methods for + * both normal and shared objects. + *------------------------------------------------------------------ + */ + +extern ObjectAddress CommentObject(CommentStmt *stmt); + +extern void DeleteComments(Oid oid, Oid classoid, int32 subid); + +extern void CreateComments(Oid oid, Oid classoid, int32 subid, const char *comment); + +extern void DeleteSharedComments(Oid oid, Oid classoid); + +extern void CreateSharedComments(Oid oid, Oid classoid, const char *comment); + +extern char *GetComment(Oid oid, Oid classoid, int32 subid); + +#endif /* COMMENT_H */ diff --git a/src/include/commands/conversioncmds.h b/src/include/commands/conversioncmds.h new file mode 100644 index 0000000..0438538 --- /dev/null +++ b/src/include/commands/conversioncmds.h @@ -0,0 +1,23 @@ +/*------------------------------------------------------------------------- + * + * conversioncmds.h + * prototypes for conversioncmds.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/conversioncmds.h + * + *------------------------------------------------------------------------- + */ + +#ifndef CONVERSIONCMDS_H +#define CONVERSIONCMDS_H + +#include "catalog/objectaddress.h" +#include "nodes/parsenodes.h" + +extern ObjectAddress CreateConversionCommand(CreateConversionStmt *parsetree); + +#endif /* CONVERSIONCMDS_H */ diff --git a/src/include/commands/copy.h b/src/include/commands/copy.h new file mode 100644 index 0000000..264895d --- /dev/null +++ b/src/include/commands/copy.h @@ -0,0 +1,89 @@ +/*------------------------------------------------------------------------- + * + * copy.h + * Definitions for using the POSTGRES copy command. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/copy.h + * + *------------------------------------------------------------------------- + */ +#ifndef COPY_H +#define COPY_H + +#include "nodes/execnodes.h" +#include "nodes/parsenodes.h" +#include "parser/parse_node.h" +#include "tcop/dest.h" + +/* + * A struct to hold COPY options, in a parsed form. All of these are related + * to formatting, except for 'freeze', which doesn't really belong here, but + * it's expedient to parse it along with all the other options. + */ +typedef struct CopyFormatOptions +{ + /* parameters from the COPY command */ + int file_encoding; /* file or remote side's character encoding, + * -1 if not specified */ + bool binary; /* binary format? */ + bool freeze; /* freeze rows on loading? */ + bool csv_mode; /* Comma Separated Value format? */ + bool header_line; /* CSV header line? */ + char *null_print; /* NULL marker string (server encoding!) */ + int null_print_len; /* length of same */ + char *null_print_client; /* same converted to file encoding */ + char *delim; /* column delimiter (must be 1 byte) */ + char *quote; /* CSV quote char (must be 1 byte) */ + char *escape; /* CSV escape char (must be 1 byte) */ + List *force_quote; /* list of column names */ + bool force_quote_all; /* FORCE_QUOTE *? */ + bool *force_quote_flags; /* per-column CSV FQ flags */ + List *force_notnull; /* list of column names */ + bool *force_notnull_flags; /* per-column CSV FNN flags */ + List *force_null; /* list of column names */ + bool *force_null_flags; /* per-column CSV FN flags */ + bool convert_selectively; /* do selective binary conversion? */ + List *convert_select; /* list of column names (can be NIL) */ +} CopyFormatOptions; + +/* These are private in commands/copy[from|to].c */ +typedef struct CopyFromStateData *CopyFromState; +typedef struct CopyToStateData *CopyToState; + +typedef int (*copy_data_source_cb) (void *outbuf, int minread, int maxread); + +extern void DoCopy(ParseState *state, const CopyStmt *stmt, + int stmt_location, int stmt_len, + uint64 *processed); + +extern void ProcessCopyOptions(ParseState *pstate, CopyFormatOptions *ops_out, bool is_from, List *options); +extern CopyFromState BeginCopyFrom(ParseState *pstate, Relation rel, Node *whereClause, + const char *filename, + bool is_program, copy_data_source_cb data_source_cb, List *attnamelist, List *options); +extern void EndCopyFrom(CopyFromState cstate); +extern bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext, + Datum *values, bool *nulls); +extern bool NextCopyFromRawFields(CopyFromState cstate, + char ***fields, int *nfields); +extern void CopyFromErrorCallback(void *arg); + +extern uint64 CopyFrom(CopyFromState cstate); + +extern DestReceiver *CreateCopyDestReceiver(void); + +/* + * internal prototypes + */ +extern CopyToState BeginCopyTo(ParseState *pstate, Relation rel, RawStmt *query, + Oid queryRelId, const char *filename, bool is_program, + List *attnamelist, List *options); +extern void EndCopyTo(CopyToState cstate); +extern uint64 DoCopyTo(CopyToState cstate); +extern List *CopyGetAttnums(TupleDesc tupDesc, Relation rel, + List *attnamelist); + +#endif /* COPY_H */ diff --git a/src/include/commands/copyfrom_internal.h b/src/include/commands/copyfrom_internal.h new file mode 100644 index 0000000..4d68d9c --- /dev/null +++ b/src/include/commands/copyfrom_internal.h @@ -0,0 +1,172 @@ +/*------------------------------------------------------------------------- + * + * copyfrom_internal.h + * Internal definitions for COPY FROM command. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/copyfrom_internal.h + * + *------------------------------------------------------------------------- + */ +#ifndef COPYFROM_INTERNAL_H +#define COPYFROM_INTERNAL_H + +#include "commands/copy.h" +#include "commands/trigger.h" + +/* + * Represents the different source cases we need to worry about at + * the bottom level + */ +typedef enum CopySource +{ + COPY_FILE, /* from file (or a piped program) */ + COPY_FRONTEND, /* from frontend */ + COPY_CALLBACK /* from callback function */ +} CopySource; + +/* + * Represents the end-of-line terminator type of the input + */ +typedef enum EolType +{ + EOL_UNKNOWN, + EOL_NL, + EOL_CR, + EOL_CRNL +} EolType; + +/* + * Represents the heap insert method to be used during COPY FROM. + */ +typedef enum CopyInsertMethod +{ + CIM_SINGLE, /* use table_tuple_insert or fdw routine */ + CIM_MULTI, /* always use table_multi_insert */ + CIM_MULTI_CONDITIONAL /* use table_multi_insert only if valid */ +} CopyInsertMethod; + +/* + * This struct contains all the state variables used throughout a COPY FROM + * operation. + */ +typedef struct CopyFromStateData +{ + /* low-level state data */ + CopySource copy_src; /* type of copy source */ + FILE *copy_file; /* used if copy_src == COPY_FILE */ + StringInfo fe_msgbuf; /* used if copy_src == COPY_NEW_FE */ + + EolType eol_type; /* EOL type of input */ + int file_encoding; /* file or remote side's character encoding */ + bool need_transcoding; /* file encoding diff from server? */ + Oid conversion_proc; /* encoding conversion function */ + + /* parameters from the COPY command */ + Relation rel; /* relation to copy from */ + List *attnumlist; /* integer list of attnums to copy */ + char *filename; /* filename, or NULL for STDIN */ + bool is_program; /* is 'filename' a program to popen? */ + copy_data_source_cb data_source_cb; /* function for reading data */ + + CopyFormatOptions opts; + bool *convert_select_flags; /* per-column CSV/TEXT CS flags */ + Node *whereClause; /* WHERE condition (or NULL) */ + + /* these are just for error messages, see CopyFromErrorCallback */ + const char *cur_relname; /* table name for error messages */ + uint64 cur_lineno; /* line number for error messages */ + const char *cur_attname; /* current att for error messages */ + const char *cur_attval; /* current att value for error messages */ + + /* + * Working state + */ + MemoryContext copycontext; /* per-copy execution context */ + + AttrNumber num_defaults; + FmgrInfo *in_functions; /* array of input functions for each attrs */ + Oid *typioparams; /* array of element types for in_functions */ + int *defmap; /* array of default att numbers */ + ExprState **defexprs; /* array of default att expressions */ + bool volatile_defexprs; /* is any of defexprs volatile? */ + List *range_table; + ExprState *qualexpr; + + TransitionCaptureState *transition_capture; + + /* + * These variables are used to reduce overhead in COPY FROM. + * + * attribute_buf holds the separated, de-escaped text for each field of + * the current line. The CopyReadAttributes functions return arrays of + * pointers into this buffer. We avoid palloc/pfree overhead by re-using + * the buffer on each cycle. + * + * In binary COPY FROM, attribute_buf holds the binary data for the + * current field, but the usage is otherwise similar. + */ + StringInfoData attribute_buf; + + /* field raw data pointers found by COPY FROM */ + + int max_fields; + char **raw_fields; + + /* + * Similarly, line_buf holds the whole input line being processed. The + * input cycle is first to read the whole line into line_buf, and then + * extract the individual attribute fields into attribute_buf. line_buf + * is preserved unmodified so that we can display it in error messages if + * appropriate. (In binary mode, line_buf is not used.) + */ + StringInfoData line_buf; + bool line_buf_valid; /* contains the row being processed? */ + + /* + * input_buf holds input data, already converted to database encoding. + * + * In text mode, CopyReadLine parses this data sufficiently to locate line + * boundaries, then transfers the data to line_buf. We guarantee that + * there is a \0 at input_buf[input_buf_len] at all times. (In binary + * mode, input_buf is not used.) + * + * If encoding conversion is not required, input_buf is not a separate + * buffer but points directly to raw_buf. In that case, input_buf_len + * tracks the number of bytes that have been verified as valid in the + * database encoding, and raw_buf_len is the total number of bytes stored + * in the buffer. + */ +#define INPUT_BUF_SIZE 65536 /* we palloc INPUT_BUF_SIZE+1 bytes */ + char *input_buf; + int input_buf_index; /* next byte to process */ + int input_buf_len; /* total # of bytes stored */ + bool input_reached_eof; /* true if we reached EOF */ + bool input_reached_error; /* true if a conversion error happened */ + /* Shorthand for number of unconsumed bytes available in input_buf */ +#define INPUT_BUF_BYTES(cstate) ((cstate)->input_buf_len - (cstate)->input_buf_index) + + /* + * raw_buf holds raw input data read from the data source (file or client + * connection), not yet converted to the database encoding. Like with + * 'input_buf', we guarantee that there is a \0 at raw_buf[raw_buf_len]. + */ +#define RAW_BUF_SIZE 65536 /* we palloc RAW_BUF_SIZE+1 bytes */ + char *raw_buf; + int raw_buf_index; /* next byte to process */ + int raw_buf_len; /* total # of bytes stored */ + bool raw_reached_eof; /* true if we reached EOF */ + + /* Shorthand for number of unconsumed bytes available in raw_buf */ +#define RAW_BUF_BYTES(cstate) ((cstate)->raw_buf_len - (cstate)->raw_buf_index) + + uint64 bytes_processed; /* number of bytes processed so far */ +} CopyFromStateData; + +extern void ReceiveCopyBegin(CopyFromState cstate); +extern void ReceiveCopyBinaryHeader(CopyFromState cstate); + +#endif /* COPYFROM_INTERNAL_H */ diff --git a/src/include/commands/createas.h b/src/include/commands/createas.h new file mode 100644 index 0000000..ad5054d --- /dev/null +++ b/src/include/commands/createas.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * + * createas.h + * prototypes for createas.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/createas.h + * + *------------------------------------------------------------------------- + */ +#ifndef CREATEAS_H +#define CREATEAS_H + +#include "catalog/objectaddress.h" +#include "nodes/params.h" +#include "parser/parse_node.h" +#include "tcop/dest.h" +#include "utils/queryenvironment.h" + + +extern ObjectAddress ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, + ParamListInfo params, QueryEnvironment *queryEnv, + QueryCompletion *qc); + +extern int GetIntoRelEFlags(IntoClause *intoClause); + +extern DestReceiver *CreateIntoRelDestReceiver(IntoClause *intoClause); + +extern bool CreateTableAsRelExists(CreateTableAsStmt *ctas); + +#endif /* CREATEAS_H */ diff --git a/src/include/commands/dbcommands.h b/src/include/commands/dbcommands.h new file mode 100644 index 0000000..29b6206 --- /dev/null +++ b/src/include/commands/dbcommands.h @@ -0,0 +1,35 @@ +/*------------------------------------------------------------------------- + * + * dbcommands.h + * Database management commands (create/drop database). + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/dbcommands.h + * + *------------------------------------------------------------------------- + */ +#ifndef DBCOMMANDS_H +#define DBCOMMANDS_H + +#include "access/xlogreader.h" +#include "catalog/objectaddress.h" +#include "lib/stringinfo.h" +#include "parser/parse_node.h" + +extern Oid createdb(ParseState *pstate, const CreatedbStmt *stmt); +extern void dropdb(const char *dbname, bool missing_ok, bool force); +extern void DropDatabase(ParseState *pstate, DropdbStmt *stmt); +extern ObjectAddress RenameDatabase(const char *oldname, const char *newname); +extern Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel); +extern Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt); +extern ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId); + +extern Oid get_database_oid(const char *dbname, bool missing_ok); +extern char *get_database_name(Oid dbid); + +extern void check_encoding_locale_matches(int encoding, const char *collate, const char *ctype); + +#endif /* DBCOMMANDS_H */ diff --git a/src/include/commands/dbcommands_xlog.h b/src/include/commands/dbcommands_xlog.h new file mode 100644 index 0000000..f5ed762 --- /dev/null +++ b/src/include/commands/dbcommands_xlog.h @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + * + * dbcommands_xlog.h + * Database resource manager XLOG definitions (create/drop database). + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/dbcommands_xlog.h + * + *------------------------------------------------------------------------- + */ +#ifndef DBCOMMANDS_XLOG_H +#define DBCOMMANDS_XLOG_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +/* record types */ +#define XLOG_DBASE_CREATE 0x00 +#define XLOG_DBASE_DROP 0x10 + +typedef struct xl_dbase_create_rec +{ + /* Records copying of a single subdirectory incl. contents */ + Oid db_id; + Oid tablespace_id; + Oid src_db_id; + Oid src_tablespace_id; +} xl_dbase_create_rec; + +typedef struct xl_dbase_drop_rec +{ + Oid db_id; + int ntablespaces; /* number of tablespace IDs */ + Oid tablespace_ids[FLEXIBLE_ARRAY_MEMBER]; +} xl_dbase_drop_rec; +#define MinSizeOfDbaseDropRec offsetof(xl_dbase_drop_rec, tablespace_ids) + +extern void dbase_redo(XLogReaderState *rptr); +extern void dbase_desc(StringInfo buf, XLogReaderState *rptr); +extern const char *dbase_identify(uint8 info); + +#endif /* DBCOMMANDS_XLOG_H */ diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h new file mode 100644 index 0000000..42bf1c7 --- /dev/null +++ b/src/include/commands/defrem.h @@ -0,0 +1,157 @@ +/*------------------------------------------------------------------------- + * + * defrem.h + * POSTGRES define and remove utility definitions. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/defrem.h + * + *------------------------------------------------------------------------- + */ +#ifndef DEFREM_H +#define DEFREM_H + +#include "catalog/objectaddress.h" +#include "nodes/params.h" +#include "parser/parse_node.h" +#include "tcop/dest.h" +#include "utils/array.h" + +/* commands/dropcmds.c */ +extern void RemoveObjects(DropStmt *stmt); + +/* commands/indexcmds.c */ +extern ObjectAddress DefineIndex(Oid relationId, + IndexStmt *stmt, + Oid indexRelationId, + Oid parentIndexId, + Oid parentConstraintId, + bool is_alter_table, + bool check_rights, + bool check_not_in_use, + bool skip_build, + bool quiet); +extern void ExecReindex(ParseState *pstate, ReindexStmt *stmt, bool isTopLevel); +extern char *makeObjectName(const char *name1, const char *name2, + const char *label); +extern char *ChooseRelationName(const char *name1, const char *name2, + const char *label, Oid namespaceid, + bool isconstraint); +extern bool CheckIndexCompatible(Oid oldId, + const char *accessMethodName, + List *attributeList, + List *exclusionOpNames); +extern Oid GetDefaultOpClass(Oid type_id, Oid am_id); +extern Oid ResolveOpClass(List *opclass, Oid attrType, + const char *accessMethodName, Oid accessMethodId); + +/* commands/functioncmds.c */ +extern ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt); +extern void RemoveFunctionById(Oid funcOid); +extern ObjectAddress AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt); +extern ObjectAddress CreateCast(CreateCastStmt *stmt); +extern ObjectAddress CreateTransform(CreateTransformStmt *stmt); +extern void IsThereFunctionInNamespace(const char *proname, int pronargs, + oidvector *proargtypes, Oid nspOid); +extern void ExecuteDoStmt(DoStmt *stmt, bool atomic); +extern void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest); +extern TupleDesc CallStmtResultDesc(CallStmt *stmt); +extern Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok); +extern void interpret_function_parameter_list(ParseState *pstate, + List *parameters, + Oid languageOid, + ObjectType objtype, + oidvector **parameterTypes, + List **parameterTypes_list, + ArrayType **allParameterTypes, + ArrayType **parameterModes, + ArrayType **parameterNames, + List **inParameterNames_list, + List **parameterDefaults, + Oid *variadicArgType, + Oid *requiredResultType); + +/* commands/operatorcmds.c */ +extern ObjectAddress DefineOperator(List *names, List *parameters); +extern void RemoveOperatorById(Oid operOid); +extern ObjectAddress AlterOperator(AlterOperatorStmt *stmt); + +/* commands/statscmds.c */ +extern ObjectAddress CreateStatistics(CreateStatsStmt *stmt); +extern ObjectAddress AlterStatistics(AlterStatsStmt *stmt); +extern void RemoveStatisticsById(Oid statsOid); +extern Oid StatisticsGetRelation(Oid statId, bool missing_ok); + +/* commands/aggregatecmds.c */ +extern ObjectAddress DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, + List *parameters, bool replace); + +/* commands/opclasscmds.c */ +extern ObjectAddress DefineOpClass(CreateOpClassStmt *stmt); +extern ObjectAddress DefineOpFamily(CreateOpFamilyStmt *stmt); +extern Oid AlterOpFamily(AlterOpFamilyStmt *stmt); +extern void IsThereOpClassInNamespace(const char *opcname, Oid opcmethod, + Oid opcnamespace); +extern void IsThereOpFamilyInNamespace(const char *opfname, Oid opfmethod, + Oid opfnamespace); +extern Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok); +extern Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok); + +/* commands/tsearchcmds.c */ +extern ObjectAddress DefineTSParser(List *names, List *parameters); + +extern ObjectAddress DefineTSDictionary(List *names, List *parameters); +extern ObjectAddress AlterTSDictionary(AlterTSDictionaryStmt *stmt); + +extern ObjectAddress DefineTSTemplate(List *names, List *parameters); + +extern ObjectAddress DefineTSConfiguration(List *names, List *parameters, + ObjectAddress *copied); +extern void RemoveTSConfigurationById(Oid cfgId); +extern ObjectAddress AlterTSConfiguration(AlterTSConfigurationStmt *stmt); + +extern text *serialize_deflist(List *deflist); +extern List *deserialize_deflist(Datum txt); + +/* commands/foreigncmds.c */ +extern ObjectAddress AlterForeignServerOwner(const char *name, Oid newOwnerId); +extern void AlterForeignServerOwner_oid(Oid, Oid newOwnerId); +extern ObjectAddress AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId); +extern void AlterForeignDataWrapperOwner_oid(Oid fwdId, Oid newOwnerId); +extern ObjectAddress CreateForeignDataWrapper(CreateFdwStmt *stmt); +extern ObjectAddress AlterForeignDataWrapper(AlterFdwStmt *stmt); +extern ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt); +extern ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt); +extern ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt); +extern ObjectAddress AlterUserMapping(AlterUserMappingStmt *stmt); +extern Oid RemoveUserMapping(DropUserMappingStmt *stmt); +extern void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid); +extern void ImportForeignSchema(ImportForeignSchemaStmt *stmt); +extern Datum transformGenericOptions(Oid catalogId, + Datum oldOptions, + List *options, + Oid fdwvalidator); + +/* commands/amcmds.c */ +extern ObjectAddress CreateAccessMethod(CreateAmStmt *stmt); +extern Oid get_index_am_oid(const char *amname, bool missing_ok); +extern Oid get_table_am_oid(const char *amname, bool missing_ok); +extern Oid get_am_oid(const char *amname, bool missing_ok); +extern char *get_am_name(Oid amOid); + +/* support routines in commands/define.c */ + +extern char *defGetString(DefElem *def); +extern double defGetNumeric(DefElem *def); +extern bool defGetBoolean(DefElem *def); +extern int32 defGetInt32(DefElem *def); +extern int64 defGetInt64(DefElem *def); +extern List *defGetQualifiedName(DefElem *def); +extern TypeName *defGetTypeName(DefElem *def); +extern int defGetTypeLength(DefElem *def); +extern List *defGetStringList(DefElem *def); + +#endif /* DEFREM_H */ diff --git a/src/include/commands/discard.h b/src/include/commands/discard.h new file mode 100644 index 0000000..54b9dbb --- /dev/null +++ b/src/include/commands/discard.h @@ -0,0 +1,20 @@ +/*------------------------------------------------------------------------- + * + * discard.h + * prototypes for discard.c. + * + * + * Copyright (c) 1996-2021, PostgreSQL Global Development Group + * + * src/include/commands/discard.h + * + *------------------------------------------------------------------------- + */ +#ifndef DISCARD_H +#define DISCARD_H + +#include "nodes/parsenodes.h" + +extern void DiscardCommand(DiscardStmt *stmt, bool isTopLevel); + +#endif /* DISCARD_H */ diff --git a/src/include/commands/event_trigger.h b/src/include/commands/event_trigger.h new file mode 100644 index 0000000..c11bf2d --- /dev/null +++ b/src/include/commands/event_trigger.h @@ -0,0 +1,87 @@ +/*------------------------------------------------------------------------- + * + * event_trigger.h + * Declarations for command trigger handling. + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/event_trigger.h + * + *------------------------------------------------------------------------- + */ +#ifndef EVENT_TRIGGER_H +#define EVENT_TRIGGER_H + +#include "catalog/dependency.h" +#include "catalog/objectaddress.h" +#include "catalog/pg_event_trigger.h" +#include "nodes/parsenodes.h" +#include "tcop/cmdtag.h" +#include "tcop/deparse_utility.h" +#include "utils/aclchk_internal.h" + +typedef struct EventTriggerData +{ + NodeTag type; + const char *event; /* event name */ + Node *parsetree; /* parse tree */ + CommandTag tag; +} EventTriggerData; + +#define AT_REWRITE_ALTER_PERSISTENCE 0x01 +#define AT_REWRITE_DEFAULT_VAL 0x02 +#define AT_REWRITE_COLUMN_REWRITE 0x04 + +/* + * EventTriggerData is the node type that is passed as fmgr "context" info + * when a function is called by the event trigger manager. + */ +#define CALLED_AS_EVENT_TRIGGER(fcinfo) \ + ((fcinfo)->context != NULL && IsA((fcinfo)->context, EventTriggerData)) + +extern Oid CreateEventTrigger(CreateEventTrigStmt *stmt); +extern Oid get_event_trigger_oid(const char *trigname, bool missing_ok); + +extern Oid AlterEventTrigger(AlterEventTrigStmt *stmt); +extern ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId); +extern void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId); + +extern bool EventTriggerSupportsObjectType(ObjectType obtype); +extern bool EventTriggerSupportsObjectClass(ObjectClass objclass); +extern void EventTriggerDDLCommandStart(Node *parsetree); +extern void EventTriggerDDLCommandEnd(Node *parsetree); +extern void EventTriggerSQLDrop(Node *parsetree); +extern void EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason); + +extern bool EventTriggerBeginCompleteQuery(void); +extern void EventTriggerEndCompleteQuery(void); +extern bool trackDroppedObjectsNeeded(void); +extern void EventTriggerSQLDropAddObject(const ObjectAddress *object, + bool original, bool normal); + +extern void EventTriggerInhibitCommandCollection(void); +extern void EventTriggerUndoInhibitCommandCollection(void); + +extern void EventTriggerCollectSimpleCommand(ObjectAddress address, + ObjectAddress secondaryObject, + Node *parsetree); + +extern void EventTriggerAlterTableStart(Node *parsetree); +extern void EventTriggerAlterTableRelid(Oid objectId); +extern void EventTriggerCollectAlterTableSubcmd(Node *subcmd, + ObjectAddress address); +extern void EventTriggerAlterTableEnd(void); + +extern void EventTriggerCollectGrant(InternalGrant *istmt); +extern void EventTriggerCollectAlterOpFam(AlterOpFamilyStmt *stmt, + Oid opfamoid, List *operators, + List *procedures); +extern void EventTriggerCollectCreateOpClass(CreateOpClassStmt *stmt, + Oid opcoid, List *operators, + List *procedures); +extern void EventTriggerCollectAlterTSConfig(AlterTSConfigurationStmt *stmt, + Oid cfgId, Oid *dictIds, int ndicts); +extern void EventTriggerCollectAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt); + +#endif /* EVENT_TRIGGER_H */ diff --git a/src/include/commands/explain.h b/src/include/commands/explain.h new file mode 100644 index 0000000..e94d9e4 --- /dev/null +++ b/src/include/commands/explain.h @@ -0,0 +1,127 @@ +/*------------------------------------------------------------------------- + * + * explain.h + * prototypes for explain.c + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994-5, Regents of the University of California + * + * src/include/commands/explain.h + * + *------------------------------------------------------------------------- + */ +#ifndef EXPLAIN_H +#define EXPLAIN_H + +#include "executor/executor.h" +#include "lib/stringinfo.h" +#include "parser/parse_node.h" + +typedef enum ExplainFormat +{ + EXPLAIN_FORMAT_TEXT, + EXPLAIN_FORMAT_XML, + EXPLAIN_FORMAT_JSON, + EXPLAIN_FORMAT_YAML +} ExplainFormat; + +typedef struct ExplainWorkersState +{ + int num_workers; /* # of worker processes the plan used */ + bool *worker_inited; /* per-worker state-initialized flags */ + StringInfoData *worker_str; /* per-worker transient output buffers */ + int *worker_state_save; /* per-worker grouping state save areas */ + StringInfo prev_str; /* saved output buffer while redirecting */ +} ExplainWorkersState; + +typedef struct ExplainState +{ + StringInfo str; /* output buffer */ + /* options */ + bool verbose; /* be verbose */ + bool analyze; /* print actual times */ + bool costs; /* print estimated costs */ + bool buffers; /* print buffer usage */ + bool wal; /* print WAL usage */ + bool timing; /* print detailed node timing */ + bool summary; /* print total planning and execution timing */ + bool settings; /* print modified settings */ + ExplainFormat format; /* output format */ + /* state for output formatting --- not reset for each new plan tree */ + int indent; /* current indentation level */ + List *grouping_stack; /* format-specific grouping state */ + /* state related to the current plan tree (filled by ExplainPrintPlan) */ + PlannedStmt *pstmt; /* top of plan */ + List *rtable; /* range table */ + List *rtable_names; /* alias names for RTEs */ + List *deparse_cxt; /* context list for deparsing expressions */ + Bitmapset *printed_subplans; /* ids of SubPlans we've printed */ + bool hide_workers; /* set if we find an invisible Gather */ + /* state related to the current plan node */ + ExplainWorkersState *workers_state; /* needed if parallel plan */ +} ExplainState; + +/* Hook for plugins to get control in ExplainOneQuery() */ +typedef void (*ExplainOneQuery_hook_type) (Query *query, + int cursorOptions, + IntoClause *into, + ExplainState *es, + const char *queryString, + ParamListInfo params, + QueryEnvironment *queryEnv); +extern PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook; + +/* Hook for plugins to get control in explain_get_index_name() */ +typedef const char *(*explain_get_index_name_hook_type) (Oid indexId); +extern PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook; + + +extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, + ParamListInfo params, DestReceiver *dest); + +extern ExplainState *NewExplainState(void); + +extern TupleDesc ExplainResultDesc(ExplainStmt *stmt); + +extern void ExplainOneUtility(Node *utilityStmt, IntoClause *into, + ExplainState *es, const char *queryString, + ParamListInfo params, QueryEnvironment *queryEnv); + +extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, + ExplainState *es, const char *queryString, + ParamListInfo params, QueryEnvironment *queryEnv, + const instr_time *planduration, + const BufferUsage *bufusage); + +extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc); +extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc); + +extern void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc); + +extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc); + +extern void ExplainBeginOutput(ExplainState *es); +extern void ExplainEndOutput(ExplainState *es); +extern void ExplainSeparatePlans(ExplainState *es); + +extern void ExplainPropertyList(const char *qlabel, List *data, + ExplainState *es); +extern void ExplainPropertyListNested(const char *qlabel, List *data, + ExplainState *es); +extern void ExplainPropertyText(const char *qlabel, const char *value, + ExplainState *es); +extern void ExplainPropertyInteger(const char *qlabel, const char *unit, + int64 value, ExplainState *es); +extern void ExplainPropertyUInteger(const char *qlabel, const char *unit, + uint64 value, ExplainState *es); +extern void ExplainPropertyFloat(const char *qlabel, const char *unit, + double value, int ndigits, ExplainState *es); +extern void ExplainPropertyBool(const char *qlabel, bool value, + ExplainState *es); + +extern void ExplainOpenGroup(const char *objtype, const char *labelname, + bool labeled, ExplainState *es); +extern void ExplainCloseGroup(const char *objtype, const char *labelname, + bool labeled, ExplainState *es); + +#endif /* EXPLAIN_H */ diff --git a/src/include/commands/extension.h b/src/include/commands/extension.h new file mode 100644 index 0000000..24dbf86 --- /dev/null +++ b/src/include/commands/extension.h @@ -0,0 +1,55 @@ +/*------------------------------------------------------------------------- + * + * extension.h + * Extension management commands (create/drop extension). + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/extension.h + * + *------------------------------------------------------------------------- + */ +#ifndef EXTENSION_H +#define EXTENSION_H + +#include "catalog/objectaddress.h" +#include "parser/parse_node.h" + + +/* + * creating_extension is only true while running a CREATE EXTENSION or ALTER + * EXTENSION UPDATE command. It instructs recordDependencyOnCurrentExtension() + * to register a dependency on the current pg_extension object for each SQL + * object created by an extension script. It also instructs performDeletion() + * to remove such dependencies without following them, so that extension + * scripts can drop member objects without having to explicitly dissociate + * them from the extension first. + */ +extern PGDLLIMPORT bool creating_extension; +extern PGDLLIMPORT Oid CurrentExtensionObject; + + +extern ObjectAddress CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt); + +extern void RemoveExtensionById(Oid extId); + +extern ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner, + Oid schemaOid, bool relocatable, const char *extVersion, + Datum extConfig, Datum extCondition, + List *requiredExtensions); + +extern ObjectAddress ExecAlterExtensionStmt(ParseState *pstate, AlterExtensionStmt *stmt); + +extern ObjectAddress ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt, + ObjectAddress *objAddr); + +extern Oid get_extension_oid(const char *extname, bool missing_ok); +extern char *get_extension_name(Oid ext_oid); +extern bool extension_file_exists(const char *extensionName); + +extern ObjectAddress AlterExtensionNamespace(const char *extensionName, const char *newschema, + Oid *oldschema); + +#endif /* EXTENSION_H */ diff --git a/src/include/commands/lockcmds.h b/src/include/commands/lockcmds.h new file mode 100644 index 0000000..c005dee --- /dev/null +++ b/src/include/commands/lockcmds.h @@ -0,0 +1,24 @@ +/*------------------------------------------------------------------------- + * + * lockcmds.h + * prototypes for lockcmds.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/lockcmds.h + * + *------------------------------------------------------------------------- + */ +#ifndef LOCKCMDS_H +#define LOCKCMDS_H + +#include "nodes/parsenodes.h" + +/* + * LOCK + */ +extern void LockTableCommand(LockStmt *lockstmt); + +#endif /* LOCKCMDS_H */ diff --git a/src/include/commands/matview.h b/src/include/commands/matview.h new file mode 100644 index 0000000..214b1c1 --- /dev/null +++ b/src/include/commands/matview.h @@ -0,0 +1,33 @@ +/*------------------------------------------------------------------------- + * + * matview.h + * prototypes for matview.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/matview.h + * + *------------------------------------------------------------------------- + */ +#ifndef MATVIEW_H +#define MATVIEW_H + +#include "catalog/objectaddress.h" +#include "nodes/params.h" +#include "nodes/parsenodes.h" +#include "tcop/dest.h" +#include "utils/relcache.h" + + +extern void SetMatViewPopulatedState(Relation relation, bool newstate); + +extern ObjectAddress ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, + ParamListInfo params, QueryCompletion *qc); + +extern DestReceiver *CreateTransientRelDestReceiver(Oid oid); + +extern bool MatViewIncrementalMaintenanceIsEnabled(void); + +#endif /* MATVIEW_H */ diff --git a/src/include/commands/policy.h b/src/include/commands/policy.h new file mode 100644 index 0000000..116af68 --- /dev/null +++ b/src/include/commands/policy.h @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + * + * policy.h + * prototypes for policy.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/policy.h + * + *------------------------------------------------------------------------- + */ + +#ifndef POLICY_H +#define POLICY_H + +#include "catalog/objectaddress.h" +#include "nodes/parsenodes.h" +#include "utils/relcache.h" + +extern void RelationBuildRowSecurity(Relation relation); + +extern void RemovePolicyById(Oid policy_id); + +extern bool RemoveRoleFromObjectPolicy(Oid roleid, Oid classid, Oid objid); + +extern ObjectAddress CreatePolicy(CreatePolicyStmt *stmt); +extern ObjectAddress AlterPolicy(AlterPolicyStmt *stmt); + +extern Oid get_relation_policy_oid(Oid relid, const char *policy_name, + bool missing_ok); + +extern ObjectAddress rename_policy(RenameStmt *stmt); + +extern bool relation_has_policies(Relation rel); + +#endif /* POLICY_H */ diff --git a/src/include/commands/portalcmds.h b/src/include/commands/portalcmds.h new file mode 100644 index 0000000..5d5e766 --- /dev/null +++ b/src/include/commands/portalcmds.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * + * portalcmds.h + * prototypes for portalcmds.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/portalcmds.h + * + *------------------------------------------------------------------------- + */ +#ifndef PORTALCMDS_H +#define PORTALCMDS_H + +#include "nodes/parsenodes.h" +#include "parser/parse_node.h" +#include "utils/portal.h" + + +extern void PerformCursorOpen(ParseState *pstate, DeclareCursorStmt *cstmt, ParamListInfo params, + bool isTopLevel); + +extern void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest, + QueryCompletion *qc); + +extern void PerformPortalClose(const char *name); + +extern void PortalCleanup(Portal portal); + +extern void PersistHoldablePortal(Portal portal); + +#endif /* PORTALCMDS_H */ diff --git a/src/include/commands/prepare.h b/src/include/commands/prepare.h new file mode 100644 index 0000000..9352581 --- /dev/null +++ b/src/include/commands/prepare.h @@ -0,0 +1,61 @@ +/*------------------------------------------------------------------------- + * + * prepare.h + * PREPARE, EXECUTE and DEALLOCATE commands, and prepared-stmt storage + * + * + * Copyright (c) 2002-2021, PostgreSQL Global Development Group + * + * src/include/commands/prepare.h + * + *------------------------------------------------------------------------- + */ +#ifndef PREPARE_H +#define PREPARE_H + +#include "commands/explain.h" +#include "datatype/timestamp.h" +#include "utils/plancache.h" + +/* + * The data structure representing a prepared statement. This is now just + * a thin veneer over a plancache entry --- the main addition is that of + * a name. + * + * Note: all subsidiary storage lives in the referenced plancache entry. + */ +typedef struct +{ + /* dynahash.c requires key to be first field */ + char stmt_name[NAMEDATALEN]; + CachedPlanSource *plansource; /* the actual cached plan */ + bool from_sql; /* prepared via SQL, not FE/BE protocol? */ + TimestampTz prepare_time; /* the time when the stmt was prepared */ +} PreparedStatement; + + +/* Utility statements PREPARE, EXECUTE, DEALLOCATE, EXPLAIN EXECUTE */ +extern void PrepareQuery(ParseState *pstate, PrepareStmt *stmt, + int stmt_location, int stmt_len); +extern void ExecuteQuery(ParseState *pstate, + ExecuteStmt *stmt, IntoClause *intoClause, + ParamListInfo params, + DestReceiver *dest, QueryCompletion *qc); +extern void DeallocateQuery(DeallocateStmt *stmt); +extern void ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, + ExplainState *es, const char *queryString, + ParamListInfo params, QueryEnvironment *queryEnv); + +/* Low-level access to stored prepared statements */ +extern void StorePreparedStatement(const char *stmt_name, + CachedPlanSource *plansource, + bool from_sql); +extern PreparedStatement *FetchPreparedStatement(const char *stmt_name, + bool throwError); +extern void DropPreparedStatement(const char *stmt_name, bool showError); +extern TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt); +extern List *FetchPreparedStatementTargetList(PreparedStatement *stmt); + +extern void DropAllPreparedStatements(void); + +#endif /* PREPARE_H */ diff --git a/src/include/commands/proclang.h b/src/include/commands/proclang.h new file mode 100644 index 0000000..16e857f --- /dev/null +++ b/src/include/commands/proclang.h @@ -0,0 +1,23 @@ +/*------------------------------------------------------------------------- + * + * proclang.h + * prototypes for proclang.c. + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/proclang.h + * + *------------------------------------------------------------------------- + */ +#ifndef PROCLANG_H +#define PROCLANG_H + +#include "catalog/objectaddress.h" +#include "nodes/parsenodes.h" + +extern ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt); + +extern Oid get_language_oid(const char *langname, bool missing_ok); + +#endif /* PROCLANG_H */ diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h new file mode 100644 index 0000000..d7bf163 --- /dev/null +++ b/src/include/commands/progress.h @@ -0,0 +1,154 @@ +/*------------------------------------------------------------------------- + * + * progress.h + * Constants used with the progress reporting facilities defined in + * backend_status.h. These are possibly interesting to extensions, so we + * expose them via this header file. Note that if you update these + * constants, you probably also need to update the views based on them + * in system_views.sql. + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/progress.h + * + *------------------------------------------------------------------------- + */ +#ifndef PROGRESS_H +#define PROGRESS_H + +/* Progress parameters for (lazy) vacuum */ +#define PROGRESS_VACUUM_PHASE 0 +#define PROGRESS_VACUUM_TOTAL_HEAP_BLKS 1 +#define PROGRESS_VACUUM_HEAP_BLKS_SCANNED 2 +#define PROGRESS_VACUUM_HEAP_BLKS_VACUUMED 3 +#define PROGRESS_VACUUM_NUM_INDEX_VACUUMS 4 +#define PROGRESS_VACUUM_MAX_DEAD_TUPLES 5 +#define PROGRESS_VACUUM_NUM_DEAD_TUPLES 6 + +/* Phases of vacuum (as advertised via PROGRESS_VACUUM_PHASE) */ +#define PROGRESS_VACUUM_PHASE_SCAN_HEAP 1 +#define PROGRESS_VACUUM_PHASE_VACUUM_INDEX 2 +#define PROGRESS_VACUUM_PHASE_VACUUM_HEAP 3 +#define PROGRESS_VACUUM_PHASE_INDEX_CLEANUP 4 +#define PROGRESS_VACUUM_PHASE_TRUNCATE 5 +#define PROGRESS_VACUUM_PHASE_FINAL_CLEANUP 6 + +/* Progress parameters for analyze */ +#define PROGRESS_ANALYZE_PHASE 0 +#define PROGRESS_ANALYZE_BLOCKS_TOTAL 1 +#define PROGRESS_ANALYZE_BLOCKS_DONE 2 +#define PROGRESS_ANALYZE_EXT_STATS_TOTAL 3 +#define PROGRESS_ANALYZE_EXT_STATS_COMPUTED 4 +#define PROGRESS_ANALYZE_CHILD_TABLES_TOTAL 5 +#define PROGRESS_ANALYZE_CHILD_TABLES_DONE 6 +#define PROGRESS_ANALYZE_CURRENT_CHILD_TABLE_RELID 7 + +/* Phases of analyze (as advertised via PROGRESS_ANALYZE_PHASE) */ +#define PROGRESS_ANALYZE_PHASE_ACQUIRE_SAMPLE_ROWS 1 +#define PROGRESS_ANALYZE_PHASE_ACQUIRE_SAMPLE_ROWS_INH 2 +#define PROGRESS_ANALYZE_PHASE_COMPUTE_STATS 3 +#define PROGRESS_ANALYZE_PHASE_COMPUTE_EXT_STATS 4 +#define PROGRESS_ANALYZE_PHASE_FINALIZE_ANALYZE 5 + +/* Progress parameters for cluster */ +#define PROGRESS_CLUSTER_COMMAND 0 +#define PROGRESS_CLUSTER_PHASE 1 +#define PROGRESS_CLUSTER_INDEX_RELID 2 +#define PROGRESS_CLUSTER_HEAP_TUPLES_SCANNED 3 +#define PROGRESS_CLUSTER_HEAP_TUPLES_WRITTEN 4 +#define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 +#define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 +#define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 + +/* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ +#define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 +#define PROGRESS_CLUSTER_PHASE_INDEX_SCAN_HEAP 2 +#define PROGRESS_CLUSTER_PHASE_SORT_TUPLES 3 +#define PROGRESS_CLUSTER_PHASE_WRITE_NEW_HEAP 4 +#define PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES 5 +#define PROGRESS_CLUSTER_PHASE_REBUILD_INDEX 6 +#define PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP 7 + +/* Commands of PROGRESS_CLUSTER */ +#define PROGRESS_CLUSTER_COMMAND_CLUSTER 1 +#define PROGRESS_CLUSTER_COMMAND_VACUUM_FULL 2 + +/* Progress parameters for CREATE INDEX */ +/* 3, 4 and 5 reserved for "waitfor" metrics */ +#define PROGRESS_CREATEIDX_COMMAND 0 +#define PROGRESS_CREATEIDX_INDEX_OID 6 +#define PROGRESS_CREATEIDX_ACCESS_METHOD_OID 8 +#define PROGRESS_CREATEIDX_PHASE 9 /* AM-agnostic phase # */ +#define PROGRESS_CREATEIDX_SUBPHASE 10 /* phase # filled by AM */ +#define PROGRESS_CREATEIDX_TUPLES_TOTAL 11 +#define PROGRESS_CREATEIDX_TUPLES_DONE 12 +#define PROGRESS_CREATEIDX_PARTITIONS_TOTAL 13 +#define PROGRESS_CREATEIDX_PARTITIONS_DONE 14 +/* 15 and 16 reserved for "block number" metrics */ + +/* Phases of CREATE INDEX (as advertised via PROGRESS_CREATEIDX_PHASE) */ +#define PROGRESS_CREATEIDX_PHASE_WAIT_1 1 +#define PROGRESS_CREATEIDX_PHASE_BUILD 2 +#define PROGRESS_CREATEIDX_PHASE_WAIT_2 3 +#define PROGRESS_CREATEIDX_PHASE_VALIDATE_IDXSCAN 4 +#define PROGRESS_CREATEIDX_PHASE_VALIDATE_SORT 5 +#define PROGRESS_CREATEIDX_PHASE_VALIDATE_TABLESCAN 6 +#define PROGRESS_CREATEIDX_PHASE_WAIT_3 7 +#define PROGRESS_CREATEIDX_PHASE_WAIT_4 8 +#define PROGRESS_CREATEIDX_PHASE_WAIT_5 9 + +/* + * Subphases of CREATE INDEX, for index_build. + */ +#define PROGRESS_CREATEIDX_SUBPHASE_INITIALIZE 1 +/* Additional phases are defined by each AM */ + +/* Commands of PROGRESS_CREATEIDX */ +#define PROGRESS_CREATEIDX_COMMAND_CREATE 1 +#define PROGRESS_CREATEIDX_COMMAND_CREATE_CONCURRENTLY 2 +#define PROGRESS_CREATEIDX_COMMAND_REINDEX 3 +#define PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY 4 + +/* Lock holder wait counts */ +#define PROGRESS_WAITFOR_TOTAL 3 +#define PROGRESS_WAITFOR_DONE 4 +#define PROGRESS_WAITFOR_CURRENT_PID 5 + +/* Block numbers in a generic relation scan */ +#define PROGRESS_SCAN_BLOCKS_TOTAL 15 +#define PROGRESS_SCAN_BLOCKS_DONE 16 + +/* Progress parameters for pg_basebackup */ +#define PROGRESS_BASEBACKUP_PHASE 0 +#define PROGRESS_BASEBACKUP_BACKUP_TOTAL 1 +#define PROGRESS_BASEBACKUP_BACKUP_STREAMED 2 +#define PROGRESS_BASEBACKUP_TBLSPC_TOTAL 3 +#define PROGRESS_BASEBACKUP_TBLSPC_STREAMED 4 + +/* Phases of pg_basebackup (as advertised via PROGRESS_BASEBACKUP_PHASE) */ +#define PROGRESS_BASEBACKUP_PHASE_WAIT_CHECKPOINT 1 +#define PROGRESS_BASEBACKUP_PHASE_ESTIMATE_BACKUP_SIZE 2 +#define PROGRESS_BASEBACKUP_PHASE_STREAM_BACKUP 3 +#define PROGRESS_BASEBACKUP_PHASE_WAIT_WAL_ARCHIVE 4 +#define PROGRESS_BASEBACKUP_PHASE_TRANSFER_WAL 5 + +/* Progress parameters for PROGRESS_COPY */ +#define PROGRESS_COPY_BYTES_PROCESSED 0 +#define PROGRESS_COPY_BYTES_TOTAL 1 +#define PROGRESS_COPY_TUPLES_PROCESSED 2 +#define PROGRESS_COPY_TUPLES_EXCLUDED 3 +#define PROGRESS_COPY_COMMAND 4 +#define PROGRESS_COPY_TYPE 5 + +/* Commands of COPY (as advertised via PROGRESS_COPY_COMMAND) */ +#define PROGRESS_COPY_COMMAND_FROM 1 +#define PROGRESS_COPY_COMMAND_TO 2 + +/* Types of COPY commands (as advertised via PROGRESS_COPY_TYPE) */ +#define PROGRESS_COPY_TYPE_FILE 1 +#define PROGRESS_COPY_TYPE_PROGRAM 2 +#define PROGRESS_COPY_TYPE_PIPE 3 +#define PROGRESS_COPY_TYPE_CALLBACK 4 + +#endif diff --git a/src/include/commands/publicationcmds.h b/src/include/commands/publicationcmds.h new file mode 100644 index 0000000..5432dda --- /dev/null +++ b/src/include/commands/publicationcmds.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * + * publicationcmds.h + * prototypes for publicationcmds.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/publicationcmds.h + * + *------------------------------------------------------------------------- + */ + +#ifndef PUBLICATIONCMDS_H +#define PUBLICATIONCMDS_H + +#include "catalog/objectaddress.h" +#include "nodes/parsenodes.h" +#include "utils/inval.h" + +/* Same as MAXNUMMESSAGES in sinvaladt.c */ +#define MAX_RELCACHE_INVAL_MSGS 4096 + +extern ObjectAddress CreatePublication(CreatePublicationStmt *stmt); +extern void AlterPublication(AlterPublicationStmt *stmt); +extern void RemovePublicationById(Oid pubid); +extern void RemovePublicationRelById(Oid proid); + +extern ObjectAddress AlterPublicationOwner(const char *name, Oid newOwnerId); +extern void AlterPublicationOwner_oid(Oid pubid, Oid newOwnerId); +extern void InvalidatePublicationRels(List *relids); + +#endif /* PUBLICATIONCMDS_H */ diff --git a/src/include/commands/schemacmds.h b/src/include/commands/schemacmds.h new file mode 100644 index 0000000..25f4876 --- /dev/null +++ b/src/include/commands/schemacmds.h @@ -0,0 +1,29 @@ +/*------------------------------------------------------------------------- + * + * schemacmds.h + * prototypes for schemacmds.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/schemacmds.h + * + *------------------------------------------------------------------------- + */ + +#ifndef SCHEMACMDS_H +#define SCHEMACMDS_H + +#include "catalog/objectaddress.h" +#include "nodes/parsenodes.h" + +extern Oid CreateSchemaCommand(CreateSchemaStmt *parsetree, + const char *queryString, + int stmt_location, int stmt_len); + +extern ObjectAddress RenameSchema(const char *oldname, const char *newname); +extern ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId); +extern void AlterSchemaOwner_oid(Oid schemaOid, Oid newOwnerId); + +#endif /* SCHEMACMDS_H */ diff --git a/src/include/commands/seclabel.h b/src/include/commands/seclabel.h new file mode 100644 index 0000000..40e284e --- /dev/null +++ b/src/include/commands/seclabel.h @@ -0,0 +1,34 @@ +/* + * seclabel.h + * + * Prototypes for functions in commands/seclabel.c + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + */ +#ifndef SECLABEL_H +#define SECLABEL_H + +#include "catalog/objectaddress.h" + +/* + * Internal APIs + */ +extern char *GetSecurityLabel(const ObjectAddress *object, + const char *provider); +extern void SetSecurityLabel(const ObjectAddress *object, + const char *provider, const char *label); +extern void DeleteSecurityLabel(const ObjectAddress *object); +extern void DeleteSharedSecurityLabel(Oid objectId, Oid classId); + +/* + * Statement and ESP hook support + */ +extern ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt); + +typedef void (*check_object_relabel_type) (const ObjectAddress *object, + const char *seclabel); +extern void register_label_provider(const char *provider, + check_object_relabel_type hook); + +#endif /* SECLABEL_H */ diff --git a/src/include/commands/sequence.h b/src/include/commands/sequence.h new file mode 100644 index 0000000..40544dd --- /dev/null +++ b/src/include/commands/sequence.h @@ -0,0 +1,69 @@ +/*------------------------------------------------------------------------- + * + * sequence.h + * prototypes for sequence.c. + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/sequence.h + * + *------------------------------------------------------------------------- + */ +#ifndef SEQUENCE_H +#define SEQUENCE_H + +#include "access/xlogreader.h" +#include "catalog/objectaddress.h" +#include "fmgr.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "parser/parse_node.h" +#include "storage/relfilenode.h" + + +typedef struct FormData_pg_sequence_data +{ + int64 last_value; + int64 log_cnt; + bool is_called; +} FormData_pg_sequence_data; + +typedef FormData_pg_sequence_data *Form_pg_sequence_data; + +/* + * Columns of a sequence relation + */ + +#define SEQ_COL_LASTVAL 1 +#define SEQ_COL_LOG 2 +#define SEQ_COL_CALLED 3 + +#define SEQ_COL_FIRSTCOL SEQ_COL_LASTVAL +#define SEQ_COL_LASTCOL SEQ_COL_CALLED + +/* XLOG stuff */ +#define XLOG_SEQ_LOG 0x00 + +typedef struct xl_seq_rec +{ + RelFileNode node; + /* SEQUENCE TUPLE DATA FOLLOWS AT THE END */ +} xl_seq_rec; + +extern int64 nextval_internal(Oid relid, bool check_permissions); +extern Datum nextval(PG_FUNCTION_ARGS); +extern List *sequence_options(Oid relid); + +extern ObjectAddress DefineSequence(ParseState *pstate, CreateSeqStmt *stmt); +extern ObjectAddress AlterSequence(ParseState *pstate, AlterSeqStmt *stmt); +extern void DeleteSequenceTuple(Oid relid); +extern void ResetSequence(Oid seq_relid); +extern void ResetSequenceCaches(void); + +extern void seq_redo(XLogReaderState *rptr); +extern void seq_desc(StringInfo buf, XLogReaderState *rptr); +extern const char *seq_identify(uint8 info); +extern void seq_mask(char *pagedata, BlockNumber blkno); + +#endif /* SEQUENCE_H */ diff --git a/src/include/commands/subscriptioncmds.h b/src/include/commands/subscriptioncmds.h new file mode 100644 index 0000000..3b926f3 --- /dev/null +++ b/src/include/commands/subscriptioncmds.h @@ -0,0 +1,29 @@ +/*------------------------------------------------------------------------- + * + * subscriptioncmds.h + * prototypes for subscriptioncmds.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/subscriptioncmds.h + * + *------------------------------------------------------------------------- + */ + +#ifndef SUBSCRIPTIONCMDS_H +#define SUBSCRIPTIONCMDS_H + +#include "catalog/objectaddress.h" +#include "nodes/parsenodes.h" + +extern ObjectAddress CreateSubscription(CreateSubscriptionStmt *stmt, + bool isTopLevel); +extern ObjectAddress AlterSubscription(AlterSubscriptionStmt *stmt, bool isTopLevel); +extern void DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel); + +extern ObjectAddress AlterSubscriptionOwner(const char *name, Oid newOwnerId); +extern void AlterSubscriptionOwner_oid(Oid subid, Oid newOwnerId); + +#endif /* SUBSCRIPTIONCMDS_H */ diff --git a/src/include/commands/tablecmds.h b/src/include/commands/tablecmds.h new file mode 100644 index 0000000..336549c --- /dev/null +++ b/src/include/commands/tablecmds.h @@ -0,0 +1,106 @@ +/*------------------------------------------------------------------------- + * + * tablecmds.h + * prototypes for tablecmds.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/tablecmds.h + * + *------------------------------------------------------------------------- + */ +#ifndef TABLECMDS_H +#define TABLECMDS_H + +#include "access/htup.h" +#include "catalog/dependency.h" +#include "catalog/objectaddress.h" +#include "nodes/parsenodes.h" +#include "storage/lock.h" +#include "utils/relcache.h" + +struct AlterTableUtilityContext; /* avoid including tcop/utility.h here */ + + +extern ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, + ObjectAddress *typaddress, const char *queryString); + +extern void RemoveRelations(DropStmt *drop); + +extern Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode); + +extern void AlterTable(AlterTableStmt *stmt, LOCKMODE lockmode, + struct AlterTableUtilityContext *context); + +extern LOCKMODE AlterTableGetLockLevel(List *cmds); + +extern void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lockmode); + +extern void AlterTableInternal(Oid relid, List *cmds, bool recurse); + +extern Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt); + +extern ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt, + Oid *oldschema); + +extern void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, + Oid nspOid, ObjectAddresses *objsMoved); + +extern void AlterRelationNamespaceInternal(Relation classRel, Oid relOid, + Oid oldNspOid, Oid newNspOid, + bool hasDependEntry, + ObjectAddresses *objsMoved); + +extern void CheckTableNotInUse(Relation rel, const char *stmt); + +extern void ExecuteTruncate(TruncateStmt *stmt); +extern void ExecuteTruncateGuts(List *explicit_rels, + List *relids, + List *relids_logged, + DropBehavior behavior, + bool restart_seqs); + +extern void SetRelationHasSubclass(Oid relationId, bool relhassubclass); + +extern bool CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId); +extern void SetRelationTableSpace(Relation rel, Oid newTableSpaceId, + Oid newRelFileNode); + +extern ObjectAddress renameatt(RenameStmt *stmt); + +extern ObjectAddress RenameConstraint(RenameStmt *stmt); + +extern ObjectAddress RenameRelation(RenameStmt *stmt); + +extern void RenameRelationInternal(Oid myrelid, + const char *newrelname, bool is_internal, + bool is_index); + +extern void ResetRelRewrite(Oid myrelid); + +extern void find_composite_type_dependencies(Oid typeOid, + Relation origRelation, + const char *origTypeName); + +extern void check_of_type(HeapTuple typetuple); + +extern void register_on_commit_action(Oid relid, OnCommitAction action); +extern void remove_on_commit_action(Oid relid); + +extern void PreCommit_on_commit_actions(void); +extern void AtEOXact_on_commit_actions(bool isCommit); +extern void AtEOSubXact_on_commit_actions(bool isCommit, + SubTransactionId mySubid, + SubTransactionId parentSubid); + +extern void RangeVarCallbackOwnsTable(const RangeVar *relation, + Oid relId, Oid oldRelId, void *arg); + +extern void RangeVarCallbackOwnsRelation(const RangeVar *relation, + Oid relId, Oid oldRelId, void *arg); +extern bool PartConstraintImpliedByRelConstraint(Relation scanrel, + List *partConstraint); + +#endif /* TABLECMDS_H */ diff --git a/src/include/commands/tablespace.h b/src/include/commands/tablespace.h new file mode 100644 index 0000000..f33ba51 --- /dev/null +++ b/src/include/commands/tablespace.h @@ -0,0 +1,69 @@ +/*------------------------------------------------------------------------- + * + * tablespace.h + * Tablespace management commands (create/drop tablespace). + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/tablespace.h + * + *------------------------------------------------------------------------- + */ +#ifndef TABLESPACE_H +#define TABLESPACE_H + +#include "access/xlogreader.h" +#include "catalog/objectaddress.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" + +extern bool allow_in_place_tablespaces; + +/* XLOG stuff */ +#define XLOG_TBLSPC_CREATE 0x00 +#define XLOG_TBLSPC_DROP 0x10 + +typedef struct xl_tblspc_create_rec +{ + Oid ts_id; + char ts_path[FLEXIBLE_ARRAY_MEMBER]; /* null-terminated string */ +} xl_tblspc_create_rec; + +typedef struct xl_tblspc_drop_rec +{ + Oid ts_id; +} xl_tblspc_drop_rec; + +typedef struct TableSpaceOpts +{ + int32 vl_len_; /* varlena header (do not touch directly!) */ + float8 random_page_cost; + float8 seq_page_cost; + int effective_io_concurrency; + int maintenance_io_concurrency; +} TableSpaceOpts; + +extern Oid CreateTableSpace(CreateTableSpaceStmt *stmt); +extern void DropTableSpace(DropTableSpaceStmt *stmt); +extern ObjectAddress RenameTableSpace(const char *oldname, const char *newname); +extern Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt); + +extern void TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo); + +extern Oid GetDefaultTablespace(char relpersistence, bool partitioned); + +extern void PrepareTempTablespaces(void); + +extern Oid get_tablespace_oid(const char *tablespacename, bool missing_ok); +extern char *get_tablespace_name(Oid spc_oid); + +extern bool directory_is_empty(const char *path); +extern void remove_tablespace_symlink(const char *linkloc); + +extern void tblspc_redo(XLogReaderState *rptr); +extern void tblspc_desc(StringInfo buf, XLogReaderState *rptr); +extern const char *tblspc_identify(uint8 info); + +#endif /* TABLESPACE_H */ diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h new file mode 100644 index 0000000..a97a2ef --- /dev/null +++ b/src/include/commands/trigger.h @@ -0,0 +1,277 @@ +/*------------------------------------------------------------------------- + * + * trigger.h + * Declarations for trigger handling. + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/trigger.h + * + *------------------------------------------------------------------------- + */ +#ifndef TRIGGER_H +#define TRIGGER_H + +#include "catalog/objectaddress.h" +#include "nodes/execnodes.h" +#include "nodes/parsenodes.h" + +/* + * TriggerData is the node type that is passed as fmgr "context" info + * when a function is called by the trigger manager. + */ + +#define CALLED_AS_TRIGGER(fcinfo) \ + ((fcinfo)->context != NULL && IsA((fcinfo)->context, TriggerData)) + +typedef uint32 TriggerEvent; + +typedef struct TriggerData +{ + NodeTag type; + TriggerEvent tg_event; + Relation tg_relation; + HeapTuple tg_trigtuple; + HeapTuple tg_newtuple; + Trigger *tg_trigger; + TupleTableSlot *tg_trigslot; + TupleTableSlot *tg_newslot; + Tuplestorestate *tg_oldtable; + Tuplestorestate *tg_newtable; + const Bitmapset *tg_updatedcols; +} TriggerData; + +/* + * The state for capturing old and new tuples into transition tables for a + * single ModifyTable node (or other operation source, e.g. copyfrom.c). + * + * This is per-caller to avoid conflicts in setting + * tcs_original_insert_tuple. Note, however, that the pointed-to + * private data may be shared across multiple callers. + */ +struct AfterTriggersTableData; /* private in trigger.c */ + +typedef struct TransitionCaptureState +{ + /* + * Is there at least one trigger specifying each transition relation on + * the relation explicitly named in the DML statement or COPY command? + * Note: in current usage, these flags could be part of the private state, + * but it seems possibly useful to let callers see them. + */ + bool tcs_delete_old_table; + bool tcs_update_old_table; + bool tcs_update_new_table; + bool tcs_insert_new_table; + + /* + * For INSERT and COPY, it would be wasteful to convert tuples from child + * format to parent format after they have already been converted in the + * opposite direction during routing. In that case we bypass conversion + * and allow the inserting code (copyfrom.c and nodeModifyTable.c) to + * provide a slot containing the original tuple directly. + */ + TupleTableSlot *tcs_original_insert_tuple; + + /* + * Private data including the tuplestore(s) into which to insert tuples. + */ + struct AfterTriggersTableData *tcs_private; +} TransitionCaptureState; + +/* + * TriggerEvent bit flags + * + * Note that we assume different event types (INSERT/DELETE/UPDATE/TRUNCATE) + * can't be OR'd together in a single TriggerEvent. This is unlike the + * situation for pg_trigger rows, so pg_trigger.tgtype uses a different + * representation! + */ +#define TRIGGER_EVENT_INSERT 0x00000000 +#define TRIGGER_EVENT_DELETE 0x00000001 +#define TRIGGER_EVENT_UPDATE 0x00000002 +#define TRIGGER_EVENT_TRUNCATE 0x00000003 +#define TRIGGER_EVENT_OPMASK 0x00000003 + +#define TRIGGER_EVENT_ROW 0x00000004 + +#define TRIGGER_EVENT_BEFORE 0x00000008 +#define TRIGGER_EVENT_AFTER 0x00000000 +#define TRIGGER_EVENT_INSTEAD 0x00000010 +#define TRIGGER_EVENT_TIMINGMASK 0x00000018 + +/* More TriggerEvent flags, used only within trigger.c */ + +#define AFTER_TRIGGER_DEFERRABLE 0x00000020 +#define AFTER_TRIGGER_INITDEFERRED 0x00000040 + +#define TRIGGER_FIRED_BY_INSERT(event) \ + (((event) & TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_INSERT) + +#define TRIGGER_FIRED_BY_DELETE(event) \ + (((event) & TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_DELETE) + +#define TRIGGER_FIRED_BY_UPDATE(event) \ + (((event) & TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_UPDATE) + +#define TRIGGER_FIRED_BY_TRUNCATE(event) \ + (((event) & TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_TRUNCATE) + +#define TRIGGER_FIRED_FOR_ROW(event) \ + ((event) & TRIGGER_EVENT_ROW) + +#define TRIGGER_FIRED_FOR_STATEMENT(event) \ + (!TRIGGER_FIRED_FOR_ROW(event)) + +#define TRIGGER_FIRED_BEFORE(event) \ + (((event) & TRIGGER_EVENT_TIMINGMASK) == TRIGGER_EVENT_BEFORE) + +#define TRIGGER_FIRED_AFTER(event) \ + (((event) & TRIGGER_EVENT_TIMINGMASK) == TRIGGER_EVENT_AFTER) + +#define TRIGGER_FIRED_INSTEAD(event) \ + (((event) & TRIGGER_EVENT_TIMINGMASK) == TRIGGER_EVENT_INSTEAD) + +/* + * Definitions for replication role based firing. + */ +#define SESSION_REPLICATION_ROLE_ORIGIN 0 +#define SESSION_REPLICATION_ROLE_REPLICA 1 +#define SESSION_REPLICATION_ROLE_LOCAL 2 +extern PGDLLIMPORT int SessionReplicationRole; + +/* + * States at which a trigger can be fired. These are the + * possible values for pg_trigger.tgenabled. + */ +#define TRIGGER_FIRES_ON_ORIGIN 'O' +#define TRIGGER_FIRES_ALWAYS 'A' +#define TRIGGER_FIRES_ON_REPLICA 'R' +#define TRIGGER_DISABLED 'D' + +extern ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString, + Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, + Oid funcoid, Oid parentTriggerOid, Node *whenClause, + bool isInternal, bool in_partition); +extern ObjectAddress CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString, + Oid relOid, Oid refRelOid, Oid constraintOid, + Oid indexOid, Oid funcoid, Oid parentTriggerOid, + Node *whenClause, bool isInternal, bool in_partition, + char trigger_fires_when); + +extern void RemoveTriggerById(Oid trigOid); +extern Oid get_trigger_oid(Oid relid, const char *name, bool missing_ok); + +extern ObjectAddress renametrig(RenameStmt *stmt); + +extern void EnableDisableTriggerNew(Relation rel, const char *tgname, + char fires_when, bool skip_system, bool recurse, + LOCKMODE lockmode); +extern void EnableDisableTrigger(Relation rel, const char *tgname, + char fires_when, bool skip_system, LOCKMODE lockmode); + +extern void RelationBuildTriggers(Relation relation); + +extern TriggerDesc *CopyTriggerDesc(TriggerDesc *trigdesc); + +extern const char *FindTriggerIncompatibleWithInheritance(TriggerDesc *trigdesc); + +extern TransitionCaptureState *MakeTransitionCaptureState(TriggerDesc *trigdesc, + Oid relid, CmdType cmdType); + +extern void FreeTriggerDesc(TriggerDesc *trigdesc); + +extern void ExecBSInsertTriggers(EState *estate, + ResultRelInfo *relinfo); +extern void ExecASInsertTriggers(EState *estate, + ResultRelInfo *relinfo, + TransitionCaptureState *transition_capture); +extern bool ExecBRInsertTriggers(EState *estate, + ResultRelInfo *relinfo, + TupleTableSlot *slot); +extern void ExecARInsertTriggers(EState *estate, + ResultRelInfo *relinfo, + TupleTableSlot *slot, + List *recheckIndexes, + TransitionCaptureState *transition_capture); +extern bool ExecIRInsertTriggers(EState *estate, + ResultRelInfo *relinfo, + TupleTableSlot *slot); +extern void ExecBSDeleteTriggers(EState *estate, + ResultRelInfo *relinfo); +extern void ExecASDeleteTriggers(EState *estate, + ResultRelInfo *relinfo, + TransitionCaptureState *transition_capture); +extern bool ExecBRDeleteTriggers(EState *estate, + EPQState *epqstate, + ResultRelInfo *relinfo, + ItemPointer tupleid, + HeapTuple fdw_trigtuple, + TupleTableSlot **epqslot); +extern void ExecARDeleteTriggers(EState *estate, + ResultRelInfo *relinfo, + ItemPointer tupleid, + HeapTuple fdw_trigtuple, + TransitionCaptureState *transition_capture); +extern bool ExecIRDeleteTriggers(EState *estate, + ResultRelInfo *relinfo, + HeapTuple trigtuple); +extern void ExecBSUpdateTriggers(EState *estate, + ResultRelInfo *relinfo); +extern void ExecASUpdateTriggers(EState *estate, + ResultRelInfo *relinfo, + TransitionCaptureState *transition_capture); +extern bool ExecBRUpdateTriggers(EState *estate, + EPQState *epqstate, + ResultRelInfo *relinfo, + ItemPointer tupleid, + HeapTuple fdw_trigtuple, + TupleTableSlot *slot); +extern void ExecARUpdateTriggers(EState *estate, + ResultRelInfo *relinfo, + ItemPointer tupleid, + HeapTuple fdw_trigtuple, + TupleTableSlot *slot, + List *recheckIndexes, + TransitionCaptureState *transition_capture); +extern bool ExecIRUpdateTriggers(EState *estate, + ResultRelInfo *relinfo, + HeapTuple trigtuple, + TupleTableSlot *slot); +extern void ExecBSTruncateTriggers(EState *estate, + ResultRelInfo *relinfo); +extern void ExecASTruncateTriggers(EState *estate, + ResultRelInfo *relinfo); + +extern void AfterTriggerBeginXact(void); +extern void AfterTriggerBeginQuery(void); +extern void AfterTriggerEndQuery(EState *estate); +extern void AfterTriggerFireDeferred(void); +extern void AfterTriggerEndXact(bool isCommit); +extern void AfterTriggerBeginSubXact(void); +extern void AfterTriggerEndSubXact(bool isCommit); +extern void AfterTriggerSetState(ConstraintsSetStmt *stmt); +extern bool AfterTriggerPendingOnRel(Oid relid); + + +/* + * in utils/adt/ri_triggers.c + */ +extern bool RI_FKey_pk_upd_check_required(Trigger *trigger, Relation pk_rel, + TupleTableSlot *old_slot, TupleTableSlot *new_slot); +extern bool RI_FKey_fk_upd_check_required(Trigger *trigger, Relation fk_rel, + TupleTableSlot *old_slot, TupleTableSlot *new_slot); +extern bool RI_Initial_Check(Trigger *trigger, + Relation fk_rel, Relation pk_rel); +extern void RI_PartitionRemove_Check(Trigger *trigger, Relation fk_rel, + Relation pk_rel); + +/* result values for RI_FKey_trigger_type: */ +#define RI_TRIGGER_PK 1 /* is a trigger on the PK relation */ +#define RI_TRIGGER_FK 2 /* is a trigger on the FK relation */ +#define RI_TRIGGER_NONE 0 /* is not an RI trigger function */ + +extern int RI_FKey_trigger_type(Oid tgfoid); + +#endif /* TRIGGER_H */ diff --git a/src/include/commands/typecmds.h b/src/include/commands/typecmds.h new file mode 100644 index 0000000..8806791 --- /dev/null +++ b/src/include/commands/typecmds.h @@ -0,0 +1,61 @@ +/*------------------------------------------------------------------------- + * + * typecmds.h + * prototypes for typecmds.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/typecmds.h + * + *------------------------------------------------------------------------- + */ +#ifndef TYPECMDS_H +#define TYPECMDS_H + +#include "access/htup.h" +#include "catalog/dependency.h" +#include "parser/parse_node.h" + + +#define DEFAULT_TYPDELIM ',' + +extern ObjectAddress DefineType(ParseState *pstate, List *names, List *parameters); +extern void RemoveTypeById(Oid typeOid); +extern ObjectAddress DefineDomain(CreateDomainStmt *stmt); +extern ObjectAddress DefineEnum(CreateEnumStmt *stmt); +extern ObjectAddress DefineRange(CreateRangeStmt *stmt); +extern ObjectAddress AlterEnum(AlterEnumStmt *stmt); +extern ObjectAddress DefineCompositeType(RangeVar *typevar, List *coldeflist); +extern Oid AssignTypeArrayOid(void); +extern Oid AssignTypeMultirangeOid(void); +extern Oid AssignTypeMultirangeArrayOid(void); + +extern ObjectAddress AlterDomainDefault(List *names, Node *defaultRaw); +extern ObjectAddress AlterDomainNotNull(List *names, bool notNull); +extern ObjectAddress AlterDomainAddConstraint(List *names, Node *constr, + ObjectAddress *constrAddr); +extern ObjectAddress AlterDomainValidateConstraint(List *names, const char *constrName); +extern ObjectAddress AlterDomainDropConstraint(List *names, const char *constrName, + DropBehavior behavior, bool missing_ok); + +extern void checkDomainOwner(HeapTuple tup); + +extern ObjectAddress RenameType(RenameStmt *stmt); + +extern ObjectAddress AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype); +extern void AlterTypeOwner_oid(Oid typeOid, Oid newOwnerId, bool hasDependEntry); +extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId); + +extern ObjectAddress AlterTypeNamespace(List *names, const char *newschema, + ObjectType objecttype, Oid *oldschema); +extern Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses *objsMoved); +extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid, + bool isImplicitArray, + bool errorOnTableType, + ObjectAddresses *objsMoved); + +extern ObjectAddress AlterType(AlterTypeStmt *stmt); + +#endif /* TYPECMDS_H */ diff --git a/src/include/commands/user.h b/src/include/commands/user.h new file mode 100644 index 0000000..028e0dd --- /dev/null +++ b/src/include/commands/user.h @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + * + * user.h + * Commands for manipulating roles (formerly called users). + * + * + * src/include/commands/user.h + * + *------------------------------------------------------------------------- + */ +#ifndef USER_H +#define USER_H + +#include "catalog/objectaddress.h" +#include "libpq/crypt.h" +#include "nodes/parsenodes.h" +#include "parser/parse_node.h" + +/* GUC. Is actually of type PasswordType. */ +extern int Password_encryption; + +/* Hook to check passwords in CreateRole() and AlterRole() */ +typedef void (*check_password_hook_type) (const char *username, const char *shadow_pass, PasswordType password_type, Datum validuntil_time, bool validuntil_null); + +extern PGDLLIMPORT check_password_hook_type check_password_hook; + +extern Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt); +extern Oid AlterRole(AlterRoleStmt *stmt); +extern Oid AlterRoleSet(AlterRoleSetStmt *stmt); +extern void DropRole(DropRoleStmt *stmt); +extern void GrantRole(GrantRoleStmt *stmt); +extern ObjectAddress RenameRole(const char *oldname, const char *newname); +extern void DropOwnedObjects(DropOwnedStmt *stmt); +extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt); +extern List *roleSpecsToIds(List *memberNames); + +#endif /* USER_H */ diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h new file mode 100644 index 0000000..4cfd52e --- /dev/null +++ b/src/include/commands/vacuum.h @@ -0,0 +1,297 @@ +/*------------------------------------------------------------------------- + * + * vacuum.h + * header file for postgres vacuum cleaner and statistics analyzer + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/vacuum.h + * + *------------------------------------------------------------------------- + */ +#ifndef VACUUM_H +#define VACUUM_H + +#include "access/htup.h" +#include "catalog/pg_class.h" +#include "catalog/pg_statistic.h" +#include "catalog/pg_type.h" +#include "parser/parse_node.h" +#include "storage/buf.h" +#include "storage/lock.h" +#include "utils/relcache.h" + +/* + * Flags for amparallelvacuumoptions to control the participation of bulkdelete + * and vacuumcleanup in parallel vacuum. + */ + +/* + * Both bulkdelete and vacuumcleanup are disabled by default. This will be + * used by IndexAM's that don't want to or cannot participate in parallel + * vacuum. For example, if an index AM doesn't have a way to communicate the + * index statistics allocated by the first ambulkdelete call to the subsequent + * ones until amvacuumcleanup, the index AM cannot participate in parallel + * vacuum. + */ +#define VACUUM_OPTION_NO_PARALLEL 0 + +/* + * bulkdelete can be performed in parallel. This option can be used by + * index AMs that need to scan indexes to delete tuples. + */ +#define VACUUM_OPTION_PARALLEL_BULKDEL (1 << 0) + +/* + * vacuumcleanup can be performed in parallel if bulkdelete is not performed + * yet. This will be used by IndexAM's that can scan the index if the + * bulkdelete is not performed. + */ +#define VACUUM_OPTION_PARALLEL_COND_CLEANUP (1 << 1) + +/* + * vacuumcleanup can be performed in parallel even if bulkdelete has already + * processed the index. This will be used by IndexAM's that scan the index + * during the cleanup phase of index irrespective of whether the index is + * already scanned or not during bulkdelete phase. + */ +#define VACUUM_OPTION_PARALLEL_CLEANUP (1 << 2) + +/* value for checking vacuum flags */ +#define VACUUM_OPTION_MAX_VALID_VALUE ((1 << 3) - 1) + +/*---------- + * ANALYZE builds one of these structs for each attribute (column) that is + * to be analyzed. The struct and subsidiary data are in anl_context, + * so they live until the end of the ANALYZE operation. + * + * The type-specific typanalyze function is passed a pointer to this struct + * and must return true to continue analysis, false to skip analysis of this + * column. In the true case it must set the compute_stats and minrows fields, + * and can optionally set extra_data to pass additional info to compute_stats. + * minrows is its request for the minimum number of sample rows to be gathered + * (but note this request might not be honored, eg if there are fewer rows + * than that in the table). + * + * The compute_stats routine will be called after sample rows have been + * gathered. Aside from this struct, it is passed: + * fetchfunc: a function for accessing the column values from the + * sample rows + * samplerows: the number of sample tuples + * totalrows: estimated total number of rows in relation + * The fetchfunc may be called with rownum running from 0 to samplerows-1. + * It returns a Datum and an isNull flag. + * + * compute_stats should set stats_valid true if it is able to compute + * any useful statistics. If it does, the remainder of the struct holds + * the information to be stored in a pg_statistic row for the column. Be + * careful to allocate any pointed-to data in anl_context, which will NOT + * be CurrentMemoryContext when compute_stats is called. + * + * Note: all comparisons done for statistical purposes should use the + * underlying column's collation (attcollation), except in situations + * where a noncollatable container type contains a collatable type; + * in that case use the type's default collation. Be sure to record + * the appropriate collation in stacoll. + *---------- + */ +typedef struct VacAttrStats *VacAttrStatsP; + +typedef Datum (*AnalyzeAttrFetchFunc) (VacAttrStatsP stats, int rownum, + bool *isNull); + +typedef void (*AnalyzeAttrComputeStatsFunc) (VacAttrStatsP stats, + AnalyzeAttrFetchFunc fetchfunc, + int samplerows, + double totalrows); + +typedef struct VacAttrStats +{ + /* + * These fields are set up by the main ANALYZE code before invoking the + * type-specific typanalyze function. + * + * Note: do not assume that the data being analyzed has the same datatype + * shown in attr, ie do not trust attr->atttypid, attlen, etc. This is + * because some index opclasses store a different type than the underlying + * column/expression. Instead use attrtypid, attrtypmod, and attrtype for + * information about the datatype being fed to the typanalyze function. + * Likewise, use attrcollid not attr->attcollation. + */ + Form_pg_attribute attr; /* copy of pg_attribute row for column */ + Oid attrtypid; /* type of data being analyzed */ + int32 attrtypmod; /* typmod of data being analyzed */ + Form_pg_type attrtype; /* copy of pg_type row for attrtypid */ + Oid attrcollid; /* collation of data being analyzed */ + MemoryContext anl_context; /* where to save long-lived data */ + + /* + * These fields must be filled in by the typanalyze routine, unless it + * returns false. + */ + AnalyzeAttrComputeStatsFunc compute_stats; /* function pointer */ + int minrows; /* Minimum # of rows wanted for stats */ + void *extra_data; /* for extra type-specific data */ + + /* + * These fields are to be filled in by the compute_stats routine. (They + * are initialized to zero when the struct is created.) + */ + bool stats_valid; + float4 stanullfrac; /* fraction of entries that are NULL */ + int32 stawidth; /* average width of column values */ + float4 stadistinct; /* # distinct values */ + int16 stakind[STATISTIC_NUM_SLOTS]; + Oid staop[STATISTIC_NUM_SLOTS]; + Oid stacoll[STATISTIC_NUM_SLOTS]; + int numnumbers[STATISTIC_NUM_SLOTS]; + float4 *stanumbers[STATISTIC_NUM_SLOTS]; + int numvalues[STATISTIC_NUM_SLOTS]; + Datum *stavalues[STATISTIC_NUM_SLOTS]; + + /* + * These fields describe the stavalues[n] element types. They will be + * initialized to match attrtypid, but a custom typanalyze function might + * want to store an array of something other than the analyzed column's + * elements. It should then overwrite these fields. + */ + Oid statypid[STATISTIC_NUM_SLOTS]; + int16 statyplen[STATISTIC_NUM_SLOTS]; + bool statypbyval[STATISTIC_NUM_SLOTS]; + char statypalign[STATISTIC_NUM_SLOTS]; + + /* + * These fields are private to the main ANALYZE code and should not be + * looked at by type-specific functions. + */ + int tupattnum; /* attribute number within tuples */ + HeapTuple *rows; /* access info for std fetch function */ + TupleDesc tupDesc; + Datum *exprvals; /* access info for index fetch function */ + bool *exprnulls; + int rowstride; +} VacAttrStats; + +/* flag bits for VacuumParams->options */ +#define VACOPT_VACUUM 0x01 /* do VACUUM */ +#define VACOPT_ANALYZE 0x02 /* do ANALYZE */ +#define VACOPT_VERBOSE 0x04 /* print progress info */ +#define VACOPT_FREEZE 0x08 /* FREEZE option */ +#define VACOPT_FULL 0x10 /* FULL (non-concurrent) vacuum */ +#define VACOPT_SKIP_LOCKED 0x20 /* skip if cannot get lock */ +#define VACOPT_PROCESS_TOAST 0x40 /* process the TOAST table, if any */ +#define VACOPT_DISABLE_PAGE_SKIPPING 0x80 /* don't skip any pages */ + +/* + * Values used by index_cleanup and truncate params. + * + * VACOPTVALUE_UNSPECIFIED is used as an initial placeholder when VACUUM + * command has no explicit value. When that happens the final usable value + * comes from the corresponding reloption (though the reloption default is + * usually used). + */ +typedef enum VacOptValue +{ + VACOPTVALUE_UNSPECIFIED = 0, + VACOPTVALUE_AUTO, + VACOPTVALUE_DISABLED, + VACOPTVALUE_ENABLED, +} VacOptValue; + +/* + * Parameters customizing behavior of VACUUM and ANALYZE. + * + * Note that at least one of VACOPT_VACUUM and VACOPT_ANALYZE must be set + * in options. + */ +typedef struct VacuumParams +{ + bits32 options; /* bitmask of VACOPT_* */ + int freeze_min_age; /* min freeze age, -1 to use default */ + int freeze_table_age; /* age at which to scan whole table */ + int multixact_freeze_min_age; /* min multixact freeze age, -1 to + * use default */ + int multixact_freeze_table_age; /* multixact age at which to scan + * whole table */ + bool is_wraparound; /* force a for-wraparound vacuum */ + int log_min_duration; /* minimum execution threshold in ms at + * which verbose logs are activated, -1 + * to use default */ + VacOptValue index_cleanup; /* Do index vacuum and cleanup */ + VacOptValue truncate; /* Truncate empty pages at the end */ + + /* + * The number of parallel vacuum workers. 0 by default which means choose + * based on the number of indexes. -1 indicates parallel vacuum is + * disabled. + */ + int nworkers; +} VacuumParams; + +/* GUC parameters */ +extern PGDLLIMPORT int default_statistics_target; /* PGDLLIMPORT for PostGIS */ +extern int vacuum_freeze_min_age; +extern int vacuum_freeze_table_age; +extern int vacuum_multixact_freeze_min_age; +extern int vacuum_multixact_freeze_table_age; +extern int vacuum_failsafe_age; +extern int vacuum_multixact_failsafe_age; + +/* Variables for cost-based parallel vacuum */ +extern pg_atomic_uint32 *VacuumSharedCostBalance; +extern pg_atomic_uint32 *VacuumActiveNWorkers; +extern int VacuumCostBalanceLocal; + + +/* in commands/vacuum.c */ +extern void ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel); +extern void vacuum(List *relations, VacuumParams *params, + BufferAccessStrategy bstrategy, bool isTopLevel); +extern void vac_open_indexes(Relation relation, LOCKMODE lockmode, + int *nindexes, Relation **Irel); +extern void vac_close_indexes(int nindexes, Relation *Irel, LOCKMODE lockmode); +extern double vac_estimate_reltuples(Relation relation, + BlockNumber total_pages, + BlockNumber scanned_pages, + double scanned_tuples); +extern void vac_update_relstats(Relation relation, + BlockNumber num_pages, + double num_tuples, + BlockNumber num_all_visible_pages, + bool hasindex, + TransactionId frozenxid, + MultiXactId minmulti, + bool in_outer_xact); +extern void vacuum_set_xid_limits(Relation rel, + int freeze_min_age, int freeze_table_age, + int multixact_freeze_min_age, + int multixact_freeze_table_age, + TransactionId *oldestXmin, + TransactionId *freezeLimit, + TransactionId *xidFullScanLimit, + MultiXactId *multiXactCutoff, + MultiXactId *mxactFullScanLimit); +extern bool vacuum_xid_failsafe_check(TransactionId relfrozenxid, + MultiXactId relminmxid); +extern void vac_update_datfrozenxid(void); +extern void vacuum_delay_point(void); +extern bool vacuum_is_relation_owner(Oid relid, Form_pg_class reltuple, + bits32 options); +extern Relation vacuum_open_relation(Oid relid, RangeVar *relation, + bits32 options, bool verbose, + LOCKMODE lmode); + +/* in commands/analyze.c */ +extern void analyze_rel(Oid relid, RangeVar *relation, + VacuumParams *params, List *va_cols, bool in_outer_xact, + BufferAccessStrategy bstrategy); +extern bool std_typanalyze(VacAttrStats *stats); + +/* in utils/misc/sampling.c --- duplicate of declarations in utils/sampling.h */ +extern double anl_random_fract(void); +extern double anl_init_selection_state(int n); +extern double anl_get_next_S(double t, int n, double *stateptr); + +#endif /* VACUUM_H */ diff --git a/src/include/commands/variable.h b/src/include/commands/variable.h new file mode 100644 index 0000000..483bc79 --- /dev/null +++ b/src/include/commands/variable.h @@ -0,0 +1,38 @@ +/* + * variable.h + * Routines for handling specialized SET variables. + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/variable.h + */ +#ifndef VARIABLE_H +#define VARIABLE_H + +#include "utils/guc.h" + + +extern bool check_datestyle(char **newval, void **extra, GucSource source); +extern void assign_datestyle(const char *newval, void *extra); +extern bool check_timezone(char **newval, void **extra, GucSource source); +extern void assign_timezone(const char *newval, void *extra); +extern const char *show_timezone(void); +extern bool check_log_timezone(char **newval, void **extra, GucSource source); +extern void assign_log_timezone(const char *newval, void *extra); +extern const char *show_log_timezone(void); +extern bool check_transaction_read_only(bool *newval, void **extra, GucSource source); +extern bool check_XactIsoLevel(int *newval, void **extra, GucSource source); +extern bool check_transaction_deferrable(bool *newval, void **extra, GucSource source); +extern bool check_random_seed(double *newval, void **extra, GucSource source); +extern void assign_random_seed(double newval, void *extra); +extern const char *show_random_seed(void); +extern bool check_client_encoding(char **newval, void **extra, GucSource source); +extern void assign_client_encoding(const char *newval, void *extra); +extern bool check_session_authorization(char **newval, void **extra, GucSource source); +extern void assign_session_authorization(const char *newval, void *extra); +extern bool check_role(char **newval, void **extra, GucSource source); +extern void assign_role(const char *newval, void *extra); +extern const char *show_role(void); + +#endif /* VARIABLE_H */ diff --git a/src/include/commands/view.h b/src/include/commands/view.h new file mode 100644 index 0000000..d28f817 --- /dev/null +++ b/src/include/commands/view.h @@ -0,0 +1,25 @@ +/*------------------------------------------------------------------------- + * + * view.h + * + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/view.h + * + *------------------------------------------------------------------------- + */ +#ifndef VIEW_H +#define VIEW_H + +#include "catalog/objectaddress.h" +#include "nodes/parsenodes.h" + +extern ObjectAddress DefineView(ViewStmt *stmt, const char *queryString, + int stmt_location, int stmt_len); + +extern void StoreViewQuery(Oid viewOid, Query *viewParse, bool replace); + +#endif /* VIEW_H */ |