├── .gitattributes ├── .gitignore ├── go.work ├── internal ├── cparser │ ├── include │ │ ├── postgres │ │ │ ├── port │ │ │ │ ├── win32 │ │ │ │ │ ├── dlfcn.h │ │ │ │ │ ├── grp.h │ │ │ │ │ ├── pwd.h │ │ │ │ │ ├── sys │ │ │ │ │ │ ├── wait.h │ │ │ │ │ │ ├── select.h │ │ │ │ │ │ ├── un.h │ │ │ │ │ │ ├── resource.h │ │ │ │ │ │ └── socket.h │ │ │ │ │ ├── arpa │ │ │ │ │ │ └── inet.h │ │ │ │ │ ├── netinet │ │ │ │ │ │ ├── in.h │ │ │ │ │ │ └── tcp.h │ │ │ │ │ └── netdb.h │ │ │ │ ├── win32_msvc │ │ │ │ │ ├── sys │ │ │ │ │ │ ├── file.h │ │ │ │ │ │ ├── param.h │ │ │ │ │ │ └── time.h │ │ │ │ │ ├── utime.h │ │ │ │ │ ├── unistd.h │ │ │ │ │ └── dirent.h │ │ │ │ ├── atomics │ │ │ │ │ ├── arch-hppa.h │ │ │ │ │ └── arch-arm.h │ │ │ │ └── win32.h │ │ │ ├── pg_config_os.h │ │ │ ├── pg_config_ext.h │ │ │ ├── pg_trace.h │ │ │ ├── storage │ │ │ │ ├── item.h │ │ │ │ ├── sharedfileset.h │ │ │ │ ├── buf.h │ │ │ │ ├── fileset.h │ │ │ │ ├── procnumber.h │ │ │ │ ├── off.h │ │ │ │ ├── proclist_types.h │ │ │ │ ├── dsm.h │ │ │ │ └── sync.h │ │ │ ├── tcop │ │ │ │ ├── fastpath.h │ │ │ │ ├── pquery.h │ │ │ │ └── cmdtag.h │ │ │ ├── utils │ │ │ │ ├── bytea.h │ │ │ │ ├── ps_status.h │ │ │ │ ├── injection_point.h │ │ │ │ ├── backend_progress.h │ │ │ │ ├── aclchk_internal.h │ │ │ │ ├── regproc.h │ │ │ │ ├── fmgrtab.h │ │ │ │ ├── varlena.h │ │ │ │ ├── ruleutils.h │ │ │ │ ├── sharedtuplestore.h │ │ │ │ └── inval.h │ │ │ ├── mb │ │ │ │ └── stringinfo_mb.h │ │ │ ├── postmaster │ │ │ │ ├── walwriter.h │ │ │ │ ├── interrupt.h │ │ │ │ ├── walsummarizer.h │ │ │ │ ├── pgarch.h │ │ │ │ ├── startup.h │ │ │ │ └── bgwriter.h │ │ │ ├── partitioning │ │ │ │ └── partdefs.h │ │ │ ├── parser │ │ │ │ ├── parse_expr.h │ │ │ │ ├── scansup.h │ │ │ │ └── parsetree.h │ │ │ ├── rewrite │ │ │ │ ├── rewriteSupport.h │ │ │ │ ├── prs2lock.h │ │ │ │ └── rewriteHandler.h │ │ │ ├── common │ │ │ │ ├── keywords.h │ │ │ │ ├── sha2.h │ │ │ │ ├── cryptohash.h │ │ │ │ ├── kwlookup.h │ │ │ │ ├── string.h │ │ │ │ ├── file_perm.h │ │ │ │ └── file_utils.h │ │ │ ├── access │ │ │ │ ├── sysattr.h │ │ │ │ ├── table.h │ │ │ │ ├── relation.h │ │ │ │ ├── printtup.h │ │ │ │ ├── xlogbackup.h │ │ │ │ ├── rmgr.h │ │ │ │ ├── xlogprefetcher.h │ │ │ │ ├── attnum.h │ │ │ │ ├── tidstore.h │ │ │ │ ├── attmap.h │ │ │ │ ├── tupconvert.h │ │ │ │ ├── clog.h │ │ │ │ └── sdir.h │ │ │ ├── catalog │ │ │ │ ├── pg_transform_d.h │ │ │ │ ├── pg_ts_config_d.h │ │ │ │ ├── pg_ts_template_d.h │ │ │ │ ├── pg_ts_dict_d.h │ │ │ │ ├── pg_depend_d.h │ │ │ │ ├── pg_namespace_d.h │ │ │ │ ├── pg_replication_origin_d.h │ │ │ │ ├── pg_ts_parser_d.h │ │ │ │ ├── pg_event_trigger_d.h │ │ │ │ ├── pg_conversion_d.h │ │ │ │ ├── pg_publication_d.h │ │ │ │ ├── pg_partitioned_table_d.h │ │ │ │ ├── pg_language_d.h │ │ │ │ ├── pg_am_d.h │ │ │ │ ├── pg_statistic_ext_d.h │ │ │ │ ├── catalog.h │ │ │ │ ├── pg_opclass_d.h │ │ │ │ ├── pg_opfamily_d.h │ │ │ │ ├── pg_transform.h │ │ │ │ ├── pg_database_d.h │ │ │ │ ├── pg_ts_config.h │ │ │ │ ├── pg_ts_template.h │ │ │ │ ├── pg_am.h │ │ │ │ ├── storage.h │ │ │ │ ├── pg_collation_d.h │ │ │ │ ├── pg_ts_dict.h │ │ │ │ ├── indexing.h │ │ │ │ ├── pg_index_d.h │ │ │ │ ├── pg_ts_parser.h │ │ │ │ ├── pg_authid_d.h │ │ │ │ ├── pg_attribute_d.h │ │ │ │ ├── pg_event_trigger.h │ │ │ │ └── pg_namespace.h │ │ │ ├── replication │ │ │ │ ├── logicalworker.h │ │ │ │ ├── logicallauncher.h │ │ │ │ └── slotsync.h │ │ │ ├── nodes │ │ │ │ ├── print.h │ │ │ │ └── lockoptions.h │ │ │ ├── optimizer │ │ │ │ └── geqo_gene.h │ │ │ ├── libpq │ │ │ │ ├── scram.h │ │ │ │ ├── auth.h │ │ │ │ ├── crypt.h │ │ │ │ └── pqsignal.h │ │ │ ├── commands │ │ │ │ ├── dbcommands.h │ │ │ │ ├── async.h │ │ │ │ └── user.h │ │ │ ├── pl_reserved_kwlist.h │ │ │ ├── pg_getopt.h │ │ │ └── executor │ │ │ │ └── functions.h │ │ └── pg_query_json_helper.c │ ├── pg_query_json_plpgsql.h │ ├── postgres_deparse.h │ ├── pg_query_readfuncs.h │ ├── pg_query_outfuncs.h │ ├── pg_query_fingerprint.h │ ├── pg_query_internal.h │ ├── src_port_qsort.c │ ├── src_common_keywords.c │ ├── pg_query_deparse.c │ ├── src_backend_nodes_value.c │ ├── xxhash.c │ └── src_backend_nodes_extensible.c ├── wasm │ ├── libpg_query.so │ └── wasm.go └── errors │ └── errors.go ├── mage ├── go.mod ├── go.sum └── main.go ├── parser ├── parser.go └── parser_cgo.go ├── go.mod ├── .github └── workflows │ ├── bench.yaml │ └── ci.yaml ├── libpgquery_plpgsql_test.go ├── LICENSE ├── magefiles ├── go.mod └── magefile.go ├── NOTICE.txt ├── normalize_test.go ├── go.sum └── fingerprint_test.go /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | build 3 | go.work.sum 4 | 5 | -------------------------------------------------------------------------------- /go.work: -------------------------------------------------------------------------------- 1 | go 1.22.0 2 | 3 | use ( 4 | . 5 | ./mage 6 | ./magefiles 7 | ) 8 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/dlfcn.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32/dlfcn.h */ 2 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/grp.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32/grp.h */ 2 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/pwd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * src/include/port/win32/pwd.h 3 | */ 4 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/sys/wait.h: -------------------------------------------------------------------------------- 1 | /* 2 | * src/include/port/win32/sys/wait.h 3 | */ 4 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32_msvc/sys/file.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32_msvc/sys/file.h */ 2 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32_msvc/sys/param.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32_msvc/sys/param.h */ 2 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32_msvc/sys/time.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32_msvc/sys/time.h */ 2 | -------------------------------------------------------------------------------- /internal/wasm/libpg_query.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasilibs/go-pgquery/HEAD/internal/wasm/libpg_query.so -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/sys/select.h: -------------------------------------------------------------------------------- 1 | /* 2 | * src/include/port/win32/sys/select.h 3 | */ 4 | -------------------------------------------------------------------------------- /internal/wasm/wasm.go: -------------------------------------------------------------------------------- 1 | package wasm 2 | 3 | import _ "embed" 4 | 5 | //go:embed libpg_query.so 6 | var LibPGQuery []byte 7 | -------------------------------------------------------------------------------- /mage/go.mod: -------------------------------------------------------------------------------- 1 | module mage 2 | 3 | go 1.22.0 4 | 5 | require github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a 6 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/arpa/inet.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32/arpa/inet.h */ 2 | 3 | #include 4 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/netinet/in.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32/netinet/in.h */ 2 | 3 | #include 4 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32_msvc/utime.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32_msvc/utime.h */ 2 | 3 | #include /* for non-unicode version */ 4 | -------------------------------------------------------------------------------- /parser/parser.go: -------------------------------------------------------------------------------- 1 | //go:build !pgquery_cgo && !tinygo 2 | 3 | package parser 4 | 5 | import "github.com/wasilibs/go-pgquery/internal/errors" 6 | 7 | type Error = errors.Error 8 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/netdb.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32/netdb.h */ 2 | #ifndef WIN32_NETDB_H 3 | #define WIN32_NETDB_H 4 | 5 | #include 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/netinet/tcp.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32/netinet/tcp.h */ 2 | #ifndef WIN32_NETINET_TCP_H 3 | #define WIN32_NETINET_TCP_H 4 | 5 | #include 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/pg_config_os.h: -------------------------------------------------------------------------------- 1 | #if defined(_WIN32) || defined(_WIN64) 2 | #include "port/win32.h" 3 | #undef PGDLLIMPORT 4 | #undef PGDLLEXPORT 5 | #ifdef __clang__ 6 | #undef __MINGW64__ 7 | #endif /* __clang__ */ 8 | #endif 9 | -------------------------------------------------------------------------------- /internal/cparser/pg_query_json_plpgsql.h: -------------------------------------------------------------------------------- 1 | #ifndef PG_QUERY_JSON_PLPGSQL_H 2 | #define PG_QUERY_JSON_PLPGSQL_H 3 | 4 | #include "postgres.h" 5 | #include "plpgsql.h" 6 | 7 | char* plpgsqlToJSON(PLpgSQL_function* func); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /mage/go.sum: -------------------------------------------------------------------------------- 1 | github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a h1:tdPcGgyiH0K+SbsJBBm2oPyEIOTAvLBwD9TuUwVtZho= 2 | github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= 3 | -------------------------------------------------------------------------------- /internal/cparser/postgres_deparse.h: -------------------------------------------------------------------------------- 1 | #ifndef POSTGRES_DEPARSE_H 2 | #define POSTGRES_DEPARSE_H 3 | 4 | #include "lib/stringinfo.h" 5 | #include "nodes/parsenodes.h" 6 | 7 | extern void deparseRawStmt(StringInfo str, RawStmt *raw_stmt); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /mage/main.go: -------------------------------------------------------------------------------- 1 | // Entrypoint to mage for running without needing to install the command. 2 | // https://magefile.org/zeroinstall/ 3 | package main 4 | 5 | import ( 6 | "os" 7 | 8 | "github.com/magefile/mage/mage" 9 | ) 10 | 11 | func main() { 12 | os.Exit(mage.Main()) 13 | } 14 | -------------------------------------------------------------------------------- /internal/cparser/pg_query_readfuncs.h: -------------------------------------------------------------------------------- 1 | #ifndef PG_QUERY_READFUNCS_H 2 | #define PG_QUERY_READFUNCS_H 3 | 4 | #include "pg_query.h" 5 | 6 | #include "postgres.h" 7 | #include "nodes/pg_list.h" 8 | 9 | List * pg_query_protobuf_to_nodes(PgQueryProtobuf protobuf); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /internal/cparser/pg_query_outfuncs.h: -------------------------------------------------------------------------------- 1 | #ifndef PG_QUERY_OUTFUNCS_H 2 | #define PG_QUERY_OUTFUNCS_H 3 | 4 | #include "pg_query.h" 5 | 6 | PgQueryProtobuf pg_query_nodes_to_protobuf(const void *obj); 7 | 8 | char *pg_query_node_to_json(const void *obj); 9 | char *pg_query_nodes_to_json(const void *obj); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32_msvc/unistd.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32_msvc/unistd.h */ 2 | 3 | /* 4 | * MSVC does not define these, nor does _fileno(stdin) etc reliably work 5 | * (returns -1 if stdin/out/err are closed). 6 | */ 7 | #define STDIN_FILENO 0 8 | #define STDOUT_FILENO 1 9 | #define STDERR_FILENO 2 10 | -------------------------------------------------------------------------------- /internal/cparser/pg_query_fingerprint.h: -------------------------------------------------------------------------------- 1 | #ifndef PG_QUERY_FINGERPRINT_H 2 | #define PG_QUERY_FINGERPRINT_H 3 | 4 | #include 5 | 6 | extern PgQueryFingerprintResult pg_query_fingerprint_with_opts(const char* input, int parser_options, bool printTokens); 7 | 8 | extern uint64_t pg_query_fingerprint_node(const void * node); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/wasilibs/go-pgquery 2 | 3 | go 1.22.0 4 | 5 | require ( 6 | github.com/google/go-cmp v0.6.0 7 | github.com/pganalyze/pg_query_go/v6 v6.1.0 8 | github.com/tetratelabs/wazero v1.9.0 9 | github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 10 | google.golang.org/protobuf v1.31.0 11 | ) 12 | 13 | require golang.org/x/sys v0.21.0 // indirect 14 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/pg_config_ext.h: -------------------------------------------------------------------------------- 1 | /* src/include/pg_config_ext.h. Generated from pg_config_ext.h.in by configure. */ 2 | /* 3 | * src/include/pg_config_ext.h.in. This is generated manually, not by 4 | * autoheader, since we want to limit which symbols get defined here. 5 | */ 6 | 7 | /* Define to the name of a signed 64-bit integer type. */ 8 | #define PG_INT64_TYPE long int 9 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/sys/un.h: -------------------------------------------------------------------------------- 1 | /* 2 | * src/include/port/win32/sys/un.h 3 | */ 4 | #ifndef WIN32_SYS_UN_H 5 | #define WIN32_SYS_UN_H 6 | 7 | /* 8 | * Windows defines this structure in , but not all tool chains have 9 | * the header yet, so we define it here for now. 10 | */ 11 | struct sockaddr_un 12 | { 13 | unsigned short sun_family; 14 | char sun_path[108]; 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/pg_trace.h: -------------------------------------------------------------------------------- 1 | /* ---------- 2 | * pg_trace.h 3 | * 4 | * Definitions for the PostgreSQL tracing framework 5 | * 6 | * Copyright (c) 2006-2024, PostgreSQL Global Development Group 7 | * 8 | * src/include/pg_trace.h 9 | * ---------- 10 | */ 11 | 12 | #ifndef PG_TRACE_H 13 | #define PG_TRACE_H 14 | 15 | #include "utils/probes.h" /* pgrminclude ignore */ 16 | 17 | #endif /* PG_TRACE_H */ 18 | -------------------------------------------------------------------------------- /internal/errors/errors.go: -------------------------------------------------------------------------------- 1 | package errors 2 | 3 | type Error struct { 4 | Message string // exception message 5 | Funcname string // source function of exception (e.g. SearchSysCache) 6 | Filename string // source of exception (e.g. parse.l) 7 | Lineno int // source of exception (e.g. 104) 8 | Cursorpos int // char in query at which exception occurred 9 | Context string // additional context (optional, can be NULL) 10 | } 11 | 12 | func (e *Error) Error() string { 13 | return e.Message 14 | } 15 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/sys/resource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Replacement for for Windows. 3 | */ 4 | #ifndef WIN32_SYS_RESOURCE_H 5 | #define WIN32_SYS_RESOURCE_H 6 | 7 | #include /* for struct timeval */ 8 | 9 | #define RUSAGE_SELF 0 10 | #define RUSAGE_CHILDREN (-1) 11 | 12 | struct rusage 13 | { 14 | struct timeval ru_utime; /* user time used */ 15 | struct timeval ru_stime; /* system time used */ 16 | }; 17 | 18 | extern int getrusage(int who, struct rusage *rusage); 19 | 20 | #endif /* WIN32_SYS_RESOURCE_H */ 21 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/storage/item.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * item.h 4 | * POSTGRES disk item definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/storage/item.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef ITEM_H 15 | #define ITEM_H 16 | 17 | typedef Pointer Item; 18 | 19 | #endif /* ITEM_H */ 20 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/tcop/fastpath.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * fastpath.h 4 | * 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/tcop/fastpath.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef FASTPATH_H 14 | #define FASTPATH_H 15 | 16 | #include "lib/stringinfo.h" 17 | 18 | extern void HandleFunctionRequest(StringInfo msgBuf); 19 | 20 | #endif /* FASTPATH_H */ 21 | -------------------------------------------------------------------------------- /.github/workflows/bench.yaml: -------------------------------------------------------------------------------- 1 | name: Benchmark 2 | on: 3 | push: 4 | branches: 5 | - main 6 | paths-ignore: 7 | - '**/*.md' 8 | - '**/*.txt' 9 | - '**/*.yaml' 10 | workflow_dispatch: 11 | 12 | jobs: 13 | bench: 14 | runs-on: ubuntu-22.04 15 | steps: 16 | - uses: actions/checkout@v4 17 | with: 18 | fetch-depth: 0 19 | - uses: actions/setup-go@v4 20 | with: 21 | go-version: '^1.21' 22 | 23 | - run: go run mage benchall 24 | 25 | - uses: actions/upload-artifact@v4 26 | with: 27 | name: results 28 | path: build/*bench*.txt 29 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/atomics/arch-hppa.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * arch-hppa.h 4 | * Atomic operations considerations specific to HPPA 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES: 10 | * 11 | * src/include/port/atomics/arch-hppa.h 12 | * 13 | *------------------------------------------------------------------------- 14 | */ 15 | 16 | /* HPPA doesn't do either read or write reordering */ 17 | #define pg_memory_barrier_impl() pg_compiler_barrier_impl() 18 | -------------------------------------------------------------------------------- /internal/cparser/pg_query_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef PG_QUERY_INTERNAL_H 2 | #define PG_QUERY_INTERNAL_H 3 | 4 | #include "postgres.h" 5 | #include "utils/memutils.h" 6 | #include "nodes/pg_list.h" 7 | 8 | #define STDERR_BUFFER_LEN 4096 9 | #define DEBUG 10 | 11 | typedef struct { 12 | List *tree; 13 | char* stderr_buffer; 14 | PgQueryError* error; 15 | } PgQueryInternalParsetreeAndError; 16 | 17 | PgQueryInternalParsetreeAndError pg_query_raw_parse(const char* input, int parser_options); 18 | 19 | void pg_query_free_error(PgQueryError *error); 20 | 21 | MemoryContext pg_query_enter_memory_context(); 22 | void pg_query_exit_memory_context(MemoryContext ctx); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /internal/cparser/src_port_qsort.c: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | * Symbols referenced in this file: 3 | * - pg_qsort_strcmp 4 | *-------------------------------------------------------------------- 5 | */ 6 | 7 | /* 8 | * qsort.c: standard quicksort algorithm 9 | */ 10 | 11 | #include "c.h" 12 | 13 | #define ST_SORT pg_qsort 14 | #define ST_ELEMENT_TYPE_VOID 15 | #define ST_COMPARE_RUNTIME_POINTER 16 | #define ST_SCOPE 17 | #define ST_DECLARE 18 | #define ST_DEFINE 19 | #include "lib/sort_template.h" 20 | 21 | /* 22 | * qsort comparator wrapper for strcmp. 23 | */ 24 | int 25 | pg_qsort_strcmp(const void *a, const void *b) 26 | { 27 | return strcmp(*(const char *const *) a, *(const char *const *) b); 28 | } 29 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/utils/bytea.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * bytea.h 4 | * Declarations for BYTEA data type support. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/utils/bytea.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef BYTEA_H 15 | #define BYTEA_H 16 | 17 | 18 | 19 | typedef enum 20 | { 21 | BYTEA_OUTPUT_ESCAPE, 22 | BYTEA_OUTPUT_HEX, 23 | } ByteaOutputType; 24 | 25 | extern PGDLLIMPORT int bytea_output; /* ByteaOutputType, but int for GUC 26 | * enum */ 27 | 28 | #endif /* BYTEA_H */ 29 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/mb/stringinfo_mb.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * stringinfo_mb.h 4 | * multibyte support for StringInfo 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/mb/stringinfo_mb.h 10 | *------------------------------------------------------------------------- 11 | */ 12 | #ifndef STRINGINFO_MB_H 13 | #define STRINGINFO_MB_H 14 | 15 | 16 | #include "lib/stringinfo.h" 17 | 18 | /* 19 | * Multibyte-aware StringInfo support function. 20 | */ 21 | extern void appendStringInfoStringQuoted(StringInfo str, 22 | const char *s, int maxlen); 23 | 24 | #endif /* STRINGINFO_MB_H */ 25 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/postmaster/walwriter.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * walwriter.h 4 | * Exports from postmaster/walwriter.c. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * 8 | * src/include/postmaster/walwriter.h 9 | * 10 | *------------------------------------------------------------------------- 11 | */ 12 | #ifndef _WALWRITER_H 13 | #define _WALWRITER_H 14 | 15 | #define DEFAULT_WAL_WRITER_FLUSH_AFTER ((1024 * 1024) / XLOG_BLCKSZ) 16 | 17 | /* GUC options */ 18 | extern PGDLLIMPORT int WalWriterDelay; 19 | extern PGDLLIMPORT int WalWriterFlushAfter; 20 | 21 | extern void WalWriterMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); 22 | 23 | #endif /* _WALWRITER_H */ 24 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/partitioning/partdefs.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * partdefs.h 4 | * Base definitions for partitioned table handling 5 | * 6 | * Copyright (c) 2007-2024, PostgreSQL Global Development Group 7 | * 8 | * src/include/partitioning/partdefs.h 9 | * 10 | *------------------------------------------------------------------------- 11 | */ 12 | #ifndef PARTDEFS_H 13 | #define PARTDEFS_H 14 | 15 | 16 | typedef struct PartitionBoundInfoData *PartitionBoundInfo; 17 | 18 | typedef struct PartitionKeyData *PartitionKey; 19 | 20 | typedef struct PartitionBoundSpec PartitionBoundSpec; 21 | 22 | typedef struct PartitionDescData *PartitionDesc; 23 | 24 | typedef struct PartitionDirectoryData *PartitionDirectory; 25 | 26 | #endif /* PARTDEFS_H */ 27 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32_msvc/dirent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Headers for port/dirent.c, win32 native implementation of dirent functions 3 | * 4 | * src/include/port/win32_msvc/dirent.h 5 | */ 6 | 7 | #ifndef _WIN32VC_DIRENT_H 8 | #define _WIN32VC_DIRENT_H 9 | struct dirent 10 | { 11 | long d_ino; 12 | unsigned short d_reclen; 13 | unsigned char d_type; 14 | unsigned short d_namlen; 15 | char d_name[MAX_PATH]; 16 | }; 17 | 18 | typedef struct DIR DIR; 19 | 20 | DIR *opendir(const char *); 21 | struct dirent *readdir(DIR *); 22 | int closedir(DIR *); 23 | 24 | /* File types for 'd_type'. */ 25 | #define DT_UNKNOWN 0 26 | #define DT_FIFO 1 27 | #define DT_CHR 2 28 | #define DT_DIR 4 29 | #define DT_BLK 6 30 | #define DT_REG 8 31 | #define DT_LNK 10 32 | #define DT_SOCK 12 33 | #define DT_WHT 14 34 | #endif 35 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/parser/parse_expr.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * parse_expr.h 4 | * handle expressions in parser 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/parser/parse_expr.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef PARSE_EXPR_H 14 | #define PARSE_EXPR_H 15 | 16 | #include "parser/parse_node.h" 17 | 18 | /* GUC parameters */ 19 | extern PGDLLIMPORT bool Transform_null_equals; 20 | 21 | extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind); 22 | 23 | extern const char *ParseExprKindName(ParseExprKind exprKind); 24 | 25 | #endif /* PARSE_EXPR_H */ 26 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/parser/scansup.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * scansup.h 4 | * scanner support routines used by the core lexer 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/parser/scansup.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | 14 | #ifndef SCANSUP_H 15 | #define SCANSUP_H 16 | 17 | extern char *downcase_truncate_identifier(const char *ident, int len, 18 | bool warn); 19 | 20 | extern char *downcase_identifier(const char *ident, int len, 21 | bool warn, bool truncate); 22 | 23 | extern void truncate_identifier(char *ident, int len, bool warn); 24 | 25 | extern bool scanner_isspace(char ch); 26 | 27 | #endif /* SCANSUP_H */ 28 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/rewrite/rewriteSupport.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * rewriteSupport.h 4 | * 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/rewrite/rewriteSupport.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef REWRITESUPPORT_H 15 | #define REWRITESUPPORT_H 16 | 17 | /* The ON SELECT rule of a view is always named this: */ 18 | #define ViewSelectRuleName "_RETURN" 19 | 20 | extern bool IsDefinedRewriteRule(Oid owningRel, const char *ruleName); 21 | 22 | extern void SetRelationRuleStatus(Oid relationId, bool relHasRules); 23 | 24 | extern Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok); 25 | 26 | #endif /* REWRITESUPPORT_H */ 27 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32/sys/socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * src/include/port/win32/sys/socket.h 3 | */ 4 | #ifndef WIN32_SYS_SOCKET_H 5 | #define WIN32_SYS_SOCKET_H 6 | 7 | /* 8 | * Unfortunately, of VC++ also defines ERROR. 9 | * To avoid the conflict, we include here and undefine ERROR 10 | * immediately. 11 | * 12 | * Note: Don't include directly. It causes compile errors. 13 | */ 14 | #include 15 | #include 16 | #include 17 | 18 | #undef ERROR 19 | #undef small 20 | 21 | /* Restore old ERROR value */ 22 | #ifdef PGERROR 23 | #define ERROR PGERROR 24 | #endif 25 | 26 | /* 27 | * We don't use the Windows gai_strerror[A] function because it is not 28 | * thread-safe. We define our own in src/port/win32gai_strerror.c. 29 | */ 30 | #undef gai_strerror 31 | 32 | extern const char *gai_strerror(int ecode); 33 | 34 | #endif /* WIN32_SYS_SOCKET_H */ 35 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/common/keywords.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * keywords.h 4 | * PostgreSQL's list of SQL keywords 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/common/keywords.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef KEYWORDS_H 15 | #define KEYWORDS_H 16 | 17 | #include "common/kwlookup.h" 18 | 19 | /* Keyword categories --- should match lists in gram.y */ 20 | #define UNRESERVED_KEYWORD 0 21 | #define COL_NAME_KEYWORD 1 22 | #define TYPE_FUNC_NAME_KEYWORD 2 23 | #define RESERVED_KEYWORD 3 24 | 25 | extern PGDLLIMPORT const ScanKeywordList ScanKeywords; 26 | extern PGDLLIMPORT const uint8 ScanKeywordCategories[]; 27 | extern PGDLLIMPORT const bool ScanKeywordBareLabel[]; 28 | 29 | #endif /* KEYWORDS_H */ 30 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/sysattr.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * sysattr.h 4 | * POSTGRES system attribute definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/access/sysattr.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef SYSATTR_H 15 | #define SYSATTR_H 16 | 17 | 18 | /* 19 | * Attribute numbers for the system-defined attributes 20 | */ 21 | #define SelfItemPointerAttributeNumber (-1) 22 | #define MinTransactionIdAttributeNumber (-2) 23 | #define MinCommandIdAttributeNumber (-3) 24 | #define MaxTransactionIdAttributeNumber (-4) 25 | #define MaxCommandIdAttributeNumber (-5) 26 | #define TableOidAttributeNumber (-6) 27 | #define FirstLowInvalidHeapAttributeNumber (-7) 28 | 29 | #endif /* SYSATTR_H */ 30 | -------------------------------------------------------------------------------- /libpgquery_plpgsql_test.go: -------------------------------------------------------------------------------- 1 | package pg_query_test 2 | 3 | import ( 4 | _ "embed" 5 | "encoding/json" 6 | "reflect" 7 | "testing" 8 | 9 | pg_query "github.com/wasilibs/go-pgquery" 10 | ) 11 | 12 | //go:embed libpgquery_plpgsql_samples.sql 13 | var plpgsqlSamples string 14 | 15 | //go:embed libpgquery_plpgsql_samples.expected.json 16 | var plpgsqlSamplesExpected string 17 | 18 | func TestLibPgqueryPlsql(t *testing.T) { 19 | actual, err := pg_query.ParsePlPgSqlToJSON(plpgsqlSamples) 20 | if err != nil { 21 | t.Errorf("unexpected error: %v", err) 22 | } 23 | var actualParsed []interface{} 24 | if err := json.Unmarshal([]byte(actual), &actualParsed); err != nil { 25 | t.Errorf("unexpected error: %v", err) 26 | } 27 | var expectedParsed []interface{} 28 | if err := json.Unmarshal([]byte(plpgsqlSamplesExpected), &expectedParsed); err != nil { 29 | t.Errorf("unexpected error: %v", err) 30 | } 31 | 32 | if !reflect.DeepEqual(actualParsed, expectedParsed) { 33 | t.Errorf("expected %q, got %q", expectedParsed, actualParsed) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/table.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * table.h 4 | * Generic routines for table related code. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/access/table.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef TABLE_H 15 | #define TABLE_H 16 | 17 | #include "nodes/primnodes.h" 18 | #include "storage/lockdefs.h" 19 | #include "utils/relcache.h" 20 | 21 | extern Relation table_open(Oid relationId, LOCKMODE lockmode); 22 | extern Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode); 23 | extern Relation table_openrv_extended(const RangeVar *relation, 24 | LOCKMODE lockmode, bool missing_ok); 25 | extern Relation try_table_open(Oid relationId, LOCKMODE lockmode); 26 | extern void table_close(Relation relation, LOCKMODE lockmode); 27 | 28 | #endif /* TABLE_H */ 29 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/atomics/arch-arm.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * arch-arm.h 4 | * Atomic operations considerations specific to ARM 5 | * 6 | * Portions Copyright (c) 2013-2024, PostgreSQL Global Development Group 7 | * 8 | * NOTES: 9 | * 10 | * src/include/port/atomics/arch-arm.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | 15 | /* intentionally no include guards, should only be included by atomics.h */ 16 | #ifndef INSIDE_ATOMICS_H 17 | #error "should be included via atomics.h" 18 | #endif 19 | 20 | /* 21 | * 64 bit atomics on ARM32 are implemented using kernel fallbacks and thus 22 | * might be slow, so disable entirely. On ARM64 that problem doesn't exist. 23 | */ 24 | #if !defined(__aarch64__) 25 | #define PG_DISABLE_64_BIT_ATOMICS 26 | #else 27 | /* 28 | * Architecture Reference Manual for ARMv8 states aligned read/write to/from 29 | * general purpose register is atomic. 30 | */ 31 | #define PG_HAVE_8BYTE_SINGLE_COPY_ATOMICITY 32 | #endif /* __aarch64__ */ 33 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/relation.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * relation.h 4 | * Generic relation related routines. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/access/relation.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef ACCESS_RELATION_H 15 | #define ACCESS_RELATION_H 16 | 17 | #include "nodes/primnodes.h" 18 | #include "storage/lockdefs.h" 19 | #include "utils/relcache.h" 20 | 21 | extern Relation relation_open(Oid relationId, LOCKMODE lockmode); 22 | extern Relation try_relation_open(Oid relationId, LOCKMODE lockmode); 23 | extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode); 24 | extern Relation relation_openrv_extended(const RangeVar *relation, 25 | LOCKMODE lockmode, bool missing_ok); 26 | extern void relation_close(Relation relation, LOCKMODE lockmode); 27 | 28 | #endif /* ACCESS_RELATION_H */ 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) wasilibs authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_transform_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_transform_d.h 4 | * Macro definitions for pg_transform 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_TRANSFORM_D_H 19 | #define PG_TRANSFORM_D_H 20 | 21 | #define TransformRelationId 3576 22 | #define TransformOidIndexId 3574 23 | #define TransformTypeLangIndexId 3575 24 | 25 | #define Anum_pg_transform_oid 1 26 | #define Anum_pg_transform_trftype 2 27 | #define Anum_pg_transform_trflang 3 28 | #define Anum_pg_transform_trffromsql 4 29 | #define Anum_pg_transform_trftosql 5 30 | 31 | #define Natts_pg_transform 5 32 | 33 | 34 | #endif /* PG_TRANSFORM_D_H */ 35 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_ts_config_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_ts_config_d.h 4 | * Macro definitions for pg_ts_config 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_TS_CONFIG_D_H 19 | #define PG_TS_CONFIG_D_H 20 | 21 | #define TSConfigRelationId 3602 22 | #define TSConfigNameNspIndexId 3608 23 | #define TSConfigOidIndexId 3712 24 | 25 | #define Anum_pg_ts_config_oid 1 26 | #define Anum_pg_ts_config_cfgname 2 27 | #define Anum_pg_ts_config_cfgnamespace 3 28 | #define Anum_pg_ts_config_cfgowner 4 29 | #define Anum_pg_ts_config_cfgparser 5 30 | 31 | #define Natts_pg_ts_config 5 32 | 33 | 34 | #endif /* PG_TS_CONFIG_D_H */ 35 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/replication/logicalworker.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * logicalworker.h 4 | * Exports for logical replication workers. 5 | * 6 | * Portions Copyright (c) 2016-2024, PostgreSQL Global Development Group 7 | * 8 | * src/include/replication/logicalworker.h 9 | * 10 | *------------------------------------------------------------------------- 11 | */ 12 | #ifndef LOGICALWORKER_H 13 | #define LOGICALWORKER_H 14 | 15 | #include 16 | 17 | extern PGDLLIMPORT volatile sig_atomic_t ParallelApplyMessagePending; 18 | 19 | extern void ApplyWorkerMain(Datum main_arg); 20 | extern void ParallelApplyWorkerMain(Datum main_arg); 21 | extern void TablesyncWorkerMain(Datum main_arg); 22 | 23 | extern bool IsLogicalWorker(void); 24 | extern bool IsLogicalParallelApplyWorker(void); 25 | 26 | extern void HandleParallelApplyMessageInterrupt(void); 27 | extern void HandleParallelApplyMessages(void); 28 | 29 | extern void LogicalRepWorkersWakeupAtCommit(Oid subid); 30 | 31 | extern void AtEOXact_LogicalRepWorkers(bool isCommit); 32 | 33 | #endif /* LOGICALWORKER_H */ 34 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_ts_template_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_ts_template_d.h 4 | * Macro definitions for pg_ts_template 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_TS_TEMPLATE_D_H 19 | #define PG_TS_TEMPLATE_D_H 20 | 21 | #define TSTemplateRelationId 3764 22 | #define TSTemplateNameNspIndexId 3766 23 | #define TSTemplateOidIndexId 3767 24 | 25 | #define Anum_pg_ts_template_oid 1 26 | #define Anum_pg_ts_template_tmplname 2 27 | #define Anum_pg_ts_template_tmplnamespace 3 28 | #define Anum_pg_ts_template_tmplinit 4 29 | #define Anum_pg_ts_template_tmpllexize 5 30 | 31 | #define Natts_pg_ts_template 5 32 | 33 | 34 | #endif /* PG_TS_TEMPLATE_D_H */ 35 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_ts_dict_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_ts_dict_d.h 4 | * Macro definitions for pg_ts_dict 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_TS_DICT_D_H 19 | #define PG_TS_DICT_D_H 20 | 21 | #define TSDictionaryRelationId 3600 22 | #define TSDictionaryNameNspIndexId 3604 23 | #define TSDictionaryOidIndexId 3605 24 | 25 | #define Anum_pg_ts_dict_oid 1 26 | #define Anum_pg_ts_dict_dictname 2 27 | #define Anum_pg_ts_dict_dictnamespace 3 28 | #define Anum_pg_ts_dict_dictowner 4 29 | #define Anum_pg_ts_dict_dicttemplate 5 30 | #define Anum_pg_ts_dict_dictinitoption 6 31 | 32 | #define Natts_pg_ts_dict 6 33 | 34 | 35 | #endif /* PG_TS_DICT_D_H */ 36 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_depend_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_depend_d.h 4 | * Macro definitions for pg_depend 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_DEPEND_D_H 19 | #define PG_DEPEND_D_H 20 | 21 | #define DependRelationId 2608 22 | #define DependDependerIndexId 2673 23 | #define DependReferenceIndexId 2674 24 | 25 | #define Anum_pg_depend_classid 1 26 | #define Anum_pg_depend_objid 2 27 | #define Anum_pg_depend_objsubid 3 28 | #define Anum_pg_depend_refclassid 4 29 | #define Anum_pg_depend_refobjid 5 30 | #define Anum_pg_depend_refobjsubid 6 31 | #define Anum_pg_depend_deptype 7 32 | 33 | #define Natts_pg_depend 7 34 | 35 | 36 | #endif /* PG_DEPEND_D_H */ 37 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/postmaster/interrupt.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * interrupt.h 4 | * Interrupt handling routines. 5 | * 6 | * Responses to interrupts are fairly varied and many types of backends 7 | * have their own implementations, but we provide a few generic things 8 | * here to facilitate code reuse. 9 | * 10 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 11 | * Portions Copyright (c) 1994, Regents of the University of California 12 | * 13 | * IDENTIFICATION 14 | * src/include/postmaster/interrupt.h 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | 19 | #ifndef INTERRUPT_H 20 | #define INTERRUPT_H 21 | 22 | #include 23 | 24 | extern PGDLLIMPORT volatile sig_atomic_t ConfigReloadPending; 25 | extern PGDLLIMPORT volatile sig_atomic_t ShutdownRequestPending; 26 | 27 | extern void HandleMainLoopInterrupts(void); 28 | extern void SignalHandlerForConfigReload(SIGNAL_ARGS); 29 | extern void SignalHandlerForCrashExit(SIGNAL_ARGS); 30 | extern void SignalHandlerForShutdownRequest(SIGNAL_ARGS); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /magefiles/go.mod: -------------------------------------------------------------------------------- 1 | module magefiles 2 | 3 | go 1.22.0 4 | 5 | require ( 6 | github.com/aymanbagabas/go-osc52 v1.0.3 // indirect 7 | github.com/cli/go-gh/v2 v2.5.0 // indirect 8 | github.com/cli/safeexec v1.0.0 // indirect 9 | github.com/cli/shurcooL-graphql v0.0.4 // indirect 10 | github.com/google/go-github v17.0.0+incompatible // indirect 11 | github.com/google/go-querystring v1.1.0 // indirect 12 | github.com/henvic/httpretty v0.0.6 // indirect 13 | github.com/lucasb-eyer/go-colorful v1.2.0 // indirect 14 | github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a // indirect 15 | github.com/mattn/go-isatty v0.0.19 // indirect 16 | github.com/mattn/go-runewidth v0.0.14 // indirect 17 | github.com/muesli/termenv v0.13.0 // indirect 18 | github.com/rivo/uniseg v0.4.4 // indirect 19 | github.com/stretchr/testify v1.9.0 // indirect 20 | github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect 21 | golang.org/x/sys v0.21.0 // indirect 22 | golang.org/x/term v0.13.0 // indirect 23 | golang.org/x/text v0.13.0 // indirect 24 | gopkg.in/yaml.v3 v3.0.1 // indirect 25 | ) 26 | 27 | require github.com/wasilibs/magefiles v0.0.0-20250219051227-1485a49a5a46 28 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_namespace_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_namespace_d.h 4 | * Macro definitions for pg_namespace 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_NAMESPACE_D_H 19 | #define PG_NAMESPACE_D_H 20 | 21 | #define NamespaceRelationId 2615 22 | #define NamespaceNameIndexId 2684 23 | #define NamespaceOidIndexId 2685 24 | 25 | #define Anum_pg_namespace_oid 1 26 | #define Anum_pg_namespace_nspname 2 27 | #define Anum_pg_namespace_nspowner 3 28 | #define Anum_pg_namespace_nspacl 4 29 | 30 | #define Natts_pg_namespace 4 31 | 32 | #define PG_CATALOG_NAMESPACE 11 33 | #define PG_TOAST_NAMESPACE 99 34 | #define PG_PUBLIC_NAMESPACE 2200 35 | 36 | #endif /* PG_NAMESPACE_D_H */ 37 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_replication_origin_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_replication_origin_d.h 4 | * Macro definitions for pg_replication_origin 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_REPLICATION_ORIGIN_D_H 19 | #define PG_REPLICATION_ORIGIN_D_H 20 | 21 | #define ReplicationOriginRelationId 6000 22 | #define PgReplicationOriginToastTable 4181 23 | #define PgReplicationOriginToastIndex 4182 24 | #define ReplicationOriginIdentIndex 6001 25 | #define ReplicationOriginNameIndex 6002 26 | 27 | #define Anum_pg_replication_origin_roident 1 28 | #define Anum_pg_replication_origin_roname 2 29 | 30 | #define Natts_pg_replication_origin 2 31 | 32 | 33 | #endif /* PG_REPLICATION_ORIGIN_D_H */ 34 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/replication/logicallauncher.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * logicallauncher.h 4 | * Exports for logical replication launcher. 5 | * 6 | * Portions Copyright (c) 2016-2024, PostgreSQL Global Development Group 7 | * 8 | * src/include/replication/logicallauncher.h 9 | * 10 | *------------------------------------------------------------------------- 11 | */ 12 | #ifndef LOGICALLAUNCHER_H 13 | #define LOGICALLAUNCHER_H 14 | 15 | extern PGDLLIMPORT int max_logical_replication_workers; 16 | extern PGDLLIMPORT int max_sync_workers_per_subscription; 17 | extern PGDLLIMPORT int max_parallel_apply_workers_per_subscription; 18 | 19 | extern void ApplyLauncherRegister(void); 20 | extern void ApplyLauncherMain(Datum main_arg); 21 | 22 | extern Size ApplyLauncherShmemSize(void); 23 | extern void ApplyLauncherShmemInit(void); 24 | 25 | extern void ApplyLauncherForgetWorkerStartTime(Oid subid); 26 | 27 | extern void ApplyLauncherWakeupAtCommit(void); 28 | extern void AtEOXact_ApplyLauncher(bool isCommit); 29 | 30 | extern bool IsLogicalLauncher(void); 31 | 32 | extern pid_t GetLeaderApplyWorkerPid(pid_t pid); 33 | 34 | #endif /* LOGICALLAUNCHER_H */ 35 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/storage/sharedfileset.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * sharedfileset.h 4 | * Shared temporary file management. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/storage/sharedfileset.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | 15 | #ifndef SHAREDFILESET_H 16 | #define SHAREDFILESET_H 17 | 18 | #include "storage/dsm.h" 19 | #include "storage/fd.h" 20 | #include "storage/fileset.h" 21 | #include "storage/spin.h" 22 | 23 | /* 24 | * A set of temporary files that can be shared by multiple backends. 25 | */ 26 | typedef struct SharedFileSet 27 | { 28 | FileSet fs; 29 | slock_t mutex; /* mutex protecting the reference count */ 30 | int refcnt; /* number of attached backends */ 31 | } SharedFileSet; 32 | 33 | extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); 34 | extern void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg); 35 | extern void SharedFileSetDeleteAll(SharedFileSet *fileset); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/nodes/print.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * print.h 4 | * definitions for nodes/print.c 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/nodes/print.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef PRINT_H 15 | #define PRINT_H 16 | 17 | #include "executor/tuptable.h" 18 | 19 | 20 | #define nodeDisplay(x) pprint(x) 21 | 22 | extern void print(const void *obj); 23 | extern void pprint(const void *obj); 24 | extern void elog_node_display(int lev, const char *title, 25 | const void *obj, bool pretty); 26 | extern char *format_node_dump(const char *dump); 27 | extern char *pretty_format_node_dump(const char *dump); 28 | extern void print_rt(const List *rtable); 29 | extern void print_expr(const Node *expr, const List *rtable); 30 | extern void print_pathkeys(const List *pathkeys, const List *rtable); 31 | extern void print_tl(const List *tlist, const List *rtable); 32 | extern void print_slot(TupleTableSlot *slot); 33 | 34 | #endif /* PRINT_H */ 35 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/printtup.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * printtup.h 4 | * 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/access/printtup.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef PRINTTUP_H 15 | #define PRINTTUP_H 16 | 17 | #include "utils/portal.h" 18 | 19 | extern DestReceiver *printtup_create_DR(CommandDest dest); 20 | 21 | extern void SetRemoteDestReceiverParams(DestReceiver *self, Portal portal); 22 | 23 | extern void SendRowDescriptionMessage(StringInfo buf, 24 | TupleDesc typeinfo, List *targetlist, int16 *formats); 25 | 26 | extern void debugStartup(DestReceiver *self, int operation, 27 | TupleDesc typeinfo); 28 | extern bool debugtup(TupleTableSlot *slot, DestReceiver *self); 29 | 30 | /* XXX these are really in executor/spi.c */ 31 | extern void spi_dest_startup(DestReceiver *self, int operation, 32 | TupleDesc typeinfo); 33 | extern bool spi_printtup(TupleTableSlot *slot, DestReceiver *self); 34 | 35 | #endif /* PRINTTUP_H */ 36 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_ts_parser_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_ts_parser_d.h 4 | * Macro definitions for pg_ts_parser 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_TS_PARSER_D_H 19 | #define PG_TS_PARSER_D_H 20 | 21 | #define TSParserRelationId 3601 22 | #define TSParserNameNspIndexId 3606 23 | #define TSParserOidIndexId 3607 24 | 25 | #define Anum_pg_ts_parser_oid 1 26 | #define Anum_pg_ts_parser_prsname 2 27 | #define Anum_pg_ts_parser_prsnamespace 3 28 | #define Anum_pg_ts_parser_prsstart 4 29 | #define Anum_pg_ts_parser_prstoken 5 30 | #define Anum_pg_ts_parser_prsend 6 31 | #define Anum_pg_ts_parser_prsheadline 7 32 | #define Anum_pg_ts_parser_prslextype 8 33 | 34 | #define Natts_pg_ts_parser 8 35 | 36 | 37 | #endif /* PG_TS_PARSER_D_H */ 38 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_event_trigger_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_event_trigger_d.h 4 | * Macro definitions for pg_event_trigger 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_EVENT_TRIGGER_D_H 19 | #define PG_EVENT_TRIGGER_D_H 20 | 21 | #define EventTriggerRelationId 3466 22 | #define EventTriggerNameIndexId 3467 23 | #define EventTriggerOidIndexId 3468 24 | 25 | #define Anum_pg_event_trigger_oid 1 26 | #define Anum_pg_event_trigger_evtname 2 27 | #define Anum_pg_event_trigger_evtevent 3 28 | #define Anum_pg_event_trigger_evtowner 4 29 | #define Anum_pg_event_trigger_evtfoid 5 30 | #define Anum_pg_event_trigger_evtenabled 6 31 | #define Anum_pg_event_trigger_evttags 7 32 | 33 | #define Natts_pg_event_trigger 7 34 | 35 | 36 | #endif /* PG_EVENT_TRIGGER_D_H */ 37 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/postmaster/walsummarizer.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * walsummarizer.h 4 | * 5 | * Header file for background WAL summarization process. 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * 9 | * IDENTIFICATION 10 | * src/include/postmaster/walsummarizer.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef WALSUMMARIZER_H 15 | #define WALSUMMARIZER_H 16 | 17 | #include "access/xlogdefs.h" 18 | 19 | extern PGDLLIMPORT bool summarize_wal; 20 | extern PGDLLIMPORT int wal_summary_keep_time; 21 | 22 | extern Size WalSummarizerShmemSize(void); 23 | extern void WalSummarizerShmemInit(void); 24 | extern void WalSummarizerMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); 25 | 26 | extern void GetWalSummarizerState(TimeLineID *summarized_tli, 27 | XLogRecPtr *summarized_lsn, 28 | XLogRecPtr *pending_lsn, 29 | int *summarizer_pid); 30 | extern XLogRecPtr GetOldestUnsummarizedLSN(TimeLineID *tli, 31 | bool *lsn_is_exact); 32 | extern void SetWalSummarizerLatch(void); 33 | extern void WaitForWalSummarization(XLogRecPtr lsn); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/rewrite/prs2lock.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * prs2lock.h 4 | * data structures for POSTGRES Rule System II (rewrite rules only) 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/rewrite/prs2lock.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef PRS2LOCK_H 14 | #define PRS2LOCK_H 15 | 16 | #include "access/attnum.h" 17 | #include "nodes/pg_list.h" 18 | 19 | /* 20 | * RewriteRule - 21 | * holds an info for a rewrite rule 22 | * 23 | */ 24 | typedef struct RewriteRule 25 | { 26 | Oid ruleId; 27 | CmdType event; 28 | Node *qual; 29 | List *actions; 30 | char enabled; 31 | bool isInstead; 32 | } RewriteRule; 33 | 34 | /* 35 | * RuleLock - 36 | * all rules that apply to a particular relation. Even though we only 37 | * have the rewrite rule system left and these are not really "locks", 38 | * the name is kept for historical reasons. 39 | */ 40 | typedef struct RuleLock 41 | { 42 | int numLocks; 43 | RewriteRule **rules; 44 | } RuleLock; 45 | 46 | #endif /* PRS2LOCK_H */ 47 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/storage/buf.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * buf.h 4 | * Basic buffer manager data types. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/storage/buf.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef BUF_H 15 | #define BUF_H 16 | 17 | /* 18 | * Buffer identifiers. 19 | * 20 | * Zero is invalid, positive is the index of a shared buffer (1..NBuffers), 21 | * negative is the index of a local buffer (-1 .. -NLocBuffer). 22 | */ 23 | typedef int Buffer; 24 | 25 | #define InvalidBuffer 0 26 | 27 | /* 28 | * BufferIsInvalid 29 | * True iff the buffer is invalid. 30 | */ 31 | #define BufferIsInvalid(buffer) ((buffer) == InvalidBuffer) 32 | 33 | /* 34 | * BufferIsLocal 35 | * True iff the buffer is local (not visible to other backends). 36 | */ 37 | #define BufferIsLocal(buffer) ((buffer) < 0) 38 | 39 | /* 40 | * Buffer access strategy objects. 41 | * 42 | * BufferAccessStrategyData is private to freelist.c 43 | */ 44 | typedef struct BufferAccessStrategyData *BufferAccessStrategy; 45 | 46 | #endif /* BUF_H */ 47 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/common/sha2.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * sha2.h 4 | * Constants related to SHA224, 256, 384 AND 512. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * IDENTIFICATION 10 | * src/include/common/sha2.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | 15 | #ifndef _PG_SHA2_H_ 16 | #define _PG_SHA2_H_ 17 | 18 | /*** SHA224/256/384/512 Various Length Definitions ***********************/ 19 | #define PG_SHA224_BLOCK_LENGTH 64 20 | #define PG_SHA224_DIGEST_LENGTH 28 21 | #define PG_SHA224_DIGEST_STRING_LENGTH (PG_SHA224_DIGEST_LENGTH * 2 + 1) 22 | #define PG_SHA256_BLOCK_LENGTH 64 23 | #define PG_SHA256_DIGEST_LENGTH 32 24 | #define PG_SHA256_DIGEST_STRING_LENGTH (PG_SHA256_DIGEST_LENGTH * 2 + 1) 25 | #define PG_SHA384_BLOCK_LENGTH 128 26 | #define PG_SHA384_DIGEST_LENGTH 48 27 | #define PG_SHA384_DIGEST_STRING_LENGTH (PG_SHA384_DIGEST_LENGTH * 2 + 1) 28 | #define PG_SHA512_BLOCK_LENGTH 128 29 | #define PG_SHA512_DIGEST_LENGTH 64 30 | #define PG_SHA512_DIGEST_STRING_LENGTH (PG_SHA512_DIGEST_LENGTH * 2 + 1) 31 | 32 | #endif /* _PG_SHA2_H_ */ 33 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_conversion_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_conversion_d.h 4 | * Macro definitions for pg_conversion 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_CONVERSION_D_H 19 | #define PG_CONVERSION_D_H 20 | 21 | #define ConversionRelationId 2607 22 | #define ConversionDefaultIndexId 2668 23 | #define ConversionNameNspIndexId 2669 24 | #define ConversionOidIndexId 2670 25 | 26 | #define Anum_pg_conversion_oid 1 27 | #define Anum_pg_conversion_conname 2 28 | #define Anum_pg_conversion_connamespace 3 29 | #define Anum_pg_conversion_conowner 4 30 | #define Anum_pg_conversion_conforencoding 5 31 | #define Anum_pg_conversion_contoencoding 6 32 | #define Anum_pg_conversion_conproc 7 33 | #define Anum_pg_conversion_condefault 8 34 | 35 | #define Natts_pg_conversion 8 36 | 37 | 38 | #endif /* PG_CONVERSION_D_H */ 39 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_publication_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_publication_d.h 4 | * Macro definitions for pg_publication 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_PUBLICATION_D_H 19 | #define PG_PUBLICATION_D_H 20 | 21 | #define PublicationRelationId 6104 22 | #define PublicationObjectIndexId 6110 23 | #define PublicationNameIndexId 6111 24 | 25 | #define Anum_pg_publication_oid 1 26 | #define Anum_pg_publication_pubname 2 27 | #define Anum_pg_publication_pubowner 3 28 | #define Anum_pg_publication_puballtables 4 29 | #define Anum_pg_publication_pubinsert 5 30 | #define Anum_pg_publication_pubupdate 6 31 | #define Anum_pg_publication_pubdelete 7 32 | #define Anum_pg_publication_pubtruncate 8 33 | #define Anum_pg_publication_pubviaroot 9 34 | 35 | #define Natts_pg_publication 9 36 | 37 | 38 | #endif /* PG_PUBLICATION_D_H */ 39 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/optimizer/geqo_gene.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * geqo_gene.h 4 | * genome representation in optimizer/geqo 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/optimizer/geqo_gene.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | 14 | /* contributed by: 15 | =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= 16 | * Martin Utesch * Institute of Automatic Control * 17 | = = University of Mining and Technology = 18 | * utesch@aut.tu-freiberg.de * Freiberg, Germany * 19 | =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= 20 | */ 21 | 22 | 23 | #ifndef GEQO_GENE_H 24 | #define GEQO_GENE_H 25 | 26 | #include "nodes/nodes.h" 27 | 28 | /* we presume that int instead of Relid 29 | is o.k. for Gene; so don't change it! */ 30 | typedef int Gene; 31 | 32 | typedef struct Chromosome 33 | { 34 | Gene *string; 35 | Cost worth; 36 | } Chromosome; 37 | 38 | typedef struct Pool 39 | { 40 | Chromosome *data; 41 | int size; 42 | int string_length; 43 | } Pool; 44 | 45 | #endif /* GEQO_GENE_H */ 46 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/replication/slotsync.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * slotsync.h 4 | * Exports for slot synchronization. 5 | * 6 | * Portions Copyright (c) 2016-2024, PostgreSQL Global Development Group 7 | * 8 | * src/include/replication/slotsync.h 9 | * 10 | *------------------------------------------------------------------------- 11 | */ 12 | #ifndef SLOTSYNC_H 13 | #define SLOTSYNC_H 14 | 15 | #include "replication/walreceiver.h" 16 | 17 | extern PGDLLIMPORT bool sync_replication_slots; 18 | 19 | /* 20 | * GUCs needed by slot sync worker to connect to the primary 21 | * server and carry on with slots synchronization. 22 | */ 23 | extern PGDLLIMPORT char *PrimaryConnInfo; 24 | extern PGDLLIMPORT char *PrimarySlotName; 25 | 26 | extern char *CheckAndGetDbnameFromConninfo(void); 27 | extern bool ValidateSlotSyncParams(int elevel); 28 | 29 | extern void ReplSlotSyncWorkerMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); 30 | 31 | extern void ShutDownSlotSync(void); 32 | extern bool SlotSyncWorkerCanRestart(void); 33 | extern bool IsSyncingReplicationSlots(void); 34 | extern Size SlotSyncShmemSize(void); 35 | extern void SlotSyncShmemInit(void); 36 | extern void SyncReplicationSlots(WalReceiverConn *wrconn); 37 | 38 | #endif /* SLOTSYNC_H */ 39 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_partitioned_table_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_partitioned_table_d.h 4 | * Macro definitions for pg_partitioned_table 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_PARTITIONED_TABLE_D_H 19 | #define PG_PARTITIONED_TABLE_D_H 20 | 21 | #define PartitionedRelationId 3350 22 | #define PartitionedRelidIndexId 3351 23 | 24 | #define Anum_pg_partitioned_table_partrelid 1 25 | #define Anum_pg_partitioned_table_partstrat 2 26 | #define Anum_pg_partitioned_table_partnatts 3 27 | #define Anum_pg_partitioned_table_partdefid 4 28 | #define Anum_pg_partitioned_table_partattrs 5 29 | #define Anum_pg_partitioned_table_partclass 6 30 | #define Anum_pg_partitioned_table_partcollation 7 31 | #define Anum_pg_partitioned_table_partexprs 8 32 | 33 | #define Natts_pg_partitioned_table 8 34 | 35 | 36 | #endif /* PG_PARTITIONED_TABLE_D_H */ 37 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/storage/fileset.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * fileset.h 4 | * Management of named temporary files. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/storage/fileset.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | 14 | #ifndef FILESET_H 15 | #define FILESET_H 16 | 17 | #include "storage/fd.h" 18 | 19 | /* 20 | * A set of temporary files. 21 | */ 22 | typedef struct FileSet 23 | { 24 | pid_t creator_pid; /* PID of the creating process */ 25 | uint32 number; /* per-PID identifier */ 26 | int ntablespaces; /* number of tablespaces to use */ 27 | Oid tablespaces[8]; /* OIDs of tablespaces to use. Assumes that 28 | * it's rare that there more than temp 29 | * tablespaces. */ 30 | } FileSet; 31 | 32 | extern void FileSetInit(FileSet *fileset); 33 | extern File FileSetCreate(FileSet *fileset, const char *name); 34 | extern File FileSetOpen(FileSet *fileset, const char *name, 35 | int mode); 36 | extern bool FileSetDelete(FileSet *fileset, const char *name, 37 | bool error_on_failure); 38 | extern void FileSetDeleteAll(FileSet *fileset); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_language_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_language_d.h 4 | * Macro definitions for pg_language 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_LANGUAGE_D_H 19 | #define PG_LANGUAGE_D_H 20 | 21 | #define LanguageRelationId 2612 22 | #define LanguageNameIndexId 2681 23 | #define LanguageOidIndexId 2682 24 | 25 | #define Anum_pg_language_oid 1 26 | #define Anum_pg_language_lanname 2 27 | #define Anum_pg_language_lanowner 3 28 | #define Anum_pg_language_lanispl 4 29 | #define Anum_pg_language_lanpltrusted 5 30 | #define Anum_pg_language_lanplcallfoid 6 31 | #define Anum_pg_language_laninline 7 32 | #define Anum_pg_language_lanvalidator 8 33 | #define Anum_pg_language_lanacl 9 34 | 35 | #define Natts_pg_language 9 36 | 37 | #define INTERNALlanguageId 12 38 | #define ClanguageId 13 39 | #define SQLlanguageId 14 40 | 41 | #endif /* PG_LANGUAGE_D_H */ 42 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/postmaster/pgarch.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pgarch.h 4 | * Exports from postmaster/pgarch.c. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/postmaster/pgarch.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef _PGARCH_H 14 | #define _PGARCH_H 15 | 16 | /* ---------- 17 | * Archiver control info. 18 | * 19 | * We expect that archivable files within pg_wal will have names between 20 | * MIN_XFN_CHARS and MAX_XFN_CHARS in length, consisting only of characters 21 | * appearing in VALID_XFN_CHARS. The status files in archive_status have 22 | * corresponding names with ".ready" or ".done" appended. 23 | * ---------- 24 | */ 25 | #define MIN_XFN_CHARS 16 26 | #define MAX_XFN_CHARS 40 27 | #define VALID_XFN_CHARS "0123456789ABCDEF.history.backup.partial" 28 | 29 | extern Size PgArchShmemSize(void); 30 | extern void PgArchShmemInit(void); 31 | extern bool PgArchCanRestart(void); 32 | extern void PgArchiverMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); 33 | extern void PgArchWakeup(void); 34 | extern void PgArchForceDirScan(void); 35 | 36 | #endif /* _PGARCH_H */ 37 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/utils/ps_status.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * ps_status.h 4 | * 5 | * Declarations for backend/utils/misc/ps_status.c 6 | * 7 | * src/include/utils/ps_status.h 8 | * 9 | *------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef PS_STATUS_H 13 | #define PS_STATUS_H 14 | 15 | /* disabled on Windows as the performance overhead can be significant */ 16 | #ifdef WIN32 17 | #define DEFAULT_UPDATE_PROCESS_TITLE false 18 | #else 19 | #define DEFAULT_UPDATE_PROCESS_TITLE true 20 | #endif 21 | 22 | extern PGDLLIMPORT bool update_process_title; 23 | 24 | extern char **save_ps_display_args(int argc, char **argv); 25 | 26 | extern void init_ps_display(const char *fixed_part); 27 | 28 | extern void set_ps_display_suffix(const char *suffix); 29 | 30 | extern void set_ps_display_remove_suffix(void); 31 | 32 | extern void set_ps_display_with_len(const char *activity, size_t len); 33 | 34 | /* 35 | * set_ps_display 36 | * inlined to allow strlen to be evaluated during compilation when 37 | * passing string constants. 38 | */ 39 | static inline void 40 | set_ps_display(const char *activity) 41 | { 42 | set_ps_display_with_len(activity, strlen(activity)); 43 | } 44 | 45 | extern const char *get_ps_display(int *displen); 46 | 47 | #endif /* PS_STATUS_H */ 48 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_am_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_am_d.h 4 | * Macro definitions for pg_am 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_AM_D_H 19 | #define PG_AM_D_H 20 | 21 | #define AccessMethodRelationId 2601 22 | #define AmNameIndexId 2651 23 | #define AmOidIndexId 2652 24 | 25 | #define Anum_pg_am_oid 1 26 | #define Anum_pg_am_amname 2 27 | #define Anum_pg_am_amhandler 3 28 | #define Anum_pg_am_amtype 4 29 | 30 | #define Natts_pg_am 4 31 | 32 | 33 | /* 34 | * Allowed values for amtype 35 | */ 36 | #define AMTYPE_INDEX 'i' /* index access method */ 37 | #define AMTYPE_TABLE 't' /* table access method */ 38 | 39 | #define HEAP_TABLE_AM_OID 2 40 | #define BTREE_AM_OID 403 41 | #define HASH_AM_OID 405 42 | #define GIST_AM_OID 783 43 | #define GIN_AM_OID 2742 44 | #define SPGIST_AM_OID 4000 45 | #define BRIN_AM_OID 3580 46 | 47 | #endif /* PG_AM_D_H */ 48 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/libpq/scram.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * scram.h 4 | * Interface to libpq/scram.c 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/libpq/scram.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef PG_SCRAM_H 14 | #define PG_SCRAM_H 15 | 16 | #include "common/cryptohash.h" 17 | #include "lib/stringinfo.h" 18 | #include "libpq/libpq-be.h" 19 | #include "libpq/sasl.h" 20 | 21 | /* Number of iterations when generating new secrets */ 22 | extern PGDLLIMPORT int scram_sha_256_iterations; 23 | 24 | /* SASL implementation callbacks */ 25 | extern PGDLLIMPORT const pg_be_sasl_mech pg_be_scram_mech; 26 | 27 | /* Routines to handle and check SCRAM-SHA-256 secret */ 28 | extern char *pg_be_scram_build_secret(const char *password); 29 | extern bool parse_scram_secret(const char *secret, 30 | int *iterations, 31 | pg_cryptohash_type *hash_type, 32 | int *key_length, char **salt, 33 | uint8 *stored_key, uint8 *server_key); 34 | extern bool scram_verify_plain_password(const char *username, 35 | const char *password, const char *secret); 36 | 37 | #endif /* PG_SCRAM_H */ 38 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/libpq/auth.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * auth.h 4 | * Definitions for network authentication routines 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/libpq/auth.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef AUTH_H 15 | #define AUTH_H 16 | 17 | #include "libpq/libpq-be.h" 18 | 19 | extern PGDLLIMPORT char *pg_krb_server_keyfile; 20 | extern PGDLLIMPORT bool pg_krb_caseins_users; 21 | extern PGDLLIMPORT bool pg_gss_accept_delegation; 22 | 23 | extern void ClientAuthentication(Port *port); 24 | extern void sendAuthRequest(Port *port, AuthRequest areq, const char *extradata, 25 | int extralen); 26 | 27 | /* Hook for plugins to get control in ClientAuthentication() */ 28 | typedef void (*ClientAuthentication_hook_type) (Port *, int); 29 | extern PGDLLIMPORT ClientAuthentication_hook_type ClientAuthentication_hook; 30 | 31 | /* hook type for password manglers */ 32 | typedef char *(*auth_password_hook_typ) (char *input); 33 | 34 | /* Default LDAP password mutator hook, can be overridden by a shared library */ 35 | extern PGDLLIMPORT auth_password_hook_typ ldap_password_hook; 36 | 37 | #endif /* AUTH_H */ 38 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/common/cryptohash.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * cryptohash.h 4 | * Generic headers for cryptographic hash functions. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * IDENTIFICATION 10 | * src/include/common/cryptohash.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | 15 | #ifndef PG_CRYPTOHASH_H 16 | #define PG_CRYPTOHASH_H 17 | 18 | /* Context Structures for each hash function */ 19 | typedef enum 20 | { 21 | PG_MD5 = 0, 22 | PG_SHA1, 23 | PG_SHA224, 24 | PG_SHA256, 25 | PG_SHA384, 26 | PG_SHA512, 27 | } pg_cryptohash_type; 28 | 29 | /* opaque context, private to each cryptohash implementation */ 30 | typedef struct pg_cryptohash_ctx pg_cryptohash_ctx; 31 | 32 | extern pg_cryptohash_ctx *pg_cryptohash_create(pg_cryptohash_type type); 33 | extern int pg_cryptohash_init(pg_cryptohash_ctx *ctx); 34 | extern int pg_cryptohash_update(pg_cryptohash_ctx *ctx, const uint8 *data, size_t len); 35 | extern int pg_cryptohash_final(pg_cryptohash_ctx *ctx, uint8 *dest, size_t len); 36 | extern void pg_cryptohash_free(pg_cryptohash_ctx *ctx); 37 | extern const char *pg_cryptohash_error(pg_cryptohash_ctx *ctx); 38 | 39 | #endif /* PG_CRYPTOHASH_H */ 40 | -------------------------------------------------------------------------------- /internal/cparser/src_common_keywords.c: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | * Symbols referenced in this file: 3 | * - ScanKeywordCategories 4 | *-------------------------------------------------------------------- 5 | */ 6 | 7 | /*------------------------------------------------------------------------- 8 | * 9 | * keywords.c 10 | * PostgreSQL's list of SQL keywords 11 | * 12 | * 13 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 14 | * Portions Copyright (c) 1994, Regents of the University of California 15 | * 16 | * 17 | * IDENTIFICATION 18 | * src/common/keywords.c 19 | * 20 | *------------------------------------------------------------------------- 21 | */ 22 | #include "c.h" 23 | 24 | #include "common/keywords.h" 25 | 26 | 27 | /* ScanKeywordList lookup data for SQL keywords */ 28 | 29 | #include "kwlist_d.h" 30 | 31 | /* Keyword categories for SQL keywords */ 32 | 33 | #define PG_KEYWORD(kwname, value, category, collabel) category, 34 | 35 | const uint8 ScanKeywordCategories[SCANKEYWORDS_NUM_KEYWORDS] = { 36 | #include "parser/kwlist.h" 37 | }; 38 | 39 | #undef PG_KEYWORD 40 | 41 | /* Keyword can-be-bare-label flags for SQL keywords */ 42 | 43 | #define PG_KEYWORD(kwname, value, category, collabel) collabel, 44 | 45 | #define BARE_LABEL true 46 | #define AS_LABEL false 47 | 48 | 49 | 50 | #undef PG_KEYWORD 51 | #undef BARE_LABEL 52 | #undef AS_LABEL 53 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/utils/injection_point.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * injection_point.h 3 | * Definitions related to injection points. 4 | * 5 | * Copyright (c) 2001-2024, PostgreSQL Global Development Group 6 | * 7 | * src/include/utils/injection_point.h 8 | *------------------------------------------------------------------------- 9 | */ 10 | 11 | #ifndef INJECTION_POINT_H 12 | #define INJECTION_POINT_H 13 | 14 | /* 15 | * Injections points require --enable-injection-points. 16 | */ 17 | #ifdef USE_INJECTION_POINTS 18 | #define INJECTION_POINT(name) InjectionPointRun(name) 19 | #else 20 | #define INJECTION_POINT(name) ((void) name) 21 | #endif 22 | 23 | /* 24 | * Typedef for callback function launched by an injection point. 25 | */ 26 | typedef void (*InjectionPointCallback) (const char *name, 27 | const void *private_data); 28 | 29 | extern Size InjectionPointShmemSize(void); 30 | extern void InjectionPointShmemInit(void); 31 | 32 | extern void InjectionPointAttach(const char *name, 33 | const char *library, 34 | const char *function, 35 | const void *private_data, 36 | int private_data_size); 37 | extern void InjectionPointRun(const char *name); 38 | extern bool InjectionPointDetach(const char *name); 39 | 40 | #ifdef EXEC_BACKEND 41 | extern PGDLLIMPORT struct InjectionPointsCtl *ActiveInjectionPoints; 42 | #endif 43 | 44 | #endif /* INJECTION_POINT_H */ 45 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/rewrite/rewriteHandler.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * rewriteHandler.h 4 | * External interface to query rewriter. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/rewrite/rewriteHandler.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef REWRITEHANDLER_H 15 | #define REWRITEHANDLER_H 16 | 17 | #include "nodes/parsenodes.h" 18 | #include "utils/relcache.h" 19 | 20 | extern List *QueryRewrite(Query *parsetree); 21 | extern void AcquireRewriteLocks(Query *parsetree, 22 | bool forExecute, 23 | bool forUpdatePushedDown); 24 | 25 | extern Node *build_column_default(Relation rel, int attrno); 26 | 27 | extern Query *get_view_query(Relation view); 28 | extern bool view_has_instead_trigger(Relation view, CmdType event, 29 | List *mergeActionList); 30 | extern const char *view_query_is_auto_updatable(Query *viewquery, 31 | bool check_cols); 32 | extern int relation_is_updatable(Oid reloid, 33 | List *outer_reloids, 34 | bool include_triggers, 35 | Bitmapset *include_cols); 36 | extern void error_view_not_updatable(Relation view, 37 | CmdType command, 38 | List *mergeActionList, 39 | const char *detail); 40 | 41 | #endif /* REWRITEHANDLER_H */ 42 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | tags: 7 | - "*" 8 | pull_request: 9 | workflow_dispatch: 10 | 11 | jobs: 12 | build: 13 | runs-on: ${{ matrix.os }} 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | mode: 18 | - cgo 19 | - wazero 20 | os: 21 | - macos-13 22 | - macos-14 23 | - ubuntu-22.04 24 | - windows-2022 25 | steps: 26 | - uses: actions/checkout@v4 27 | with: 28 | fetch-depth: 0 29 | 30 | - uses: actions/setup-go@v4 31 | with: 32 | go-version: '^1.21' 33 | 34 | - name: run checks 35 | run: go run mage check 36 | env: 37 | WASI_TEST_MODE: ${{ matrix.mode }} 38 | 39 | # Runs tests using wazero inside a minimal golang docker image. This makes sure the code builds 40 | # even when there is no C toolchain available. It is possible for code to work fine with CGO_ENABLED=0 41 | # but not build without a C toolchain available, e.g. if C source files are checked into the repo 42 | # without a build tag to exclude them from pure-Go builds. 43 | docker-build: 44 | runs-on: ubuntu-22.04 45 | container: 46 | image: golang:alpine 47 | steps: 48 | - uses: actions/checkout@v4 49 | with: 50 | fetch-depth: 0 51 | 52 | - run: if command -v gcc &> /dev/null; then echo "GCC found but not expected"; exit 321; fi 53 | 54 | - run: go run mage test 55 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/postmaster/startup.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * startup.h 4 | * Exports from postmaster/startup.c. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * 8 | * src/include/postmaster/startup.h 9 | * 10 | *------------------------------------------------------------------------- 11 | */ 12 | #ifndef _STARTUP_H 13 | #define _STARTUP_H 14 | 15 | /* 16 | * Log the startup progress message if a timer has expired. 17 | */ 18 | #define ereport_startup_progress(msg, ...) \ 19 | do { \ 20 | long secs; \ 21 | int usecs; \ 22 | if (has_startup_progress_timeout_expired(&secs, &usecs)) \ 23 | ereport(LOG, errmsg(msg, secs, (usecs / 10000), __VA_ARGS__ )); \ 24 | } while(0) 25 | 26 | extern PGDLLIMPORT int log_startup_progress_interval; 27 | 28 | extern void HandleStartupProcInterrupts(void); 29 | extern void StartupProcessMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); 30 | extern void PreRestoreCommand(void); 31 | extern void PostRestoreCommand(void); 32 | extern bool IsPromoteSignaled(void); 33 | extern void ResetPromoteSignaled(void); 34 | 35 | extern void enable_startup_progress_timeout(void); 36 | extern void disable_startup_progress_timeout(void); 37 | extern void begin_startup_progress_phase(void); 38 | extern void startup_progress_timeout_handler(void); 39 | extern bool has_startup_progress_timeout_expired(long *secs, int *usecs); 40 | 41 | #endif /* _STARTUP_H */ 42 | -------------------------------------------------------------------------------- /internal/cparser/include/pg_query_json_helper.c: -------------------------------------------------------------------------------- 1 | #include "lib/stringinfo.h" 2 | 3 | #define booltostr(x) ((x) ? "true" : "false") 4 | 5 | static void 6 | removeTrailingDelimiter(StringInfo str) 7 | { 8 | if (str->len >= 1 && str->data[str->len - 1] == ',') { 9 | str->len -= 1; 10 | str->data[str->len] = '\0'; 11 | } 12 | } 13 | 14 | static void 15 | _outToken(StringInfo buf, const char *str) 16 | { 17 | if (str == NULL) 18 | { 19 | appendStringInfoString(buf, "null"); 20 | return; 21 | } 22 | 23 | // copied directly from https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/json.c#L2428 24 | const char *p; 25 | 26 | appendStringInfoCharMacro(buf, '"'); 27 | for (p = str; *p; p++) 28 | { 29 | switch (*p) 30 | { 31 | case '\b': 32 | appendStringInfoString(buf, "\\b"); 33 | break; 34 | case '\f': 35 | appendStringInfoString(buf, "\\f"); 36 | break; 37 | case '\n': 38 | appendStringInfoString(buf, "\\n"); 39 | break; 40 | case '\r': 41 | appendStringInfoString(buf, "\\r"); 42 | break; 43 | case '\t': 44 | appendStringInfoString(buf, "\\t"); 45 | break; 46 | case '"': 47 | appendStringInfoString(buf, "\\\""); 48 | break; 49 | case '\\': 50 | appendStringInfoString(buf, "\\\\"); 51 | break; 52 | default: 53 | if ((unsigned char) *p < ' ' || *p == '<' || *p == '>') 54 | appendStringInfo(buf, "\\u%04x", (int) *p); 55 | else 56 | appendStringInfoCharMacro(buf, *p); 57 | break; 58 | } 59 | } 60 | appendStringInfoCharMacro(buf, '"'); 61 | } 62 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_statistic_ext_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_statistic_ext_d.h 4 | * Macro definitions for pg_statistic_ext 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_STATISTIC_EXT_D_H 19 | #define PG_STATISTIC_EXT_D_H 20 | 21 | #define StatisticExtRelationId 3381 22 | #define StatisticExtOidIndexId 3380 23 | #define StatisticExtNameIndexId 3997 24 | #define StatisticExtRelidIndexId 3379 25 | 26 | #define Anum_pg_statistic_ext_oid 1 27 | #define Anum_pg_statistic_ext_stxrelid 2 28 | #define Anum_pg_statistic_ext_stxname 3 29 | #define Anum_pg_statistic_ext_stxnamespace 4 30 | #define Anum_pg_statistic_ext_stxowner 5 31 | #define Anum_pg_statistic_ext_stxkeys 6 32 | #define Anum_pg_statistic_ext_stxstattarget 7 33 | #define Anum_pg_statistic_ext_stxkind 8 34 | #define Anum_pg_statistic_ext_stxexprs 9 35 | 36 | #define Natts_pg_statistic_ext 9 37 | 38 | 39 | #define STATS_EXT_NDISTINCT 'd' 40 | #define STATS_EXT_DEPENDENCIES 'f' 41 | #define STATS_EXT_MCV 'm' 42 | #define STATS_EXT_EXPRESSIONS 'e' 43 | 44 | 45 | #endif /* PG_STATISTIC_EXT_D_H */ 46 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/utils/backend_progress.h: -------------------------------------------------------------------------------- 1 | /* ---------- 2 | * backend_progress.h 3 | * Command progress reporting definition. 4 | * 5 | * Note that this file provides the infrastructure for storing a single 6 | * backend's command progress counters, without ascribing meaning to the 7 | * individual fields. See commands/progress.h and system_views.sql for that. 8 | * 9 | * Copyright (c) 2001-2024, PostgreSQL Global Development Group 10 | * 11 | * src/include/utils/backend_progress.h 12 | * ---------- 13 | */ 14 | #ifndef BACKEND_PROGRESS_H 15 | #define BACKEND_PROGRESS_H 16 | 17 | 18 | /* ---------- 19 | * Command type for progress reporting purposes 20 | * ---------- 21 | */ 22 | typedef enum ProgressCommandType 23 | { 24 | PROGRESS_COMMAND_INVALID, 25 | PROGRESS_COMMAND_VACUUM, 26 | PROGRESS_COMMAND_ANALYZE, 27 | PROGRESS_COMMAND_CLUSTER, 28 | PROGRESS_COMMAND_CREATE_INDEX, 29 | PROGRESS_COMMAND_BASEBACKUP, 30 | PROGRESS_COMMAND_COPY, 31 | } ProgressCommandType; 32 | 33 | #define PGSTAT_NUM_PROGRESS_PARAM 20 34 | 35 | 36 | extern void pgstat_progress_start_command(ProgressCommandType cmdtype, 37 | Oid relid); 38 | extern void pgstat_progress_update_param(int index, int64 val); 39 | extern void pgstat_progress_incr_param(int index, int64 incr); 40 | extern void pgstat_progress_parallel_incr_param(int index, int64 incr); 41 | extern void pgstat_progress_update_multi_param(int nparam, const int *index, 42 | const int64 *val); 43 | extern void pgstat_progress_end_command(void); 44 | 45 | 46 | #endif /* BACKEND_PROGRESS_H */ 47 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/tcop/pquery.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pquery.h 4 | * prototypes for pquery.c. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/tcop/pquery.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef PQUERY_H 15 | #define PQUERY_H 16 | 17 | #include "nodes/parsenodes.h" 18 | #include "utils/portal.h" 19 | 20 | struct PlannedStmt; /* avoid including plannodes.h here */ 21 | 22 | 23 | extern PGDLLIMPORT Portal ActivePortal; 24 | 25 | 26 | extern PortalStrategy ChoosePortalStrategy(List *stmts); 27 | 28 | extern List *FetchPortalTargetList(Portal portal); 29 | 30 | extern List *FetchStatementTargetList(Node *stmt); 31 | 32 | extern void PortalStart(Portal portal, ParamListInfo params, 33 | int eflags, Snapshot snapshot); 34 | 35 | extern void PortalSetResultFormat(Portal portal, int nFormats, 36 | int16 *formats); 37 | 38 | extern bool PortalRun(Portal portal, long count, bool isTopLevel, 39 | bool run_once, DestReceiver *dest, DestReceiver *altdest, 40 | QueryCompletion *qc); 41 | 42 | extern uint64 PortalRunFetch(Portal portal, 43 | FetchDirection fdirection, 44 | long count, 45 | DestReceiver *dest); 46 | 47 | extern bool PlannedStmtRequiresSnapshot(struct PlannedStmt *pstmt); 48 | 49 | extern void EnsurePortalSnapshotExists(void); 50 | 51 | #endif /* PQUERY_H */ 52 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/storage/procnumber.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * procnumber.h 4 | * definition of process number 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/storage/procnumber.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef PROCNUMBER_H 15 | #define PROCNUMBER_H 16 | 17 | /* 18 | * ProcNumber uniquely identifies an active backend or auxiliary process. 19 | * It's assigned at backend startup after authentication, when the process 20 | * adds itself to the proc array. It is an index into the proc array, 21 | * starting from 0. Note that a ProcNumber can be reused for a different 22 | * backend immediately after a backend exits. 23 | */ 24 | typedef int ProcNumber; 25 | 26 | #define INVALID_PROC_NUMBER (-1) 27 | 28 | /* 29 | * Proc number of this backend (same as GetNumberFromPGProc(MyProc)) 30 | */ 31 | extern PGDLLIMPORT ProcNumber MyProcNumber; 32 | 33 | /* proc number of our parallel session leader, or INVALID_PROC_NUMBER if none */ 34 | extern PGDLLIMPORT ProcNumber ParallelLeaderProcNumber; 35 | 36 | /* 37 | * The ProcNumber to use for our session's temp relations is normally our own, 38 | * but parallel workers should use their leader's proc number. 39 | */ 40 | #define ProcNumberForTempRelations() \ 41 | (ParallelLeaderProcNumber == INVALID_PROC_NUMBER ? MyProcNumber : ParallelLeaderProcNumber) 42 | 43 | #endif /* PROCNUMBER_H */ 44 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/commands/dbcommands.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * dbcommands.h 4 | * Database management commands (create/drop database). 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/commands/dbcommands.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef DBCOMMANDS_H 15 | #define DBCOMMANDS_H 16 | 17 | #include "access/xlogreader.h" 18 | #include "catalog/objectaddress.h" 19 | #include "lib/stringinfo.h" 20 | #include "parser/parse_node.h" 21 | 22 | extern Oid createdb(ParseState *pstate, const CreatedbStmt *stmt); 23 | extern void dropdb(const char *dbname, bool missing_ok, bool force); 24 | extern void DropDatabase(ParseState *pstate, DropdbStmt *stmt); 25 | extern ObjectAddress RenameDatabase(const char *oldname, const char *newname); 26 | extern Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel); 27 | extern ObjectAddress AlterDatabaseRefreshColl(AlterDatabaseRefreshCollStmt *stmt); 28 | extern Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt); 29 | extern ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId); 30 | 31 | extern Oid get_database_oid(const char *dbname, bool missing_ok); 32 | extern char *get_database_name(Oid dbid); 33 | extern bool have_createdb_privilege(void); 34 | 35 | extern void check_encoding_locale_matches(int encoding, const char *collate, const char *ctype); 36 | 37 | #endif /* DBCOMMANDS_H */ 38 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/catalog.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * catalog.h 4 | * prototypes for functions in backend/catalog/catalog.c 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/catalog/catalog.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef CATALOG_H 15 | #define CATALOG_H 16 | 17 | #include "catalog/pg_class.h" 18 | #include "utils/relcache.h" 19 | 20 | 21 | extern bool IsSystemRelation(Relation relation); 22 | extern bool IsToastRelation(Relation relation); 23 | extern bool IsCatalogRelation(Relation relation); 24 | extern bool IsInplaceUpdateRelation(Relation relation); 25 | 26 | extern bool IsSystemClass(Oid relid, Form_pg_class reltuple); 27 | extern bool IsToastClass(Form_pg_class reltuple); 28 | 29 | extern bool IsCatalogRelationOid(Oid relid); 30 | extern bool IsInplaceUpdateOid(Oid relid); 31 | 32 | extern bool IsCatalogNamespace(Oid namespaceId); 33 | extern bool IsToastNamespace(Oid namespaceId); 34 | 35 | extern bool IsReservedName(const char *name); 36 | 37 | extern bool IsSharedRelation(Oid relationId); 38 | 39 | extern bool IsPinnedObject(Oid classId, Oid objectId); 40 | 41 | extern Oid GetNewOidWithIndex(Relation relation, Oid indexId, 42 | AttrNumber oidcolumn); 43 | extern RelFileNumber GetNewRelFileNumber(Oid reltablespace, 44 | Relation pg_class, 45 | char relpersistence); 46 | 47 | #endif /* CATALOG_H */ 48 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | This project contains work from pganalyze. Following is its license 2 | 3 | Copyright (c) 2015, Lukas Fittl 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of pg_query nor the names of its contributors may be used 17 | to endorse or promote products derived from this software without specific 18 | prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/xlogbackup.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * xlogbackup.h 4 | * Definitions for internals of base backups. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * IDENTIFICATION 10 | * src/include/access/xlogbackup.h 11 | *------------------------------------------------------------------------- 12 | */ 13 | 14 | #ifndef XLOG_BACKUP_H 15 | #define XLOG_BACKUP_H 16 | 17 | #include "access/xlogdefs.h" 18 | #include "pgtime.h" 19 | 20 | /* Structure to hold backup state. */ 21 | typedef struct BackupState 22 | { 23 | /* Fields saved at backup start */ 24 | /* Backup label name one extra byte for null-termination */ 25 | char name[MAXPGPATH + 1]; 26 | XLogRecPtr startpoint; /* backup start WAL location */ 27 | TimeLineID starttli; /* backup start TLI */ 28 | XLogRecPtr checkpointloc; /* last checkpoint location */ 29 | pg_time_t starttime; /* backup start time */ 30 | bool started_in_recovery; /* backup started in recovery? */ 31 | XLogRecPtr istartpoint; /* incremental based on backup at this LSN */ 32 | TimeLineID istarttli; /* incremental based on backup on this TLI */ 33 | 34 | /* Fields saved at the end of backup */ 35 | XLogRecPtr stoppoint; /* backup stop WAL location */ 36 | TimeLineID stoptli; /* backup stop TLI */ 37 | pg_time_t stoptime; /* backup stop time */ 38 | } BackupState; 39 | 40 | extern char *build_backup_content(BackupState *state, 41 | bool ishistoryfile); 42 | 43 | #endif /* XLOG_BACKUP_H */ 44 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/postmaster/bgwriter.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * bgwriter.h 4 | * Exports from postmaster/bgwriter.c and postmaster/checkpointer.c. 5 | * 6 | * The bgwriter process used to handle checkpointing duties too. Now 7 | * there is a separate process, but we did not bother to split this header. 8 | * 9 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 10 | * 11 | * src/include/postmaster/bgwriter.h 12 | * 13 | *------------------------------------------------------------------------- 14 | */ 15 | #ifndef _BGWRITER_H 16 | #define _BGWRITER_H 17 | 18 | #include "storage/block.h" 19 | #include "storage/relfilelocator.h" 20 | #include "storage/smgr.h" 21 | #include "storage/sync.h" 22 | 23 | 24 | /* GUC options */ 25 | extern PGDLLIMPORT int BgWriterDelay; 26 | extern PGDLLIMPORT int CheckPointTimeout; 27 | extern PGDLLIMPORT int CheckPointWarning; 28 | extern PGDLLIMPORT double CheckPointCompletionTarget; 29 | 30 | extern void BackgroundWriterMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); 31 | extern void CheckpointerMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); 32 | 33 | extern void RequestCheckpoint(int flags); 34 | extern void CheckpointWriteDelay(int flags, double progress); 35 | 36 | extern bool ForwardSyncRequest(const FileTag *ftag, SyncRequestType type); 37 | 38 | extern void AbsorbSyncRequests(void); 39 | 40 | extern Size CheckpointerShmemSize(void); 41 | extern void CheckpointerShmemInit(void); 42 | 43 | extern bool FirstCallSinceLastCheckpoint(void); 44 | 45 | #endif /* _BGWRITER_H */ 46 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/utils/aclchk_internal.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * aclchk_internal.h 4 | * 5 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 6 | * Portions Copyright (c) 1994, Regents of the University of California 7 | * 8 | * src/include/utils/aclchk_internal.h 9 | * 10 | *------------------------------------------------------------------------- 11 | */ 12 | #ifndef ACLCHK_INTERNAL_H 13 | #define ACLCHK_INTERNAL_H 14 | 15 | #include "nodes/parsenodes.h" 16 | #include "nodes/pg_list.h" 17 | 18 | /* 19 | * The information about one Grant/Revoke statement, in internal format: object 20 | * and grantees names have been turned into Oids, the privilege list is an 21 | * AclMode bitmask. If 'privileges' is ACL_NO_RIGHTS (the 0 value) and 22 | * all_privs is true, 'privileges' will be internally set to the right kind of 23 | * ACL_ALL_RIGHTS_*, depending on the object type (NB - this will modify the 24 | * InternalGrant struct!) 25 | * 26 | * Note: 'all_privs' and 'privileges' represent object-level privileges only. 27 | * There might also be column-level privilege specifications, which are 28 | * represented in col_privs (this is a list of untransformed AccessPriv nodes). 29 | * Column privileges are only valid for objtype OBJECT_TABLE. 30 | */ 31 | typedef struct 32 | { 33 | bool is_grant; 34 | ObjectType objtype; 35 | List *objects; 36 | bool all_privs; 37 | AclMode privileges; 38 | List *col_privs; 39 | List *grantees; 40 | bool grant_option; 41 | DropBehavior behavior; 42 | } InternalGrant; 43 | 44 | 45 | #endif /* ACLCHK_INTERNAL_H */ 46 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/common/kwlookup.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * kwlookup.h 4 | * Key word lookup for PostgreSQL 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/common/kwlookup.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef KWLOOKUP_H 15 | #define KWLOOKUP_H 16 | 17 | /* Hash function used by ScanKeywordLookup */ 18 | typedef int (*ScanKeywordHashFunc) (const void *key, size_t keylen); 19 | 20 | /* 21 | * This struct contains the data needed by ScanKeywordLookup to perform a 22 | * search within a set of keywords. The contents are typically generated by 23 | * src/tools/gen_keywordlist.pl from a header containing PG_KEYWORD macros. 24 | */ 25 | typedef struct ScanKeywordList 26 | { 27 | const char *kw_string; /* all keywords in order, separated by \0 */ 28 | const uint16 *kw_offsets; /* offsets to the start of each keyword */ 29 | ScanKeywordHashFunc hash; /* perfect hash function for keywords */ 30 | int num_keywords; /* number of keywords */ 31 | int max_kw_len; /* length of longest keyword */ 32 | } ScanKeywordList; 33 | 34 | 35 | extern int ScanKeywordLookup(const char *str, const ScanKeywordList *keywords); 36 | 37 | /* Code that wants to retrieve the text of the N'th keyword should use this. */ 38 | static inline const char * 39 | GetScanKeyword(int n, const ScanKeywordList *keywords) 40 | { 41 | return keywords->kw_string + keywords->kw_offsets[n]; 42 | } 43 | 44 | #endif /* KWLOOKUP_H */ 45 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/rmgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rmgr.h 3 | * 4 | * Resource managers definition 5 | * 6 | * src/include/access/rmgr.h 7 | */ 8 | #ifndef RMGR_H 9 | #define RMGR_H 10 | 11 | typedef uint8 RmgrId; 12 | 13 | /* 14 | * Built-in resource managers 15 | * 16 | * The actual numerical values for each rmgr ID are defined by the order 17 | * of entries in rmgrlist.h. 18 | * 19 | * Note: RM_MAX_ID must fit in RmgrId; widening that type will affect the XLOG 20 | * file format. 21 | */ 22 | #define PG_RMGR(symname,name,redo,desc,identify,startup,cleanup,mask,decode) \ 23 | symname, 24 | 25 | typedef enum RmgrIds 26 | { 27 | #include "access/rmgrlist.h" 28 | RM_NEXT_ID 29 | } RmgrIds; 30 | 31 | #undef PG_RMGR 32 | 33 | #define RM_MAX_ID UINT8_MAX 34 | #define RM_MAX_BUILTIN_ID (RM_NEXT_ID - 1) 35 | #define RM_MIN_CUSTOM_ID 128 36 | #define RM_MAX_CUSTOM_ID UINT8_MAX 37 | #define RM_N_IDS (UINT8_MAX + 1) 38 | #define RM_N_BUILTIN_IDS (RM_MAX_BUILTIN_ID + 1) 39 | #define RM_N_CUSTOM_IDS (RM_MAX_CUSTOM_ID - RM_MIN_CUSTOM_ID + 1) 40 | 41 | static inline bool 42 | RmgrIdIsBuiltin(int rmid) 43 | { 44 | return rmid <= RM_MAX_BUILTIN_ID; 45 | } 46 | 47 | static inline bool 48 | RmgrIdIsCustom(int rmid) 49 | { 50 | return rmid >= RM_MIN_CUSTOM_ID && rmid <= RM_MAX_CUSTOM_ID; 51 | } 52 | 53 | #define RmgrIdIsValid(rmid) (RmgrIdIsBuiltin((rmid)) || RmgrIdIsCustom((rmid))) 54 | 55 | /* 56 | * RmgrId to use for extensions that require an RmgrId, but are still in 57 | * development and have not reserved their own unique RmgrId yet. See: 58 | * https://wiki.postgresql.org/wiki/CustomWALResourceManagers 59 | */ 60 | #define RM_EXPERIMENTAL_ID 128 61 | 62 | #endif /* RMGR_H */ 63 | -------------------------------------------------------------------------------- /internal/cparser/pg_query_deparse.c: -------------------------------------------------------------------------------- 1 | #include "pg_query.h" 2 | #include "pg_query_internal.h" 3 | #include "pg_query_readfuncs.h" 4 | 5 | #include "postgres_deparse.h" 6 | 7 | PgQueryDeparseResult pg_query_deparse_protobuf(PgQueryProtobuf parse_tree) 8 | { 9 | PgQueryDeparseResult result = {0}; 10 | StringInfoData str; 11 | MemoryContext ctx; 12 | List *stmts; 13 | ListCell *lc; 14 | 15 | ctx = pg_query_enter_memory_context(); 16 | 17 | PG_TRY(); 18 | { 19 | stmts = pg_query_protobuf_to_nodes(parse_tree); 20 | 21 | initStringInfo(&str); 22 | 23 | foreach(lc, stmts) { 24 | deparseRawStmt(&str, castNode(RawStmt, lfirst(lc))); 25 | if (lnext(stmts, lc)) 26 | appendStringInfoString(&str, "; "); 27 | } 28 | result.query = strdup(str.data); 29 | } 30 | PG_CATCH(); 31 | { 32 | ErrorData* error_data; 33 | PgQueryError* error; 34 | 35 | MemoryContextSwitchTo(ctx); 36 | error_data = CopyErrorData(); 37 | 38 | // Note: This is intentionally malloc so exiting the memory context doesn't free this 39 | error = malloc(sizeof(PgQueryError)); 40 | error->message = strdup(error_data->message); 41 | error->filename = strdup(error_data->filename); 42 | error->funcname = strdup(error_data->funcname); 43 | error->context = NULL; 44 | error->lineno = error_data->lineno; 45 | error->cursorpos = error_data->cursorpos; 46 | 47 | result.error = error; 48 | FlushErrorState(); 49 | } 50 | PG_END_TRY(); 51 | 52 | pg_query_exit_memory_context(ctx); 53 | 54 | return result; 55 | } 56 | 57 | void pg_query_free_deparse_result(PgQueryDeparseResult result) 58 | { 59 | if (result.error) { 60 | pg_query_free_error(result.error); 61 | } 62 | 63 | free(result.query); 64 | } 65 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/utils/regproc.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * regproc.h 4 | * Functions for the built-in types regproc, regclass, regtype, etc. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/utils/regproc.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef REGPROC_H 14 | #define REGPROC_H 15 | 16 | #include "nodes/pg_list.h" 17 | 18 | /* Control flags for format_procedure_extended */ 19 | #define FORMAT_PROC_INVALID_AS_NULL 0x01 /* NULL if undefined */ 20 | #define FORMAT_PROC_FORCE_QUALIFY 0x02 /* force qualification */ 21 | extern char *format_procedure_extended(Oid procedure_oid, bits16 flags); 22 | 23 | /* Control flags for format_operator_extended */ 24 | #define FORMAT_OPERATOR_INVALID_AS_NULL 0x01 /* NULL if undefined */ 25 | #define FORMAT_OPERATOR_FORCE_QUALIFY 0x02 /* force qualification */ 26 | extern char *format_operator_extended(Oid operator_oid, bits16 flags); 27 | 28 | extern List *stringToQualifiedNameList(const char *string, Node *escontext); 29 | extern char *format_procedure(Oid procedure_oid); 30 | extern char *format_procedure_qualified(Oid procedure_oid); 31 | extern void format_procedure_parts(Oid procedure_oid, List **objnames, 32 | List **objargs, bool missing_ok); 33 | 34 | extern char *format_operator(Oid operator_oid); 35 | extern char *format_operator_qualified(Oid operator_oid); 36 | extern void format_operator_parts(Oid operator_oid, List **objnames, 37 | List **objargs, bool missing_ok); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/utils/fmgrtab.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * fmgrtab.h 4 | * The function manager's table of internal functions. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/utils/fmgrtab.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef FMGRTAB_H 14 | #define FMGRTAB_H 15 | 16 | #include "access/transam.h" 17 | #include "fmgr.h" 18 | 19 | 20 | /* 21 | * This table stores info about all the built-in functions (ie, functions 22 | * that are compiled into the Postgres executable). 23 | */ 24 | 25 | typedef struct 26 | { 27 | Oid foid; /* OID of the function */ 28 | short nargs; /* 0..FUNC_MAX_ARGS, or -1 if variable count */ 29 | bool strict; /* T if function is "strict" */ 30 | bool retset; /* T if function returns a set */ 31 | const char *funcName; /* C name of the function */ 32 | PGFunction func; /* pointer to compiled function */ 33 | } FmgrBuiltin; 34 | 35 | extern PGDLLIMPORT const FmgrBuiltin fmgr_builtins[]; 36 | 37 | extern PGDLLIMPORT const int fmgr_nbuiltins; /* number of entries in table */ 38 | 39 | extern PGDLLIMPORT const Oid fmgr_last_builtin_oid; /* highest function OID in 40 | * table */ 41 | 42 | /* 43 | * Mapping from a builtin function's OID to its index in the fmgr_builtins 44 | * array. This is indexed from 0 through fmgr_last_builtin_oid. 45 | */ 46 | #define InvalidOidBuiltinMapping PG_UINT16_MAX 47 | extern PGDLLIMPORT const uint16 fmgr_builtin_oid_index[]; 48 | 49 | #endif /* FMGRTAB_H */ 50 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/libpq/crypt.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * crypt.h 4 | * Interface to libpq/crypt.c 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/libpq/crypt.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef PG_CRYPT_H 14 | #define PG_CRYPT_H 15 | 16 | #include "datatype/timestamp.h" 17 | 18 | /* 19 | * Types of password hashes or secrets. 20 | * 21 | * Plaintext passwords can be passed in by the user, in a CREATE/ALTER USER 22 | * command. They will be encrypted to MD5 or SCRAM-SHA-256 format, before 23 | * storing on-disk, so only MD5 and SCRAM-SHA-256 passwords should appear 24 | * in pg_authid.rolpassword. They are also the allowed values for the 25 | * password_encryption GUC. 26 | */ 27 | typedef enum PasswordType 28 | { 29 | PASSWORD_TYPE_PLAINTEXT = 0, 30 | PASSWORD_TYPE_MD5, 31 | PASSWORD_TYPE_SCRAM_SHA_256, 32 | } PasswordType; 33 | 34 | extern PasswordType get_password_type(const char *shadow_pass); 35 | extern char *encrypt_password(PasswordType target_type, const char *role, 36 | const char *password); 37 | 38 | extern char *get_role_password(const char *role, const char **logdetail); 39 | 40 | extern int md5_crypt_verify(const char *role, const char *shadow_pass, 41 | const char *client_pass, const char *md5_salt, 42 | int md5_salt_len, const char **logdetail); 43 | extern int plain_crypt_verify(const char *role, const char *shadow_pass, 44 | const char *client_pass, 45 | const char **logdetail); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/commands/async.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * async.h 4 | * Asynchronous notification: NOTIFY, LISTEN, UNLISTEN 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/commands/async.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef ASYNC_H 14 | #define ASYNC_H 15 | 16 | #include 17 | 18 | extern PGDLLIMPORT bool Trace_notify; 19 | extern PGDLLIMPORT int max_notify_queue_pages; 20 | extern PGDLLIMPORT volatile sig_atomic_t notifyInterruptPending; 21 | 22 | extern Size AsyncShmemSize(void); 23 | extern void AsyncShmemInit(void); 24 | 25 | extern void NotifyMyFrontEnd(const char *channel, 26 | const char *payload, 27 | int32 srcPid); 28 | 29 | /* notify-related SQL statements */ 30 | extern void Async_Notify(const char *channel, const char *payload); 31 | extern void Async_Listen(const char *channel); 32 | extern void Async_Unlisten(const char *channel); 33 | extern void Async_UnlistenAll(void); 34 | 35 | /* perform (or cancel) outbound notify processing at transaction commit */ 36 | extern void PreCommit_Notify(void); 37 | extern void AtCommit_Notify(void); 38 | extern void AtAbort_Notify(void); 39 | extern void AtSubCommit_Notify(void); 40 | extern void AtSubAbort_Notify(void); 41 | extern void AtPrepare_Notify(void); 42 | 43 | /* signal handler for inbound notifies (PROCSIG_NOTIFY_INTERRUPT) */ 44 | extern void HandleNotifyInterrupt(void); 45 | 46 | /* process interrupts */ 47 | extern void ProcessNotifyInterrupt(bool flush); 48 | 49 | #endif /* ASYNC_H */ 50 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/parser/parsetree.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * parsetree.h 4 | * Routines to access various components and subcomponents of 5 | * parse trees. 6 | * 7 | * 8 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 9 | * Portions Copyright (c) 1994, Regents of the University of California 10 | * 11 | * src/include/parser/parsetree.h 12 | * 13 | *------------------------------------------------------------------------- 14 | */ 15 | #ifndef PARSETREE_H 16 | #define PARSETREE_H 17 | 18 | #include "nodes/parsenodes.h" 19 | 20 | 21 | /* ---------------- 22 | * range table operations 23 | * ---------------- 24 | */ 25 | 26 | /* 27 | * rt_fetch 28 | * 29 | * NB: this will crash and burn if handed an out-of-range RT index 30 | */ 31 | #define rt_fetch(rangetable_index, rangetable) \ 32 | ((RangeTblEntry *) list_nth(rangetable, (rangetable_index)-1)) 33 | 34 | /* 35 | * Given an RTE and an attribute number, return the appropriate 36 | * variable name or alias for that attribute of that RTE. 37 | */ 38 | extern char *get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum); 39 | 40 | /* 41 | * Check whether an attribute of an RTE has been dropped 42 | */ 43 | extern bool get_rte_attribute_is_dropped(RangeTblEntry *rte, 44 | AttrNumber attnum); 45 | 46 | 47 | /* ---------------- 48 | * target list operations 49 | * ---------------- 50 | */ 51 | 52 | extern TargetEntry *get_tle_by_resno(List *tlist, AttrNumber resno); 53 | 54 | /* ---------------- 55 | * FOR UPDATE/SHARE info 56 | * ---------------- 57 | */ 58 | 59 | extern RowMarkClause *get_parse_rowmark(Query *qry, Index rtindex); 60 | 61 | #endif /* PARSETREE_H */ 62 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/xlogprefetcher.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * xlogprefetcher.h 4 | * Declarations for the recovery prefetching module. 5 | * 6 | * Portions Copyright (c) 2022-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * IDENTIFICATION 10 | * src/include/access/xlogprefetcher.h 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef XLOGPREFETCHER_H 14 | #define XLOGPREFETCHER_H 15 | 16 | #include "access/xlogdefs.h" 17 | #include "access/xlogreader.h" 18 | #include "access/xlogrecord.h" 19 | 20 | /* GUCs */ 21 | extern PGDLLIMPORT int recovery_prefetch; 22 | 23 | /* Possible values for recovery_prefetch */ 24 | typedef enum 25 | { 26 | RECOVERY_PREFETCH_OFF, 27 | RECOVERY_PREFETCH_ON, 28 | RECOVERY_PREFETCH_TRY, 29 | } RecoveryPrefetchValue; 30 | 31 | struct XLogPrefetcher; 32 | typedef struct XLogPrefetcher XLogPrefetcher; 33 | 34 | 35 | extern void XLogPrefetchReconfigure(void); 36 | 37 | extern size_t XLogPrefetchShmemSize(void); 38 | extern void XLogPrefetchShmemInit(void); 39 | 40 | extern void XLogPrefetchResetStats(void); 41 | 42 | extern XLogPrefetcher *XLogPrefetcherAllocate(XLogReaderState *reader); 43 | extern void XLogPrefetcherFree(XLogPrefetcher *prefetcher); 44 | 45 | extern XLogReaderState *XLogPrefetcherGetReader(XLogPrefetcher *prefetcher); 46 | 47 | extern void XLogPrefetcherBeginRead(XLogPrefetcher *prefetcher, 48 | XLogRecPtr recPtr); 49 | 50 | extern XLogRecord *XLogPrefetcherReadRecord(XLogPrefetcher *prefetcher, 51 | char **errmsg); 52 | 53 | extern void XLogPrefetcherComputeStats(XLogPrefetcher *prefetcher); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_opclass_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_opclass_d.h 4 | * Macro definitions for pg_opclass 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_OPCLASS_D_H 19 | #define PG_OPCLASS_D_H 20 | 21 | #define OperatorClassRelationId 2616 22 | #define OpclassAmNameNspIndexId 2686 23 | #define OpclassOidIndexId 2687 24 | 25 | #define Anum_pg_opclass_oid 1 26 | #define Anum_pg_opclass_opcmethod 2 27 | #define Anum_pg_opclass_opcname 3 28 | #define Anum_pg_opclass_opcnamespace 4 29 | #define Anum_pg_opclass_opcowner 5 30 | #define Anum_pg_opclass_opcfamily 6 31 | #define Anum_pg_opclass_opcintype 7 32 | #define Anum_pg_opclass_opcdefault 8 33 | #define Anum_pg_opclass_opckeytype 9 34 | 35 | #define Natts_pg_opclass 9 36 | 37 | #define DATE_BTREE_OPS_OID 3122 38 | #define FLOAT8_BTREE_OPS_OID 3123 39 | #define INT2_BTREE_OPS_OID 1979 40 | #define INT4_BTREE_OPS_OID 1978 41 | #define INT8_BTREE_OPS_OID 3124 42 | #define NUMERIC_BTREE_OPS_OID 3125 43 | #define OID_BTREE_OPS_OID 1981 44 | #define TEXT_BTREE_OPS_OID 3126 45 | #define TIMESTAMPTZ_BTREE_OPS_OID 3127 46 | #define TIMESTAMP_BTREE_OPS_OID 3128 47 | #define TEXT_BTREE_PATTERN_OPS_OID 4217 48 | #define VARCHAR_BTREE_PATTERN_OPS_OID 4218 49 | #define BPCHAR_BTREE_PATTERN_OPS_OID 4219 50 | 51 | #endif /* PG_OPCLASS_D_H */ 52 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/commands/user.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * user.h 4 | * Commands for manipulating roles (formerly called users). 5 | * 6 | * 7 | * src/include/commands/user.h 8 | * 9 | *------------------------------------------------------------------------- 10 | */ 11 | #ifndef USER_H 12 | #define USER_H 13 | 14 | #include "catalog/objectaddress.h" 15 | #include "libpq/crypt.h" 16 | #include "nodes/parsenodes.h" 17 | #include "parser/parse_node.h" 18 | #include "utils/guc.h" 19 | 20 | /* GUCs */ 21 | extern PGDLLIMPORT int Password_encryption; /* values from enum PasswordType */ 22 | extern PGDLLIMPORT char *createrole_self_grant; 23 | 24 | /* Hook to check passwords in CreateRole() and AlterRole() */ 25 | typedef void (*check_password_hook_type) (const char *username, const char *shadow_pass, PasswordType password_type, Datum validuntil_time, bool validuntil_null); 26 | 27 | extern PGDLLIMPORT check_password_hook_type check_password_hook; 28 | 29 | extern Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt); 30 | extern Oid AlterRole(ParseState *pstate, AlterRoleStmt *stmt); 31 | extern Oid AlterRoleSet(AlterRoleSetStmt *stmt); 32 | extern void DropRole(DropRoleStmt *stmt); 33 | extern void GrantRole(ParseState *pstate, GrantRoleStmt *stmt); 34 | extern ObjectAddress RenameRole(const char *oldname, const char *newname); 35 | extern void DropOwnedObjects(DropOwnedStmt *stmt); 36 | extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt); 37 | extern List *roleSpecsToIds(List *memberNames); 38 | 39 | extern bool check_createrole_self_grant(char **newval, void **extra, 40 | GucSource source); 41 | extern void assign_createrole_self_grant(const char *newval, void *extra); 42 | 43 | #endif /* USER_H */ 44 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/common/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * string.h 3 | * string handling helpers 4 | * 5 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 6 | * Portions Copyright (c) 1994, Regents of the University of California 7 | * 8 | * src/include/common/string.h 9 | */ 10 | #ifndef COMMON_STRING_H 11 | #define COMMON_STRING_H 12 | 13 | #include 14 | 15 | struct StringInfoData; /* avoid including stringinfo.h here */ 16 | 17 | typedef struct PromptInterruptContext 18 | { 19 | /* To avoid including here, jmpbuf is declared "void *" */ 20 | void *jmpbuf; /* existing longjmp buffer */ 21 | volatile sig_atomic_t *enabled; /* flag that enables longjmp-on-interrupt */ 22 | bool canceled; /* indicates whether cancellation occurred */ 23 | } PromptInterruptContext; 24 | 25 | /* functions in src/common/string.c */ 26 | extern bool pg_str_endswith(const char *str, const char *end); 27 | extern int strtoint(const char *pg_restrict str, char **pg_restrict endptr, 28 | int base); 29 | extern char *pg_clean_ascii(const char *str, int alloc_flags); 30 | extern int pg_strip_crlf(char *str); 31 | extern bool pg_is_ascii(const char *str); 32 | 33 | /* functions in src/common/pg_get_line.c */ 34 | extern char *pg_get_line(FILE *stream, PromptInterruptContext *prompt_ctx); 35 | extern bool pg_get_line_buf(FILE *stream, struct StringInfoData *buf); 36 | extern bool pg_get_line_append(FILE *stream, struct StringInfoData *buf, 37 | PromptInterruptContext *prompt_ctx); 38 | 39 | /* functions in src/common/sprompt.c */ 40 | extern char *simple_prompt(const char *prompt, bool echo); 41 | extern char *simple_prompt_extended(const char *prompt, bool echo, 42 | PromptInterruptContext *prompt_ctx); 43 | 44 | #endif /* COMMON_STRING_H */ 45 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/libpq/pqsignal.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pqsignal.h 4 | * Backend signal(2) support (see also src/port/pqsignal.c) 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/libpq/pqsignal.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef PQSIGNAL_H 14 | #define PQSIGNAL_H 15 | 16 | #include 17 | 18 | #ifdef WIN32 19 | /* Emulate POSIX sigset_t APIs on Windows */ 20 | typedef int sigset_t; 21 | 22 | #define SA_RESTART 1 23 | #define SA_NODEFER 2 24 | 25 | struct sigaction 26 | { 27 | void (*sa_handler) (int); 28 | /* sa_sigaction not yet implemented */ 29 | sigset_t sa_mask; 30 | int sa_flags; 31 | }; 32 | 33 | extern int pqsigprocmask(int how, const sigset_t *set, sigset_t *oset); 34 | extern int pqsigaction(int signum, const struct sigaction *act, 35 | struct sigaction *oldact); 36 | 37 | #define SIG_BLOCK 1 38 | #define SIG_UNBLOCK 2 39 | #define SIG_SETMASK 3 40 | #define sigprocmask(how, set, oset) pqsigprocmask((how), (set), (oset)) 41 | #define sigaction(signum, act, oldact) pqsigaction((signum), (act), (oldact)) 42 | #define sigemptyset(set) (*(set) = 0) 43 | #define sigfillset(set) (*(set) = ~0) 44 | #define sigaddset(set, signum) (*(set) |= (sigmask(signum))) 45 | #define sigdelset(set, signum) (*(set) &= ~(sigmask(signum))) 46 | #endif /* WIN32 */ 47 | 48 | extern PGDLLIMPORT sigset_t UnBlockSig; 49 | extern PGDLLIMPORT sigset_t BlockSig; 50 | extern PGDLLIMPORT sigset_t StartupBlockSig; 51 | 52 | extern void pqinitmask(void); 53 | 54 | #endif /* PQSIGNAL_H */ 55 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_opfamily_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_opfamily_d.h 4 | * Macro definitions for pg_opfamily 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_OPFAMILY_D_H 19 | #define PG_OPFAMILY_D_H 20 | 21 | #define OperatorFamilyRelationId 2753 22 | #define OpfamilyAmNameNspIndexId 2754 23 | #define OpfamilyOidIndexId 2755 24 | 25 | #define Anum_pg_opfamily_oid 1 26 | #define Anum_pg_opfamily_opfmethod 2 27 | #define Anum_pg_opfamily_opfname 3 28 | #define Anum_pg_opfamily_opfnamespace 4 29 | #define Anum_pg_opfamily_opfowner 5 30 | 31 | #define Natts_pg_opfamily 5 32 | 33 | 34 | /* This does not account for non-core opfamilies that might accept boolean */ 35 | #define IsBuiltinBooleanOpfamily(opfamily) \ 36 | ((opfamily) == BOOL_BTREE_FAM_OID || (opfamily) == BOOL_HASH_FAM_OID) 37 | 38 | #define BOOL_BTREE_FAM_OID 424 39 | #define BPCHAR_BTREE_FAM_OID 426 40 | #define BYTEA_BTREE_FAM_OID 428 41 | #define NETWORK_BTREE_FAM_OID 1974 42 | #define INTEGER_BTREE_FAM_OID 1976 43 | #define INTERVAL_BTREE_FAM_OID 1982 44 | #define OID_BTREE_FAM_OID 1989 45 | #define TEXT_BTREE_FAM_OID 1994 46 | #define TEXT_PATTERN_BTREE_FAM_OID 2095 47 | #define BPCHAR_PATTERN_BTREE_FAM_OID 2097 48 | #define BOOL_HASH_FAM_OID 2222 49 | #define TEXT_SPGIST_FAM_OID 4017 50 | 51 | #endif /* PG_OPFAMILY_D_H */ 52 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/storage/off.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * off.h 4 | * POSTGRES disk "offset" definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/storage/off.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef OFF_H 15 | #define OFF_H 16 | 17 | #include "storage/itemid.h" 18 | /* 19 | * OffsetNumber: 20 | * 21 | * this is a 1-based index into the linp (ItemIdData) array in the 22 | * header of each disk page. 23 | */ 24 | typedef uint16 OffsetNumber; 25 | 26 | #define InvalidOffsetNumber ((OffsetNumber) 0) 27 | #define FirstOffsetNumber ((OffsetNumber) 1) 28 | #define MaxOffsetNumber ((OffsetNumber) (BLCKSZ / sizeof(ItemIdData))) 29 | 30 | /* ---------------- 31 | * support macros 32 | * ---------------- 33 | */ 34 | 35 | /* 36 | * OffsetNumberIsValid 37 | * True iff the offset number is valid. 38 | */ 39 | #define OffsetNumberIsValid(offsetNumber) \ 40 | ((bool) ((offsetNumber != InvalidOffsetNumber) && \ 41 | (offsetNumber <= MaxOffsetNumber))) 42 | 43 | /* 44 | * OffsetNumberNext 45 | * OffsetNumberPrev 46 | * Increments/decrements the argument. These macros look pointless 47 | * but they help us disambiguate the different manipulations on 48 | * OffsetNumbers (e.g., sometimes we subtract one from an 49 | * OffsetNumber to move back, and sometimes we do so to form a 50 | * real C array index). 51 | */ 52 | #define OffsetNumberNext(offsetNumber) \ 53 | ((OffsetNumber) (1 + (offsetNumber))) 54 | #define OffsetNumberPrev(offsetNumber) \ 55 | ((OffsetNumber) (-1 + (offsetNumber))) 56 | 57 | #endif /* OFF_H */ 58 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/pl_reserved_kwlist.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pl_reserved_kwlist.h 4 | * 5 | * The keyword lists are kept in their own source files for use by 6 | * automatic tools. The exact representation of a keyword is determined 7 | * by the PG_KEYWORD macro, which is not defined in this file; it can 8 | * be defined by the caller for special purposes. 9 | * 10 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 11 | * Portions Copyright (c) 1994, Regents of the University of California 12 | * 13 | * src/pl/plpgsql/src/pl_reserved_kwlist.h 14 | * 15 | *------------------------------------------------------------------------- 16 | */ 17 | 18 | /* There is deliberately not an #ifndef PL_RESERVED_KWLIST_H here. */ 19 | 20 | /* 21 | * List of (keyword-name, keyword-token-value) pairs. 22 | * 23 | * Be careful not to put the same word into pl_unreserved_kwlist.h. 24 | * 25 | * Note: gen_keywordlist.pl requires the entries to appear in ASCII order. 26 | */ 27 | 28 | /* name, value */ 29 | PG_KEYWORD("all", K_ALL) 30 | PG_KEYWORD("begin", K_BEGIN) 31 | PG_KEYWORD("by", K_BY) 32 | PG_KEYWORD("case", K_CASE) 33 | PG_KEYWORD("declare", K_DECLARE) 34 | PG_KEYWORD("else", K_ELSE) 35 | PG_KEYWORD("end", K_END) 36 | PG_KEYWORD("execute", K_EXECUTE) 37 | PG_KEYWORD("for", K_FOR) 38 | PG_KEYWORD("foreach", K_FOREACH) 39 | PG_KEYWORD("from", K_FROM) 40 | PG_KEYWORD("if", K_IF) 41 | PG_KEYWORD("in", K_IN) 42 | PG_KEYWORD("into", K_INTO) 43 | PG_KEYWORD("loop", K_LOOP) 44 | PG_KEYWORD("not", K_NOT) 45 | PG_KEYWORD("null", K_NULL) 46 | PG_KEYWORD("or", K_OR) 47 | PG_KEYWORD("strict", K_STRICT) 48 | PG_KEYWORD("then", K_THEN) 49 | PG_KEYWORD("to", K_TO) 50 | PG_KEYWORD("using", K_USING) 51 | PG_KEYWORD("when", K_WHEN) 52 | PG_KEYWORD("while", K_WHILE) 53 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/attnum.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * attnum.h 4 | * POSTGRES attribute number definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/access/attnum.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef ATTNUM_H 15 | #define ATTNUM_H 16 | 17 | 18 | /* 19 | * user defined attribute numbers start at 1. -ay 2/95 20 | */ 21 | typedef int16 AttrNumber; 22 | 23 | #define InvalidAttrNumber 0 24 | #define MaxAttrNumber 32767 25 | 26 | /* ---------------- 27 | * support macros 28 | * ---------------- 29 | */ 30 | /* 31 | * AttributeNumberIsValid 32 | * True iff the attribute number is valid. 33 | */ 34 | #define AttributeNumberIsValid(attributeNumber) \ 35 | ((bool) ((attributeNumber) != InvalidAttrNumber)) 36 | 37 | /* 38 | * AttrNumberIsForUserDefinedAttr 39 | * True iff the attribute number corresponds to a user defined attribute. 40 | */ 41 | #define AttrNumberIsForUserDefinedAttr(attributeNumber) \ 42 | ((bool) ((attributeNumber) > 0)) 43 | 44 | /* 45 | * AttrNumberGetAttrOffset 46 | * Returns the attribute offset for an attribute number. 47 | * 48 | * Note: 49 | * Assumes the attribute number is for a user defined attribute. 50 | */ 51 | #define AttrNumberGetAttrOffset(attNum) \ 52 | ( \ 53 | AssertMacro(AttrNumberIsForUserDefinedAttr(attNum)), \ 54 | ((attNum) - 1) \ 55 | ) 56 | 57 | /* 58 | * AttrOffsetGetAttrNumber 59 | * Returns the attribute number for an attribute offset. 60 | */ 61 | #define AttrOffsetGetAttrNumber(attributeOffset) \ 62 | ((AttrNumber) (1 + (attributeOffset))) 63 | 64 | #endif /* ATTNUM_H */ 65 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_transform.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_transform.h 4 | * definition of the "transform" system catalog (pg_transform) 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/catalog/pg_transform.h 11 | * 12 | * NOTES 13 | * The Catalog.pm module reads this file and derives schema 14 | * information. 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_TRANSFORM_H 19 | #define PG_TRANSFORM_H 20 | 21 | #include "catalog/genbki.h" 22 | #include "catalog/pg_transform_d.h" 23 | 24 | /* ---------------- 25 | * pg_transform definition. cpp turns this into 26 | * typedef struct FormData_pg_transform 27 | * ---------------- 28 | */ 29 | CATALOG(pg_transform,3576,TransformRelationId) 30 | { 31 | Oid oid; /* oid */ 32 | Oid trftype BKI_LOOKUP(pg_type); 33 | Oid trflang BKI_LOOKUP(pg_language); 34 | regproc trffromsql BKI_LOOKUP_OPT(pg_proc); 35 | regproc trftosql BKI_LOOKUP_OPT(pg_proc); 36 | } FormData_pg_transform; 37 | 38 | /* ---------------- 39 | * Form_pg_transform corresponds to a pointer to a tuple with 40 | * the format of pg_transform relation. 41 | * ---------------- 42 | */ 43 | typedef FormData_pg_transform *Form_pg_transform; 44 | 45 | DECLARE_UNIQUE_INDEX_PKEY(pg_transform_oid_index, 3574, TransformOidIndexId, pg_transform, btree(oid oid_ops)); 46 | DECLARE_UNIQUE_INDEX(pg_transform_type_lang_index, 3575, TransformTypeLangIndexId, pg_transform, btree(trftype oid_ops, trflang oid_ops)); 47 | 48 | MAKE_SYSCACHE(TRFOID, pg_transform_oid_index, 16); 49 | MAKE_SYSCACHE(TRFTYPELANG, pg_transform_type_lang_index, 16); 50 | 51 | #endif /* PG_TRANSFORM_H */ 52 | -------------------------------------------------------------------------------- /internal/cparser/src_backend_nodes_value.c: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | * Symbols referenced in this file: 3 | * - makeString 4 | * - makeBoolean 5 | * - makeInteger 6 | * - makeFloat 7 | * - makeBitString 8 | *-------------------------------------------------------------------- 9 | */ 10 | 11 | /*------------------------------------------------------------------------- 12 | * 13 | * value.c 14 | * implementation of value nodes 15 | * 16 | * 17 | * Copyright (c) 2003-2024, PostgreSQL Global Development Group 18 | * 19 | * 20 | * IDENTIFICATION 21 | * src/backend/nodes/value.c 22 | * 23 | *------------------------------------------------------------------------- 24 | */ 25 | #include "postgres.h" 26 | 27 | #include "nodes/value.h" 28 | 29 | /* 30 | * makeInteger 31 | */ 32 | Integer * 33 | makeInteger(int i) 34 | { 35 | Integer *v = makeNode(Integer); 36 | 37 | v->ival = i; 38 | return v; 39 | } 40 | 41 | /* 42 | * makeFloat 43 | * 44 | * Caller is responsible for passing a palloc'd string. 45 | */ 46 | Float * 47 | makeFloat(char *numericStr) 48 | { 49 | Float *v = makeNode(Float); 50 | 51 | v->fval = numericStr; 52 | return v; 53 | } 54 | 55 | /* 56 | * makeBoolean 57 | */ 58 | Boolean * 59 | makeBoolean(bool val) 60 | { 61 | Boolean *v = makeNode(Boolean); 62 | 63 | v->boolval = val; 64 | return v; 65 | } 66 | 67 | /* 68 | * makeString 69 | * 70 | * Caller is responsible for passing a palloc'd string. 71 | */ 72 | String * 73 | makeString(char *str) 74 | { 75 | String *v = makeNode(String); 76 | 77 | v->sval = str; 78 | return v; 79 | } 80 | 81 | /* 82 | * makeBitString 83 | * 84 | * Caller is responsible for passing a palloc'd string. 85 | */ 86 | BitString * 87 | makeBitString(char *str) 88 | { 89 | BitString *v = makeNode(BitString); 90 | 91 | v->bsval = str; 92 | return v; 93 | } 94 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_database_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_database_d.h 4 | * Macro definitions for pg_database 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_DATABASE_D_H 19 | #define PG_DATABASE_D_H 20 | 21 | #define DatabaseRelationId 1262 22 | #define DatabaseRelation_Rowtype_Id 1248 23 | #define PgDatabaseToastTable 4177 24 | #define PgDatabaseToastIndex 4178 25 | #define DatabaseNameIndexId 2671 26 | #define DatabaseOidIndexId 2672 27 | #define Template0DbOid 4 28 | #define PostgresDbOid 5 29 | 30 | #define Anum_pg_database_oid 1 31 | #define Anum_pg_database_datname 2 32 | #define Anum_pg_database_datdba 3 33 | #define Anum_pg_database_encoding 4 34 | #define Anum_pg_database_datlocprovider 5 35 | #define Anum_pg_database_datistemplate 6 36 | #define Anum_pg_database_datallowconn 7 37 | #define Anum_pg_database_dathasloginevt 8 38 | #define Anum_pg_database_datconnlimit 9 39 | #define Anum_pg_database_datfrozenxid 10 40 | #define Anum_pg_database_datminmxid 11 41 | #define Anum_pg_database_dattablespace 12 42 | #define Anum_pg_database_datcollate 13 43 | #define Anum_pg_database_datctype 14 44 | #define Anum_pg_database_datlocale 15 45 | #define Anum_pg_database_daticurules 16 46 | #define Anum_pg_database_datcollversion 17 47 | #define Anum_pg_database_datacl 18 48 | 49 | #define Natts_pg_database 18 50 | 51 | #define Template1DbOid 1 52 | 53 | #endif /* PG_DATABASE_D_H */ 54 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_ts_config.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_ts_config.h 4 | * definition of the "text search configuration" system catalog 5 | * (pg_ts_config) 6 | * 7 | * 8 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 9 | * Portions Copyright (c) 1994, Regents of the University of California 10 | * 11 | * src/include/catalog/pg_ts_config.h 12 | * 13 | * NOTES 14 | * The Catalog.pm module reads this file and derives schema 15 | * information. 16 | * 17 | *------------------------------------------------------------------------- 18 | */ 19 | #ifndef PG_TS_CONFIG_H 20 | #define PG_TS_CONFIG_H 21 | 22 | #include "catalog/genbki.h" 23 | #include "catalog/pg_ts_config_d.h" 24 | 25 | /* ---------------- 26 | * pg_ts_config definition. cpp turns this into 27 | * typedef struct FormData_pg_ts_config 28 | * ---------------- 29 | */ 30 | CATALOG(pg_ts_config,3602,TSConfigRelationId) 31 | { 32 | /* oid */ 33 | Oid oid; 34 | 35 | /* name of configuration */ 36 | NameData cfgname; 37 | 38 | /* name space */ 39 | Oid cfgnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace); 40 | 41 | /* owner */ 42 | Oid cfgowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid); 43 | 44 | /* OID of parser */ 45 | Oid cfgparser BKI_LOOKUP(pg_ts_parser); 46 | } FormData_pg_ts_config; 47 | 48 | typedef FormData_pg_ts_config *Form_pg_ts_config; 49 | 50 | DECLARE_UNIQUE_INDEX(pg_ts_config_cfgname_index, 3608, TSConfigNameNspIndexId, pg_ts_config, btree(cfgname name_ops, cfgnamespace oid_ops)); 51 | DECLARE_UNIQUE_INDEX_PKEY(pg_ts_config_oid_index, 3712, TSConfigOidIndexId, pg_ts_config, btree(oid oid_ops)); 52 | 53 | MAKE_SYSCACHE(TSCONFIGNAMENSP, pg_ts_config_cfgname_index, 2); 54 | MAKE_SYSCACHE(TSCONFIGOID, pg_ts_config_oid_index, 2); 55 | 56 | #endif /* PG_TS_CONFIG_H */ 57 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/storage/proclist_types.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * proclist_types.h 4 | * doubly-linked lists of pgprocnos 5 | * 6 | * See proclist.h for functions that operate on these types. 7 | * 8 | * Portions Copyright (c) 2016-2024, PostgreSQL Global Development Group 9 | * 10 | * IDENTIFICATION 11 | * src/include/storage/proclist_types.h 12 | *------------------------------------------------------------------------- 13 | */ 14 | 15 | #ifndef PROCLIST_TYPES_H 16 | #define PROCLIST_TYPES_H 17 | 18 | #include "storage/procnumber.h" 19 | 20 | /* 21 | * A node in a doubly-linked list of processes. The link fields contain 22 | * the 0-based PGPROC indexes of the next and previous process, or 23 | * INVALID_PROC_NUMBER in the next-link of the last node and the prev-link 24 | * of the first node. A node that is currently not in any list 25 | * should have next == prev == 0; this is not a possible state for a node 26 | * that is in a list, because we disallow circularity. 27 | */ 28 | typedef struct proclist_node 29 | { 30 | ProcNumber next; /* pgprocno of the next PGPROC */ 31 | ProcNumber prev; /* pgprocno of the prev PGPROC */ 32 | } proclist_node; 33 | 34 | /* 35 | * Header of a doubly-linked list of PGPROCs, identified by pgprocno. 36 | * An empty list is represented by head == tail == INVALID_PROC_NUMBER. 37 | */ 38 | typedef struct proclist_head 39 | { 40 | ProcNumber head; /* pgprocno of the head PGPROC */ 41 | ProcNumber tail; /* pgprocno of the tail PGPROC */ 42 | } proclist_head; 43 | 44 | /* 45 | * List iterator allowing some modifications while iterating. 46 | */ 47 | typedef struct proclist_mutable_iter 48 | { 49 | ProcNumber cur; /* pgprocno of the current PGPROC */ 50 | ProcNumber next; /* pgprocno of the next PGPROC */ 51 | } proclist_mutable_iter; 52 | 53 | #endif /* PROCLIST_TYPES_H */ 54 | -------------------------------------------------------------------------------- /normalize_test.go: -------------------------------------------------------------------------------- 1 | package pg_query_test 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | 7 | pg_query "github.com/wasilibs/go-pgquery" 8 | "github.com/wasilibs/go-pgquery/parser" 9 | ) 10 | 11 | var normalizeTests = []struct { 12 | input string 13 | expected string 14 | }{ 15 | { 16 | "SELECT 1", 17 | "SELECT $1", 18 | }, 19 | } 20 | 21 | func TestNormalize(t *testing.T) { 22 | for _, test := range normalizeTests { 23 | actual, err := pg_query.Normalize(test.input) 24 | 25 | if err != nil { 26 | t.Errorf("Normalize(%s)\nerror %s\n\n", test.input, err) 27 | } else if !reflect.DeepEqual(actual, test.expected) { 28 | t.Errorf("Normalize(%s)\nexpected %s\nactual %s\n\n", test.input, test.expected, actual) 29 | } 30 | } 31 | } 32 | 33 | var normalizeErrorTests = []struct { 34 | input string 35 | expectedErr error 36 | }{ 37 | { 38 | "SELECT $", 39 | &parser.Error{ 40 | Message: "syntax error at or near \"$\"", 41 | Cursorpos: 8, 42 | Filename: "scan.l", 43 | Funcname: "scanner_yyerror", 44 | }, 45 | }, 46 | } 47 | 48 | func TestNormalizeError(t *testing.T) { 49 | for _, test := range normalizeErrorTests { 50 | _, actualErr := pg_query.Normalize(test.input) 51 | 52 | if actualErr == nil { 53 | t.Errorf("Normalize(%s)\nexpected error but none returned\n\n", test.input) 54 | } else { 55 | exp := test.expectedErr.(*parser.Error) 56 | act := actualErr.(*parser.Error) 57 | act.Lineno = 0 // Line number is architecture dependent, so we ignore it 58 | if !reflect.DeepEqual(act, exp) { 59 | t.Errorf( 60 | "Normalize(%s)\nexpected error %s at %d (%s:%d), func: %s, context: %s\nactual error %+v at %d (%s:%d), func: %s, context: %s\n\n", 61 | test.input, 62 | exp.Message, exp.Cursorpos, exp.Filename, exp.Lineno, exp.Funcname, exp.Context, 63 | act.Message, act.Cursorpos, act.Filename, act.Lineno, act.Funcname, act.Context) 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/tidstore.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * tidstore.h 4 | * TidStore interface. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/access/tidstore.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef TIDSTORE_H 15 | #define TIDSTORE_H 16 | 17 | #include "storage/itemptr.h" 18 | #include "utils/dsa.h" 19 | 20 | typedef struct TidStore TidStore; 21 | typedef struct TidStoreIter TidStoreIter; 22 | 23 | /* Result struct for TidStoreIterateNext */ 24 | typedef struct TidStoreIterResult 25 | { 26 | BlockNumber blkno; 27 | int max_offset; 28 | int num_offsets; 29 | OffsetNumber *offsets; 30 | } TidStoreIterResult; 31 | 32 | extern TidStore *TidStoreCreateLocal(size_t max_bytes, bool insert_only); 33 | extern TidStore *TidStoreCreateShared(size_t max_bytes, int tranche_id); 34 | extern TidStore *TidStoreAttach(dsa_handle area_handle, dsa_pointer handle); 35 | extern void TidStoreDetach(TidStore *ts); 36 | extern void TidStoreLockExclusive(TidStore *ts); 37 | extern void TidStoreLockShare(TidStore *ts); 38 | extern void TidStoreUnlock(TidStore *ts); 39 | extern void TidStoreDestroy(TidStore *ts); 40 | extern void TidStoreSetBlockOffsets(TidStore *ts, BlockNumber blkno, OffsetNumber *offsets, 41 | int num_offsets); 42 | extern bool TidStoreIsMember(TidStore *ts, ItemPointer tid); 43 | extern TidStoreIter *TidStoreBeginIterate(TidStore *ts); 44 | extern TidStoreIterResult *TidStoreIterateNext(TidStoreIter *iter); 45 | extern void TidStoreEndIterate(TidStoreIter *iter); 46 | extern size_t TidStoreMemoryUsage(TidStore *ts); 47 | extern dsa_pointer TidStoreGetHandle(TidStore *ts); 48 | extern dsa_area *TidStoreGetDSA(TidStore *ts); 49 | 50 | #endif /* TIDSTORE_H */ 51 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_ts_template.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_ts_template.h 4 | * definition of the "text search template" system catalog (pg_ts_template) 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/catalog/pg_ts_template.h 11 | * 12 | * NOTES 13 | * The Catalog.pm module reads this file and derives schema 14 | * information. 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_TS_TEMPLATE_H 19 | #define PG_TS_TEMPLATE_H 20 | 21 | #include "catalog/genbki.h" 22 | #include "catalog/pg_ts_template_d.h" 23 | 24 | /* ---------------- 25 | * pg_ts_template definition. cpp turns this into 26 | * typedef struct FormData_pg_ts_template 27 | * ---------------- 28 | */ 29 | CATALOG(pg_ts_template,3764,TSTemplateRelationId) 30 | { 31 | Oid oid; /* oid */ 32 | 33 | /* template name */ 34 | NameData tmplname; 35 | 36 | /* name space */ 37 | Oid tmplnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace); 38 | 39 | /* initialization method of dict (may be 0) */ 40 | regproc tmplinit BKI_LOOKUP_OPT(pg_proc); 41 | 42 | /* base method of dictionary */ 43 | regproc tmpllexize BKI_LOOKUP(pg_proc); 44 | } FormData_pg_ts_template; 45 | 46 | typedef FormData_pg_ts_template *Form_pg_ts_template; 47 | 48 | DECLARE_UNIQUE_INDEX(pg_ts_template_tmplname_index, 3766, TSTemplateNameNspIndexId, pg_ts_template, btree(tmplname name_ops, tmplnamespace oid_ops)); 49 | DECLARE_UNIQUE_INDEX_PKEY(pg_ts_template_oid_index, 3767, TSTemplateOidIndexId, pg_ts_template, btree(oid oid_ops)); 50 | 51 | MAKE_SYSCACHE(TSTEMPLATENAMENSP, pg_ts_template_tmplname_index, 2); 52 | MAKE_SYSCACHE(TSTEMPLATEOID, pg_ts_template_oid_index, 2); 53 | 54 | #endif /* PG_TS_TEMPLATE_H */ 55 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/attmap.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * attmap.h 4 | * Definitions for PostgreSQL attribute mappings 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/access/attmap.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef ATTMAP_H 15 | #define ATTMAP_H 16 | 17 | #include "access/attnum.h" 18 | #include "access/tupdesc.h" 19 | 20 | /* 21 | * Attribute mapping structure 22 | * 23 | * This maps attribute numbers between a pair of relations, designated 24 | * 'input' and 'output' (most typically inheritance parent and child 25 | * relations), whose common columns may have different attribute numbers. 26 | * Such difference may arise due to the columns being ordered differently 27 | * in the two relations or the two relations having dropped columns at 28 | * different positions. 29 | * 30 | * 'maplen' is set to the number of attributes of the 'output' relation, 31 | * taking into account any of its dropped attributes, with the corresponding 32 | * elements of the 'attnums' array set to 0. 33 | */ 34 | typedef struct AttrMap 35 | { 36 | AttrNumber *attnums; 37 | int maplen; 38 | } AttrMap; 39 | 40 | extern AttrMap *make_attrmap(int maplen); 41 | extern void free_attrmap(AttrMap *map); 42 | 43 | /* Conversion routines to build mappings */ 44 | extern AttrMap *build_attrmap_by_name(TupleDesc indesc, 45 | TupleDesc outdesc, 46 | bool missing_ok); 47 | extern AttrMap *build_attrmap_by_name_if_req(TupleDesc indesc, 48 | TupleDesc outdesc, 49 | bool missing_ok); 50 | extern AttrMap *build_attrmap_by_position(TupleDesc indesc, 51 | TupleDesc outdesc, 52 | const char *msg); 53 | 54 | #endif /* ATTMAP_H */ 55 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/port/win32.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32.h */ 2 | 3 | /* 4 | * We always rely on the WIN32 macro being set by our build system, 5 | * but _WIN32 is the compiler pre-defined macro. So make sure we define 6 | * WIN32 whenever _WIN32 is set, to facilitate standalone building. 7 | */ 8 | #if defined(_WIN32) && !defined(WIN32) 9 | #define WIN32 10 | #endif 11 | 12 | /* 13 | * Make sure _WIN32_WINNT has the minimum required value. 14 | * Leave a higher value in place. The minimum requirement is Windows 10. 15 | */ 16 | #ifdef _WIN32_WINNT 17 | #undef _WIN32_WINNT 18 | #endif 19 | 20 | #define _WIN32_WINNT 0x0A00 21 | 22 | /* 23 | * We need to prevent from defining a symbol conflicting with 24 | * our errcode() function. Since it's likely to get included by standard 25 | * system headers, pre-emptively include it now. 26 | */ 27 | #if defined(_MSC_VER) || defined(HAVE_CRTDEFS_H) 28 | #define errcode __msvc_errcode 29 | #include 30 | #undef errcode 31 | #endif 32 | 33 | /* 34 | * defines for dynamic linking on Win32 platform 35 | */ 36 | 37 | /* 38 | * Variables declared in the core backend and referenced by loadable 39 | * modules need to be marked "dllimport" in the core build, but 40 | * "dllexport" when the declaration is read in a loadable module. 41 | * No special markings should be used when compiling frontend code. 42 | */ 43 | #ifndef FRONTEND 44 | #ifdef BUILDING_DLL 45 | #define PGDLLIMPORT __declspec (dllexport) 46 | #else 47 | #define PGDLLIMPORT __declspec (dllimport) 48 | #endif 49 | #endif 50 | 51 | /* 52 | * Functions exported by a loadable module must be marked "dllexport". 53 | * 54 | * While mingw would otherwise fall back to 55 | * __attribute__((visibility("default"))), that appears to only work as long 56 | * as no symbols are declared with __declspec(dllexport). But we can end up 57 | * with some, e.g. plpython's Py_Init. 58 | */ 59 | #define PGDLLEXPORT __declspec (dllexport) 60 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_am.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_am.h 4 | * definition of the "access method" system catalog (pg_am) 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/catalog/pg_am.h 11 | * 12 | * NOTES 13 | * The Catalog.pm module reads this file and derives schema 14 | * information. 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_AM_H 19 | #define PG_AM_H 20 | 21 | #include "catalog/genbki.h" 22 | #include "catalog/pg_am_d.h" 23 | 24 | /* ---------------- 25 | * pg_am definition. cpp turns this into 26 | * typedef struct FormData_pg_am 27 | * ---------------- 28 | */ 29 | CATALOG(pg_am,2601,AccessMethodRelationId) 30 | { 31 | Oid oid; /* oid */ 32 | 33 | /* access method name */ 34 | NameData amname; 35 | 36 | /* handler function */ 37 | regproc amhandler BKI_LOOKUP(pg_proc); 38 | 39 | /* see AMTYPE_xxx constants below */ 40 | char amtype; 41 | } FormData_pg_am; 42 | 43 | /* ---------------- 44 | * Form_pg_am corresponds to a pointer to a tuple with 45 | * the format of pg_am relation. 46 | * ---------------- 47 | */ 48 | typedef FormData_pg_am *Form_pg_am; 49 | 50 | DECLARE_UNIQUE_INDEX(pg_am_name_index, 2651, AmNameIndexId, pg_am, btree(amname name_ops)); 51 | DECLARE_UNIQUE_INDEX_PKEY(pg_am_oid_index, 2652, AmOidIndexId, pg_am, btree(oid oid_ops)); 52 | 53 | MAKE_SYSCACHE(AMNAME, pg_am_name_index, 4); 54 | MAKE_SYSCACHE(AMOID, pg_am_oid_index, 4); 55 | 56 | #ifdef EXPOSE_TO_CLIENT_CODE 57 | 58 | /* 59 | * Allowed values for amtype 60 | */ 61 | #define AMTYPE_INDEX 'i' /* index access method */ 62 | #define AMTYPE_TABLE 't' /* table access method */ 63 | 64 | #endif /* EXPOSE_TO_CLIENT_CODE */ 65 | 66 | #endif /* PG_AM_H */ 67 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/pg_getopt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Postgres files that use getopt(3) always include this file. 3 | * We must cope with three different scenarios: 4 | * 1. We're using the platform's getopt(), and we should just import the 5 | * appropriate declarations. 6 | * 2. The platform lacks getopt(), and we must declare everything. 7 | * 3. The platform has getopt(), but we're not using it because we don't 8 | * like its behavior. The declarations we make here must be compatible 9 | * with both the platform's getopt() and our src/port/getopt.c. 10 | * 11 | * Portions Copyright (c) 1987, 1993, 1994 12 | * The Regents of the University of California. All rights reserved. 13 | * 14 | * Portions Copyright (c) 2003-2024, PostgreSQL Global Development Group 15 | * 16 | * src/include/pg_getopt.h 17 | */ 18 | #ifndef PG_GETOPT_H 19 | #define PG_GETOPT_H 20 | 21 | /* POSIX says getopt() is provided by unistd.h */ 22 | #include 23 | 24 | /* rely on the system's getopt.h if present */ 25 | #ifdef HAVE_GETOPT_H 26 | #include 27 | #endif 28 | 29 | /* 30 | * If we have , assume it declares these variables, else do that 31 | * ourselves. (We used to just declare them unconditionally, but Cygwin 32 | * doesn't like that.) 33 | */ 34 | #ifndef HAVE_GETOPT_H 35 | 36 | extern PGDLLIMPORT char *optarg; 37 | extern PGDLLIMPORT int optind; 38 | extern PGDLLIMPORT int opterr; 39 | extern PGDLLIMPORT int optopt; 40 | 41 | #endif /* HAVE_GETOPT_H */ 42 | 43 | /* 44 | * Some platforms have optreset but fail to declare it in , so cope. 45 | * Cygwin, however, doesn't like this either. 46 | */ 47 | #if defined(HAVE_INT_OPTRESET) && !defined(__CYGWIN__) 48 | extern PGDLLIMPORT int optreset; 49 | #endif 50 | 51 | /* Provide getopt() declaration if the platform doesn't have it */ 52 | #ifndef HAVE_GETOPT 53 | extern int getopt(int nargc, char *const *nargv, const char *ostr); 54 | #endif 55 | 56 | #endif /* PG_GETOPT_H */ 57 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/common/file_perm.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * File and directory permission definitions 4 | * 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/common/file_perm.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef FILE_PERM_H 14 | #define FILE_PERM_H 15 | 16 | #include 17 | 18 | /* 19 | * Mode mask for data directory permissions that only allows the owner to 20 | * read/write directories and files. 21 | * 22 | * This is the default. 23 | */ 24 | #define PG_MODE_MASK_OWNER (S_IRWXG | S_IRWXO) 25 | 26 | /* 27 | * Mode mask for data directory permissions that also allows group read/execute. 28 | */ 29 | #define PG_MODE_MASK_GROUP (S_IWGRP | S_IRWXO) 30 | 31 | /* Default mode for creating directories */ 32 | #define PG_DIR_MODE_OWNER S_IRWXU 33 | 34 | /* Mode for creating directories that allows group read/execute */ 35 | #define PG_DIR_MODE_GROUP (S_IRWXU | S_IRGRP | S_IXGRP) 36 | 37 | /* Default mode for creating files */ 38 | #define PG_FILE_MODE_OWNER (S_IRUSR | S_IWUSR) 39 | 40 | /* Mode for creating files that allows group read */ 41 | #define PG_FILE_MODE_GROUP (S_IRUSR | S_IWUSR | S_IRGRP) 42 | 43 | /* Modes for creating directories and files in the data directory */ 44 | extern PGDLLIMPORT int pg_dir_create_mode; 45 | extern PGDLLIMPORT int pg_file_create_mode; 46 | 47 | /* Mode mask to pass to umask() */ 48 | extern PGDLLIMPORT int pg_mode_mask; 49 | 50 | /* Set permissions and mask based on the provided mode */ 51 | extern void SetDataDirectoryCreatePerm(int dataDirMode); 52 | 53 | /* Set permissions and mask based on the mode of the data directory */ 54 | extern bool GetDataDirectoryCreatePerm(const char *dataDir); 55 | 56 | #endif /* FILE_PERM_H */ 57 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/tcop/cmdtag.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * cmdtag.h 4 | * Declarations for commandtag names and enumeration. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/tcop/cmdtag.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef CMDTAG_H 14 | #define CMDTAG_H 15 | 16 | /* buffer size required for command completion tags */ 17 | #define COMPLETION_TAG_BUFSIZE 64 18 | 19 | #define PG_CMDTAG(tag, name, evtrgok, rwrok, rowcnt) \ 20 | tag, 21 | 22 | typedef enum CommandTag 23 | { 24 | #include "tcop/cmdtaglist.h" 25 | } CommandTag; 26 | 27 | #undef PG_CMDTAG 28 | 29 | typedef struct QueryCompletion 30 | { 31 | CommandTag commandTag; 32 | uint64 nprocessed; 33 | } QueryCompletion; 34 | 35 | 36 | static inline void 37 | SetQueryCompletion(QueryCompletion *qc, CommandTag commandTag, 38 | uint64 nprocessed) 39 | { 40 | qc->commandTag = commandTag; 41 | qc->nprocessed = nprocessed; 42 | } 43 | 44 | static inline void 45 | CopyQueryCompletion(QueryCompletion *dst, const QueryCompletion *src) 46 | { 47 | dst->commandTag = src->commandTag; 48 | dst->nprocessed = src->nprocessed; 49 | } 50 | 51 | 52 | extern void InitializeQueryCompletion(QueryCompletion *qc); 53 | extern const char *GetCommandTagName(CommandTag commandTag); 54 | extern const char *GetCommandTagNameAndLen(CommandTag commandTag, Size *len); 55 | extern bool command_tag_display_rowcount(CommandTag commandTag); 56 | extern bool command_tag_event_trigger_ok(CommandTag commandTag); 57 | extern bool command_tag_table_rewrite_ok(CommandTag commandTag); 58 | extern CommandTag GetCommandTagEnum(const char *commandname); 59 | extern Size BuildQueryCompletionString(char *buff, const QueryCompletion *qc, 60 | bool nameonly); 61 | 62 | #endif /* CMDTAG_H */ 63 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/storage.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * storage.h 4 | * prototypes for functions in backend/catalog/storage.c 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/catalog/storage.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef STORAGE_H 15 | #define STORAGE_H 16 | 17 | #include "storage/block.h" 18 | #include "storage/relfilelocator.h" 19 | #include "storage/smgr.h" 20 | #include "utils/relcache.h" 21 | 22 | /* GUC variables */ 23 | extern PGDLLIMPORT int wal_skip_threshold; 24 | 25 | extern SMgrRelation RelationCreateStorage(RelFileLocator rlocator, 26 | char relpersistence, 27 | bool register_delete); 28 | extern void RelationDropStorage(Relation rel); 29 | extern void RelationPreserveStorage(RelFileLocator rlocator, bool atCommit); 30 | extern void RelationPreTruncate(Relation rel); 31 | extern void RelationTruncate(Relation rel, BlockNumber nblocks); 32 | extern void RelationCopyStorage(SMgrRelation src, SMgrRelation dst, 33 | ForkNumber forkNum, char relpersistence); 34 | extern bool RelFileLocatorSkippingWAL(RelFileLocator rlocator); 35 | extern Size EstimatePendingSyncsSpace(void); 36 | extern void SerializePendingSyncs(Size maxSize, char *startAddress); 37 | extern void RestorePendingSyncs(char *startAddress); 38 | 39 | /* 40 | * These functions used to be in storage/smgr/smgr.c, which explains the 41 | * naming 42 | */ 43 | extern void smgrDoPendingDeletes(bool isCommit); 44 | extern void smgrDoPendingSyncs(bool isCommit, bool isParallelWorker); 45 | extern int smgrGetPendingDeletes(bool forCommit, RelFileLocator **ptr); 46 | extern void AtSubCommit_smgr(void); 47 | extern void AtSubAbort_smgr(void); 48 | extern void PostPrepare_smgr(void); 49 | 50 | #endif /* STORAGE_H */ 51 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/tupconvert.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * tupconvert.h 4 | * Tuple conversion support. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/access/tupconvert.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef TUPCONVERT_H 15 | #define TUPCONVERT_H 16 | 17 | #include "access/attmap.h" 18 | #include "access/htup.h" 19 | #include "access/tupdesc.h" 20 | #include "executor/tuptable.h" 21 | #include "nodes/bitmapset.h" 22 | 23 | 24 | typedef struct TupleConversionMap 25 | { 26 | TupleDesc indesc; /* tupdesc for source rowtype */ 27 | TupleDesc outdesc; /* tupdesc for result rowtype */ 28 | AttrMap *attrMap; /* indexes of input fields, or 0 for null */ 29 | Datum *invalues; /* workspace for deconstructing source */ 30 | bool *inisnull; 31 | Datum *outvalues; /* workspace for constructing result */ 32 | bool *outisnull; 33 | } TupleConversionMap; 34 | 35 | 36 | extern TupleConversionMap *convert_tuples_by_position(TupleDesc indesc, 37 | TupleDesc outdesc, 38 | const char *msg); 39 | 40 | extern TupleConversionMap *convert_tuples_by_name(TupleDesc indesc, 41 | TupleDesc outdesc); 42 | extern TupleConversionMap *convert_tuples_by_name_attrmap(TupleDesc indesc, 43 | TupleDesc outdesc, 44 | AttrMap *attrMap); 45 | 46 | extern HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map); 47 | extern TupleTableSlot *execute_attr_map_slot(AttrMap *attrMap, 48 | TupleTableSlot *in_slot, 49 | TupleTableSlot *out_slot); 50 | extern Bitmapset *execute_attr_map_cols(AttrMap *attrMap, Bitmapset *in_cols); 51 | 52 | extern void free_conversion_map(TupleConversionMap *map); 53 | 54 | #endif /* TUPCONVERT_H */ 55 | -------------------------------------------------------------------------------- /internal/cparser/xxhash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * xxHash - Extremely Fast Hash algorithm 3 | * Copyright (C) 2012-2020 Yann Collet 4 | * 5 | * BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following disclaimer 15 | * in the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * You can contact the author at: 31 | * - xxHash homepage: https://www.xxhash.com 32 | * - xxHash source repository: https://github.com/Cyan4973/xxHash 33 | */ 34 | 35 | 36 | /* 37 | * xxhash.c instantiates functions defined in xxhash.h 38 | */ 39 | 40 | #define XXH_STATIC_LINKING_ONLY /* access advanced declarations */ 41 | #define XXH_IMPLEMENTATION /* access definitions */ 42 | 43 | #include "xxhash.h" -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/clog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clog.h 3 | * 4 | * PostgreSQL transaction-commit-log manager 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/access/clog.h 10 | */ 11 | #ifndef CLOG_H 12 | #define CLOG_H 13 | 14 | #include "access/xlogreader.h" 15 | #include "storage/sync.h" 16 | #include "lib/stringinfo.h" 17 | 18 | /* 19 | * Possible transaction statuses --- note that all-zeroes is the initial 20 | * state. 21 | * 22 | * A "subcommitted" transaction is a committed subtransaction whose parent 23 | * hasn't committed or aborted yet. 24 | */ 25 | typedef int XidStatus; 26 | 27 | #define TRANSACTION_STATUS_IN_PROGRESS 0x00 28 | #define TRANSACTION_STATUS_COMMITTED 0x01 29 | #define TRANSACTION_STATUS_ABORTED 0x02 30 | #define TRANSACTION_STATUS_SUB_COMMITTED 0x03 31 | 32 | typedef struct xl_clog_truncate 33 | { 34 | int64 pageno; 35 | TransactionId oldestXact; 36 | Oid oldestXactDb; 37 | } xl_clog_truncate; 38 | 39 | extern void TransactionIdSetTreeStatus(TransactionId xid, int nsubxids, 40 | TransactionId *subxids, XidStatus status, XLogRecPtr lsn); 41 | extern XidStatus TransactionIdGetStatus(TransactionId xid, XLogRecPtr *lsn); 42 | 43 | extern Size CLOGShmemSize(void); 44 | extern void CLOGShmemInit(void); 45 | extern void BootStrapCLOG(void); 46 | extern void StartupCLOG(void); 47 | extern void TrimCLOG(void); 48 | extern void CheckPointCLOG(void); 49 | extern void ExtendCLOG(TransactionId newestXact); 50 | extern void TruncateCLOG(TransactionId oldestXact, Oid oldestxid_datoid); 51 | 52 | extern int clogsyncfiletag(const FileTag *ftag, char *path); 53 | 54 | /* XLOG stuff */ 55 | #define CLOG_ZEROPAGE 0x00 56 | #define CLOG_TRUNCATE 0x10 57 | 58 | extern void clog_redo(XLogReaderState *record); 59 | extern void clog_desc(StringInfo buf, XLogReaderState *record); 60 | extern const char *clog_identify(uint8 info); 61 | 62 | #endif /* CLOG_H */ 63 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_collation_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_collation_d.h 4 | * Macro definitions for pg_collation 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_COLLATION_D_H 19 | #define PG_COLLATION_D_H 20 | 21 | #define CollationRelationId 3456 22 | #define CollationNameEncNspIndexId 3164 23 | #define CollationOidIndexId 3085 24 | 25 | #define Anum_pg_collation_oid 1 26 | #define Anum_pg_collation_collname 2 27 | #define Anum_pg_collation_collnamespace 3 28 | #define Anum_pg_collation_collowner 4 29 | #define Anum_pg_collation_collprovider 5 30 | #define Anum_pg_collation_collisdeterministic 6 31 | #define Anum_pg_collation_collencoding 7 32 | #define Anum_pg_collation_collcollate 8 33 | #define Anum_pg_collation_collctype 9 34 | #define Anum_pg_collation_colllocale 10 35 | #define Anum_pg_collation_collicurules 11 36 | #define Anum_pg_collation_collversion 12 37 | 38 | #define Natts_pg_collation 12 39 | 40 | 41 | #define COLLPROVIDER_DEFAULT 'd' 42 | #define COLLPROVIDER_BUILTIN 'b' 43 | #define COLLPROVIDER_ICU 'i' 44 | #define COLLPROVIDER_LIBC 'c' 45 | 46 | static inline const char * 47 | collprovider_name(char c) 48 | { 49 | switch (c) 50 | { 51 | case COLLPROVIDER_BUILTIN: 52 | return "builtin"; 53 | case COLLPROVIDER_ICU: 54 | return "icu"; 55 | case COLLPROVIDER_LIBC: 56 | return "libc"; 57 | default: 58 | return "???"; 59 | } 60 | } 61 | 62 | #define DEFAULT_COLLATION_OID 100 63 | #define C_COLLATION_OID 950 64 | #define POSIX_COLLATION_OID 951 65 | 66 | #endif /* PG_COLLATION_D_H */ 67 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_ts_dict.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_ts_dict.h 4 | * definition of the "text search dictionary" system catalog (pg_ts_dict) 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/catalog/pg_ts_dict.h 11 | * 12 | * NOTES 13 | * The Catalog.pm module reads this file and derives schema 14 | * information. 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_TS_DICT_H 19 | #define PG_TS_DICT_H 20 | 21 | #include "catalog/genbki.h" 22 | #include "catalog/pg_ts_dict_d.h" 23 | 24 | /* ---------------- 25 | * pg_ts_dict definition. cpp turns this into 26 | * typedef struct FormData_pg_ts_dict 27 | * ---------------- 28 | */ 29 | CATALOG(pg_ts_dict,3600,TSDictionaryRelationId) 30 | { 31 | /* oid */ 32 | Oid oid; 33 | 34 | /* dictionary name */ 35 | NameData dictname; 36 | 37 | /* name space */ 38 | Oid dictnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace); 39 | 40 | /* owner */ 41 | Oid dictowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid); 42 | 43 | /* dictionary's template */ 44 | Oid dicttemplate BKI_LOOKUP(pg_ts_template); 45 | 46 | #ifdef CATALOG_VARLEN /* variable-length fields start here */ 47 | /* options passed to dict_init() */ 48 | text dictinitoption; 49 | #endif 50 | } FormData_pg_ts_dict; 51 | 52 | typedef FormData_pg_ts_dict *Form_pg_ts_dict; 53 | 54 | DECLARE_TOAST(pg_ts_dict, 4169, 4170); 55 | 56 | DECLARE_UNIQUE_INDEX(pg_ts_dict_dictname_index, 3604, TSDictionaryNameNspIndexId, pg_ts_dict, btree(dictname name_ops, dictnamespace oid_ops)); 57 | DECLARE_UNIQUE_INDEX_PKEY(pg_ts_dict_oid_index, 3605, TSDictionaryOidIndexId, pg_ts_dict, btree(oid oid_ops)); 58 | 59 | MAKE_SYSCACHE(TSDICTNAMENSP, pg_ts_dict_dictname_index, 2); 60 | MAKE_SYSCACHE(TSDICTOID, pg_ts_dict_oid_index, 2); 61 | 62 | #endif /* PG_TS_DICT_H */ 63 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/indexing.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * indexing.h 4 | * This file provides some definitions to support indexing 5 | * on system catalogs 6 | * 7 | * 8 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 9 | * Portions Copyright (c) 1994, Regents of the University of California 10 | * 11 | * src/include/catalog/indexing.h 12 | * 13 | *------------------------------------------------------------------------- 14 | */ 15 | #ifndef INDEXING_H 16 | #define INDEXING_H 17 | 18 | #include "access/htup.h" 19 | #include "nodes/execnodes.h" 20 | #include "utils/relcache.h" 21 | 22 | /* 23 | * The state object used by CatalogOpenIndexes and friends is actually the 24 | * same as the executor's ResultRelInfo, but we give it another type name 25 | * to decouple callers from that fact. 26 | */ 27 | typedef struct ResultRelInfo *CatalogIndexState; 28 | 29 | /* 30 | * Cap the maximum amount of bytes allocated for multi-inserts with system 31 | * catalogs, limiting the number of slots used. 32 | */ 33 | #define MAX_CATALOG_MULTI_INSERT_BYTES 65535 34 | 35 | /* 36 | * indexing.c prototypes 37 | */ 38 | extern CatalogIndexState CatalogOpenIndexes(Relation heapRel); 39 | extern void CatalogCloseIndexes(CatalogIndexState indstate); 40 | extern void CatalogTupleInsert(Relation heapRel, HeapTuple tup); 41 | extern void CatalogTupleInsertWithInfo(Relation heapRel, HeapTuple tup, 42 | CatalogIndexState indstate); 43 | extern void CatalogTuplesMultiInsertWithInfo(Relation heapRel, 44 | TupleTableSlot **slot, 45 | int ntuples, 46 | CatalogIndexState indstate); 47 | extern void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, 48 | HeapTuple tup); 49 | extern void CatalogTupleUpdateWithInfo(Relation heapRel, 50 | ItemPointer otid, HeapTuple tup, 51 | CatalogIndexState indstate); 52 | extern void CatalogTupleDelete(Relation heapRel, ItemPointer tid); 53 | 54 | #endif /* INDEXING_H */ 55 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/common/file_utils.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * Assorted utility functions to work on files. 4 | * 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/common/file_utils.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef FILE_UTILS_H 14 | #define FILE_UTILS_H 15 | 16 | #include 17 | 18 | typedef enum PGFileType 19 | { 20 | PGFILETYPE_ERROR, 21 | PGFILETYPE_UNKNOWN, 22 | PGFILETYPE_REG, 23 | PGFILETYPE_DIR, 24 | PGFILETYPE_LNK, 25 | } PGFileType; 26 | 27 | typedef enum DataDirSyncMethod 28 | { 29 | DATA_DIR_SYNC_METHOD_FSYNC, 30 | DATA_DIR_SYNC_METHOD_SYNCFS, 31 | } DataDirSyncMethod; 32 | 33 | struct iovec; /* avoid including port/pg_iovec.h here */ 34 | 35 | #ifdef FRONTEND 36 | extern int fsync_fname(const char *fname, bool isdir); 37 | extern void sync_pgdata(const char *pg_data, int serverVersion, 38 | DataDirSyncMethod sync_method); 39 | extern void sync_dir_recurse(const char *dir, DataDirSyncMethod sync_method); 40 | extern int durable_rename(const char *oldfile, const char *newfile); 41 | extern int fsync_parent_path(const char *fname); 42 | #endif 43 | 44 | extern PGFileType get_dirent_type(const char *path, 45 | const struct dirent *de, 46 | bool look_through_symlinks, 47 | int elevel); 48 | 49 | extern int compute_remaining_iovec(struct iovec *destination, 50 | const struct iovec *source, 51 | int iovcnt, 52 | size_t transferred); 53 | 54 | extern ssize_t pg_pwritev_with_retry(int fd, 55 | const struct iovec *iov, 56 | int iovcnt, 57 | off_t offset); 58 | 59 | extern ssize_t pg_pwrite_zeros(int fd, size_t size, off_t offset); 60 | 61 | /* Filename components */ 62 | #define PG_TEMP_FILES_DIR "pgsql_tmp" 63 | #define PG_TEMP_FILE_PREFIX "pgsql_tmp" 64 | 65 | #endif /* FILE_UTILS_H */ 66 | -------------------------------------------------------------------------------- /internal/cparser/src_backend_nodes_extensible.c: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | * Symbols referenced in this file: 3 | * - GetExtensibleNodeMethods 4 | *-------------------------------------------------------------------- 5 | */ 6 | 7 | /*------------------------------------------------------------------------- 8 | * 9 | * extensible.c 10 | * Support for extensible node types 11 | * 12 | * Loadable modules can define what are in effect new types of nodes using 13 | * the routines in this file. All such nodes are flagged T_ExtensibleNode, 14 | * with the extnodename field distinguishing the specific type. Use 15 | * RegisterExtensibleNodeMethods to register a new type of extensible node, 16 | * and GetExtensibleNodeMethods to get information about a previously 17 | * registered type of extensible node. 18 | * 19 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 20 | * Portions Copyright (c) 1994, Regents of the University of California 21 | * 22 | * IDENTIFICATION 23 | * src/backend/nodes/extensible.c 24 | * 25 | *------------------------------------------------------------------------- 26 | */ 27 | #include "postgres.h" 28 | 29 | #include "nodes/extensible.h" 30 | #include "utils/hsearch.h" 31 | 32 | 33 | 34 | 35 | typedef struct 36 | { 37 | char extnodename[EXTNODENAME_MAX_LEN]; 38 | const void *extnodemethods; 39 | } ExtensibleNodeEntry; 40 | 41 | /* 42 | * An internal function to register a new callback structure 43 | */ 44 | 45 | 46 | /* 47 | * Register a new type of extensible node. 48 | */ 49 | 50 | 51 | /* 52 | * Register a new type of custom scan node 53 | */ 54 | 55 | 56 | /* 57 | * An internal routine to get an ExtensibleNodeEntry by the given identifier 58 | */ 59 | 60 | 61 | /* 62 | * Get the methods for a given type of extensible node. 63 | */ 64 | 65 | const ExtensibleNodeMethods * 66 | GetExtensibleNodeMethods(const char *extnodename, bool missing_ok) 67 | { 68 | return NULL; 69 | } 70 | 71 | 72 | 73 | /* 74 | * Get the methods for a given name of CustomScanMethods 75 | */ 76 | 77 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_index_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_index_d.h 4 | * Macro definitions for pg_index 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_INDEX_D_H 19 | #define PG_INDEX_D_H 20 | 21 | #define IndexRelationId 2610 22 | #define IndexIndrelidIndexId 2678 23 | #define IndexRelidIndexId 2679 24 | 25 | #define Anum_pg_index_indexrelid 1 26 | #define Anum_pg_index_indrelid 2 27 | #define Anum_pg_index_indnatts 3 28 | #define Anum_pg_index_indnkeyatts 4 29 | #define Anum_pg_index_indisunique 5 30 | #define Anum_pg_index_indnullsnotdistinct 6 31 | #define Anum_pg_index_indisprimary 7 32 | #define Anum_pg_index_indisexclusion 8 33 | #define Anum_pg_index_indimmediate 9 34 | #define Anum_pg_index_indisclustered 10 35 | #define Anum_pg_index_indisvalid 11 36 | #define Anum_pg_index_indcheckxmin 12 37 | #define Anum_pg_index_indisready 13 38 | #define Anum_pg_index_indislive 14 39 | #define Anum_pg_index_indisreplident 15 40 | #define Anum_pg_index_indkey 16 41 | #define Anum_pg_index_indcollation 17 42 | #define Anum_pg_index_indclass 18 43 | #define Anum_pg_index_indoption 19 44 | #define Anum_pg_index_indexprs 20 45 | #define Anum_pg_index_indpred 21 46 | 47 | #define Natts_pg_index 21 48 | 49 | 50 | /* 51 | * Index AMs that support ordered scans must support these two indoption 52 | * bits. Otherwise, the content of the per-column indoption fields is 53 | * open for future definition. 54 | */ 55 | #define INDOPTION_DESC 0x0001 /* values are in reverse order */ 56 | #define INDOPTION_NULLS_FIRST 0x0002 /* NULLs are first instead of last */ 57 | 58 | 59 | #endif /* PG_INDEX_D_H */ 60 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/executor/functions.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * functions.h 4 | * Declarations for execution of SQL-language functions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/executor/functions.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef FUNCTIONS_H 15 | #define FUNCTIONS_H 16 | 17 | #include "nodes/execnodes.h" 18 | #include "tcop/dest.h" 19 | 20 | /* 21 | * Data structure needed by the parser callback hooks to resolve parameter 22 | * references during parsing of a SQL function's body. This is separate from 23 | * SQLFunctionCache since we sometimes do parsing separately from execution. 24 | */ 25 | typedef struct SQLFunctionParseInfo 26 | { 27 | char *fname; /* function's name */ 28 | int nargs; /* number of input arguments */ 29 | Oid *argtypes; /* resolved types of input arguments */ 30 | char **argnames; /* names of input arguments; NULL if none */ 31 | /* Note that argnames[i] can be NULL, if some args are unnamed */ 32 | Oid collation; /* function's input collation, if known */ 33 | } SQLFunctionParseInfo; 34 | 35 | typedef SQLFunctionParseInfo *SQLFunctionParseInfoPtr; 36 | 37 | extern Datum fmgr_sql(PG_FUNCTION_ARGS); 38 | 39 | extern SQLFunctionParseInfoPtr prepare_sql_fn_parse_info(HeapTuple procedureTuple, 40 | Node *call_expr, 41 | Oid inputCollation); 42 | 43 | extern void sql_fn_parser_setup(struct ParseState *pstate, 44 | SQLFunctionParseInfoPtr pinfo); 45 | 46 | extern void check_sql_fn_statements(List *queryTreeLists); 47 | 48 | extern bool check_sql_fn_retval(List *queryTreeLists, 49 | Oid rettype, TupleDesc rettupdesc, 50 | char prokind, 51 | bool insertDroppedCols, 52 | List **resultTargetList); 53 | 54 | extern DestReceiver *CreateSQLFunctionDestReceiver(void); 55 | 56 | #endif /* FUNCTIONS_H */ 57 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/utils/varlena.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * varlena.h 4 | * Functions for the variable-length built-in types. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/utils/varlena.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef VARLENA_H 14 | #define VARLENA_H 15 | 16 | #include "nodes/pg_list.h" 17 | #include "utils/sortsupport.h" 18 | 19 | extern int varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid); 20 | extern void varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid); 21 | extern int varstr_levenshtein(const char *source, int slen, 22 | const char *target, int tlen, 23 | int ins_c, int del_c, int sub_c, 24 | bool trusted); 25 | extern int varstr_levenshtein_less_equal(const char *source, int slen, 26 | const char *target, int tlen, 27 | int ins_c, int del_c, int sub_c, 28 | int max_d, bool trusted); 29 | extern List *textToQualifiedNameList(text *textval); 30 | extern bool SplitIdentifierString(char *rawstring, char separator, 31 | List **namelist); 32 | extern bool SplitDirectoriesString(char *rawstring, char separator, 33 | List **namelist); 34 | extern bool SplitGUCList(char *rawstring, char separator, 35 | List **namelist); 36 | extern text *replace_text_regexp(text *src_text, text *pattern_text, 37 | text *replace_text, 38 | int cflags, Oid collation, 39 | int search_start, int n); 40 | 41 | typedef struct ClosestMatchState 42 | { 43 | const char *source; 44 | int min_d; 45 | int max_d; 46 | const char *match; 47 | } ClosestMatchState; 48 | 49 | extern void initClosestMatch(ClosestMatchState *state, const char *source, int max_d); 50 | extern void updateClosestMatch(ClosestMatchState *state, const char *candidate); 51 | extern const char *getClosestMatch(ClosestMatchState *state); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /magefiles/magefile.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "archive/zip" 5 | "bytes" 6 | "fmt" 7 | "io" 8 | "net/http" 9 | "os" 10 | "path/filepath" 11 | "strings" 12 | 13 | "github.com/wasilibs/magefiles" // mage:import 14 | ) 15 | 16 | func init() { 17 | magefiles.SetLibraryName("pgquery") 18 | } 19 | 20 | func UpdateCParser() error { 21 | ref := "v6.1.0" 22 | uri := fmt.Sprintf("https://github.com/pganalyze/pg_query_go/archive/%s.zip", ref) 23 | res, err := http.Get(uri) 24 | if err != nil { 25 | return err 26 | } 27 | defer res.Body.Close() 28 | if res.StatusCode != http.StatusOK { 29 | return fmt.Errorf("unexpected status code %d", res.StatusCode) 30 | } 31 | 32 | srcZip, err := io.ReadAll(res.Body) 33 | if err != nil { 34 | return err 35 | } 36 | 37 | r, err := zip.NewReader(bytes.NewReader(srcZip), int64(len(srcZip))) 38 | if err != nil { 39 | return err 40 | } 41 | 42 | if err := filepath.WalkDir(filepath.Join("internal", "cparser"), func(path string, d os.DirEntry, err error) error { 43 | if d.IsDir() { 44 | return nil 45 | } 46 | 47 | if filepath.Ext(path) == ".go" { 48 | return nil 49 | } 50 | 51 | if err := os.Remove(path); err != nil { 52 | return err 53 | } 54 | 55 | return nil 56 | }); err != nil { 57 | return err 58 | } 59 | 60 | for _, f := range r.File { 61 | if f.FileInfo().IsDir() { 62 | continue 63 | } 64 | pathParts := strings.Split(f.Name, string(filepath.Separator)) 65 | if len(pathParts) < 2 { 66 | continue 67 | } 68 | if pathParts[1] != "parser" { 69 | continue 70 | } 71 | if filepath.Ext(f.Name) == ".go" { 72 | continue 73 | } 74 | outPath := filepath.Join(append([]string{"internal", "cparser"}, pathParts[2:]...)...) 75 | if err := os.MkdirAll(filepath.Dir(outPath), 0o755); err != nil { 76 | return err 77 | } 78 | out, err := os.Create(outPath) 79 | if err != nil { 80 | return err 81 | } 82 | defer out.Close() 83 | rc, err := f.Open() 84 | if err != nil { 85 | return err 86 | } 87 | defer rc.Close() 88 | if _, err := io.Copy(out, rc); err != nil { 89 | return err 90 | } 91 | } 92 | 93 | return nil 94 | } 95 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_ts_parser.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_ts_parser.h 4 | * definition of the "text search parser" system catalog (pg_ts_parser) 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/catalog/pg_ts_parser.h 11 | * 12 | * NOTES 13 | * The Catalog.pm module reads this file and derives schema 14 | * information. 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_TS_PARSER_H 19 | #define PG_TS_PARSER_H 20 | 21 | #include "catalog/genbki.h" 22 | #include "catalog/pg_ts_parser_d.h" 23 | 24 | /* ---------------- 25 | * pg_ts_parser definition. cpp turns this into 26 | * typedef struct FormData_pg_ts_parser 27 | * ---------------- 28 | */ 29 | CATALOG(pg_ts_parser,3601,TSParserRelationId) 30 | { 31 | Oid oid; /* oid */ 32 | 33 | /* parser's name */ 34 | NameData prsname; 35 | 36 | /* name space */ 37 | Oid prsnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace); 38 | 39 | /* init parsing session */ 40 | regproc prsstart BKI_LOOKUP(pg_proc); 41 | 42 | /* return next token */ 43 | regproc prstoken BKI_LOOKUP(pg_proc); 44 | 45 | /* finalize parsing session */ 46 | regproc prsend BKI_LOOKUP(pg_proc); 47 | 48 | /* return data for headline creation */ 49 | regproc prsheadline BKI_LOOKUP_OPT(pg_proc); 50 | 51 | /* return descriptions of lexeme's types */ 52 | regproc prslextype BKI_LOOKUP(pg_proc); 53 | } FormData_pg_ts_parser; 54 | 55 | typedef FormData_pg_ts_parser *Form_pg_ts_parser; 56 | 57 | DECLARE_UNIQUE_INDEX(pg_ts_parser_prsname_index, 3606, TSParserNameNspIndexId, pg_ts_parser, btree(prsname name_ops, prsnamespace oid_ops)); 58 | DECLARE_UNIQUE_INDEX_PKEY(pg_ts_parser_oid_index, 3607, TSParserOidIndexId, pg_ts_parser, btree(oid oid_ops)); 59 | 60 | MAKE_SYSCACHE(TSPARSERNAMENSP, pg_ts_parser_prsname_index, 2); 61 | MAKE_SYSCACHE(TSPARSEROID, pg_ts_parser_oid_index, 2); 62 | 63 | #endif /* PG_TS_PARSER_H */ 64 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_authid_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_authid_d.h 4 | * Macro definitions for pg_authid 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_AUTHID_D_H 19 | #define PG_AUTHID_D_H 20 | 21 | #define AuthIdRelationId 1260 22 | #define AuthIdRelation_Rowtype_Id 2842 23 | #define PgAuthidToastTable 4175 24 | #define PgAuthidToastIndex 4176 25 | #define AuthIdRolnameIndexId 2676 26 | #define AuthIdOidIndexId 2677 27 | 28 | #define Anum_pg_authid_oid 1 29 | #define Anum_pg_authid_rolname 2 30 | #define Anum_pg_authid_rolsuper 3 31 | #define Anum_pg_authid_rolinherit 4 32 | #define Anum_pg_authid_rolcreaterole 5 33 | #define Anum_pg_authid_rolcreatedb 6 34 | #define Anum_pg_authid_rolcanlogin 7 35 | #define Anum_pg_authid_rolreplication 8 36 | #define Anum_pg_authid_rolbypassrls 9 37 | #define Anum_pg_authid_rolconnlimit 10 38 | #define Anum_pg_authid_rolpassword 11 39 | #define Anum_pg_authid_rolvaliduntil 12 40 | 41 | #define Natts_pg_authid 12 42 | 43 | #define BOOTSTRAP_SUPERUSERID 10 44 | #define ROLE_PG_DATABASE_OWNER 6171 45 | #define ROLE_PG_READ_ALL_DATA 6181 46 | #define ROLE_PG_WRITE_ALL_DATA 6182 47 | #define ROLE_PG_MONITOR 3373 48 | #define ROLE_PG_READ_ALL_SETTINGS 3374 49 | #define ROLE_PG_READ_ALL_STATS 3375 50 | #define ROLE_PG_STAT_SCAN_TABLES 3377 51 | #define ROLE_PG_READ_SERVER_FILES 4569 52 | #define ROLE_PG_WRITE_SERVER_FILES 4570 53 | #define ROLE_PG_EXECUTE_SERVER_PROGRAM 4571 54 | #define ROLE_PG_SIGNAL_BACKEND 4200 55 | #define ROLE_PG_CHECKPOINT 4544 56 | #define ROLE_PG_MAINTAIN 6337 57 | #define ROLE_PG_USE_RESERVED_CONNECTIONS 4550 58 | #define ROLE_PG_CREATE_SUBSCRIPTION 6304 59 | 60 | #endif /* PG_AUTHID_D_H */ 61 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/nodes/lockoptions.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * lockoptions.h 4 | * Common header for some locking-related declarations. 5 | * 6 | * 7 | * Copyright (c) 2014-2024, PostgreSQL Global Development Group 8 | * 9 | * src/include/nodes/lockoptions.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef LOCKOPTIONS_H 14 | #define LOCKOPTIONS_H 15 | 16 | /* 17 | * This enum represents the different strengths of FOR UPDATE/SHARE clauses. 18 | * The ordering here is important, because the highest numerical value takes 19 | * precedence when a RTE is specified multiple ways. See applyLockingClause. 20 | */ 21 | typedef enum LockClauseStrength 22 | { 23 | LCS_NONE, /* no such clause - only used in PlanRowMark */ 24 | LCS_FORKEYSHARE, /* FOR KEY SHARE */ 25 | LCS_FORSHARE, /* FOR SHARE */ 26 | LCS_FORNOKEYUPDATE, /* FOR NO KEY UPDATE */ 27 | LCS_FORUPDATE, /* FOR UPDATE */ 28 | } LockClauseStrength; 29 | 30 | /* 31 | * This enum controls how to deal with rows being locked by FOR UPDATE/SHARE 32 | * clauses (i.e., it represents the NOWAIT and SKIP LOCKED options). 33 | * The ordering here is important, because the highest numerical value takes 34 | * precedence when a RTE is specified multiple ways. See applyLockingClause. 35 | */ 36 | typedef enum LockWaitPolicy 37 | { 38 | /* Wait for the lock to become available (default behavior) */ 39 | LockWaitBlock, 40 | /* Skip rows that can't be locked (SKIP LOCKED) */ 41 | LockWaitSkip, 42 | /* Raise an error if a row cannot be locked (NOWAIT) */ 43 | LockWaitError, 44 | } LockWaitPolicy; 45 | 46 | /* 47 | * Possible lock modes for a tuple. 48 | */ 49 | typedef enum LockTupleMode 50 | { 51 | /* SELECT FOR KEY SHARE */ 52 | LockTupleKeyShare, 53 | /* SELECT FOR SHARE */ 54 | LockTupleShare, 55 | /* SELECT FOR NO KEY UPDATE, and UPDATEs that don't modify key columns */ 56 | LockTupleNoKeyExclusive, 57 | /* SELECT FOR UPDATE, UPDATEs that modify key columns, and DELETE */ 58 | LockTupleExclusive, 59 | } LockTupleMode; 60 | 61 | #endif /* LOCKOPTIONS_H */ 62 | -------------------------------------------------------------------------------- /parser/parser_cgo.go: -------------------------------------------------------------------------------- 1 | //go:build pgquery_cgo || tinygo 2 | 3 | package parser 4 | 5 | import pganalyze "github.com/pganalyze/pg_query_go/v6/parser" 6 | 7 | type Error = pganalyze.Error 8 | 9 | // ParseToJSON - Parses the given SQL statement into a parse tree (JSON format) 10 | func ParseToJSON(input string) (result string, err error) { 11 | return pganalyze.ParseToJSON(input) 12 | } 13 | 14 | // Scans the given SQL statement into a protobuf ScanResult 15 | func ScanToProtobuf(input string) (result []byte, err error) { 16 | return pganalyze.ScanToProtobuf(input) 17 | } 18 | 19 | // ParseToProtobuf - Parses the given SQL statement into a parse tree (Protobuf format) 20 | func ParseToProtobuf(input string) (result []byte, err error) { 21 | return pganalyze.ParseToProtobuf(input) 22 | } 23 | 24 | // DeparseFromProtobuf - Deparses the given Protobuf format parse tree into a SQL statement 25 | func DeparseFromProtobuf(input []byte) (result string, err error) { 26 | return pganalyze.DeparseFromProtobuf(input) 27 | } 28 | 29 | // ParsePlPgSqlToJSON - Parses the given PL/pgSQL function statement into a parse tree (JSON format) 30 | func ParsePlPgSqlToJSON(input string) (result string, err error) { 31 | return pganalyze.ParsePlPgSqlToJSON(input) 32 | } 33 | 34 | // Normalize the passed SQL statement to replace constant values with ? characters 35 | func Normalize(input string) (result string, err error) { 36 | return pganalyze.Normalize(input) 37 | } 38 | 39 | // FingerprintToUInt64 - Fingerprint the passed SQL statement using the C extension and returns result as uint64 40 | func FingerprintToUInt64(input string) (result uint64, err error) { 41 | return pganalyze.FingerprintToUInt64(input) 42 | } 43 | 44 | // FingerprintToHexStr - Fingerprint the passed SQL statement using the C extension and returns result as hex string 45 | func FingerprintToHexStr(input string) (result string, err error) { 46 | return pganalyze.FingerprintToHexStr(input) 47 | } 48 | 49 | // HashXXH3_64 - Helper method to run XXH3 hash function (64-bit variant) on the given bytes, with the specified seed 50 | func HashXXH3_64(input []byte, seed uint64) (result uint64) { 51 | return pganalyze.HashXXH3_64(input, seed) 52 | } 53 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/utils/ruleutils.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * ruleutils.h 4 | * Declarations for ruleutils.c 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/utils/ruleutils.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef RULEUTILS_H 14 | #define RULEUTILS_H 15 | 16 | #include "nodes/nodes.h" 17 | #include "nodes/parsenodes.h" 18 | #include "nodes/pg_list.h" 19 | 20 | struct Plan; /* avoid including plannodes.h here */ 21 | struct PlannedStmt; 22 | 23 | /* Flags for pg_get_indexdef_columns_extended() */ 24 | #define RULE_INDEXDEF_PRETTY 0x01 25 | #define RULE_INDEXDEF_KEYS_ONLY 0x02 /* ignore included attributes */ 26 | 27 | extern char *pg_get_indexdef_string(Oid indexrelid); 28 | extern char *pg_get_indexdef_columns(Oid indexrelid, bool pretty); 29 | extern char *pg_get_indexdef_columns_extended(Oid indexrelid, 30 | bits16 flags); 31 | extern char *pg_get_querydef(Query *query, bool pretty); 32 | 33 | extern char *pg_get_partkeydef_columns(Oid relid, bool pretty); 34 | extern char *pg_get_partconstrdef_string(Oid partitionId, char *aliasname); 35 | 36 | extern char *pg_get_constraintdef_command(Oid constraintId); 37 | extern char *deparse_expression(Node *expr, List *dpcontext, 38 | bool forceprefix, bool showimplicit); 39 | extern List *deparse_context_for(const char *aliasname, Oid relid); 40 | extern List *deparse_context_for_plan_tree(struct PlannedStmt *pstmt, 41 | List *rtable_names); 42 | extern List *set_deparse_context_plan(List *dpcontext, 43 | struct Plan *plan, List *ancestors); 44 | extern List *select_rtable_names_for_explain(List *rtable, 45 | Bitmapset *rels_used); 46 | extern char *generate_collation_name(Oid collid); 47 | extern char *generate_opclass_name(Oid opclass); 48 | extern char *get_range_partbound_string(List *bound_datums); 49 | 50 | extern char *pg_get_statisticsobjdef_string(Oid statextid); 51 | 52 | #endif /* RULEUTILS_H */ 53 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/utils/sharedtuplestore.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * sharedtuplestore.h 4 | * Simple mechanism for sharing tuples between backends. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/utils/sharedtuplestore.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef SHAREDTUPLESTORE_H 14 | #define SHAREDTUPLESTORE_H 15 | 16 | #include "access/htup.h" 17 | #include "storage/fd.h" 18 | #include "storage/sharedfileset.h" 19 | 20 | struct SharedTuplestore; 21 | typedef struct SharedTuplestore SharedTuplestore; 22 | 23 | struct SharedTuplestoreAccessor; 24 | typedef struct SharedTuplestoreAccessor SharedTuplestoreAccessor; 25 | 26 | /* 27 | * A flag indicating that the tuplestore will only be scanned once, so backing 28 | * files can be unlinked early. 29 | */ 30 | #define SHARED_TUPLESTORE_SINGLE_PASS 0x01 31 | 32 | extern size_t sts_estimate(int participants); 33 | 34 | extern SharedTuplestoreAccessor *sts_initialize(SharedTuplestore *sts, 35 | int participants, 36 | int my_participant_number, 37 | size_t meta_data_size, 38 | int flags, 39 | SharedFileSet *fileset, 40 | const char *name); 41 | 42 | extern SharedTuplestoreAccessor *sts_attach(SharedTuplestore *sts, 43 | int my_participant_number, 44 | SharedFileSet *fileset); 45 | 46 | extern void sts_end_write(SharedTuplestoreAccessor *accessor); 47 | 48 | extern void sts_reinitialize(SharedTuplestoreAccessor *accessor); 49 | 50 | extern void sts_begin_parallel_scan(SharedTuplestoreAccessor *accessor); 51 | 52 | extern void sts_end_parallel_scan(SharedTuplestoreAccessor *accessor); 53 | 54 | extern void sts_puttuple(SharedTuplestoreAccessor *accessor, 55 | void *meta_data, 56 | MinimalTuple tuple); 57 | 58 | extern MinimalTuple sts_parallel_scan_next(SharedTuplestoreAccessor *accessor, 59 | void *meta_data); 60 | 61 | #endif /* SHAREDTUPLESTORE_H */ 62 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 4 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 5 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 6 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 7 | github.com/pganalyze/pg_query_go/v6 v6.1.0 h1:jG5ZLhcVgL1FAw4C/0VNQaVmX1SUJx71wBGdtTtBvls= 8 | github.com/pganalyze/pg_query_go/v6 v6.1.0/go.mod h1:nvTHIuoud6e1SfrUaFwHqT0i4b5Nr+1rPWVds3B5+50= 9 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 | github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= 12 | github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 13 | github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I= 14 | github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM= 15 | github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4= 16 | github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY= 17 | golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= 18 | golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 19 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 20 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 21 | google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= 22 | google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 23 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 24 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 25 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/access/sdir.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * sdir.h 4 | * POSTGRES scan direction definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/access/sdir.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef SDIR_H 15 | #define SDIR_H 16 | 17 | 18 | /* 19 | * Defines the direction for scanning a table or an index. Scans are never 20 | * invoked using NoMovementScanDirectionScans. For convenience, we use the 21 | * values -1 and 1 for backward and forward scans. This allows us to perform 22 | * a few mathematical tricks such as what is done in ScanDirectionCombine. 23 | */ 24 | typedef enum ScanDirection 25 | { 26 | BackwardScanDirection = -1, 27 | NoMovementScanDirection = 0, 28 | ForwardScanDirection = 1 29 | } ScanDirection; 30 | 31 | /* 32 | * Determine the net effect of two direction specifications. 33 | * This relies on having ForwardScanDirection = +1, BackwardScanDirection = -1, 34 | * and will probably not do what you want if applied to any other values. 35 | */ 36 | #define ScanDirectionCombine(a, b) ((a) * (b)) 37 | 38 | /* 39 | * ScanDirectionIsValid 40 | * True iff scan direction is valid. 41 | */ 42 | #define ScanDirectionIsValid(direction) \ 43 | ((bool) (BackwardScanDirection <= (direction) && \ 44 | (direction) <= ForwardScanDirection)) 45 | 46 | /* 47 | * ScanDirectionIsBackward 48 | * True iff scan direction is backward. 49 | */ 50 | #define ScanDirectionIsBackward(direction) \ 51 | ((bool) ((direction) == BackwardScanDirection)) 52 | 53 | /* 54 | * ScanDirectionIsNoMovement 55 | * True iff scan direction indicates no movement. 56 | */ 57 | #define ScanDirectionIsNoMovement(direction) \ 58 | ((bool) ((direction) == NoMovementScanDirection)) 59 | 60 | /* 61 | * ScanDirectionIsForward 62 | * True iff scan direction is forward. 63 | */ 64 | #define ScanDirectionIsForward(direction) \ 65 | ((bool) ((direction) == ForwardScanDirection)) 66 | 67 | #endif /* SDIR_H */ 68 | -------------------------------------------------------------------------------- /fingerprint_test.go: -------------------------------------------------------------------------------- 1 | package pg_query_test 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "os" 7 | "strconv" 8 | "testing" 9 | 10 | pg_query "github.com/wasilibs/go-pgquery" 11 | ) 12 | 13 | type fingerprintTest struct { 14 | Input string 15 | ExpectedParts []string 16 | ExpectedHash string 17 | } 18 | 19 | func TestFingerprint(t *testing.T) { 20 | var fingerprintTests []fingerprintTest 21 | 22 | file, err := os.ReadFile("./testdata/fingerprint.json") 23 | if err != nil { 24 | t.Errorf("Could not load test file: %v\n", err) 25 | } 26 | 27 | err = json.Unmarshal(file, &fingerprintTests) 28 | if err != nil { 29 | t.Errorf("Could not parse test file: %v\n", err) 30 | } 31 | 32 | for _, test := range fingerprintTests { 33 | fmt.Printf(".") 34 | 35 | fingerprint, err := pg_query.Fingerprint(test.Input) 36 | if err != nil { 37 | t.Errorf("Fingerprint(%s)\nparse error %s\n\n", test.Input, err) 38 | } 39 | 40 | if string(fingerprint) != test.ExpectedHash { 41 | t.Errorf("Fingerprint(%s)\nexpected %s\nactual %s\n\n", test.Input, test.ExpectedHash, fingerprint) 42 | } 43 | 44 | fingerprintInt, err := pg_query.FingerprintToUInt64(test.Input) 45 | if err != nil { 46 | t.Errorf("FingerprintToUInt64(%s)\nparse error %s\n\n", test.Input, err) 47 | } 48 | 49 | expectedInt, _ := strconv.ParseUint(test.ExpectedHash, 16, 64) 50 | 51 | if fingerprintInt != expectedInt { 52 | t.Errorf("FingerprintToUInt64(%s)\nexpected %d\nactual %d\n\n", test.Input, expectedInt, fingerprintInt) 53 | } 54 | } 55 | 56 | fmt.Printf("\n") 57 | } 58 | 59 | var hashTests = []struct { 60 | input string 61 | seed uint64 62 | expected uint64 63 | }{ 64 | { 65 | "TEST", 66 | 0, 67 | 11717748491247689214, 68 | }, 69 | { 70 | "TEST", 71 | 42, 72 | 10412276358662179996, 73 | }, 74 | { 75 | "Something else", 76 | 0, 77 | 14679351602596009561, 78 | }, 79 | } 80 | 81 | func TestHashXXH3_64(t *testing.T) { 82 | for _, test := range hashTests { 83 | actual := pg_query.HashXXH3_64([]byte(test.input), test.seed) 84 | 85 | if actual != test.expected { 86 | t.Errorf("HashXXH3_64(%s)\nexpected %d\nactual %d\n\n", test.input, test.expected, actual) 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/utils/inval.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * inval.h 4 | * POSTGRES cache invalidation dispatcher definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/utils/inval.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef INVAL_H 15 | #define INVAL_H 16 | 17 | #include "access/htup.h" 18 | #include "storage/relfilelocator.h" 19 | #include "utils/relcache.h" 20 | 21 | extern PGDLLIMPORT int debug_discard_caches; 22 | 23 | typedef void (*SyscacheCallbackFunction) (Datum arg, int cacheid, uint32 hashvalue); 24 | typedef void (*RelcacheCallbackFunction) (Datum arg, Oid relid); 25 | 26 | 27 | extern void AcceptInvalidationMessages(void); 28 | 29 | extern void AtEOXact_Inval(bool isCommit); 30 | 31 | extern void AtEOSubXact_Inval(bool isCommit); 32 | 33 | extern void PostPrepare_Inval(void); 34 | 35 | extern void CommandEndInvalidationMessages(void); 36 | 37 | extern void CacheInvalidateHeapTuple(Relation relation, 38 | HeapTuple tuple, 39 | HeapTuple newtuple); 40 | 41 | extern void CacheInvalidateCatalog(Oid catalogId); 42 | 43 | extern void CacheInvalidateRelcache(Relation relation); 44 | 45 | extern void CacheInvalidateRelcacheAll(void); 46 | 47 | extern void CacheInvalidateRelcacheByTuple(HeapTuple classTuple); 48 | 49 | extern void CacheInvalidateRelcacheByRelid(Oid relid); 50 | 51 | extern void CacheInvalidateSmgr(RelFileLocatorBackend rlocator); 52 | 53 | extern void CacheInvalidateRelmap(Oid databaseId); 54 | 55 | extern void CacheRegisterSyscacheCallback(int cacheid, 56 | SyscacheCallbackFunction func, 57 | Datum arg); 58 | 59 | extern void CacheRegisterRelcacheCallback(RelcacheCallbackFunction func, 60 | Datum arg); 61 | 62 | extern void CallSyscacheCallbacks(int cacheid, uint32 hashvalue); 63 | 64 | extern void InvalidateSystemCaches(void); 65 | extern void InvalidateSystemCachesExtended(bool debug_discard); 66 | 67 | extern void LogLogicalInvalidations(void); 68 | #endif /* INVAL_H */ 69 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_attribute_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_attribute_d.h 4 | * Macro definitions for pg_attribute 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * NOTES 10 | * ****************************** 11 | * *** DO NOT EDIT THIS FILE! *** 12 | * ****************************** 13 | * 14 | * It has been GENERATED by src/backend/catalog/genbki.pl 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_ATTRIBUTE_D_H 19 | #define PG_ATTRIBUTE_D_H 20 | 21 | #define AttributeRelationId 1249 22 | #define AttributeRelation_Rowtype_Id 75 23 | #define AttributeRelidNameIndexId 2658 24 | #define AttributeRelidNumIndexId 2659 25 | 26 | #define Anum_pg_attribute_attrelid 1 27 | #define Anum_pg_attribute_attname 2 28 | #define Anum_pg_attribute_atttypid 3 29 | #define Anum_pg_attribute_attlen 4 30 | #define Anum_pg_attribute_attnum 5 31 | #define Anum_pg_attribute_attcacheoff 6 32 | #define Anum_pg_attribute_atttypmod 7 33 | #define Anum_pg_attribute_attndims 8 34 | #define Anum_pg_attribute_attbyval 9 35 | #define Anum_pg_attribute_attalign 10 36 | #define Anum_pg_attribute_attstorage 11 37 | #define Anum_pg_attribute_attcompression 12 38 | #define Anum_pg_attribute_attnotnull 13 39 | #define Anum_pg_attribute_atthasdef 14 40 | #define Anum_pg_attribute_atthasmissing 15 41 | #define Anum_pg_attribute_attidentity 16 42 | #define Anum_pg_attribute_attgenerated 17 43 | #define Anum_pg_attribute_attisdropped 18 44 | #define Anum_pg_attribute_attislocal 19 45 | #define Anum_pg_attribute_attinhcount 20 46 | #define Anum_pg_attribute_attcollation 21 47 | #define Anum_pg_attribute_attstattarget 22 48 | #define Anum_pg_attribute_attacl 23 49 | #define Anum_pg_attribute_attoptions 24 50 | #define Anum_pg_attribute_attfdwoptions 25 51 | #define Anum_pg_attribute_attmissingval 26 52 | 53 | #define Natts_pg_attribute 26 54 | 55 | 56 | #define ATTRIBUTE_IDENTITY_ALWAYS 'a' 57 | #define ATTRIBUTE_IDENTITY_BY_DEFAULT 'd' 58 | 59 | #define ATTRIBUTE_GENERATED_STORED 's' 60 | 61 | 62 | #endif /* PG_ATTRIBUTE_D_H */ 63 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/storage/dsm.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * dsm.h 4 | * manage dynamic shared memory segments 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/storage/dsm.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef DSM_H 14 | #define DSM_H 15 | 16 | #include "storage/dsm_impl.h" 17 | 18 | typedef struct dsm_segment dsm_segment; 19 | 20 | #define DSM_CREATE_NULL_IF_MAXSEGMENTS 0x0001 21 | 22 | /* Startup and shutdown functions. */ 23 | struct PGShmemHeader; /* avoid including pg_shmem.h */ 24 | extern void dsm_cleanup_using_control_segment(dsm_handle old_control_handle); 25 | extern void dsm_postmaster_startup(struct PGShmemHeader *); 26 | extern void dsm_backend_shutdown(void); 27 | extern void dsm_detach_all(void); 28 | 29 | extern size_t dsm_estimate_size(void); 30 | extern void dsm_shmem_init(void); 31 | 32 | #ifdef EXEC_BACKEND 33 | extern void dsm_set_control_handle(dsm_handle h); 34 | #endif 35 | 36 | /* Functions that create or remove mappings. */ 37 | extern dsm_segment *dsm_create(Size size, int flags); 38 | extern dsm_segment *dsm_attach(dsm_handle h); 39 | extern void dsm_detach(dsm_segment *seg); 40 | 41 | /* Resource management functions. */ 42 | extern void dsm_pin_mapping(dsm_segment *seg); 43 | extern void dsm_unpin_mapping(dsm_segment *seg); 44 | extern void dsm_pin_segment(dsm_segment *seg); 45 | extern void dsm_unpin_segment(dsm_handle handle); 46 | extern dsm_segment *dsm_find_mapping(dsm_handle handle); 47 | 48 | /* Informational functions. */ 49 | extern void *dsm_segment_address(dsm_segment *seg); 50 | extern Size dsm_segment_map_length(dsm_segment *seg); 51 | extern dsm_handle dsm_segment_handle(dsm_segment *seg); 52 | 53 | /* Cleanup hooks. */ 54 | typedef void (*on_dsm_detach_callback) (dsm_segment *, Datum arg); 55 | extern void on_dsm_detach(dsm_segment *seg, 56 | on_dsm_detach_callback function, Datum arg); 57 | extern void cancel_on_dsm_detach(dsm_segment *seg, 58 | on_dsm_detach_callback function, Datum arg); 59 | extern void reset_on_dsm_detach(void); 60 | 61 | #endif /* DSM_H */ 62 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_event_trigger.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_event_trigger.h 4 | * definition of the "event trigger" system catalog (pg_event_trigger) 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/catalog/pg_event_trigger.h 11 | * 12 | * NOTES 13 | * The Catalog.pm module reads this file and derives schema 14 | * information. 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_EVENT_TRIGGER_H 19 | #define PG_EVENT_TRIGGER_H 20 | 21 | #include "catalog/genbki.h" 22 | #include "catalog/pg_event_trigger_d.h" 23 | 24 | /* ---------------- 25 | * pg_event_trigger definition. cpp turns this into 26 | * typedef struct FormData_pg_event_trigger 27 | * ---------------- 28 | */ 29 | CATALOG(pg_event_trigger,3466,EventTriggerRelationId) 30 | { 31 | Oid oid; /* oid */ 32 | NameData evtname; /* trigger's name */ 33 | NameData evtevent; /* trigger's event */ 34 | Oid evtowner BKI_LOOKUP(pg_authid); /* trigger's owner */ 35 | Oid evtfoid BKI_LOOKUP(pg_proc); /* OID of function to be 36 | * called */ 37 | char evtenabled; /* trigger's firing configuration WRT 38 | * session_replication_role */ 39 | 40 | #ifdef CATALOG_VARLEN 41 | text evttags[1]; /* command TAGs this event trigger targets */ 42 | #endif 43 | } FormData_pg_event_trigger; 44 | 45 | /* ---------------- 46 | * Form_pg_event_trigger corresponds to a pointer to a tuple with 47 | * the format of pg_event_trigger relation. 48 | * ---------------- 49 | */ 50 | typedef FormData_pg_event_trigger *Form_pg_event_trigger; 51 | 52 | DECLARE_TOAST(pg_event_trigger, 4145, 4146); 53 | 54 | DECLARE_UNIQUE_INDEX(pg_event_trigger_evtname_index, 3467, EventTriggerNameIndexId, pg_event_trigger, btree(evtname name_ops)); 55 | DECLARE_UNIQUE_INDEX_PKEY(pg_event_trigger_oid_index, 3468, EventTriggerOidIndexId, pg_event_trigger, btree(oid oid_ops)); 56 | 57 | MAKE_SYSCACHE(EVENTTRIGGERNAME, pg_event_trigger_evtname_index, 8); 58 | MAKE_SYSCACHE(EVENTTRIGGEROID, pg_event_trigger_oid_index, 8); 59 | 60 | #endif /* PG_EVENT_TRIGGER_H */ 61 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/storage/sync.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * sync.h 4 | * File synchronization management code. 5 | * 6 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/storage/sync.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef SYNC_H 14 | #define SYNC_H 15 | 16 | #include "storage/relfilelocator.h" 17 | 18 | /* 19 | * Type of sync request. These are used to manage the set of pending 20 | * requests to call a sync handler's sync or unlink functions at the next 21 | * checkpoint. 22 | */ 23 | typedef enum SyncRequestType 24 | { 25 | SYNC_REQUEST, /* schedule a call of sync function */ 26 | SYNC_UNLINK_REQUEST, /* schedule a call of unlink function */ 27 | SYNC_FORGET_REQUEST, /* forget all calls for a tag */ 28 | SYNC_FILTER_REQUEST, /* forget all calls satisfying match fn */ 29 | } SyncRequestType; 30 | 31 | /* 32 | * Which set of functions to use to handle a given request. The values of 33 | * the enumerators must match the indexes of the function table in sync.c. 34 | */ 35 | typedef enum SyncRequestHandler 36 | { 37 | SYNC_HANDLER_MD = 0, 38 | SYNC_HANDLER_CLOG, 39 | SYNC_HANDLER_COMMIT_TS, 40 | SYNC_HANDLER_MULTIXACT_OFFSET, 41 | SYNC_HANDLER_MULTIXACT_MEMBER, 42 | SYNC_HANDLER_NONE, 43 | } SyncRequestHandler; 44 | 45 | /* 46 | * A tag identifying a file. Currently it has the members required for md.c's 47 | * usage, but sync.c has no knowledge of the internal structure, and it is 48 | * liable to change as required by future handlers. 49 | */ 50 | typedef struct FileTag 51 | { 52 | int16 handler; /* SyncRequestHandler value, saving space */ 53 | int16 forknum; /* ForkNumber, saving space */ 54 | RelFileLocator rlocator; 55 | uint64 segno; 56 | } FileTag; 57 | 58 | extern void InitSync(void); 59 | extern void SyncPreCheckpoint(void); 60 | extern void SyncPostCheckpoint(void); 61 | extern void ProcessSyncRequests(void); 62 | extern void RememberSyncRequest(const FileTag *ftag, SyncRequestType type); 63 | extern bool RegisterSyncRequest(const FileTag *ftag, SyncRequestType type, 64 | bool retryOnError); 65 | 66 | #endif /* SYNC_H */ 67 | -------------------------------------------------------------------------------- /internal/cparser/include/postgres/catalog/pg_namespace.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_namespace.h 4 | * definition of the "namespace" system catalog (pg_namespace) 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/catalog/pg_namespace.h 11 | * 12 | * NOTES 13 | * The Catalog.pm module reads this file and derives schema 14 | * information. 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef PG_NAMESPACE_H 19 | #define PG_NAMESPACE_H 20 | 21 | #include "catalog/genbki.h" 22 | #include "catalog/pg_namespace_d.h" 23 | #include "utils/acl.h" 24 | 25 | /* ---------------------------------------------------------------- 26 | * pg_namespace definition. 27 | * 28 | * cpp turns this into typedef struct FormData_pg_namespace 29 | * 30 | * nspname name of the namespace 31 | * nspowner owner (creator) of the namespace 32 | * nspacl access privilege list 33 | * ---------------------------------------------------------------- 34 | */ 35 | CATALOG(pg_namespace,2615,NamespaceRelationId) 36 | { 37 | Oid oid; /* oid */ 38 | 39 | NameData nspname; 40 | Oid nspowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid); 41 | 42 | #ifdef CATALOG_VARLEN /* variable-length fields start here */ 43 | aclitem nspacl[1]; 44 | #endif 45 | } FormData_pg_namespace; 46 | 47 | /* ---------------- 48 | * Form_pg_namespace corresponds to a pointer to a tuple with 49 | * the format of pg_namespace relation. 50 | * ---------------- 51 | */ 52 | typedef FormData_pg_namespace *Form_pg_namespace; 53 | 54 | DECLARE_TOAST(pg_namespace, 4163, 4164); 55 | 56 | DECLARE_UNIQUE_INDEX(pg_namespace_nspname_index, 2684, NamespaceNameIndexId, pg_namespace, btree(nspname name_ops)); 57 | DECLARE_UNIQUE_INDEX_PKEY(pg_namespace_oid_index, 2685, NamespaceOidIndexId, pg_namespace, btree(oid oid_ops)); 58 | 59 | MAKE_SYSCACHE(NAMESPACENAME, pg_namespace_nspname_index, 4); 60 | MAKE_SYSCACHE(NAMESPACEOID, pg_namespace_oid_index, 16); 61 | 62 | /* 63 | * prototypes for functions in pg_namespace.c 64 | */ 65 | extern Oid NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp); 66 | 67 | #endif /* PG_NAMESPACE_H */ 68 | --------------------------------------------------------------------------------