├── tmp └── .gitkeep ├── .ruby-version ├── src ├── postgres │ ├── guc-file.c │ ├── include │ │ ├── pg_config_os.h │ │ ├── pg_config_ext.h │ │ ├── pg_trace.h │ │ ├── postmaster │ │ │ ├── fork_process.h │ │ │ ├── walwriter.h │ │ │ ├── auxprocess.h │ │ │ ├── interrupt.h │ │ │ ├── startup.h │ │ │ └── bgwriter.h │ │ ├── storage │ │ │ ├── item.h │ │ │ ├── sharedfileset.h │ │ │ ├── buf.h │ │ │ ├── backendid.h │ │ │ ├── fileset.h │ │ │ ├── off.h │ │ │ ├── sinvaladt.h │ │ │ └── proclist_types.h │ │ ├── tcop │ │ │ ├── fastpath.h │ │ │ ├── pquery.h │ │ │ └── cmdtag.h │ │ ├── replication │ │ │ ├── logicalworker.h │ │ │ └── logicallauncher.h │ │ ├── utils │ │ │ ├── dynahash.h │ │ │ ├── ps_status.h │ │ │ ├── bytea.h │ │ │ ├── pg_lsn.h │ │ │ ├── tzparser.h │ │ │ ├── backend_progress.h │ │ │ ├── aclchk_internal.h │ │ │ ├── regproc.h │ │ │ ├── fmgrtab.h │ │ │ ├── varlena.h │ │ │ ├── ruleutils.h │ │ │ └── rls.h │ │ ├── mb │ │ │ └── stringinfo_mb.h │ │ ├── partitioning │ │ │ └── partdefs.h │ │ ├── parser │ │ │ ├── parse_expr.h │ │ │ ├── scansup.h │ │ │ └── parsetree.h │ │ ├── rewrite │ │ │ ├── rewriteSupport.h │ │ │ ├── prs2lock.h │ │ │ └── rewriteHandler.h │ │ ├── common │ │ │ ├── keywords.h │ │ │ ├── ip.h │ │ │ ├── kwlookup.h │ │ │ ├── string.h │ │ │ └── file_perm.h │ │ ├── access │ │ │ ├── sysattr.h │ │ │ ├── table.h │ │ │ ├── relation.h │ │ │ ├── printtup.h │ │ │ ├── rmgr.h │ │ │ ├── sdir.h │ │ │ ├── xlogprefetcher.h │ │ │ ├── attnum.h │ │ │ ├── tupconvert.h │ │ │ ├── attmap.h │ │ │ └── clog.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_parameter_acl_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 │ │ │ ├── catalog.h │ │ │ ├── pg_statistic_ext_d.h │ │ │ ├── pg_opfamily_d.h │ │ │ ├── pg_transform.h │ │ │ ├── pg_ts_config.h │ │ │ ├── pg_opclass_d.h │ │ │ ├── pg_ts_template.h │ │ │ ├── pg_am.h │ │ │ ├── pg_collation_d.h │ │ │ ├── pg_ts_dict.h │ │ │ ├── storage.h │ │ │ ├── pg_authid_d.h │ │ │ ├── pg_ts_parser.h │ │ │ └── indexing.h │ │ ├── libpq │ │ │ ├── auth.h │ │ │ ├── pqsignal.h │ │ │ └── crypt.h │ │ ├── port │ │ │ └── atomics │ │ │ │ └── arch-arm.h │ │ ├── nodes │ │ │ └── print.h │ │ ├── optimizer │ │ │ └── geqo_gene.h │ │ ├── commands │ │ │ ├── user.h │ │ │ ├── dbcommands.h │ │ │ ├── async.h │ │ │ └── variable.h │ │ ├── pl_reserved_kwlist.h │ │ └── pg_getopt.h │ ├── src_port_qsort.c │ ├── src_port_strnlen.c │ ├── src_common_keywords.c │ └── src_backend_nodes_value.c ├── pg_query_json_plpgsql.h ├── pg_query_readfuncs.h ├── pg_query_outfuncs.h ├── pg_query_fingerprint.h ├── pg_query_internal.h └── pg_query_json_helper.c ├── test ├── valgrind.supp ├── sql │ ├── postgres_regress │ │ ├── init_privs.sql │ │ ├── select_distinct_on.sql │ │ ├── delete.sql │ │ ├── async.sql │ │ ├── lseg.sql │ │ ├── infinite_recurse.sql │ │ ├── path.sql │ │ ├── comments.sql │ │ ├── create_function_c.sql │ │ ├── random.sql │ │ ├── unicode.sql │ │ ├── oid.sql │ │ ├── line.sql │ │ ├── bitmapops.sql │ │ ├── varchar.sql │ │ ├── namespace.sql │ │ ├── circle.sql │ │ ├── drop_operator.sql │ │ ├── write_parallel.sql │ │ ├── oidjoins.sql │ │ ├── security_label.sql │ │ ├── create_cast.sql │ │ ├── portals_p2.sql │ │ ├── select_having.sql │ │ ├── macaddr.sql │ │ ├── pg_lsn.sql │ │ └── mvcc.sql │ └── plpgsql_regress │ │ ├── plpgsql_trigger.sql │ │ └── plpgsql_cache.sql ├── fuzz │ └── fuzz_parser.c ├── split_tests.c ├── parse.c ├── normalize.c ├── parse_protobuf.c ├── concurrency.c ├── fingerprint.c ├── parse_plpgsql.c └── scan.c ├── .gitignore ├── examples ├── normalize.c ├── normalize_error.c ├── simple_error.c ├── simple_plpgsql.c └── simple.c ├── scripts └── generate_fingerprint_tests.rb ├── srcdata └── all_known_enums.json ├── LICENSE ├── patches ├── 05_limit_option_enum_value_default.patch └── 06_alloc_set_delete_free_list.patch └── vendor └── xxhash └── xxhash.c /tmp/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 3.1.2 2 | -------------------------------------------------------------------------------- /src/postgres/guc-file.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/valgrind.supp: -------------------------------------------------------------------------------- 1 | { 2 | google_protobuf_cpp_unclean_shutdown 3 | Memcheck:Leak 4 | match-leak-kinds: reachable 5 | ... 6 | fun:*google*protobuf* 7 | } -------------------------------------------------------------------------------- /src/postgres/include/pg_config_os.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/darwin.h */ 2 | 3 | #define __darwin__ 1 4 | 5 | #if HAVE_DECL_F_FULLFSYNC /* not present before macOS 10.3 */ 6 | #define HAVE_FSYNC_WRITETHROUGH 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | postgres/* 2 | postgres.tar.bz2 3 | 4 | *.o 5 | *.a 6 | 7 | examples/* 8 | !examples/*.c 9 | 10 | test/* 11 | !test/*.c 12 | !test/*.sql 13 | !test/*.expected.json 14 | !test/valgrind.supp 15 | !test/**/ 16 | test/*.dSYM 17 | 18 | tmp/* 19 | !tmp/.gitkeep 20 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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, bool printTokens); 7 | 8 | extern uint64_t pg_query_fingerprint_node(const void * node); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/postgres/include/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 | -------------------------------------------------------------------------------- /src/postgres/include/pg_trace.h: -------------------------------------------------------------------------------- 1 | /* ---------- 2 | * pg_trace.h 3 | * 4 | * Definitions for the PostgreSQL tracing framework 5 | * 6 | * Copyright (c) 2006-2022, 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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/init_privs.sql: -------------------------------------------------------------------------------- 1 | -- Test initial privileges 2 | 3 | -- There should always be some initial privileges, set up by initdb 4 | SELECT count(*) > 0 FROM pg_init_privs; 5 | 6 | -- Intentionally include some non-initial privs for pg_dump to dump out 7 | GRANT SELECT ON pg_proc TO CURRENT_USER; 8 | GRANT SELECT (prosrc) ON pg_proc TO CURRENT_USER; 9 | 10 | GRANT SELECT (rolname, rolsuper) ON pg_authid TO CURRENT_USER; 11 | -------------------------------------------------------------------------------- /test/fuzz/fuzz_parser.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 9 | char *new_str = (char *)malloc(size+1); 10 | if (new_str == NULL){ 11 | return 0; 12 | } 13 | memcpy(new_str, data, size); 14 | new_str[size] = '\0'; 15 | 16 | PgQueryParseResult result = pg_query_parse(new_str); 17 | pg_query_free_parse_result(result); 18 | 19 | free(new_str); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/postgres/include/postmaster/fork_process.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * fork_process.h 4 | * Exports from postmaster/fork_process.c. 5 | * 6 | * Copyright (c) 1996-2022, PostgreSQL Global Development Group 7 | * 8 | * src/include/postmaster/fork_process.h 9 | * 10 | *------------------------------------------------------------------------- 11 | */ 12 | #ifndef FORK_PROCESS_H 13 | #define FORK_PROCESS_H 14 | 15 | extern pid_t fork_process(void); 16 | 17 | #endif /* FORK_PROCESS_H */ 18 | -------------------------------------------------------------------------------- /src/postgres/include/storage/item.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * item.h 4 | * POSTGRES disk item definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /examples/normalize.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | PgQueryNormalizeResult result; 7 | 8 | result = pg_query_normalize("SELECT 1"); 9 | 10 | if (result.error) { 11 | printf("error: %s at %d\n", result.error->message, result.error->cursorpos); 12 | } else { 13 | printf("%s\n", result.normalized_query); 14 | } 15 | 16 | pg_query_free_normalize_result(result); 17 | 18 | // Optional, this ensures all memory is freed upon program exit (useful when running Valgrind) 19 | pg_query_exit(); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/postgres/include/tcop/fastpath.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * fastpath.h 4 | * 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/replication/logicalworker.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * logicalworker.h 4 | * Exports for logical replication workers. 5 | * 6 | * Portions Copyright (c) 2016-2022, PostgreSQL Global Development Group 7 | * 8 | * src/include/replication/logicalworker.h 9 | * 10 | *------------------------------------------------------------------------- 11 | */ 12 | #ifndef LOGICALWORKER_H 13 | #define LOGICALWORKER_H 14 | 15 | extern void ApplyWorkerMain(Datum main_arg); 16 | 17 | extern bool IsLogicalWorker(void); 18 | 19 | #endif /* LOGICALWORKER_H */ 20 | -------------------------------------------------------------------------------- /src/postgres/include/utils/dynahash.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * dynahash.h 4 | * POSTGRES dynahash.h file definitions 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * IDENTIFICATION 11 | * src/include/utils/dynahash.h 12 | * 13 | *------------------------------------------------------------------------- 14 | */ 15 | #ifndef DYNAHASH_H 16 | #define DYNAHASH_H 17 | 18 | extern int my_log2(long num); 19 | 20 | #endif /* DYNAHASH_H */ 21 | -------------------------------------------------------------------------------- /test/split_tests.c: -------------------------------------------------------------------------------- 1 | const char* tests[] = { 2 | "", 3 | "", 4 | "SELECT 1", 5 | "loc=0,len=8", 6 | "SELECT 1; SELECT 2", 7 | "loc=0,len=8;loc=9,len=9", 8 | "SELECT 1; SELECT 2; SELECT 3", 9 | "loc=0,len=8;loc=9,len=9;loc=19,len=9", 10 | "SELECT /* comment with ; */ 1; SELECT 2", 11 | "loc=0,len=29;loc=30,len=9", 12 | "SELECT --othercomment with ;\n 1; SELECT 2", 13 | "loc=0,len=31;loc=32,len=9", 14 | "CREATE RULE x AS ON SELECT TO tbl DO (SELECT 1; SELECT 2)", 15 | "loc=0,len=57", 16 | "SELECT 1;\n;\n-- comment\nSELECT 2;\n;", 17 | "loc=0,len=8;loc=11,len=20" 18 | }; 19 | 20 | size_t testsLength = __LINE__ - 4; 21 | -------------------------------------------------------------------------------- /src/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); 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 | -------------------------------------------------------------------------------- /examples/normalize_error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | PgQueryNormalizeResult result; 7 | 8 | result = pg_query_normalize("SELECT $$$"); 9 | 10 | if (result.error) { 11 | printf("error: %s at location %d (%s:%d)\n", result.error->message, 12 | result.error->cursorpos, result.error->filename, result.error->lineno); 13 | } else { 14 | printf("%s\n", result.normalized_query); 15 | } 16 | 17 | pg_query_free_normalize_result(result); 18 | 19 | // Optional, this ensures all memory is freed upon program exit (useful when running Valgrind) 20 | pg_query_exit(); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /src/postgres/include/postmaster/walwriter.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * walwriter.h 4 | * Exports from postmaster/walwriter.c. 5 | * 6 | * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group 7 | * 8 | * src/include/postmaster/walwriter.h 9 | * 10 | *------------------------------------------------------------------------- 11 | */ 12 | #ifndef _WALWRITER_H 13 | #define _WALWRITER_H 14 | 15 | /* GUC options */ 16 | extern PGDLLIMPORT int WalWriterDelay; 17 | extern PGDLLIMPORT int WalWriterFlushAfter; 18 | 19 | extern void WalWriterMain(void) pg_attribute_noreturn(); 20 | 21 | #endif /* _WALWRITER_H */ 22 | -------------------------------------------------------------------------------- /examples/simple_error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | PgQueryParseResult result; 7 | 8 | result = pg_query_parse("INSERT FROM DOES NOT WORK"); 9 | 10 | if (result.error) { 11 | printf("error: %s at location %d (%s in %s:%d)\n", result.error->message, 12 | result.error->cursorpos, result.error->funcname, result.error->filename, result.error->lineno); 13 | } else { 14 | printf("%s\n", result.parse_tree); 15 | } 16 | 17 | pg_query_free_parse_result(result); 18 | 19 | // Optional, this ensures all memory is freed upon program exit (useful when running Valgrind) 20 | pg_query_exit(); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/select_distinct_on.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- SELECT_DISTINCT_ON 3 | -- 4 | 5 | SELECT DISTINCT ON (string4) string4, two, ten 6 | FROM onek 7 | ORDER BY string4 using <, two using >, ten using <; 8 | 9 | -- this will fail due to conflict of ordering requirements 10 | SELECT DISTINCT ON (string4, ten) string4, two, ten 11 | FROM onek 12 | ORDER BY string4 using <, two using <, ten using <; 13 | 14 | SELECT DISTINCT ON (string4, ten) string4, ten, two 15 | FROM onek 16 | ORDER BY string4 using <, ten using >, two using <; 17 | 18 | -- bug #5049: early 8.4.x chokes on volatile DISTINCT ON clauses 19 | select distinct on (1) floor(random()) as r, f1 from int4_tbl order by 1,2; 20 | -------------------------------------------------------------------------------- /scripts/generate_fingerprint_tests.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'bundler' 4 | require 'json' 5 | 6 | class Generator 7 | def initialize 8 | @fingerprint_tests = JSON.parse(File.read('./testdata/fingerprint.json')) 9 | end 10 | 11 | def generate! 12 | test_lines = [] 13 | 14 | @fingerprint_tests.each do |test_def| 15 | test_lines << test_def['input'] 16 | test_lines << test_def['expectedHash'] 17 | end 18 | 19 | File.write './test/fingerprint_tests.c', <<-EOF 20 | const char* tests[] = { 21 | #{test_lines.map { |test_line| format(' %s,', test_line.inspect) }.join("\n")} 22 | }; 23 | 24 | size_t testsLength = __LINE__ - 4; 25 | EOF 26 | end 27 | end 28 | 29 | Generator.new.generate! 30 | -------------------------------------------------------------------------------- /src/postgres/include/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 | extern PGDLLIMPORT bool update_process_title; 16 | 17 | extern char **save_ps_display_args(int argc, char **argv); 18 | 19 | extern void init_ps_display(const char *fixed_part); 20 | 21 | extern void set_ps_display(const char *activity); 22 | 23 | extern const char *get_ps_display(int *displen); 24 | 25 | #endif /* PS_STATUS_H */ 26 | -------------------------------------------------------------------------------- /src/postgres/include/postmaster/auxprocess.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * auxprocess.h 3 | * include file for functions related to auxiliary processes. 4 | * 5 | * 6 | * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * IDENTIFICATION 10 | * src/include/postmaster/auxprocess.h 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef AUXPROCESS_H 14 | #define AUXPROCESS_H 15 | 16 | #include "miscadmin.h" 17 | 18 | extern void AuxiliaryProcessMain(AuxProcType auxtype) pg_attribute_noreturn(); 19 | 20 | #endif /* AUXPROCESS_H */ 21 | -------------------------------------------------------------------------------- /src/postgres/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 | -------------------------------------------------------------------------------- /test/sql/plpgsql_regress/plpgsql_trigger.sql: -------------------------------------------------------------------------------- 1 | -- Simple test to verify accessibility of the OLD and NEW trigger variables 2 | 3 | create table testtr (a int, b text); 4 | 5 | create function testtr_trigger() returns trigger language plpgsql as 6 | $$begin 7 | raise notice 'tg_op = %', tg_op; 8 | raise notice 'old(%) = %', old.a, row(old.*); 9 | raise notice 'new(%) = %', new.a, row(new.*); 10 | if (tg_op = 'DELETE') then 11 | return old; 12 | else 13 | return new; 14 | end if; 15 | end$$; 16 | 17 | create trigger testtr_trigger before insert or delete or update on testtr 18 | for each row execute function testtr_trigger(); 19 | 20 | insert into testtr values (1, 'one'), (2, 'two'); 21 | 22 | update testtr set a = a + 1; 23 | 24 | delete from testtr; 25 | -------------------------------------------------------------------------------- /src/postgres/include/utils/bytea.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * bytea.h 4 | * Declarations for BYTEA data type support. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/mb/stringinfo_mb.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * stringinfo_mb.h 4 | * multibyte support for StringInfo 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/delete.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE delete_test ( 2 | id SERIAL PRIMARY KEY, 3 | a INT, 4 | b text 5 | ); 6 | 7 | INSERT INTO delete_test (a) VALUES (10); 8 | INSERT INTO delete_test (a, b) VALUES (50, repeat('x', 10000)); 9 | INSERT INTO delete_test (a) VALUES (100); 10 | 11 | -- allow an alias to be specified for DELETE's target table 12 | DELETE FROM delete_test AS dt WHERE dt.a > 75; 13 | 14 | -- if an alias is specified, don't allow the original table name 15 | -- to be referenced 16 | DELETE FROM delete_test dt WHERE delete_test.a > 25; 17 | 18 | SELECT id, a, char_length(b) FROM delete_test; 19 | 20 | -- delete a row with a TOASTed value 21 | DELETE FROM delete_test WHERE a > 25; 22 | 23 | SELECT id, a, char_length(b) FROM delete_test; 24 | 25 | DROP TABLE delete_test; 26 | -------------------------------------------------------------------------------- /src/postgres/include/partitioning/partdefs.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * partdefs.h 4 | * Base definitions for partitioned table handling 5 | * 6 | * Copyright (c) 2007-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/parser/parse_expr.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * parse_expr.h 4 | * handle expressions in parser 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /test/parse.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "parse_tests.c" 9 | 10 | int main() { 11 | size_t i; 12 | bool ret_code = 0; 13 | 14 | for (i = 0; i < testsLength; i += 2) { 15 | PgQueryParseResult result = pg_query_parse(tests[i]); 16 | 17 | if (result.error) { 18 | ret_code = -1; 19 | printf("%s\n", result.error->message); 20 | } else if (strcmp(result.parse_tree, tests[i + 1]) == 0) { 21 | printf("."); 22 | } else { 23 | ret_code = -1; 24 | printf("INVALID result for \"%s\"\nexpected: %s\n actual: %s\n", tests[i], tests[i + 1], result.parse_tree); 25 | } 26 | 27 | pg_query_free_parse_result(result); 28 | } 29 | 30 | printf("\n"); 31 | 32 | pg_query_exit(); 33 | 34 | return ret_code; 35 | } 36 | -------------------------------------------------------------------------------- /test/normalize.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "normalize_tests.c" 9 | 10 | int main() { 11 | size_t i; 12 | bool ret_code = 0; 13 | 14 | for (i = 0; i < testsLength; i += 2) { 15 | PgQueryNormalizeResult result = pg_query_normalize(tests[i]); 16 | 17 | if (result.error) { 18 | ret_code = -1; 19 | printf("%s\n", result.error->message); 20 | } else if (strcmp(result.normalized_query, tests[i + 1]) == 0) { 21 | printf("."); 22 | } else { 23 | ret_code = -1; 24 | printf("INVALID result for \"%s\"\nexpected: %s\nactual: %s\n", tests[i], tests[i + 1], result.normalized_query); 25 | } 26 | 27 | pg_query_free_normalize_result(result); 28 | } 29 | 30 | printf("\n"); 31 | 32 | pg_query_exit(); 33 | 34 | return ret_code; 35 | } 36 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/async.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- ASYNC 3 | -- 4 | 5 | --Should work. Send a valid message via a valid channel name 6 | SELECT pg_notify('notify_async1','sample message1'); 7 | SELECT pg_notify('notify_async1',''); 8 | SELECT pg_notify('notify_async1',NULL); 9 | 10 | -- Should fail. Send a valid message via an invalid channel name 11 | SELECT pg_notify('','sample message1'); 12 | SELECT pg_notify(NULL,'sample message1'); 13 | SELECT pg_notify('notify_async_channel_name_too_long______________________________','sample_message1'); 14 | 15 | --Should work. Valid NOTIFY/LISTEN/UNLISTEN commands 16 | NOTIFY notify_async2; 17 | LISTEN notify_async2; 18 | UNLISTEN notify_async2; 19 | UNLISTEN *; 20 | 21 | -- Should return zero while there are no pending notifications. 22 | -- src/test/isolation/specs/async-notify.spec tests for actual usage. 23 | SELECT pg_notification_queue_usage(); 24 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/lseg.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- LSEG 3 | -- Line segments 4 | -- 5 | 6 | --DROP TABLE LSEG_TBL; 7 | CREATE TABLE LSEG_TBL (s lseg); 8 | 9 | INSERT INTO LSEG_TBL VALUES ('[(1,2),(3,4)]'); 10 | INSERT INTO LSEG_TBL VALUES ('(0,0),(6,6)'); 11 | INSERT INTO LSEG_TBL VALUES ('10,-10 ,-3,-4'); 12 | INSERT INTO LSEG_TBL VALUES ('[-1e6,2e2,3e5, -4e1]'); 13 | INSERT INTO LSEG_TBL VALUES (lseg(point(11, 22), point(33,44))); 14 | INSERT INTO LSEG_TBL VALUES ('[(-10,2),(-10,3)]'); -- vertical 15 | INSERT INTO LSEG_TBL VALUES ('[(0,-20),(30,-20)]'); -- horizontal 16 | INSERT INTO LSEG_TBL VALUES ('[(NaN,1),(NaN,90)]'); -- NaN 17 | 18 | -- bad values for parser testing 19 | INSERT INTO LSEG_TBL VALUES ('(3asdf,2 ,3,4r2)'); 20 | INSERT INTO LSEG_TBL VALUES ('[1,2,3, 4'); 21 | INSERT INTO LSEG_TBL VALUES ('[(,2),(3,4)]'); 22 | INSERT INTO LSEG_TBL VALUES ('[(1,2),(3,4)'); 23 | 24 | select * from LSEG_TBL; 25 | -------------------------------------------------------------------------------- /src/postgres/include/parser/scansup.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * scansup.h 4 | * scanner support routines used by the core lexer 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/rewrite/rewriteSupport.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * rewriteSupport.h 4 | * 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /examples/simple_plpgsql.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | PgQueryPlpgsqlParseResult result; 7 | 8 | result = pg_query_parse_plpgsql(" \ 9 | CREATE OR REPLACE FUNCTION cs_fmt_browser_version(v_name varchar, \ 10 | v_version varchar) \ 11 | RETURNS varchar AS $$ \ 12 | BEGIN \ 13 | IF v_version IS NULL THEN \ 14 | RETURN v_name; \ 15 | END IF; \ 16 | RETURN v_name || '/' || v_version; \ 17 | END; \ 18 | $$ LANGUAGE plpgsql;"); 19 | 20 | if (result.error) { 21 | printf("error: %s at %d\n", result.error->message, result.error->cursorpos); 22 | } else { 23 | printf("%s\n", result.plpgsql_funcs); 24 | } 25 | 26 | pg_query_free_plpgsql_parse_result(result); 27 | 28 | // Optional, this ensures all memory is freed upon program exit (useful when running Valgrind) 29 | pg_query_exit(); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /test/parse_protobuf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "parse_tests.c" 9 | 10 | int main() { 11 | size_t i; 12 | bool ret_code = 0; 13 | 14 | for (i = 0; i < testsLength; i += 2) { 15 | PgQueryProtobufParseResult result = pg_query_parse_protobuf(tests[i]); 16 | 17 | if (result.error) { 18 | ret_code = -1; 19 | printf("%s\n", result.error->message); 20 | } else { 21 | printf("."); 22 | } 23 | //} else if (strcmp(result.parse_tree, tests[i + 1]) == 0) { 24 | // printf("."); 25 | //} else { 26 | // ret_code = -1; 27 | // printf("INVALID result for \"%s\"\nexpected: %s\nactual: %s\n", tests[i], tests[i + 1], result.parse_tree); 28 | //} 29 | 30 | pg_query_free_protobuf_parse_result(result); 31 | } 32 | 33 | printf("\n"); 34 | 35 | pg_query_exit(); 36 | 37 | return ret_code; 38 | } 39 | -------------------------------------------------------------------------------- /src/postgres/include/utils/pg_lsn.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_lsn.h 4 | * Declarations for operations on log sequence numbers (LSNs) of 5 | * PostgreSQL. 6 | * 7 | * 8 | * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group 9 | * Portions Copyright (c) 1994, Regents of the University of California 10 | * 11 | * src/include/utils/pg_lsn.h 12 | * 13 | *------------------------------------------------------------------------- 14 | */ 15 | #ifndef PG_LSN_H 16 | #define PG_LSN_H 17 | 18 | #include "access/xlogdefs.h" 19 | #include "fmgr.h" 20 | 21 | #define DatumGetLSN(X) ((XLogRecPtr) DatumGetInt64(X)) 22 | #define LSNGetDatum(X) (Int64GetDatum((int64) (X))) 23 | 24 | #define PG_GETARG_LSN(n) DatumGetLSN(PG_GETARG_DATUM(n)) 25 | #define PG_RETURN_LSN(x) return LSNGetDatum(x) 26 | 27 | extern XLogRecPtr pg_lsn_in_internal(const char *str, bool *have_error); 28 | 29 | #endif /* PG_LSN_H */ 30 | -------------------------------------------------------------------------------- /src/postgres/include/common/keywords.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * keywords.h 4 | * PostgreSQL's list of SQL keywords 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/access/sysattr.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * sysattr.h 4 | * POSTGRES system attribute definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/replication/logicallauncher.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * logicallauncher.h 4 | * Exports for logical replication launcher. 5 | * 6 | * Portions Copyright (c) 2016-2022, 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 | 18 | extern void ApplyLauncherRegister(void); 19 | extern void ApplyLauncherMain(Datum main_arg); 20 | 21 | extern Size ApplyLauncherShmemSize(void); 22 | extern void ApplyLauncherShmemInit(void); 23 | 24 | extern void ApplyLauncherWakeupAtCommit(void); 25 | extern void AtEOXact_ApplyLauncher(bool isCommit); 26 | 27 | extern bool IsLogicalLauncher(void); 28 | 29 | #endif /* LOGICALLAUNCHER_H */ 30 | -------------------------------------------------------------------------------- /src/postgres/include/access/table.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * table.h 4 | * Generic routines for table related code. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/common/ip.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * ip.h 4 | * Definitions for IPv6-aware network access. 5 | * 6 | * These definitions are used by both frontend and backend code. 7 | * 8 | * Copyright (c) 2003-2022, PostgreSQL Global Development Group 9 | * 10 | * src/include/common/ip.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef IP_H 15 | #define IP_H 16 | 17 | #include "getaddrinfo.h" /* pgrminclude ignore */ 18 | #include "libpq/pqcomm.h" /* pgrminclude ignore */ 19 | 20 | 21 | extern int pg_getaddrinfo_all(const char *hostname, const char *servname, 22 | const struct addrinfo *hintp, 23 | struct addrinfo **result); 24 | extern void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai); 25 | 26 | extern int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, 27 | char *node, int nodelen, 28 | char *service, int servicelen, 29 | int flags); 30 | 31 | #endif /* IP_H */ 32 | -------------------------------------------------------------------------------- /src/postgres/include/access/relation.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * relation.h 4 | * Generic relation related routines. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_transform_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_transform_d.h 4 | * Macro definitions for pg_transform 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/libpq/auth.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * auth.h 4 | * Definitions for network authentication routines 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 char *pg_krb_realm; 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 | #endif /* AUTH_H */ 32 | -------------------------------------------------------------------------------- /src/postgres/include/port/atomics/arch-arm.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * arch-arm.h 4 | * Atomic operations considerations specific to ARM 5 | * 6 | * Portions Copyright (c) 2013-2022, 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__) && !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__ || __aarch64 */ 33 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/infinite_recurse.sql: -------------------------------------------------------------------------------- 1 | -- Check that stack depth detection mechanism works and 2 | -- max_stack_depth is not set too high. 3 | 4 | create function infinite_recurse() returns int as 5 | 'select infinite_recurse()' language sql; 6 | 7 | -- Unfortunately, up till mid 2020 the Linux kernel had a bug in PPC64 8 | -- signal handling that would cause this test to crash if it happened 9 | -- to receive an sinval catchup interrupt while the stack is deep: 10 | -- https://bugzilla.kernel.org/show_bug.cgi?id=205183 11 | -- It is likely to be many years before that bug disappears from all 12 | -- production kernels, so disable this test on such platforms. 13 | -- (We still create the function, so as not to have a cross-platform 14 | -- difference in the end state of the regression database.) 15 | 16 | SELECT version() ~ 'powerpc64[^,]*-linux-gnu' 17 | AS skip_test \gset 18 | \if :skip_test 19 | \quit 20 | \endif 21 | 22 | -- The full error report is not very stable, so we show only SQLSTATE 23 | -- and primary error message. 24 | 25 | \set VERBOSITY sqlstate 26 | 27 | select infinite_recurse(); 28 | 29 | \echo :LAST_ERROR_MESSAGE 30 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_depend_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_depend_d.h 4 | * Macro definitions for pg_depend 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_parameter_acl_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_parameter_acl_d.h 4 | * Macro definitions for pg_parameter_acl 5 | * 6 | * Portions Copyright (c) 1996-2022, 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_PARAMETER_ACL_D_H 19 | #define PG_PARAMETER_ACL_D_H 20 | 21 | #define ParameterAclRelationId 6243 22 | #define PgParameterAclToastTable 6244 23 | #define PgParameterAclToastIndex 6245 24 | #define ParameterAclParnameIndexId 6246 25 | #define ParameterAclOidIndexId 6247 26 | 27 | #define Anum_pg_parameter_acl_oid 1 28 | #define Anum_pg_parameter_acl_parname 2 29 | #define Anum_pg_parameter_acl_paracl 3 30 | 31 | #define Natts_pg_parameter_acl 3 32 | 33 | 34 | #endif /* PG_PARAMETER_ACL_D_H */ 35 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_namespace_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_namespace_d.h 4 | * Macro definitions for pg_namespace 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/src_port_strnlen.c: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | * Symbols referenced in this file: 3 | * - strnlen 4 | *-------------------------------------------------------------------- 5 | */ 6 | 7 | /*------------------------------------------------------------------------- 8 | * 9 | * strnlen.c 10 | * Fallback implementation of strnlen(). 11 | * 12 | * 13 | * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group 14 | * Portions Copyright (c) 1994, Regents of the University of California 15 | * 16 | * IDENTIFICATION 17 | * src/port/strnlen.c 18 | * 19 | *------------------------------------------------------------------------- 20 | */ 21 | 22 | #include "c.h" 23 | 24 | /* 25 | * Implementation of posix' strnlen for systems where it's not available. 26 | * 27 | * Returns the number of characters before a null-byte in the string pointed 28 | * to by str, unless there's no null-byte before maxlen. In the latter case 29 | * maxlen is returned. 30 | */ 31 | size_t 32 | strnlen(const char *str, size_t maxlen) 33 | { 34 | const char *p = str; 35 | 36 | while (maxlen-- > 0 && *p) 37 | p++; 38 | return p - str; 39 | } 40 | -------------------------------------------------------------------------------- /src/postgres/include/storage/sharedfileset.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * sharedfileset.h 4 | * Shared temporary file management. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/path.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- PATH 3 | -- 4 | 5 | --DROP TABLE PATH_TBL; 6 | 7 | CREATE TABLE PATH_TBL (f1 path); 8 | 9 | INSERT INTO PATH_TBL VALUES ('[(1,2),(3,4)]'); 10 | 11 | INSERT INTO PATH_TBL VALUES (' ( ( 1 , 2 ) , ( 3 , 4 ) ) '); 12 | 13 | INSERT INTO PATH_TBL VALUES ('[ (0,0),(3,0),(4,5),(1,6) ]'); 14 | 15 | INSERT INTO PATH_TBL VALUES ('((1,2) ,(3,4 ))'); 16 | 17 | INSERT INTO PATH_TBL VALUES ('1,2 ,3,4 '); 18 | 19 | INSERT INTO PATH_TBL VALUES (' [1,2,3, 4] '); 20 | 21 | INSERT INTO PATH_TBL VALUES ('((10,20))'); -- Only one point 22 | 23 | INSERT INTO PATH_TBL VALUES ('[ 11,12,13,14 ]'); 24 | 25 | INSERT INTO PATH_TBL VALUES ('( 11,12,13,14) '); 26 | 27 | -- bad values for parser testing 28 | INSERT INTO PATH_TBL VALUES ('[]'); 29 | 30 | INSERT INTO PATH_TBL VALUES ('[(,2),(3,4)]'); 31 | 32 | INSERT INTO PATH_TBL VALUES ('[(1,2),(3,4)'); 33 | 34 | INSERT INTO PATH_TBL VALUES ('(1,2,3,4'); 35 | 36 | INSERT INTO PATH_TBL VALUES ('(1,2),(3,4)]'); 37 | 38 | SELECT f1 AS open_path FROM PATH_TBL WHERE isopen(f1); 39 | 40 | SELECT f1 AS closed_path FROM PATH_TBL WHERE isclosed(f1); 41 | 42 | SELECT pclose(f1) AS closed_path FROM PATH_TBL; 43 | 44 | SELECT popen(f1) AS open_path FROM PATH_TBL; 45 | -------------------------------------------------------------------------------- /examples/simple.c: -------------------------------------------------------------------------------- 1 | // Welcome to the easiest way to parse an SQL query :-) 2 | // Compile the file like this: 3 | // 4 | // cc -I../ -L../ simple.c -lpg_query 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | size_t testCount = 6; 11 | const char* tests[] = { 12 | "SELECT 1", 13 | "SELECT * FROM x WHERE z = 2", 14 | "SELECT 5.41414", 15 | "SELECT $1", 16 | "SELECT 999999999999999999999::numeric/1000000000000000000000", 17 | "SELECT 4790999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" 18 | }; 19 | 20 | int main() { 21 | PgQueryParseResult result; 22 | size_t i; 23 | 24 | for (i = 0; i < testCount; i++) { 25 | result = pg_query_parse(tests[i]); 26 | 27 | if (result.error) { 28 | printf("error: %s at %d\n", result.error->message, result.error->cursorpos); 29 | } else { 30 | printf("%s\n", result.parse_tree); 31 | } 32 | 33 | pg_query_free_parse_result(result); 34 | } 35 | 36 | // Optional, this ensures all memory is freed upon program exit (useful when running Valgrind) 37 | pg_query_exit(); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /src/postgres/include/nodes/print.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * print.h 4 | * definitions for nodes/print.c 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/comments.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- COMMENTS 3 | -- 4 | 5 | SELECT 'trailing' AS first; -- trailing single line 6 | SELECT /* embedded single line */ 'embedded' AS second; 7 | SELECT /* both embedded and trailing single line */ 'both' AS third; -- trailing single line 8 | 9 | SELECT 'before multi-line' AS fourth; 10 | /* This is an example of SQL which should not execute: 11 | * select 'multi-line'; 12 | */ 13 | SELECT 'after multi-line' AS fifth; 14 | 15 | -- 16 | -- Nested comments 17 | -- 18 | 19 | /* 20 | SELECT 'trailing' as x1; -- inside block comment 21 | */ 22 | 23 | /* This block comment surrounds a query which itself has a block comment... 24 | SELECT /* embedded single line */ 'embedded' AS x2; 25 | */ 26 | 27 | SELECT -- continued after the following block comments... 28 | /* Deeply nested comment. 29 | This includes a single apostrophe to make sure we aren't decoding this part as a string. 30 | SELECT 'deep nest' AS n1; 31 | /* Second level of nesting... 32 | SELECT 'deeper nest' as n2; 33 | /* Third level of nesting... 34 | SELECT 'deepest nest' as n3; 35 | */ 36 | Hoo boy. Still two deep... 37 | */ 38 | Now just one deep... 39 | */ 40 | 'deeply nested example' AS sixth; 41 | 42 | /* and this is the end of the file */ 43 | -------------------------------------------------------------------------------- /src/postgres/include/access/printtup.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * printtup.h 4 | * 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/storage/buf.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * buf.h 4 | * Basic buffer manager data types. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/storage/backendid.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * backendid.h 4 | * POSTGRES backend id communication definitions 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/storage/backendid.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef BACKENDID_H 15 | #define BACKENDID_H 16 | 17 | /* ---------------- 18 | * -cim 8/17/90 19 | * ---------------- 20 | */ 21 | typedef int BackendId; /* unique currently active backend identifier */ 22 | 23 | #define InvalidBackendId (-1) 24 | 25 | extern PGDLLIMPORT BackendId MyBackendId; /* backend id of this backend */ 26 | 27 | /* backend id of our parallel session leader, or InvalidBackendId if none */ 28 | extern PGDLLIMPORT BackendId ParallelLeaderBackendId; 29 | 30 | /* 31 | * The BackendId to use for our session's temp relations is normally our own, 32 | * but parallel workers should use their leader's ID. 33 | */ 34 | #define BackendIdForTempRelations() \ 35 | (ParallelLeaderBackendId == InvalidBackendId ? MyBackendId : ParallelLeaderBackendId) 36 | 37 | #endif /* BACKENDID_H */ 38 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_conversion_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_conversion_d.h 4 | * Macro definitions for pg_conversion 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/create_function_c.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- CREATE_FUNCTION_C 3 | -- 4 | -- This script used to create C functions for other scripts to use. 5 | -- But to get rid of the ordering dependencies that caused, such 6 | -- functions are now made either in test_setup.sql or in the specific 7 | -- test script that needs them. All that remains here is error cases. 8 | 9 | -- directory path and dlsuffix are passed to us in environment variables 10 | \getenv libdir PG_LIBDIR 11 | \getenv dlsuffix PG_DLSUFFIX 12 | 13 | \set regresslib :libdir '/regress' :dlsuffix 14 | 15 | -- 16 | -- Check LOAD command. (The alternative of implicitly loading the library 17 | -- is checked in many other test scripts.) 18 | -- 19 | LOAD :'regresslib'; 20 | 21 | -- Things that shouldn't work: 22 | 23 | CREATE FUNCTION test1 (int) RETURNS int LANGUAGE C 24 | AS 'nosuchfile'; 25 | 26 | -- To produce stable regression test output, we have to filter the name 27 | -- of the regresslib file out of the error message in this test. 28 | \set VERBOSITY sqlstate 29 | CREATE FUNCTION test1 (int) RETURNS int LANGUAGE C 30 | AS :'regresslib', 'nosuchsymbol'; 31 | \set VERBOSITY default 32 | SELECT regexp_replace(:'LAST_ERROR_MESSAGE', 'file ".*"', 'file "..."'); 33 | 34 | CREATE FUNCTION test1 (int) RETURNS int LANGUAGE internal 35 | AS 'nosuch'; 36 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_publication_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_publication_d.h 4 | * Macro definitions for pg_publication 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/optimizer/geqo_gene.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * geqo_gene.h 4 | * genome representation in optimizer/geqo 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/utils/tzparser.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * tzparser.h 4 | * Timezone offset file parsing definitions. 5 | * 6 | * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/utils/tzparser.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef TZPARSER_H 14 | #define TZPARSER_H 15 | 16 | #include "utils/datetime.h" 17 | 18 | /* 19 | * The result of parsing a timezone configuration file is an array of 20 | * these structs, in order by abbrev. We export this because datetime.c 21 | * needs it. 22 | */ 23 | typedef struct tzEntry 24 | { 25 | /* the actual data */ 26 | char *abbrev; /* TZ abbreviation (downcased) */ 27 | char *zone; /* zone name if dynamic abbrev, else NULL */ 28 | /* for a dynamic abbreviation, offset/is_dst are not used */ 29 | int offset; /* offset in seconds from UTC */ 30 | bool is_dst; /* true if a DST abbreviation */ 31 | /* source information (for error messages) */ 32 | int lineno; 33 | const char *filename; 34 | } tzEntry; 35 | 36 | 37 | extern TimeZoneAbbrevTable *load_tzoffsets(const char *filename); 38 | 39 | #endif /* TZPARSER_H */ 40 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/random.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- RANDOM 3 | -- Test the random function 4 | -- 5 | 6 | -- count the number of tuples originally, should be 1000 7 | SELECT count(*) FROM onek; 8 | 9 | -- pick three random rows, they shouldn't match 10 | (SELECT unique1 AS random 11 | FROM onek ORDER BY random() LIMIT 1) 12 | INTERSECT 13 | (SELECT unique1 AS random 14 | FROM onek ORDER BY random() LIMIT 1) 15 | INTERSECT 16 | (SELECT unique1 AS random 17 | FROM onek ORDER BY random() LIMIT 1); 18 | 19 | -- count roughly 1/10 of the tuples 20 | CREATE TABLE RANDOM_TBL AS 21 | SELECT count(*) AS random 22 | FROM onek WHERE random() < 1.0/10; 23 | 24 | -- select again, the count should be different 25 | INSERT INTO RANDOM_TBL (random) 26 | SELECT count(*) 27 | FROM onek WHERE random() < 1.0/10; 28 | 29 | -- select again, the count should be different 30 | INSERT INTO RANDOM_TBL (random) 31 | SELECT count(*) 32 | FROM onek WHERE random() < 1.0/10; 33 | 34 | -- select again, the count should be different 35 | INSERT INTO RANDOM_TBL (random) 36 | SELECT count(*) 37 | FROM onek WHERE random() < 1.0/10; 38 | 39 | -- now test that they are different counts 40 | SELECT random, count(random) FROM RANDOM_TBL 41 | GROUP BY random HAVING count(random) > 3; 42 | 43 | SELECT AVG(random) FROM RANDOM_TBL 44 | HAVING AVG(random) NOT BETWEEN 80 AND 120; 45 | -------------------------------------------------------------------------------- /src/postgres/include/rewrite/rewriteHandler.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * rewriteHandler.h 4 | * External interface to query rewriter. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 void fill_extraUpdatedCols(RangeTblEntry *target_rte, 28 | Relation target_relation); 29 | 30 | extern Query *get_view_query(Relation view); 31 | extern const char *view_query_is_auto_updatable(Query *viewquery, 32 | bool check_cols); 33 | extern int relation_is_updatable(Oid reloid, 34 | List *outer_reloids, 35 | bool include_triggers, 36 | Bitmapset *include_cols); 37 | 38 | #endif /* REWRITEHANDLER_H */ 39 | -------------------------------------------------------------------------------- /src/postgres/include/storage/fileset.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * fileset.h 4 | * Management of named temporary files. 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_language_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_language_d.h 4 | * Macro definitions for pg_language 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_am_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_am_d.h 4 | * Macro definitions for pg_am 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/postmaster/startup.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * startup.h 4 | * Exports from postmaster/startup.c. 5 | * 6 | * Portions Copyright (c) 1996-2022, 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(void) 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 begin_startup_progress_phase(void); 36 | extern void startup_progress_timeout_handler(void); 37 | extern bool has_startup_progress_timeout_expired(long *secs, int *usecs); 38 | 39 | #endif /* _STARTUP_H */ 40 | -------------------------------------------------------------------------------- /test/concurrency.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "parse_tests.c" 10 | 11 | #ifdef USE_VALGRIND 12 | #define THREAD_COUNT 50 13 | #else 14 | #define THREAD_COUNT 500 15 | #endif 16 | 17 | void* test_runner(void*); 18 | 19 | int main() { 20 | size_t i; 21 | int ret; 22 | pthread_t threads[THREAD_COUNT]; 23 | 24 | for (i = 0; i < THREAD_COUNT; i += 1) { 25 | ret = pthread_create(&threads[i], NULL, test_runner, NULL); 26 | if (ret) { 27 | perror("ERROR creating pthread"); 28 | return 1; 29 | } 30 | } 31 | 32 | for (i = 0; i < THREAD_COUNT; i += 1) { 33 | pthread_join(threads[i], NULL); 34 | } 35 | 36 | printf("\n"); 37 | 38 | return 0; 39 | } 40 | 41 | void* test_runner(void* ptr) { 42 | size_t i; 43 | 44 | for (i = 0; i < testsLength; i += 2) { 45 | PgQueryParseResult result = pg_query_parse(tests[i]); 46 | 47 | if (result.error) { 48 | printf("%s\n", result.error->message); 49 | } else if (strcmp(result.parse_tree, tests[i + 1]) == 0) { 50 | printf("."); 51 | } else { 52 | printf("INVALID result for \"%s\"\nexpected: %s\nactual: %s\n", tests[i], tests[i + 1], result.parse_tree); 53 | } 54 | 55 | pg_query_free_parse_result(result); 56 | } 57 | 58 | return NULL; 59 | } 60 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/unicode.sql: -------------------------------------------------------------------------------- 1 | SELECT getdatabaseencoding() <> 'UTF8' AS skip_test \gset 2 | \if :skip_test 3 | \quit 4 | \endif 5 | 6 | SELECT U&'\0061\0308bc' <> U&'\00E4bc' COLLATE "C" AS sanity_check; 7 | 8 | SELECT normalize(''); 9 | SELECT normalize(U&'\0061\0308\24D1c') = U&'\00E4\24D1c' COLLATE "C" AS test_default; 10 | SELECT normalize(U&'\0061\0308\24D1c', NFC) = U&'\00E4\24D1c' COLLATE "C" AS test_nfc; 11 | SELECT normalize(U&'\00E4bc', NFC) = U&'\00E4bc' COLLATE "C" AS test_nfc_idem; 12 | SELECT normalize(U&'\00E4\24D1c', NFD) = U&'\0061\0308\24D1c' COLLATE "C" AS test_nfd; 13 | SELECT normalize(U&'\0061\0308\24D1c', NFKC) = U&'\00E4bc' COLLATE "C" AS test_nfkc; 14 | SELECT normalize(U&'\00E4\24D1c', NFKD) = U&'\0061\0308bc' COLLATE "C" AS test_nfkd; 15 | 16 | SELECT "normalize"('abc', 'def'); -- run-time error 17 | 18 | SELECT U&'\00E4\24D1c' IS NORMALIZED AS test_default; 19 | SELECT U&'\00E4\24D1c' IS NFC NORMALIZED AS test_nfc; 20 | 21 | SELECT num, val, 22 | val IS NFC NORMALIZED AS NFC, 23 | val IS NFD NORMALIZED AS NFD, 24 | val IS NFKC NORMALIZED AS NFKC, 25 | val IS NFKD NORMALIZED AS NFKD 26 | FROM 27 | (VALUES (1, U&'\00E4bc'), 28 | (2, U&'\0061\0308bc'), 29 | (3, U&'\00E4\24D1c'), 30 | (4, U&'\0061\0308\24D1c'), 31 | (5, '')) vals (num, val) 32 | ORDER BY num; 33 | 34 | SELECT is_normalized('abc', 'def'); -- run-time error 35 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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_update_multi_param(int nparam, const int *index, 40 | const int64 *val); 41 | extern void pgstat_progress_end_command(void); 42 | 43 | 44 | #endif /* BACKEND_PROGRESS_H */ 45 | -------------------------------------------------------------------------------- /test/fingerprint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "fingerprint_tests.c" 9 | 10 | int main() 11 | { 12 | size_t i; 13 | bool ret_code = 0; 14 | 15 | for (i = 0; i < testsLength; i += 2) 16 | { 17 | PgQueryFingerprintResult result = pg_query_fingerprint(tests[i]); 18 | 19 | if (result.error) 20 | { 21 | ret_code = -1; 22 | printf("%s\n", result.error->message); 23 | pg_query_free_fingerprint_result(result); 24 | continue; 25 | } 26 | else if (strcmp(result.fingerprint_str, tests[i + 1]) == 0) 27 | { 28 | printf("."); 29 | } 30 | else 31 | { 32 | ret_code = -1; 33 | printf("INVALID result for \"%s\"\nexpected: \"%s\"\nactual: \"%s\"\nactual tokens: ", tests[i], tests[i + 1], result.fingerprint_str); 34 | pg_query_fingerprint_with_opts(tests[i], true); 35 | } 36 | 37 | pg_query_free_fingerprint_result(result); 38 | } 39 | 40 | // Ensures that there isn't a memory leak in the error case 41 | PgQueryFingerprintResult result = pg_query_fingerprint("SELECT !"); 42 | if (strcmp(result.error->message, "syntax error at end of input") != 0) { 43 | printf("\nERROR mismatch: %s\n", result.error->message); 44 | return EXIT_FAILURE; 45 | } 46 | pg_query_free_fingerprint_result(result); 47 | 48 | printf("\n"); 49 | 50 | pg_query_exit(); 51 | 52 | return ret_code; 53 | } 54 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | #ifndef WIN32 19 | #define PG_SETMASK(mask) sigprocmask(SIG_SETMASK, mask, NULL) 20 | #else 21 | /* Emulate POSIX sigset_t APIs on Windows */ 22 | typedef int sigset_t; 23 | 24 | extern int pqsigsetmask(int mask); 25 | 26 | #define PG_SETMASK(mask) pqsigsetmask(*(mask)) 27 | #define sigemptyset(set) (*(set) = 0) 28 | #define sigfillset(set) (*(set) = ~0) 29 | #define sigaddset(set, signum) (*(set) |= (sigmask(signum))) 30 | #define sigdelset(set, signum) (*(set) &= ~(sigmask(signum))) 31 | #endif /* WIN32 */ 32 | 33 | extern PGDLLIMPORT sigset_t UnBlockSig; 34 | extern PGDLLIMPORT sigset_t BlockSig; 35 | extern PGDLLIMPORT sigset_t StartupBlockSig; 36 | 37 | extern void pqinitmask(void); 38 | 39 | /* pqsigfunc is declared in src/include/port.h */ 40 | extern pqsigfunc pqsignal_pm(int signo, pqsigfunc func); 41 | 42 | #endif /* PQSIGNAL_H */ 43 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/oid.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- OID 3 | -- 4 | 5 | CREATE TABLE OID_TBL(f1 oid); 6 | 7 | INSERT INTO OID_TBL(f1) VALUES ('1234'); 8 | INSERT INTO OID_TBL(f1) VALUES ('1235'); 9 | INSERT INTO OID_TBL(f1) VALUES ('987'); 10 | INSERT INTO OID_TBL(f1) VALUES ('-1040'); 11 | INSERT INTO OID_TBL(f1) VALUES ('99999999'); 12 | INSERT INTO OID_TBL(f1) VALUES ('5 '); 13 | INSERT INTO OID_TBL(f1) VALUES (' 10 '); 14 | -- leading/trailing hard tab is also allowed 15 | INSERT INTO OID_TBL(f1) VALUES (' 15 '); 16 | 17 | -- bad inputs 18 | INSERT INTO OID_TBL(f1) VALUES (''); 19 | INSERT INTO OID_TBL(f1) VALUES (' '); 20 | INSERT INTO OID_TBL(f1) VALUES ('asdfasd'); 21 | INSERT INTO OID_TBL(f1) VALUES ('99asdfasd'); 22 | INSERT INTO OID_TBL(f1) VALUES ('5 d'); 23 | INSERT INTO OID_TBL(f1) VALUES (' 5d'); 24 | INSERT INTO OID_TBL(f1) VALUES ('5 5'); 25 | INSERT INTO OID_TBL(f1) VALUES (' - 500'); 26 | INSERT INTO OID_TBL(f1) VALUES ('32958209582039852935'); 27 | INSERT INTO OID_TBL(f1) VALUES ('-23582358720398502385'); 28 | 29 | SELECT * FROM OID_TBL; 30 | 31 | SELECT o.* FROM OID_TBL o WHERE o.f1 = 1234; 32 | 33 | SELECT o.* FROM OID_TBL o WHERE o.f1 <> '1234'; 34 | 35 | SELECT o.* FROM OID_TBL o WHERE o.f1 <= '1234'; 36 | 37 | SELECT o.* FROM OID_TBL o WHERE o.f1 < '1234'; 38 | 39 | SELECT o.* FROM OID_TBL o WHERE o.f1 >= '1234'; 40 | 41 | SELECT o.* FROM OID_TBL o WHERE o.f1 > '1234'; 42 | 43 | DROP TABLE OID_TBL; 44 | -------------------------------------------------------------------------------- /src/postgres/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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 | 19 | /* GUC. Is actually of type PasswordType. */ 20 | extern PGDLLIMPORT int Password_encryption; 21 | 22 | /* Hook to check passwords in CreateRole() and AlterRole() */ 23 | typedef void (*check_password_hook_type) (const char *username, const char *shadow_pass, PasswordType password_type, Datum validuntil_time, bool validuntil_null); 24 | 25 | extern PGDLLIMPORT check_password_hook_type check_password_hook; 26 | 27 | extern Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt); 28 | extern Oid AlterRole(ParseState *pstate, AlterRoleStmt *stmt); 29 | extern Oid AlterRoleSet(AlterRoleSetStmt *stmt); 30 | extern void DropRole(DropRoleStmt *stmt); 31 | extern void GrantRole(GrantRoleStmt *stmt); 32 | extern ObjectAddress RenameRole(const char *oldname, const char *newname); 33 | extern void DropOwnedObjects(DropOwnedStmt *stmt); 34 | extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt); 35 | extern List *roleSpecsToIds(List *memberNames); 36 | 37 | #endif /* USER_H */ 38 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/catalog.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * catalog.h 4 | * prototypes for functions in backend/catalog/catalog.c 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | 25 | extern bool IsSystemClass(Oid relid, Form_pg_class reltuple); 26 | extern bool IsToastClass(Form_pg_class reltuple); 27 | 28 | extern bool IsCatalogRelationOid(Oid relid); 29 | 30 | extern bool IsCatalogNamespace(Oid namespaceId); 31 | extern bool IsToastNamespace(Oid namespaceId); 32 | 33 | extern bool IsReservedName(const char *name); 34 | 35 | extern bool IsSharedRelation(Oid relationId); 36 | 37 | extern bool IsPinnedObject(Oid classId, Oid objectId); 38 | 39 | extern Oid GetNewOidWithIndex(Relation relation, Oid indexId, 40 | AttrNumber oidcolumn); 41 | extern Oid GetNewRelFileNode(Oid reltablespace, Relation pg_class, 42 | char relpersistence); 43 | 44 | #endif /* CATALOG_H */ 45 | -------------------------------------------------------------------------------- /srcdata/all_known_enums.json: -------------------------------------------------------------------------------- 1 | [ 2 | "OverridingKind", 3 | "QuerySource", 4 | "SortByDir", 5 | "SortByNulls", 6 | "SetQuantifier", 7 | "A_Expr_Kind", 8 | "RoleSpecType", 9 | "TableLikeOption", 10 | "DefElemAction", 11 | "PartitionRangeDatumKind", 12 | "RTEKind", 13 | "WCOKind", 14 | "GroupingSetKind", 15 | "CTEMaterialize", 16 | "SetOperation", 17 | "ObjectType", 18 | "DropBehavior", 19 | "AlterTableType", 20 | "GrantTargetType", 21 | "VariableSetKind", 22 | "ConstrType", 23 | "ImportForeignSchemaType", 24 | "RoleStmtType", 25 | "FetchDirection", 26 | "FunctionParameterMode", 27 | "TransactionStmtKind", 28 | "ViewCheckOption", 29 | "DiscardMode", 30 | "ReindexObjectType", 31 | "AlterTSConfigType", 32 | "PublicationObjSpecType", 33 | "AlterPublicationAction", 34 | "AlterSubscriptionType", 35 | "OnCommitAction", 36 | "ParamKind", 37 | "CoercionContext", 38 | "CoercionForm", 39 | "BoolExprType", 40 | "SubLinkType", 41 | "RowCompareType", 42 | "MinMaxOp", 43 | "SQLValueFunctionOp", 44 | "XmlExprOp", 45 | "XmlOptionType", 46 | "NullTestType", 47 | "BoolTestType", 48 | "LockClauseStrength", 49 | "LockWaitPolicy", 50 | "LockTupleMode", 51 | "NodeTag", 52 | "CmdType", 53 | "JoinType", 54 | "AggStrategy", 55 | "AggSplit", 56 | "SetOpCmd", 57 | "SetOpStrategy", 58 | "OnConflictAction", 59 | "LimitOption", 60 | "vartag_external", 61 | "VacOptValue", 62 | "ScanDirection", 63 | "pg_enc", 64 | "yytokentype" 65 | ] -------------------------------------------------------------------------------- /test/sql/postgres_regress/line.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- LINE 3 | -- Infinite lines 4 | -- 5 | 6 | --DROP TABLE LINE_TBL; 7 | CREATE TABLE LINE_TBL (s line); 8 | 9 | INSERT INTO LINE_TBL VALUES ('{0,-1,5}'); -- A == 0 10 | INSERT INTO LINE_TBL VALUES ('{1,0,5}'); -- B == 0 11 | INSERT INTO LINE_TBL VALUES ('{0,3,0}'); -- A == C == 0 12 | INSERT INTO LINE_TBL VALUES (' (0,0), (6,6)'); 13 | INSERT INTO LINE_TBL VALUES ('10,-10 ,-5,-4'); 14 | INSERT INTO LINE_TBL VALUES ('[-1e6,2e2,3e5, -4e1]'); 15 | 16 | INSERT INTO LINE_TBL VALUES ('{3,NaN,5}'); 17 | INSERT INTO LINE_TBL VALUES ('{NaN,NaN,NaN}'); 18 | 19 | -- horizontal 20 | INSERT INTO LINE_TBL VALUES ('[(1,3),(2,3)]'); 21 | -- vertical 22 | INSERT INTO LINE_TBL VALUES (line(point '(3,1)', point '(3,2)')); 23 | 24 | -- bad values for parser testing 25 | INSERT INTO LINE_TBL VALUES ('{}'); 26 | INSERT INTO LINE_TBL VALUES ('{0'); 27 | INSERT INTO LINE_TBL VALUES ('{0,0}'); 28 | INSERT INTO LINE_TBL VALUES ('{0,0,1'); 29 | INSERT INTO LINE_TBL VALUES ('{0,0,1}'); 30 | INSERT INTO LINE_TBL VALUES ('{0,0,1} x'); 31 | INSERT INTO LINE_TBL VALUES ('(3asdf,2 ,3,4r2)'); 32 | INSERT INTO LINE_TBL VALUES ('[1,2,3, 4'); 33 | INSERT INTO LINE_TBL VALUES ('[(,2),(3,4)]'); 34 | INSERT INTO LINE_TBL VALUES ('[(1,2),(3,4)'); 35 | INSERT INTO LINE_TBL VALUES ('[(1,2),(1,2)]'); 36 | 37 | INSERT INTO LINE_TBL VALUES (line(point '(1,0)', point '(1,0)')); 38 | 39 | select * from LINE_TBL; 40 | 41 | select '{nan, 1, nan}'::line = '{nan, 1, nan}'::line as true, 42 | '{nan, 1, nan}'::line = '{nan, 2, nan}'::line as false; 43 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/bitmapops.sql: -------------------------------------------------------------------------------- 1 | -- Test bitmap AND and OR 2 | 3 | 4 | -- Generate enough data that we can test the lossy bitmaps. 5 | 6 | -- There's 55 tuples per page in the table. 53 is just 7 | -- below 55, so that an index scan with qual a = constant 8 | -- will return at least one hit per page. 59 is just above 9 | -- 55, so that an index scan with qual b = constant will return 10 | -- hits on most but not all pages. 53 and 59 are prime, so that 11 | -- there's a maximum number of a,b combinations in the table. 12 | -- That allows us to test all the different combinations of 13 | -- lossy and non-lossy pages with the minimum amount of data 14 | 15 | CREATE TABLE bmscantest (a int, b int, t text); 16 | 17 | INSERT INTO bmscantest 18 | SELECT (r%53), (r%59), 'foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' 19 | FROM generate_series(1,70000) r; 20 | 21 | CREATE INDEX i_bmtest_a ON bmscantest(a); 22 | CREATE INDEX i_bmtest_b ON bmscantest(b); 23 | 24 | -- We want to use bitmapscans. With default settings, the planner currently 25 | -- chooses a bitmap scan for the queries below anyway, but let's make sure. 26 | set enable_indexscan=false; 27 | set enable_seqscan=false; 28 | 29 | -- Lower work_mem to trigger use of lossy bitmaps 30 | set work_mem = 64; 31 | 32 | 33 | -- Test bitmap-and. 34 | SELECT count(*) FROM bmscantest WHERE a = 1 AND b = 1; 35 | 36 | -- Test bitmap-or. 37 | SELECT count(*) FROM bmscantest WHERE a = 1 OR b = 1; 38 | 39 | 40 | -- clean up 41 | DROP TABLE bmscantest; 42 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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_stxstattarget 6 32 | #define Anum_pg_statistic_ext_stxkeys 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 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Lukas Fittl 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of pg_query nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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/relfilenode.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(void) pg_attribute_noreturn(); 31 | extern void CheckpointerMain(void) 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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/varchar.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- VARCHAR 3 | -- 4 | 5 | -- 6 | -- Build a table for testing 7 | -- (This temporarily hides the table created in test_setup.sql) 8 | -- 9 | 10 | CREATE TEMP TABLE VARCHAR_TBL(f1 varchar(1)); 11 | 12 | INSERT INTO VARCHAR_TBL (f1) VALUES ('a'); 13 | 14 | INSERT INTO VARCHAR_TBL (f1) VALUES ('A'); 15 | 16 | -- any of the following three input formats are acceptable 17 | INSERT INTO VARCHAR_TBL (f1) VALUES ('1'); 18 | 19 | INSERT INTO VARCHAR_TBL (f1) VALUES (2); 20 | 21 | INSERT INTO VARCHAR_TBL (f1) VALUES ('3'); 22 | 23 | -- zero-length char 24 | INSERT INTO VARCHAR_TBL (f1) VALUES (''); 25 | 26 | -- try varchar's of greater than 1 length 27 | INSERT INTO VARCHAR_TBL (f1) VALUES ('cd'); 28 | INSERT INTO VARCHAR_TBL (f1) VALUES ('c '); 29 | 30 | 31 | SELECT * FROM VARCHAR_TBL; 32 | 33 | SELECT c.* 34 | FROM VARCHAR_TBL c 35 | WHERE c.f1 <> 'a'; 36 | 37 | SELECT c.* 38 | FROM VARCHAR_TBL c 39 | WHERE c.f1 = 'a'; 40 | 41 | SELECT c.* 42 | FROM VARCHAR_TBL c 43 | WHERE c.f1 < 'a'; 44 | 45 | SELECT c.* 46 | FROM VARCHAR_TBL c 47 | WHERE c.f1 <= 'a'; 48 | 49 | SELECT c.* 50 | FROM VARCHAR_TBL c 51 | WHERE c.f1 > 'a'; 52 | 53 | SELECT c.* 54 | FROM VARCHAR_TBL c 55 | WHERE c.f1 >= 'a'; 56 | 57 | DROP TABLE VARCHAR_TBL; 58 | 59 | -- 60 | -- Now test longer arrays of char 61 | -- 62 | -- This varchar_tbl was already created and filled in test_setup.sql. 63 | -- Here we just try to insert bad values. 64 | -- 65 | 66 | INSERT INTO VARCHAR_TBL (f1) VALUES ('abcde'); 67 | 68 | SELECT * FROM VARCHAR_TBL; 69 | -------------------------------------------------------------------------------- /src/postgres/include/commands/dbcommands.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * dbcommands.h 4 | * Database management commands (create/drop database). 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | 34 | extern void check_encoding_locale_matches(int encoding, const char *collate, const char *ctype); 35 | 36 | #endif /* DBCOMMANDS_H */ 37 | -------------------------------------------------------------------------------- /src/postgres/include/tcop/pquery.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pquery.h 4 | * prototypes for pquery.c. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/namespace.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Regression tests for schemas (namespaces) 3 | -- 4 | 5 | CREATE SCHEMA test_ns_schema_1 6 | CREATE UNIQUE INDEX abc_a_idx ON abc (a) 7 | 8 | CREATE VIEW abc_view AS 9 | SELECT a+1 AS a, b+1 AS b FROM abc 10 | 11 | CREATE TABLE abc ( 12 | a serial, 13 | b int UNIQUE 14 | ); 15 | 16 | -- verify that the objects were created 17 | SELECT COUNT(*) FROM pg_class WHERE relnamespace = 18 | (SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_1'); 19 | 20 | INSERT INTO test_ns_schema_1.abc DEFAULT VALUES; 21 | INSERT INTO test_ns_schema_1.abc DEFAULT VALUES; 22 | INSERT INTO test_ns_schema_1.abc DEFAULT VALUES; 23 | 24 | SELECT * FROM test_ns_schema_1.abc; 25 | SELECT * FROM test_ns_schema_1.abc_view; 26 | 27 | ALTER SCHEMA test_ns_schema_1 RENAME TO test_ns_schema_renamed; 28 | SELECT COUNT(*) FROM pg_class WHERE relnamespace = 29 | (SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_1'); 30 | 31 | -- test IF NOT EXISTS cases 32 | CREATE SCHEMA test_ns_schema_renamed; -- fail, already exists 33 | CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed; -- ok with notice 34 | CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed -- fail, disallowed 35 | CREATE TABLE abc ( 36 | a serial, 37 | b int UNIQUE 38 | ); 39 | 40 | DROP SCHEMA test_ns_schema_renamed CASCADE; 41 | 42 | -- verify that the objects were dropped 43 | SELECT COUNT(*) FROM pg_class WHERE relnamespace = 44 | (SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_renamed'); 45 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/circle.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- CIRCLE 3 | -- 4 | 5 | -- Back off displayed precision a little bit to reduce platform-to-platform 6 | -- variation in results. 7 | SET extra_float_digits = -1; 8 | 9 | CREATE TABLE CIRCLE_TBL (f1 circle); 10 | 11 | INSERT INTO CIRCLE_TBL VALUES ('<(5,1),3>'); 12 | 13 | INSERT INTO CIRCLE_TBL VALUES ('((1,2),100)'); 14 | 15 | INSERT INTO CIRCLE_TBL VALUES (' 1 , 3 , 5 '); 16 | 17 | INSERT INTO CIRCLE_TBL VALUES (' ( ( 1 , 2 ) , 3 ) '); 18 | 19 | INSERT INTO CIRCLE_TBL VALUES (' ( 100 , 200 ) , 10 '); 20 | 21 | INSERT INTO CIRCLE_TBL VALUES (' < ( 100 , 1 ) , 115 > '); 22 | 23 | INSERT INTO CIRCLE_TBL VALUES ('<(3,5),0>'); -- Zero radius 24 | 25 | INSERT INTO CIRCLE_TBL VALUES ('<(3,5),NaN>'); -- NaN radius 26 | 27 | -- bad values 28 | 29 | INSERT INTO CIRCLE_TBL VALUES ('<(-100,0),-100>'); 30 | 31 | INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10'); 32 | 33 | INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10> x'); 34 | 35 | INSERT INTO CIRCLE_TBL VALUES ('1abc,3,5'); 36 | 37 | INSERT INTO CIRCLE_TBL VALUES ('(3,(1,2),3)'); 38 | 39 | SELECT * FROM CIRCLE_TBL; 40 | 41 | SELECT center(f1) AS center 42 | FROM CIRCLE_TBL; 43 | 44 | SELECT radius(f1) AS radius 45 | FROM CIRCLE_TBL; 46 | 47 | SELECT diameter(f1) AS diameter 48 | FROM CIRCLE_TBL; 49 | 50 | SELECT f1 FROM CIRCLE_TBL WHERE radius(f1) < 5; 51 | 52 | SELECT f1 FROM CIRCLE_TBL WHERE diameter(f1) >= 10; 53 | 54 | SELECT c1.f1 AS one, c2.f1 AS two, (c1.f1 <-> c2.f1) AS distance 55 | FROM CIRCLE_TBL c1, CIRCLE_TBL c2 56 | WHERE (c1.f1 < c2.f1) AND ((c1.f1 <-> c2.f1) > 0) 57 | ORDER BY distance, area(c1.f1), area(c2.f1); 58 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/drop_operator.sql: -------------------------------------------------------------------------------- 1 | CREATE OPERATOR === ( 2 | PROCEDURE = int8eq, 3 | LEFTARG = bigint, 4 | RIGHTARG = bigint, 5 | COMMUTATOR = === 6 | ); 7 | 8 | CREATE OPERATOR !== ( 9 | PROCEDURE = int8ne, 10 | LEFTARG = bigint, 11 | RIGHTARG = bigint, 12 | NEGATOR = ===, 13 | COMMUTATOR = !== 14 | ); 15 | 16 | DROP OPERATOR !==(bigint, bigint); 17 | 18 | SELECT ctid, oprcom 19 | FROM pg_catalog.pg_operator fk 20 | WHERE oprcom != 0 AND 21 | NOT EXISTS(SELECT 1 FROM pg_catalog.pg_operator pk WHERE pk.oid = fk.oprcom); 22 | 23 | SELECT ctid, oprnegate 24 | FROM pg_catalog.pg_operator fk 25 | WHERE oprnegate != 0 AND 26 | NOT EXISTS(SELECT 1 FROM pg_catalog.pg_operator pk WHERE pk.oid = fk.oprnegate); 27 | 28 | DROP OPERATOR ===(bigint, bigint); 29 | 30 | CREATE OPERATOR <| ( 31 | PROCEDURE = int8lt, 32 | LEFTARG = bigint, 33 | RIGHTARG = bigint 34 | ); 35 | 36 | CREATE OPERATOR |> ( 37 | PROCEDURE = int8gt, 38 | LEFTARG = bigint, 39 | RIGHTARG = bigint, 40 | NEGATOR = <|, 41 | COMMUTATOR = <| 42 | ); 43 | 44 | DROP OPERATOR |>(bigint, bigint); 45 | 46 | SELECT ctid, oprcom 47 | FROM pg_catalog.pg_operator fk 48 | WHERE oprcom != 0 AND 49 | NOT EXISTS(SELECT 1 FROM pg_catalog.pg_operator pk WHERE pk.oid = fk.oprcom); 50 | 51 | SELECT ctid, oprnegate 52 | FROM pg_catalog.pg_operator fk 53 | WHERE oprnegate != 0 AND 54 | NOT EXISTS(SELECT 1 FROM pg_catalog.pg_operator pk WHERE pk.oid = fk.oprnegate); 55 | 56 | DROP OPERATOR <|(bigint, bigint); 57 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/write_parallel.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- PARALLEL 3 | -- 4 | 5 | begin; 6 | 7 | -- encourage use of parallel plans 8 | set parallel_setup_cost=0; 9 | set parallel_tuple_cost=0; 10 | set min_parallel_table_scan_size=0; 11 | set max_parallel_workers_per_gather=4; 12 | 13 | -- 14 | -- Test write operations that has an underlying query that is eligible 15 | -- for parallel plans 16 | -- 17 | explain (costs off) create table parallel_write as 18 | select length(stringu1) from tenk1 group by length(stringu1); 19 | create table parallel_write as 20 | select length(stringu1) from tenk1 group by length(stringu1); 21 | drop table parallel_write; 22 | 23 | explain (costs off) select length(stringu1) into parallel_write 24 | from tenk1 group by length(stringu1); 25 | select length(stringu1) into parallel_write 26 | from tenk1 group by length(stringu1); 27 | drop table parallel_write; 28 | 29 | explain (costs off) create materialized view parallel_mat_view as 30 | select length(stringu1) from tenk1 group by length(stringu1); 31 | create materialized view parallel_mat_view as 32 | select length(stringu1) from tenk1 group by length(stringu1); 33 | create unique index on parallel_mat_view(length); 34 | refresh materialized view parallel_mat_view; 35 | refresh materialized view concurrently parallel_mat_view; 36 | drop materialized view parallel_mat_view; 37 | 38 | prepare prep_stmt as select length(stringu1) from tenk1 group by length(stringu1); 39 | explain (costs off) create table parallel_write as execute prep_stmt; 40 | create table parallel_write as execute prep_stmt; 41 | drop table parallel_write; 42 | 43 | rollback; 44 | -------------------------------------------------------------------------------- /patches/05_limit_option_enum_value_default.patch: -------------------------------------------------------------------------------- 1 | commit e855d8c81a0cd73aa1913825e7b4395961e6f2c9 2 | Author: Lukas Fittl 3 | Date: Sun Jan 3 15:57:25 2021 -0800 4 | 5 | LimitOption: Correctly order LIMIT_OPTION_DEFAULT enum value first 6 | 7 | This seems like an oversight in the commit that added support for 8 | FETCH FIRST... WITH TIES, and causes the parsetree to always have 9 | limitOption = LIMIT_OPTION_COUNT, even when no LIMIT/OFFSET is specified. 10 | 11 | diff --git a/src/backend/executor/nodeLimit.c b/src/backend/executor/nodeLimit.c 12 | index d85cf7d93e..f1fdac3156 100644 13 | --- a/src/backend/executor/nodeLimit.c 14 | +++ b/src/backend/executor/nodeLimit.c 15 | @@ -154,7 +154,8 @@ ExecLimit(PlanState *pstate) 16 | if (!node->noCount && 17 | node->position - node->offset >= node->count) 18 | { 19 | - if (node->limitOption == LIMIT_OPTION_COUNT) 20 | + if (node->limitOption == LIMIT_OPTION_COUNT || 21 | + node->limitOption == LIMIT_OPTION_DEFAULT) 22 | { 23 | node->lstate = LIMIT_WINDOWEND; 24 | return NULL; 25 | diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h 26 | index 381d84b4e4..a540fce7eb 100644 27 | --- a/src/include/nodes/nodes.h 28 | +++ b/src/include/nodes/nodes.h 29 | @@ -844,9 +844,9 @@ typedef enum OnConflictAction 30 | */ 31 | typedef enum LimitOption 32 | { 33 | + LIMIT_OPTION_DEFAULT, /* No limit present */ 34 | LIMIT_OPTION_COUNT, /* FETCH FIRST... ONLY */ 35 | LIMIT_OPTION_WITH_TIES, /* FETCH FIRST... WITH TIES */ 36 | - LIMIT_OPTION_DEFAULT, /* No limit present */ 37 | } LimitOption; 38 | 39 | #endif /* NODES_H */ 40 | -------------------------------------------------------------------------------- /test/parse_plpgsql.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | int main() { 16 | bool ret_code = EXIT_SUCCESS; 17 | char *sample_buffer; 18 | struct stat sample_stat; 19 | int fd; 20 | FILE* f_out; 21 | PgQueryPlpgsqlParseResult result; 22 | 23 | fd = open("test/plpgsql_samples.sql", O_RDONLY); 24 | if (fd < 0) { 25 | printf("Could not read samples file\n"); 26 | return EXIT_FAILURE; 27 | } 28 | 29 | fstat(fd, &sample_stat); 30 | sample_buffer = mmap(0, sample_stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0); 31 | 32 | if (sample_buffer != (void *) - 1) 33 | { 34 | result = pg_query_parse_plpgsql(sample_buffer); 35 | munmap(sample_buffer, sample_stat.st_size); 36 | close(fd); 37 | } else { 38 | printf("Could not mmap samples file\n"); 39 | close(fd); 40 | return EXIT_FAILURE; 41 | } 42 | 43 | if (result.error) { 44 | printf("ERROR: %s\n", result.error->message); 45 | printf("CONTEXT: %s\n", result.error->context); 46 | printf("LOCATION: %s, %s:%d\n\n", result.error->funcname, result.error->filename, result.error->lineno); 47 | 48 | pg_query_free_plpgsql_parse_result(result); 49 | return EXIT_FAILURE; 50 | } 51 | 52 | f_out = fopen("test/plpgsql_samples.actual.json", "w"); 53 | fprintf(f_out, "%s\n", result.plpgsql_funcs); 54 | fclose(f_out); 55 | 56 | pg_query_free_plpgsql_parse_result(result); 57 | 58 | pg_query_exit(); 59 | 60 | return ret_code; 61 | } 62 | -------------------------------------------------------------------------------- /src/postgres/include/utils/aclchk_internal.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * aclchk_internal.h 4 | * 5 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_opfamily_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_opfamily_d.h 4 | * Macro definitions for pg_opfamily 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | #define IsBooleanOpfamily(opfamily) \ 35 | ((opfamily) == BOOL_BTREE_FAM_OID || (opfamily) == BOOL_HASH_FAM_OID) 36 | 37 | #define BOOL_BTREE_FAM_OID 424 38 | #define BPCHAR_BTREE_FAM_OID 426 39 | #define BYTEA_BTREE_FAM_OID 428 40 | #define NETWORK_BTREE_FAM_OID 1974 41 | #define INTEGER_BTREE_FAM_OID 1976 42 | #define OID_BTREE_FAM_OID 1989 43 | #define TEXT_BTREE_FAM_OID 1994 44 | #define TEXT_PATTERN_BTREE_FAM_OID 2095 45 | #define BPCHAR_PATTERN_BTREE_FAM_OID 2097 46 | #define BOOL_HASH_FAM_OID 2222 47 | #define TEXT_SPGIST_FAM_OID 4017 48 | 49 | #endif /* PG_OPFAMILY_D_H */ 50 | -------------------------------------------------------------------------------- /src/postgres/include/common/kwlookup.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * kwlookup.h 4 | * Key word lookup for PostgreSQL 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 *text, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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); 29 | extern char *format_procedure(Oid procedure_oid); 30 | extern char *format_procedure_qualified(Oid procedure_oid); 31 | extern void format_procedure_parts(Oid operator_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 | -------------------------------------------------------------------------------- /src/postgres/include/utils/fmgrtab.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * fmgrtab.h 4 | * The function manager's table of internal functions. 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/utils/varlena.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * varlena.h 4 | * Functions for the variable-length built-in types. 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | #endif 42 | -------------------------------------------------------------------------------- /src/postgres/include/common/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * string.h 3 | * string handling helpers 4 | * 5 | * Portions Copyright (c) 1996-2022, 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 | struct StringInfoData; /* avoid including stringinfo.h here */ 14 | 15 | typedef struct PromptInterruptContext 16 | { 17 | /* To avoid including here, jmpbuf is declared "void *" */ 18 | void *jmpbuf; /* existing longjmp buffer */ 19 | volatile bool *enabled; /* flag that enables longjmp-on-interrupt */ 20 | bool canceled; /* indicates whether cancellation occurred */ 21 | } PromptInterruptContext; 22 | 23 | /* functions in src/common/string.c */ 24 | extern bool pg_str_endswith(const char *str, const char *end); 25 | extern int strtoint(const char *pg_restrict str, char **pg_restrict endptr, 26 | int base); 27 | extern void pg_clean_ascii(char *str); 28 | extern int pg_strip_crlf(char *str); 29 | extern bool pg_is_ascii(const char *str); 30 | 31 | /* functions in src/common/pg_get_line.c */ 32 | extern char *pg_get_line(FILE *stream, PromptInterruptContext *prompt_ctx); 33 | extern bool pg_get_line_buf(FILE *stream, struct StringInfoData *buf); 34 | extern bool pg_get_line_append(FILE *stream, struct StringInfoData *buf, 35 | PromptInterruptContext *prompt_ctx); 36 | 37 | /* functions in src/common/sprompt.c */ 38 | extern char *simple_prompt(const char *prompt, bool echo); 39 | extern char *simple_prompt_extended(const char *prompt, bool echo, 40 | PromptInterruptContext *prompt_ctx); 41 | 42 | #endif /* COMMON_STRING_H */ 43 | -------------------------------------------------------------------------------- /src/postgres/include/tcop/cmdtag.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * cmdtag.h 4 | * Declarations for commandtag names and enumeration. 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | 17 | #define PG_CMDTAG(tag, name, evtrgok, rwrok, rowcnt) \ 18 | tag, 19 | 20 | typedef enum CommandTag 21 | { 22 | #include "tcop/cmdtaglist.h" 23 | COMMAND_TAG_NEXTTAG 24 | } CommandTag; 25 | 26 | #undef PG_CMDTAG 27 | 28 | typedef struct QueryCompletion 29 | { 30 | CommandTag commandTag; 31 | uint64 nprocessed; 32 | } QueryCompletion; 33 | 34 | 35 | static inline void 36 | SetQueryCompletion(QueryCompletion *qc, CommandTag commandTag, 37 | uint64 nprocessed) 38 | { 39 | qc->commandTag = commandTag; 40 | qc->nprocessed = nprocessed; 41 | } 42 | 43 | static inline void 44 | CopyQueryCompletion(QueryCompletion *dst, const QueryCompletion *src) 45 | { 46 | dst->commandTag = src->commandTag; 47 | dst->nprocessed = src->nprocessed; 48 | } 49 | 50 | 51 | extern void InitializeQueryCompletion(QueryCompletion *qc); 52 | extern const char *GetCommandTagName(CommandTag commandTag); 53 | extern bool command_tag_display_rowcount(CommandTag commandTag); 54 | extern bool command_tag_event_trigger_ok(CommandTag commandTag); 55 | extern bool command_tag_table_rewrite_ok(CommandTag commandTag); 56 | extern CommandTag GetCommandTagEnum(const char *tagname); 57 | 58 | #endif /* CMDTAG_H */ 59 | -------------------------------------------------------------------------------- /src/postgres/include/access/sdir.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * sdir.h 4 | * POSTGRES scan direction definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | * ScanDirection was an int8 for no apparent reason. I kept the original 20 | * values because I'm not sure if I'll break anything otherwise. -ay 2/95 21 | */ 22 | typedef enum ScanDirection 23 | { 24 | BackwardScanDirection = -1, 25 | NoMovementScanDirection = 0, 26 | ForwardScanDirection = 1 27 | } ScanDirection; 28 | 29 | /* 30 | * ScanDirectionIsValid 31 | * True iff scan direction is valid. 32 | */ 33 | #define ScanDirectionIsValid(direction) \ 34 | ((bool) (BackwardScanDirection <= (direction) && \ 35 | (direction) <= ForwardScanDirection)) 36 | 37 | /* 38 | * ScanDirectionIsBackward 39 | * True iff scan direction is backward. 40 | */ 41 | #define ScanDirectionIsBackward(direction) \ 42 | ((bool) ((direction) == BackwardScanDirection)) 43 | 44 | /* 45 | * ScanDirectionIsNoMovement 46 | * True iff scan direction indicates no movement. 47 | */ 48 | #define ScanDirectionIsNoMovement(direction) \ 49 | ((bool) ((direction) == NoMovementScanDirection)) 50 | 51 | /* 52 | * ScanDirectionIsForward 53 | * True iff scan direction is forward. 54 | */ 55 | #define ScanDirectionIsForward(direction) \ 56 | ((bool) ((direction) == ForwardScanDirection)) 57 | 58 | #endif /* SDIR_H */ 59 | -------------------------------------------------------------------------------- /src/postgres/include/libpq/crypt.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * crypt.h 4 | * Interface to libpq/crypt.c 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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, on pg_transform using btree(oid oid_ops)); 46 | DECLARE_UNIQUE_INDEX(pg_transform_type_lang_index, 3575, TransformTypeLangIndexId, on pg_transform using btree(trftype oid_ops, trflang oid_ops)); 47 | 48 | #endif /* PG_TRANSFORM_H */ 49 | -------------------------------------------------------------------------------- /src/postgres/include/access/xlogprefetcher.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * xlogprefetcher.h 4 | * Declarations for the recovery prefetching module. 5 | * 6 | * Portions Copyright (c) 2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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, on pg_ts_config using btree(cfgname name_ops, cfgnamespace oid_ops)); 51 | DECLARE_UNIQUE_INDEX_PKEY(pg_ts_config_oid_index, 3712, TSConfigOidIndexId, on pg_ts_config using btree(oid oid_ops)); 52 | 53 | #endif /* PG_TS_CONFIG_H */ 54 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_opclass_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_opclass_d.h 4 | * Macro definitions for pg_opclass 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/oidjoins.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Verify system catalog foreign key relationships 3 | -- 4 | DO $doblock$ 5 | declare 6 | fk record; 7 | nkeys integer; 8 | cmd text; 9 | err record; 10 | begin 11 | for fk in select * from pg_get_catalog_foreign_keys() 12 | loop 13 | raise notice 'checking % % => % %', 14 | fk.fktable, fk.fkcols, fk.pktable, fk.pkcols; 15 | nkeys := array_length(fk.fkcols, 1); 16 | cmd := 'SELECT ctid'; 17 | for i in 1 .. nkeys loop 18 | cmd := cmd || ', ' || quote_ident(fk.fkcols[i]); 19 | end loop; 20 | if fk.is_array then 21 | cmd := cmd || ' FROM (SELECT ctid'; 22 | for i in 1 .. nkeys-1 loop 23 | cmd := cmd || ', ' || quote_ident(fk.fkcols[i]); 24 | end loop; 25 | cmd := cmd || ', unnest(' || quote_ident(fk.fkcols[nkeys]); 26 | cmd := cmd || ') as ' || quote_ident(fk.fkcols[nkeys]); 27 | cmd := cmd || ' FROM ' || fk.fktable::text || ') fk WHERE '; 28 | else 29 | cmd := cmd || ' FROM ' || fk.fktable::text || ' fk WHERE '; 30 | end if; 31 | if fk.is_opt then 32 | for i in 1 .. nkeys loop 33 | cmd := cmd || quote_ident(fk.fkcols[i]) || ' != 0 AND '; 34 | end loop; 35 | end if; 36 | cmd := cmd || 'NOT EXISTS(SELECT 1 FROM ' || fk.pktable::text || ' pk WHERE '; 37 | for i in 1 .. nkeys loop 38 | if i > 1 then cmd := cmd || ' AND '; end if; 39 | cmd := cmd || 'pk.' || quote_ident(fk.pkcols[i]); 40 | cmd := cmd || ' = fk.' || quote_ident(fk.fkcols[i]); 41 | end loop; 42 | cmd := cmd || ')'; 43 | -- raise notice 'cmd = %', cmd; 44 | for err in execute cmd loop 45 | raise warning 'FK VIOLATION IN %(%): %', fk.fktable, fk.fkcols, err; 46 | end loop; 47 | end loop; 48 | end 49 | $doblock$; 50 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/security_label.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Test for facilities of security label 3 | -- 4 | 5 | -- initial setups 6 | SET client_min_messages TO 'warning'; 7 | 8 | DROP ROLE IF EXISTS regress_seclabel_user1; 9 | DROP ROLE IF EXISTS regress_seclabel_user2; 10 | 11 | RESET client_min_messages; 12 | 13 | CREATE USER regress_seclabel_user1 WITH CREATEROLE; 14 | CREATE USER regress_seclabel_user2; 15 | 16 | CREATE TABLE seclabel_tbl1 (a int, b text); 17 | CREATE TABLE seclabel_tbl2 (x int, y text); 18 | CREATE VIEW seclabel_view1 AS SELECT * FROM seclabel_tbl2; 19 | CREATE FUNCTION seclabel_four() RETURNS integer AS $$SELECT 4$$ language sql; 20 | CREATE DOMAIN seclabel_domain AS text; 21 | 22 | ALTER TABLE seclabel_tbl1 OWNER TO regress_seclabel_user1; 23 | ALTER TABLE seclabel_tbl2 OWNER TO regress_seclabel_user2; 24 | 25 | -- 26 | -- Test of SECURITY LABEL statement without a plugin 27 | -- 28 | SECURITY LABEL ON TABLE seclabel_tbl1 IS 'classified'; -- fail 29 | SECURITY LABEL FOR 'dummy' ON TABLE seclabel_tbl1 IS 'classified'; -- fail 30 | SECURITY LABEL ON TABLE seclabel_tbl1 IS '...invalid label...'; -- fail 31 | SECURITY LABEL ON TABLE seclabel_tbl3 IS 'unclassified'; -- fail 32 | 33 | SECURITY LABEL ON ROLE regress_seclabel_user1 IS 'classified'; -- fail 34 | SECURITY LABEL FOR 'dummy' ON ROLE regress_seclabel_user1 IS 'classified'; -- fail 35 | SECURITY LABEL ON ROLE regress_seclabel_user1 IS '...invalid label...'; -- fail 36 | SECURITY LABEL ON ROLE regress_seclabel_user3 IS 'unclassified'; -- fail 37 | 38 | -- clean up objects 39 | DROP FUNCTION seclabel_four(); 40 | DROP DOMAIN seclabel_domain; 41 | DROP VIEW seclabel_view1; 42 | DROP TABLE seclabel_tbl1; 43 | DROP TABLE seclabel_tbl2; 44 | DROP USER regress_seclabel_user1; 45 | DROP USER regress_seclabel_user2; 46 | -------------------------------------------------------------------------------- /src/postgres/include/storage/off.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * off.h 4 | * POSTGRES disk "offset" definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/storage/sinvaladt.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * sinvaladt.h 4 | * POSTGRES shared cache invalidation data manager. 5 | * 6 | * The shared cache invalidation manager is responsible for transmitting 7 | * invalidation messages between backends. Any message sent by any backend 8 | * must be delivered to all already-running backends before it can be 9 | * forgotten. (If we run out of space, we instead deliver a "RESET" 10 | * message to backends that have fallen too far behind.) 11 | * 12 | * The struct type SharedInvalidationMessage, defining the contents of 13 | * a single message, is defined in sinval.h. 14 | * 15 | * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group 16 | * Portions Copyright (c) 1994, Regents of the University of California 17 | * 18 | * src/include/storage/sinvaladt.h 19 | * 20 | *------------------------------------------------------------------------- 21 | */ 22 | #ifndef SINVALADT_H 23 | #define SINVALADT_H 24 | 25 | #include "storage/lock.h" 26 | #include "storage/sinval.h" 27 | 28 | /* 29 | * prototypes for functions in sinvaladt.c 30 | */ 31 | extern Size SInvalShmemSize(void); 32 | extern void CreateSharedInvalidationState(void); 33 | extern void SharedInvalBackendInit(bool sendOnly); 34 | extern PGPROC *BackendIdGetProc(int backendID); 35 | extern void BackendIdGetTransactionIds(int backendID, TransactionId *xid, TransactionId *xmin); 36 | 37 | extern void SIInsertDataEntries(const SharedInvalidationMessage *data, int n); 38 | extern int SIGetDataEntries(SharedInvalidationMessage *data, int datasize); 39 | extern void SICleanupQueue(bool callerHasWriteLock, int minFree); 40 | 41 | extern LocalTransactionId GetNextLocalTransactionId(void); 42 | 43 | #endif /* SINVALADT_H */ 44 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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, on pg_ts_template using btree(tmplname name_ops, tmplnamespace oid_ops)); 49 | DECLARE_UNIQUE_INDEX_PKEY(pg_ts_template_oid_index, 3767, TSTemplateOidIndexId, on pg_ts_template using btree(oid oid_ops)); 50 | 51 | #endif /* PG_TS_TEMPLATE_H */ 52 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | /* 19 | * A node in a doubly-linked list of processes. The link fields contain 20 | * the 0-based PGPROC indexes of the next and previous process, or 21 | * INVALID_PGPROCNO in the next-link of the last node and the prev-link 22 | * of the first node. A node that is currently not in any list 23 | * should have next == prev == 0; this is not a possible state for a node 24 | * that is in a list, because we disallow circularity. 25 | */ 26 | typedef struct proclist_node 27 | { 28 | int next; /* pgprocno of the next PGPROC */ 29 | int prev; /* pgprocno of the prev PGPROC */ 30 | } proclist_node; 31 | 32 | /* 33 | * Header of a doubly-linked list of PGPROCs, identified by pgprocno. 34 | * An empty list is represented by head == tail == INVALID_PGPROCNO. 35 | */ 36 | typedef struct proclist_head 37 | { 38 | int head; /* pgprocno of the head PGPROC */ 39 | int tail; /* pgprocno of the tail PGPROC */ 40 | } proclist_head; 41 | 42 | /* 43 | * List iterator allowing some modifications while iterating. 44 | */ 45 | typedef struct proclist_mutable_iter 46 | { 47 | int cur; /* pgprocno of the current PGPROC */ 48 | int next; /* pgprocno of the next PGPROC */ 49 | } proclist_mutable_iter; 50 | 51 | #endif /* PROCLIST_TYPES_H */ 52 | -------------------------------------------------------------------------------- /src/postgres/include/commands/async.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * async.h 4 | * Asynchronous notification: NOTIFY, LISTEN, UNLISTEN 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | /* 19 | * The number of SLRU page buffers we use for the notification queue. 20 | */ 21 | #define NUM_NOTIFY_BUFFERS 8 22 | 23 | extern PGDLLIMPORT bool Trace_notify; 24 | extern PGDLLIMPORT volatile sig_atomic_t notifyInterruptPending; 25 | 26 | extern Size AsyncShmemSize(void); 27 | extern void AsyncShmemInit(void); 28 | 29 | extern void NotifyMyFrontEnd(const char *channel, 30 | const char *payload, 31 | int32 srcPid); 32 | 33 | /* notify-related SQL statements */ 34 | extern void Async_Notify(const char *channel, const char *payload); 35 | extern void Async_Listen(const char *channel); 36 | extern void Async_Unlisten(const char *channel); 37 | extern void Async_UnlistenAll(void); 38 | 39 | /* perform (or cancel) outbound notify processing at transaction commit */ 40 | extern void PreCommit_Notify(void); 41 | extern void AtCommit_Notify(void); 42 | extern void AtAbort_Notify(void); 43 | extern void AtSubCommit_Notify(void); 44 | extern void AtSubAbort_Notify(void); 45 | extern void AtPrepare_Notify(void); 46 | 47 | /* signal handler for inbound notifies (PROCSIG_NOTIFY_INTERRUPT) */ 48 | extern void HandleNotifyInterrupt(void); 49 | 50 | /* process interrupts */ 51 | extern void ProcessNotifyInterrupt(bool flush); 52 | 53 | #endif /* ASYNC_H */ 54 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/access/attnum.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * attnum.h 4 | * POSTGRES attribute number definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/create_cast.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- CREATE_CAST 3 | -- 4 | 5 | -- Create some types to test with 6 | CREATE TYPE casttesttype; 7 | 8 | CREATE FUNCTION casttesttype_in(cstring) 9 | RETURNS casttesttype 10 | AS 'textin' 11 | LANGUAGE internal STRICT IMMUTABLE; 12 | CREATE FUNCTION casttesttype_out(casttesttype) 13 | RETURNS cstring 14 | AS 'textout' 15 | LANGUAGE internal STRICT IMMUTABLE; 16 | 17 | CREATE TYPE casttesttype ( 18 | internallength = variable, 19 | input = casttesttype_in, 20 | output = casttesttype_out, 21 | alignment = int4 22 | ); 23 | 24 | -- a dummy function to test with 25 | CREATE FUNCTION casttestfunc(casttesttype) RETURNS int4 LANGUAGE SQL AS 26 | $$ SELECT 1; $$; 27 | 28 | SELECT casttestfunc('foo'::text); -- fails, as there's no cast 29 | 30 | -- Try binary coercion cast 31 | CREATE CAST (text AS casttesttype) WITHOUT FUNCTION; 32 | SELECT casttestfunc('foo'::text); -- doesn't work, as the cast is explicit 33 | SELECT casttestfunc('foo'::text::casttesttype); -- should work 34 | DROP CAST (text AS casttesttype); -- cleanup 35 | 36 | -- Try IMPLICIT binary coercion cast 37 | CREATE CAST (text AS casttesttype) WITHOUT FUNCTION AS IMPLICIT; 38 | SELECT casttestfunc('foo'::text); -- Should work now 39 | 40 | -- Try I/O conversion cast. 41 | SELECT 1234::int4::casttesttype; -- No cast yet, should fail 42 | 43 | CREATE CAST (int4 AS casttesttype) WITH INOUT; 44 | SELECT 1234::int4::casttesttype; -- Should work now 45 | 46 | DROP CAST (int4 AS casttesttype); 47 | 48 | -- Try cast with a function 49 | 50 | CREATE FUNCTION int4_casttesttype(int4) RETURNS casttesttype LANGUAGE SQL AS 51 | $$ SELECT ('foo'::text || $1::text)::casttesttype; $$; 52 | 53 | CREATE CAST (int4 AS casttesttype) WITH FUNCTION int4_casttesttype(int4) AS IMPLICIT; 54 | SELECT 1234::int4::casttesttype; -- Should work now 55 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/portals_p2.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- PORTALS_P2 3 | -- 4 | 5 | BEGIN; 6 | 7 | DECLARE foo13 CURSOR FOR 8 | SELECT * FROM onek WHERE unique1 = 50; 9 | 10 | DECLARE foo14 CURSOR FOR 11 | SELECT * FROM onek WHERE unique1 = 51; 12 | 13 | DECLARE foo15 CURSOR FOR 14 | SELECT * FROM onek WHERE unique1 = 52; 15 | 16 | DECLARE foo16 CURSOR FOR 17 | SELECT * FROM onek WHERE unique1 = 53; 18 | 19 | DECLARE foo17 CURSOR FOR 20 | SELECT * FROM onek WHERE unique1 = 54; 21 | 22 | DECLARE foo18 CURSOR FOR 23 | SELECT * FROM onek WHERE unique1 = 55; 24 | 25 | DECLARE foo19 CURSOR FOR 26 | SELECT * FROM onek WHERE unique1 = 56; 27 | 28 | DECLARE foo20 CURSOR FOR 29 | SELECT * FROM onek WHERE unique1 = 57; 30 | 31 | DECLARE foo21 CURSOR FOR 32 | SELECT * FROM onek WHERE unique1 = 58; 33 | 34 | DECLARE foo22 CURSOR FOR 35 | SELECT * FROM onek WHERE unique1 = 59; 36 | 37 | DECLARE foo23 CURSOR FOR 38 | SELECT * FROM onek WHERE unique1 = 60; 39 | 40 | DECLARE foo24 CURSOR FOR 41 | SELECT * FROM onek2 WHERE unique1 = 50; 42 | 43 | DECLARE foo25 CURSOR FOR 44 | SELECT * FROM onek2 WHERE unique1 = 60; 45 | 46 | FETCH all in foo13; 47 | 48 | FETCH all in foo14; 49 | 50 | FETCH all in foo15; 51 | 52 | FETCH all in foo16; 53 | 54 | FETCH all in foo17; 55 | 56 | FETCH all in foo18; 57 | 58 | FETCH all in foo19; 59 | 60 | FETCH all in foo20; 61 | 62 | FETCH all in foo21; 63 | 64 | FETCH all in foo22; 65 | 66 | FETCH all in foo23; 67 | 68 | FETCH all in foo24; 69 | 70 | FETCH all in foo25; 71 | 72 | CLOSE foo13; 73 | 74 | CLOSE foo14; 75 | 76 | CLOSE foo15; 77 | 78 | CLOSE foo16; 79 | 80 | CLOSE foo17; 81 | 82 | CLOSE foo18; 83 | 84 | CLOSE foo19; 85 | 86 | CLOSE foo20; 87 | 88 | CLOSE foo21; 89 | 90 | CLOSE foo22; 91 | 92 | CLOSE foo23; 93 | 94 | CLOSE foo24; 95 | 96 | CLOSE foo25; 97 | 98 | END; 99 | -------------------------------------------------------------------------------- /src/postgres/include/access/tupconvert.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * tupconvert.h 4 | * Tuple conversion support. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | 43 | extern HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map); 44 | extern TupleTableSlot *execute_attr_map_slot(AttrMap *attrMap, 45 | TupleTableSlot *in_slot, 46 | TupleTableSlot *out_slot); 47 | extern Bitmapset *execute_attr_map_cols(AttrMap *attrMap, Bitmapset *inbitmap); 48 | 49 | extern void free_conversion_map(TupleConversionMap *map); 50 | 51 | #endif /* TUPCONVERT_H */ 52 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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, on pg_am using btree(amname name_ops)); 51 | DECLARE_UNIQUE_INDEX_PKEY(pg_am_oid_index, 2652, AmOidIndexId, on pg_am using btree(oid oid_ops)); 52 | 53 | #ifdef EXPOSE_TO_CLIENT_CODE 54 | 55 | /* 56 | * Allowed values for amtype 57 | */ 58 | #define AMTYPE_INDEX 'i' /* index access method */ 59 | #define AMTYPE_TABLE 't' /* table access method */ 60 | 61 | #endif /* EXPOSE_TO_CLIENT_CODE */ 62 | 63 | #endif /* PG_AM_H */ 64 | -------------------------------------------------------------------------------- /src/postgres/include/access/attmap.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * attmap.h 4 | * Definitions for PostgreSQL attribute mappings 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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 | extern AttrMap *build_attrmap_by_name_if_req(TupleDesc indesc, 47 | TupleDesc outdesc); 48 | extern AttrMap *build_attrmap_by_position(TupleDesc indesc, 49 | TupleDesc outdesc, 50 | const char *msg); 51 | 52 | #endif /* ATTMAP_H */ 53 | -------------------------------------------------------------------------------- /src/postgres/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_collation_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_collation_d.h 4 | * Macro definitions for pg_collation 5 | * 6 | * Portions Copyright (c) 1996-2022, 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_colliculocale 10 35 | #define Anum_pg_collation_collversion 11 36 | 37 | #define Natts_pg_collation 11 38 | 39 | 40 | #define COLLPROVIDER_DEFAULT 'd' 41 | #define COLLPROVIDER_ICU 'i' 42 | #define COLLPROVIDER_LIBC 'c' 43 | 44 | static inline const char * 45 | collprovider_name(char c) 46 | { 47 | switch (c) 48 | { 49 | case COLLPROVIDER_ICU: 50 | return "icu"; 51 | case COLLPROVIDER_LIBC: 52 | return "libc"; 53 | default: 54 | return "???"; 55 | } 56 | } 57 | 58 | #define DEFAULT_COLLATION_OID 100 59 | #define C_COLLATION_OID 950 60 | #define POSIX_COLLATION_OID 951 61 | 62 | #endif /* PG_COLLATION_D_H */ 63 | -------------------------------------------------------------------------------- /test/sql/plpgsql_regress/plpgsql_cache.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Cache-behavior-dependent test cases 3 | -- 4 | -- These tests logically belong in plpgsql_record.sql, and perhaps someday 5 | -- can be merged back into it. For now, however, their results are different 6 | -- depending on debug_discard_caches, so we must have two expected-output 7 | -- files to cover both cases. To minimize the maintenance effort resulting 8 | -- from that, this file should contain only tests that do have different 9 | -- results under debug_discard_caches. 10 | -- 11 | 12 | -- check behavior with changes of a named rowtype 13 | create table c_mutable(f1 int, f2 text); 14 | 15 | create function c_sillyaddone(int) returns int language plpgsql as 16 | $$ declare r c_mutable; begin r.f1 := $1; return r.f1 + 1; end $$; 17 | select c_sillyaddone(42); 18 | 19 | alter table c_mutable drop column f1; 20 | alter table c_mutable add column f1 float8; 21 | 22 | -- currently, this fails due to cached plan for "r.f1 + 1" expression 23 | -- (but if debug_discard_caches is on, it will succeed) 24 | select c_sillyaddone(42); 25 | 26 | -- but it's OK if we force plan rebuilding 27 | discard plans; 28 | select c_sillyaddone(42); 29 | 30 | -- check behavior with changes in a record rowtype 31 | create function show_result_type(text) returns text language plpgsql as 32 | $$ 33 | declare 34 | r record; 35 | t text; 36 | begin 37 | execute $1 into r; 38 | select pg_typeof(r.a) into t; 39 | return format('type %s value %s', t, r.a::text); 40 | end; 41 | $$; 42 | 43 | select show_result_type('select 1 as a'); 44 | -- currently this fails due to cached plan for pg_typeof expression 45 | -- (but if debug_discard_caches is on, it will succeed) 46 | select show_result_type('select 2.0 as a'); 47 | 48 | -- but it's OK if we force plan rebuilding 49 | discard plans; 50 | select show_result_type('select 2.0 as a'); 51 | -------------------------------------------------------------------------------- /src/postgres/include/utils/ruleutils.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * ruleutils.h 4 | * Declarations for ruleutils.c 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | 24 | extern char *pg_get_indexdef_string(Oid indexrelid); 25 | extern char *pg_get_indexdef_columns(Oid indexrelid, bool pretty); 26 | extern char *pg_get_querydef(Query *query, bool pretty); 27 | 28 | extern char *pg_get_partkeydef_columns(Oid relid, bool pretty); 29 | extern char *pg_get_partconstrdef_string(Oid partitionId, char *aliasname); 30 | 31 | extern char *pg_get_constraintdef_command(Oid constraintId); 32 | extern char *deparse_expression(Node *expr, List *dpcontext, 33 | bool forceprefix, bool showimplicit); 34 | extern List *deparse_context_for(const char *aliasname, Oid relid); 35 | extern List *deparse_context_for_plan_tree(struct PlannedStmt *pstmt, 36 | List *rtable_names); 37 | extern List *set_deparse_context_plan(List *dpcontext, 38 | struct Plan *plan, List *ancestors); 39 | extern List *select_rtable_names_for_explain(List *rtable, 40 | Bitmapset *rels_used); 41 | extern char *generate_collation_name(Oid collid); 42 | extern char *generate_opclass_name(Oid opclass); 43 | extern char *get_range_partbound_string(List *bound_datums); 44 | 45 | extern char *pg_get_statisticsobjdef_string(Oid statextid); 46 | 47 | #endif /* RULEUTILS_H */ 48 | -------------------------------------------------------------------------------- /test/scan.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "scan_tests.c" 9 | 10 | #include "protobuf/pg_query.pb-c.h" 11 | 12 | int main() { 13 | size_t i; 14 | size_t j; 15 | bool ret_code = 0; 16 | PgQuery__ScanResult *scan_result; 17 | PgQuery__ScanToken *scan_token; 18 | const ProtobufCEnumValue *token_kind; 19 | const ProtobufCEnumValue *keyword_kind; 20 | PgQueryScanResult result; 21 | 22 | for (i = 0; i < testsCount * 2; i += 2) { 23 | char buffer[1024]; 24 | buffer[0] = '\0'; 25 | 26 | result = pg_query_scan(tests[i]); 27 | 28 | if (result.error) { 29 | ret_code = -1; 30 | printf("%s\n", result.error->message); 31 | } else { 32 | scan_result = pg_query__scan_result__unpack(NULL, result.pbuf.len, (void*) result.pbuf.data); 33 | 34 | for (j = 0; j < scan_result->n_tokens; j++) { 35 | char buffer2[1024]; 36 | scan_token = scan_result->tokens[j]; 37 | token_kind = protobuf_c_enum_descriptor_get_value(&pg_query__token__descriptor, scan_token->token); 38 | keyword_kind = protobuf_c_enum_descriptor_get_value(&pg_query__keyword_kind__descriptor, scan_token->keyword_kind); 39 | sprintf(buffer2, "%.*s = %s, %s\n", scan_token->end - scan_token->start, &(tests[i][scan_token->start]), token_kind->name, keyword_kind->name); 40 | strcat(buffer, buffer2); 41 | } 42 | 43 | pg_query__scan_result__free_unpacked(scan_result, NULL); 44 | 45 | if (strcmp(buffer, tests[i + 1]) == 0) { 46 | printf("."); 47 | } else { 48 | ret_code = -1; 49 | printf("INVALID result for \"%s\"\nexpected:\n%s\nactual:\n%s\n", tests[i], tests[i + 1], buffer); 50 | } 51 | } 52 | 53 | pg_query_free_scan_result(result); 54 | } 55 | 56 | printf("\n"); 57 | 58 | pg_query_exit(); 59 | 60 | return ret_code; 61 | } 62 | -------------------------------------------------------------------------------- /src/postgres/include/commands/variable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * variable.h 3 | * Routines for handling specialized SET variables. 4 | * 5 | * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group 6 | * Portions Copyright (c) 1994, Regents of the University of California 7 | * 8 | * src/include/commands/variable.h 9 | */ 10 | #ifndef VARIABLE_H 11 | #define VARIABLE_H 12 | 13 | #include "utils/guc.h" 14 | 15 | 16 | extern bool check_datestyle(char **newval, void **extra, GucSource source); 17 | extern void assign_datestyle(const char *newval, void *extra); 18 | extern bool check_timezone(char **newval, void **extra, GucSource source); 19 | extern void assign_timezone(const char *newval, void *extra); 20 | extern const char *show_timezone(void); 21 | extern bool check_log_timezone(char **newval, void **extra, GucSource source); 22 | extern void assign_log_timezone(const char *newval, void *extra); 23 | extern const char *show_log_timezone(void); 24 | extern bool check_transaction_read_only(bool *newval, void **extra, GucSource source); 25 | extern bool check_XactIsoLevel(int *newval, void **extra, GucSource source); 26 | extern bool check_transaction_deferrable(bool *newval, void **extra, GucSource source); 27 | extern bool check_random_seed(double *newval, void **extra, GucSource source); 28 | extern void assign_random_seed(double newval, void *extra); 29 | extern const char *show_random_seed(void); 30 | extern bool check_client_encoding(char **newval, void **extra, GucSource source); 31 | extern void assign_client_encoding(const char *newval, void *extra); 32 | extern bool check_session_authorization(char **newval, void **extra, GucSource source); 33 | extern void assign_session_authorization(const char *newval, void *extra); 34 | extern bool check_role(char **newval, void **extra, GucSource source); 35 | extern void assign_role(const char *newval, void *extra); 36 | extern const char *show_role(void); 37 | 38 | #endif /* VARIABLE_H */ 39 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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, on pg_ts_dict using btree(dictname name_ops, dictnamespace oid_ops)); 57 | DECLARE_UNIQUE_INDEX_PKEY(pg_ts_dict_oid_index, 3605, TSDictionaryOidIndexId, on pg_ts_dict using btree(oid oid_ops)); 58 | 59 | #endif /* PG_TS_DICT_H */ 60 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/common/file_perm.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * File and directory permission definitions 4 | * 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | -------------------------------------------------------------------------------- /src/postgres/include/catalog/storage.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * storage.h 4 | * prototypes for functions in backend/catalog/storage.c 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2022, 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/relfilenode.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(RelFileNode rnode, 26 | char relpersistence, 27 | bool register_delete); 28 | extern void RelationDropStorage(Relation rel); 29 | extern void RelationPreserveStorage(RelFileNode rnode, 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 RelFileNodeSkippingWAL(RelFileNode rnode); 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, RelFileNode **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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/select_having.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- SELECT_HAVING 3 | -- 4 | 5 | -- load test data 6 | CREATE TABLE test_having (a int, b int, c char(8), d char); 7 | INSERT INTO test_having VALUES (0, 1, 'XXXX', 'A'); 8 | INSERT INTO test_having VALUES (1, 2, 'AAAA', 'b'); 9 | INSERT INTO test_having VALUES (2, 2, 'AAAA', 'c'); 10 | INSERT INTO test_having VALUES (3, 3, 'BBBB', 'D'); 11 | INSERT INTO test_having VALUES (4, 3, 'BBBB', 'e'); 12 | INSERT INTO test_having VALUES (5, 3, 'bbbb', 'F'); 13 | INSERT INTO test_having VALUES (6, 4, 'cccc', 'g'); 14 | INSERT INTO test_having VALUES (7, 4, 'cccc', 'h'); 15 | INSERT INTO test_having VALUES (8, 4, 'CCCC', 'I'); 16 | INSERT INTO test_having VALUES (9, 4, 'CCCC', 'j'); 17 | 18 | SELECT b, c FROM test_having 19 | GROUP BY b, c HAVING count(*) = 1 ORDER BY b, c; 20 | 21 | -- HAVING is effectively equivalent to WHERE in this case 22 | SELECT b, c FROM test_having 23 | GROUP BY b, c HAVING b = 3 ORDER BY b, c; 24 | 25 | SELECT lower(c), count(c) FROM test_having 26 | GROUP BY lower(c) HAVING count(*) > 2 OR min(a) = max(a) 27 | ORDER BY lower(c); 28 | 29 | SELECT c, max(a) FROM test_having 30 | GROUP BY c HAVING count(*) > 2 OR min(a) = max(a) 31 | ORDER BY c; 32 | 33 | -- test degenerate cases involving HAVING without GROUP BY 34 | -- Per SQL spec, these should generate 0 or 1 row, even without aggregates 35 | 36 | SELECT min(a), max(a) FROM test_having HAVING min(a) = max(a); 37 | SELECT min(a), max(a) FROM test_having HAVING min(a) < max(a); 38 | 39 | -- errors: ungrouped column references 40 | SELECT a FROM test_having HAVING min(a) < max(a); 41 | SELECT 1 AS one FROM test_having HAVING a > 1; 42 | 43 | -- the really degenerate case: need not scan table at all 44 | SELECT 1 AS one FROM test_having HAVING 1 > 2; 45 | SELECT 1 AS one FROM test_having HAVING 1 < 2; 46 | 47 | -- and just to prove that we aren't scanning the table: 48 | SELECT 1 AS one FROM test_having WHERE 1/a = 1 HAVING 1 < 2; 49 | 50 | DROP TABLE test_having; 51 | -------------------------------------------------------------------------------- /src/postgres/include/utils/rls.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * rls.h 4 | * Header file for Row Level Security (RLS) utility commands to be used 5 | * with the rowsecurity feature. 6 | * 7 | * Copyright (c) 2007-2022, PostgreSQL Global Development Group 8 | * 9 | * src/include/utils/rls.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef RLS_H 14 | #define RLS_H 15 | 16 | /* GUC variable */ 17 | extern PGDLLIMPORT bool row_security; 18 | 19 | /* 20 | * Used by callers of check_enable_rls. 21 | * 22 | * RLS could be completely disabled on the tables involved in the query, 23 | * which is the simple case, or it may depend on the current environment 24 | * (the role which is running the query or the value of the row_security 25 | * GUC), or it might be simply enabled as usual. 26 | * 27 | * If RLS isn't on the table involved then RLS_NONE is returned to indicate 28 | * that we don't need to worry about invalidating the query plan for RLS 29 | * reasons. If RLS is on the table, but we are bypassing it for now, then 30 | * we return RLS_NONE_ENV to indicate that, if the environment changes, 31 | * we need to invalidate and replan. Finally, if RLS should be turned on 32 | * for the query, then we return RLS_ENABLED, which means we also need to 33 | * invalidate if the environment changes. 34 | * 35 | * Note that RLS_ENABLED will also be returned if noError is true 36 | * (indicating that the caller simply want to know if RLS should be applied 37 | * for this user but doesn't want an error thrown if it is; this is used 38 | * by other error cases where we're just trying to decide if data from the 39 | * table should be passed back to the user or not). 40 | */ 41 | enum CheckEnableRlsResult 42 | { 43 | RLS_NONE, 44 | RLS_NONE_ENV, 45 | RLS_ENABLED 46 | }; 47 | 48 | extern int check_enable_rls(Oid relid, Oid checkAsUser, bool noError); 49 | 50 | #endif /* RLS_H */ 51 | -------------------------------------------------------------------------------- /vendor/xxhash/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" -------------------------------------------------------------------------------- /src/postgres/include/catalog/pg_authid_d.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pg_authid_d.h 4 | * Macro definitions for pg_authid 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | 57 | #endif /* PG_AUTHID_D_H */ 58 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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, on pg_ts_parser using btree(prsname name_ops, prsnamespace oid_ops)); 58 | DECLARE_UNIQUE_INDEX_PKEY(pg_ts_parser_oid_index, 3607, TSParserOidIndexId, on pg_ts_parser using btree(oid oid_ops)); 59 | 60 | #endif /* PG_TS_PARSER_H */ 61 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/macaddr.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- macaddr 3 | -- 4 | 5 | CREATE TABLE macaddr_data (a int, b macaddr); 6 | 7 | INSERT INTO macaddr_data VALUES (1, '08:00:2b:01:02:03'); 8 | INSERT INTO macaddr_data VALUES (2, '08-00-2b-01-02-03'); 9 | INSERT INTO macaddr_data VALUES (3, '08002b:010203'); 10 | INSERT INTO macaddr_data VALUES (4, '08002b-010203'); 11 | INSERT INTO macaddr_data VALUES (5, '0800.2b01.0203'); 12 | INSERT INTO macaddr_data VALUES (6, '0800-2b01-0203'); 13 | INSERT INTO macaddr_data VALUES (7, '08002b010203'); 14 | INSERT INTO macaddr_data VALUES (8, '0800:2b01:0203'); -- invalid 15 | INSERT INTO macaddr_data VALUES (9, 'not even close'); -- invalid 16 | 17 | INSERT INTO macaddr_data VALUES (10, '08:00:2b:01:02:04'); 18 | INSERT INTO macaddr_data VALUES (11, '08:00:2b:01:02:02'); 19 | INSERT INTO macaddr_data VALUES (12, '08:00:2a:01:02:03'); 20 | INSERT INTO macaddr_data VALUES (13, '08:00:2c:01:02:03'); 21 | INSERT INTO macaddr_data VALUES (14, '08:00:2a:01:02:04'); 22 | 23 | SELECT * FROM macaddr_data; 24 | 25 | CREATE INDEX macaddr_data_btree ON macaddr_data USING btree (b); 26 | CREATE INDEX macaddr_data_hash ON macaddr_data USING hash (b); 27 | 28 | SELECT a, b, trunc(b) FROM macaddr_data ORDER BY 2, 1; 29 | 30 | SELECT b < '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true 31 | SELECT b > '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false 32 | SELECT b > '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false 33 | SELECT b <= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true 34 | SELECT b >= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false 35 | SELECT b = '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- true 36 | SELECT b <> '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true 37 | SELECT b <> '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false 38 | 39 | SELECT ~b FROM macaddr_data; 40 | SELECT b & '00:00:00:ff:ff:ff' FROM macaddr_data; 41 | SELECT b | '01:02:03:04:05:06' FROM macaddr_data; 42 | 43 | DROP TABLE macaddr_data; 44 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/pg_lsn.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- PG_LSN 3 | -- 4 | 5 | CREATE TABLE PG_LSN_TBL (f1 pg_lsn); 6 | 7 | -- Largest and smallest input 8 | INSERT INTO PG_LSN_TBL VALUES ('0/0'); 9 | INSERT INTO PG_LSN_TBL VALUES ('FFFFFFFF/FFFFFFFF'); 10 | 11 | -- Incorrect input 12 | INSERT INTO PG_LSN_TBL VALUES ('G/0'); 13 | INSERT INTO PG_LSN_TBL VALUES ('-1/0'); 14 | INSERT INTO PG_LSN_TBL VALUES (' 0/12345678'); 15 | INSERT INTO PG_LSN_TBL VALUES ('ABCD/'); 16 | INSERT INTO PG_LSN_TBL VALUES ('/ABCD'); 17 | 18 | -- Min/Max aggregation 19 | SELECT MIN(f1), MAX(f1) FROM PG_LSN_TBL; 20 | 21 | DROP TABLE PG_LSN_TBL; 22 | 23 | -- Operators 24 | SELECT '0/16AE7F8' = '0/16AE7F8'::pg_lsn; 25 | SELECT '0/16AE7F8'::pg_lsn != '0/16AE7F7'; 26 | SELECT '0/16AE7F7' < '0/16AE7F8'::pg_lsn; 27 | SELECT '0/16AE7F8' > pg_lsn '0/16AE7F7'; 28 | SELECT '0/16AE7F7'::pg_lsn - '0/16AE7F8'::pg_lsn; 29 | SELECT '0/16AE7F8'::pg_lsn - '0/16AE7F7'::pg_lsn; 30 | SELECT '0/16AE7F7'::pg_lsn + 16::numeric; 31 | SELECT 16::numeric + '0/16AE7F7'::pg_lsn; 32 | SELECT '0/16AE7F7'::pg_lsn - 16::numeric; 33 | SELECT 'FFFFFFFF/FFFFFFFE'::pg_lsn + 1::numeric; 34 | SELECT 'FFFFFFFF/FFFFFFFE'::pg_lsn + 2::numeric; -- out of range error 35 | SELECT '0/1'::pg_lsn - 1::numeric; 36 | SELECT '0/1'::pg_lsn - 2::numeric; -- out of range error 37 | SELECT '0/0'::pg_lsn + ('FFFFFFFF/FFFFFFFF'::pg_lsn - '0/0'::pg_lsn); 38 | SELECT 'FFFFFFFF/FFFFFFFF'::pg_lsn - ('FFFFFFFF/FFFFFFFF'::pg_lsn - '0/0'::pg_lsn); 39 | SELECT '0/16AE7F7'::pg_lsn + 'NaN'::numeric; 40 | SELECT '0/16AE7F7'::pg_lsn - 'NaN'::numeric; 41 | 42 | -- Check btree and hash opclasses 43 | EXPLAIN (COSTS OFF) 44 | SELECT DISTINCT (i || '/' || j)::pg_lsn f 45 | FROM generate_series(1, 10) i, 46 | generate_series(1, 10) j, 47 | generate_series(1, 5) k 48 | WHERE i <= 10 AND j > 0 AND j <= 10 49 | ORDER BY f; 50 | 51 | SELECT DISTINCT (i || '/' || j)::pg_lsn f 52 | FROM generate_series(1, 10) i, 53 | generate_series(1, 10) j, 54 | generate_series(1, 5) k 55 | WHERE i <= 10 AND j > 0 AND j <= 10 56 | ORDER BY f; 57 | -------------------------------------------------------------------------------- /src/postgres/include/access/clog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clog.h 3 | * 4 | * PostgreSQL transaction-commit-log manager 5 | * 6 | * Portions Copyright (c) 1996-2022, 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 | int 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 CLOGShmemBuffers(void); 44 | extern Size CLOGShmemSize(void); 45 | extern void CLOGShmemInit(void); 46 | extern void BootStrapCLOG(void); 47 | extern void StartupCLOG(void); 48 | extern void TrimCLOG(void); 49 | extern void CheckPointCLOG(void); 50 | extern void ExtendCLOG(TransactionId newestXact); 51 | extern void TruncateCLOG(TransactionId oldestXact, Oid oldestxid_datoid); 52 | 53 | extern int clogsyncfiletag(const FileTag *ftag, char *path); 54 | 55 | /* XLOG stuff */ 56 | #define CLOG_ZEROPAGE 0x00 57 | #define CLOG_TRUNCATE 0x10 58 | 59 | extern void clog_redo(XLogReaderState *record); 60 | extern void clog_desc(StringInfo buf, XLogReaderState *record); 61 | extern const char *clog_identify(uint8 info); 62 | 63 | #endif /* CLOG_H */ 64 | -------------------------------------------------------------------------------- /patches/06_alloc_set_delete_free_list.patch: -------------------------------------------------------------------------------- 1 | commit f716536100e86bb410341daf3f84cf23f4e3adc2 2 | Author: Lukas Fittl 3 | Date: Sat Jan 9 23:42:42 2021 -0800 4 | 5 | Add AllocSetDeleteFreeList to clean up aset.c's freelist 6 | 7 | This frees up the memory allocated to memory contexts that are kept 8 | for future allocations. This behaves similar to changing aset.c's 9 | MAX_FREE_CONTEXTS to 0, but only does the cleanup when called, and 10 | allows the freelist approach to be used during Postgres operations. 11 | 12 | diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c 13 | index 60a761caba..43c3974bed 100644 14 | --- a/src/backend/utils/mmgr/aset.c 15 | +++ b/src/backend/utils/mmgr/aset.c 16 | @@ -1518,3 +1518,25 @@ AllocSetCheck(MemoryContext context) 17 | } 18 | 19 | #endif /* MEMORY_CONTEXT_CHECKING */ 20 | + 21 | +void 22 | +AllocSetDeleteFreeList(MemoryContext context) 23 | +{ 24 | + AllocSet set = (AllocSet) context; 25 | + if (set->freeListIndex >= 0) 26 | + { 27 | + AllocSetFreeList *freelist = &context_freelists[set->freeListIndex]; 28 | + 29 | + while (freelist->first_free != NULL) 30 | + { 31 | + AllocSetContext *oldset = freelist->first_free; 32 | + 33 | + freelist->first_free = (AllocSetContext *) oldset->header.nextchild; 34 | + freelist->num_free--; 35 | + 36 | + /* All that remains is to free the header/initial block */ 37 | + free(oldset); 38 | + } 39 | + Assert(freelist->num_free == 0); 40 | + } 41 | +} 42 | diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h 43 | index 909bc2e988..1a27b6f944 100644 44 | --- a/src/include/utils/memutils.h 45 | +++ b/src/include/utils/memutils.h 46 | @@ -158,6 +158,7 @@ extern MemoryContext AllocSetContextCreateInternal(MemoryContext parent, 47 | Size minContextSize, 48 | Size initBlockSize, 49 | Size maxBlockSize); 50 | +extern void AllocSetDeleteFreeList(MemoryContext context); 51 | 52 | /* 53 | * This wrapper macro exists to check for non-constant strings used as context 54 | -------------------------------------------------------------------------------- /src/postgres/include/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-2022, 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 | -------------------------------------------------------------------------------- /test/sql/postgres_regress/mvcc.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Verify that index scans encountering dead rows produced by an 3 | -- aborted subtransaction of the current transaction can utilize the 4 | -- kill_prio_tuple optimization 5 | -- 6 | -- NB: The table size is currently *not* expected to stay the same, we 7 | -- don't have logic to trigger opportunistic pruning in cases like 8 | -- this. 9 | BEGIN; 10 | 11 | SET LOCAL enable_seqscan = false; 12 | SET LOCAL enable_indexonlyscan = false; 13 | SET LOCAL enable_bitmapscan = false; 14 | 15 | -- Can't easily use a unique index, since dead tuples can be found 16 | -- independent of the kill_prior_tuples optimization. 17 | CREATE TABLE clean_aborted_self(key int, data text); 18 | CREATE INDEX clean_aborted_self_key ON clean_aborted_self(key); 19 | INSERT INTO clean_aborted_self (key, data) VALUES (-1, 'just to allocate metapage'); 20 | 21 | -- save index size from before the changes, for comparison 22 | SELECT pg_relation_size('clean_aborted_self_key') AS clean_aborted_self_key_before \gset 23 | 24 | DO $$ 25 | BEGIN 26 | -- iterate often enough to see index growth even on larger-than-default page sizes 27 | FOR i IN 1..100 LOOP 28 | BEGIN 29 | -- perform index scan over all the inserted keys to get them to be seen as dead 30 | IF EXISTS(SELECT * FROM clean_aborted_self WHERE key > 0 AND key < 100) THEN 31 | RAISE data_corrupted USING MESSAGE = 'these rows should not exist'; 32 | END IF; 33 | INSERT INTO clean_aborted_self SELECT g.i, 'rolling back in a sec' FROM generate_series(1, 100) g(i); 34 | -- just some error that's not normally thrown 35 | RAISE reading_sql_data_not_permitted USING MESSAGE = 'round and round again'; 36 | EXCEPTION WHEN reading_sql_data_not_permitted THEN END; 37 | END LOOP; 38 | END;$$; 39 | 40 | -- show sizes only if they differ 41 | SELECT :clean_aborted_self_key_before AS size_before, pg_relation_size('clean_aborted_self_key') size_after 42 | WHERE :clean_aborted_self_key_before != pg_relation_size('clean_aborted_self_key'); 43 | 44 | ROLLBACK; 45 | --------------------------------------------------------------------------------