Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions pg_extension_base/include/pg_extension_base/pg_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,55 @@
#pragma once
#include "postgres.h"

#include "catalog/pg_type_d.h"
#include "commands/copy.h"
#include "nodes/miscnodes.h"
#include "utils/numeric.h"

#if PG_VERSION_NUM >= 190000

/*
* PG19 reshaped CopyFormatOptions: the bool fields ".binary" and ".csv_mode"
* were replaced by a single CopyFormat enum field ".format". Provide
* accessor macros so callers keep the older names.
*/
#define CopyOptsIsBinary(opts) ((opts).format == COPY_FORMAT_BINARY)
#define CopyOptsIsCsvMode(opts) ((opts).format == COPY_FORMAT_CSV)

/*
* PG19 renamed numeric_int4_opt_error -> numeric_int4_safe and switched the
* out-of-band error signal from a bool* to an ErrorSaveContext* (the standard
* "soft error" API). Wrap with the older name + bool* signature.
*/
static inline int32
numeric_int4_opt_error(Numeric num, bool *have_error)
{
ErrorSaveContext escontext = {T_ErrorSaveContext};
int32 result = numeric_int4_safe(num, (Node *) &escontext);

*have_error = escontext.error_occurred;
return result;
}

/*
* Likewise for the binary numeric arithmetic helpers, which were also
* renamed from foo_opt_error(Numeric, Numeric, bool *) to
* foo_safe(Numeric, Numeric, Node *escontext) in PG19. Our callers always
* pass NULL for the error argument, so just forward to the new name.
*/
#define numeric_add_opt_error(num1, num2, _ignored) numeric_add_safe(num1, num2, NULL)
#define numeric_sub_opt_error(num1, num2, _ignored) numeric_sub_safe(num1, num2, NULL)
#define numeric_mul_opt_error(num1, num2, _ignored) numeric_mul_safe(num1, num2, NULL)
#define numeric_div_opt_error(num1, num2, _ignored) numeric_div_safe(num1, num2, NULL)
#define numeric_mod_opt_error(num1, num2, _ignored) numeric_mod_safe(num1, num2, NULL)

#else

#define CopyOptsIsBinary(opts) ((opts).binary)
#define CopyOptsIsCsvMode(opts) ((opts).csv_mode)

#endif

#if PG_VERSION_NUM < 170000

#define foreach_ptr(type, var, lst) foreach_internal(type, *, var, lst, lfirst)
Expand Down
2 changes: 2 additions & 0 deletions pg_extension_base/include/pg_extension_base/spi_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
#ifndef SPI_UTILITIES_H
#define SPI_UTILITIES_H

#include "catalog/pg_type_d.h"
#include "miscadmin.h"

#include "executor/spi.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/jsonb.h"
#include "utils/pg_lsn.h"
#include "utils/timestamp.h"

/* SPI macros for setting parameters */
#define DATUMIZE_TEXTOID(Value) CStringGetTextDatum(Value)
Expand Down
2 changes: 2 additions & 0 deletions pg_extension_base/src/attached_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "miscadmin.h"
#include "pgstat.h"

#include "access/htup_details.h"
#include "access/xact.h"
#include "catalog/pg_authid.h"
#include "commands/dbcommands.h"
Expand Down Expand Up @@ -61,6 +62,7 @@
#include "utils/syscache.h"
#include "utils/timeout.h"
#include "utils/typcache.h"
#include "utils/tuplestore.h"

#define QUEUE_SIZE ((Size) 65536)
#define ATTACHED_WORKER_MAGIC 0x52004040
Expand Down
34 changes: 33 additions & 1 deletion pg_extension_base/src/base_worker_launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
* should still exist, or whether to clean up their shared memory records.
*/
#include "postgres.h"
#include "utils/hsearch.h"
#include "access/htup_details.h"
#include "catalog/pg_type_d.h"
#include "fmgr.h"
#include "funcapi.h"
#include "miscadmin.h"
Expand Down Expand Up @@ -94,6 +97,10 @@
#include "utils/memutils.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
#include "utils/tuplestore.h"
#if PG_VERSION_NUM >= 190000
#include "utils/wait_event.h"
#endif
#include "tcop/utility.h"

#include "pg_extension_base/base_workers.h"
Expand Down Expand Up @@ -508,11 +515,20 @@ BaseWorkerSharedMemoryInit(void)

if (!alreadyInitialized)
{
BaseWorkerControl->trancheId = LWLockNewTrancheId();
BaseWorkerControl->lockTrancheName = "pg_extension_base server starter locks";
#if PG_VERSION_NUM >= 190000

/*
* PG19 folded the name into LWLockNewTrancheId and removed
* LWLockRegisterTranche entirely.
*/
BaseWorkerControl->trancheId =
LWLockNewTrancheId(BaseWorkerControl->lockTrancheName);
#else
BaseWorkerControl->trancheId = LWLockNewTrancheId();
LWLockRegisterTranche(BaseWorkerControl->trancheId,
BaseWorkerControl->lockTrancheName);
#endif

LWLockInitialize(&BaseWorkerControl->lock,
BaseWorkerControl->trancheId);
Expand All @@ -527,7 +543,11 @@ BaseWorkerSharedMemoryInit(void)
int hashFlags = (HASH_ELEM | HASH_FUNCTION);

DatabaseStarterHash = ShmemInitHash("pg_extension_base database starter hash",
#if PG_VERSION_NUM >= 190000
2 * max_worker_processes,
#else
max_worker_processes, 2 * max_worker_processes,
#endif
&hashInfo, hashFlags);

memset(&hashInfo, 0, sizeof(hashInfo));
Expand All @@ -537,7 +557,11 @@ BaseWorkerSharedMemoryInit(void)
hashFlags = (HASH_ELEM | HASH_FUNCTION);

BaseWorkerHash = ShmemInitHash("pg_extension_base base worker hash",
#if PG_VERSION_NUM >= 190000
2 * max_worker_processes,
#else
max_worker_processes, 2 * max_worker_processes,
#endif
&hashInfo, hashFlags);

LWLockRelease(AddinShmemInitLock);
Expand Down Expand Up @@ -650,7 +674,11 @@ PgExtensionServerStarterMain(Datum arg)
/* set up signal handlers */
pqsignal(SIGHUP, HandleSighup);
pqsignal(SIGTERM, HandleSigterm);
#if PG_VERSION_NUM >= 190000
pqsignal(SIGINT, PG_SIG_IGN);
#else
pqsignal(SIGINT, SIG_IGN);
#endif

before_shmem_exit(PgBaseExtensionServerStarterSharedMemoryExit, 0);

Expand Down Expand Up @@ -1012,7 +1040,11 @@ PgExtensionBaseDatabaseStarterMain(Datum databaseIdDatum)

/* Establish signal handlers before unblocking signals. */
pqsignal(SIGHUP, HandleSighup);
#if PG_VERSION_NUM >= 190000
pqsignal(SIGINT, PG_SIG_IGN);
#else
pqsignal(SIGINT, SIG_IGN);
#endif
pqsignal(SIGTERM, HandleSigterm);

/* Set our exit handler before any calls to proc_exit */
Expand Down
1 change: 1 addition & 0 deletions pg_extension_base/src/library_preloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "utils/builtins.h"
#include "utils/conffiles.h"
#include "utils/guc.h"
#include "utils/tuplestore.h"

/* PreloadLibrary represents a library to preload */
typedef struct PreloadLibrary
Expand Down
1 change: 1 addition & 0 deletions pg_extension_updater/src/pg_extension_updater.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "catalog/pg_type_d.h"
#include "fmgr.h"
#include "miscadmin.h"

Expand Down
1 change: 1 addition & 0 deletions pg_lake_benchmark/src/tpcds.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "fmgr.h"
#include "funcapi.h"
#include "utils/builtins.h"
#include "utils/tuplestore.h"

#include "pg_lake/benchmark.h"
#include "pg_lake/copy/copy_format.h"
Expand Down
1 change: 1 addition & 0 deletions pg_lake_benchmark/src/tpch.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "fmgr.h"
#include "funcapi.h"
#include "utils/builtins.h"
#include "utils/tuplestore.h"

#include "pg_lake/benchmark.h"
#include "pg_lake/copy/copy_format.h"
Expand Down
2 changes: 2 additions & 0 deletions pg_lake_copy/src/test/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
*/

#include "postgres.h"
#include "catalog/pg_type_d.h"
#include "fmgr.h"
#include "funcapi.h"

#include "pg_lake/pgduck/type.h"
#include "pg_lake/pgduck/parse_struct.h"
#include "utils/builtins.h"
#include "utils/tuplestore.h"


PG_FUNCTION_INFO_V1(duckdb_type_by_name);
Expand Down
9 changes: 9 additions & 0 deletions pg_lake_engine/include/pg_lake/csv/csv_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
#include "commands/copy.h"
#include "nodes/pg_list.h"

#if PG_VERSION_NUM >= 190000
/*
* PG19 dropped the CopyHeaderChoice enum and stores the header choice as a
* plain int holding COPY_HEADER_FALSE / COPY_HEADER_TRUE / COPY_HEADER_MATCH.
* Reintroduce the typedef here so we keep a stable signature.
*/
typedef int CopyHeaderChoice;
#endif

extern PGDLLEXPORT List *InternalCSVOptions(bool includeHeader);
extern PGDLLEXPORT List *NormalizedExternalCSVOptions(List *inputOptions);
extern PGDLLEXPORT CopyHeaderChoice GetCopyHeaderChoice(DefElem *def, bool is_from);
Expand Down
1 change: 1 addition & 0 deletions pg_lake_engine/include/pg_lake/pgduck/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include "postgres.h"
#include "catalog/pg_type_d.h"
#include "fmgr.h"

#include "pg_lake/parquet/field.h"
Expand Down
2 changes: 2 additions & 0 deletions pg_lake_engine/src/cleanup/deletion_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Functions for cleaning up orphaned files.
*/
#include "postgres.h"
#include "catalog/pg_type_d.h"
#include "funcapi.h"
#include "miscadmin.h"

Expand All @@ -30,6 +31,7 @@
#include "pg_lake/util/string_utils.h"
#include "datatype/timestamp.h"
#include "storage/procarray.h"
#include "utils/tuplestore.h"

#define DELETION_QUEUE_TABLE "lake_engine.deletion_queue"

Expand Down
3 changes: 3 additions & 0 deletions pg_lake_engine/src/cleanup/in_progress_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* via VACUUM.
*/
#include "postgres.h"
#include "catalog/pg_type_d.h"
#include "funcapi.h"
#include "miscadmin.h"

Expand All @@ -42,11 +43,13 @@
#include "pg_lake/util/plan_cache.h"
#include "pg_lake/util/string_utils.h"
#include "datatype/timestamp.h"
#include "storage/lock.h"
#include "storage/procarray.h"
#include "utils/fmgroids.h"
#include "utils/memutils.h"
#include "utils/lsyscache.h"
#include "utils/snapmgr.h"
#include "utils/tuplestore.h"

#define OPERATION_ID_SEQUENCE "operationid_seq"

Expand Down
22 changes: 12 additions & 10 deletions pg_lake_engine/src/csv/csv_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
#include "mb/pg_wchar.h"
#include "nodes/execnodes.h"
#include "nodes/makefuncs.h"
#include "pg_extension_base/pg_compat.h"
#include "port/pg_bswap.h"
#include "storage/fd.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
Expand Down Expand Up @@ -198,7 +200,7 @@ CopySendEndOfRow(CopyToState cstate)
switch (cstate->copy_dest)
{
case COPY_FILE:
if (!cstate->opts.binary)
if (!CopyOptsIsBinary(cstate->opts))
{
/* Default line termination depends on platform */
#ifndef WIN32
Expand Down Expand Up @@ -264,7 +266,7 @@ CopySendInt16(CopyToState cstate, int16 val)
static void
EndCopy(CopyToState cstate)
{
if (cstate->opts.binary)
if (CopyOptsIsBinary(cstate->opts))
{
/* Generate trailer for a binary copy */
CopySendInt16(cstate, -1);
Expand Down Expand Up @@ -461,7 +463,7 @@ StartCopyTo(CopyToState cstate, TupleDesc tupDesc)
bool isvarlena;
Form_pg_attribute attr = TupleDescAttr(tupDesc, attnum - 1);

if (cstate->opts.binary)
if (CopyOptsIsBinary(cstate->opts))
getTypeBinaryOutputInfo(attr->atttypid,
&out_func_oid,
&isvarlena);
Expand All @@ -482,7 +484,7 @@ StartCopyTo(CopyToState cstate, TupleDesc tupDesc)
"COPY TO",
ALLOCSET_DEFAULT_SIZES);

if (cstate->opts.binary)
if (CopyOptsIsBinary(cstate->opts))
{
/* Generate header for a binary copy */
int32 tmp;
Expand Down Expand Up @@ -523,7 +525,7 @@ StartCopyTo(CopyToState cstate, TupleDesc tupDesc)

colname = NameStr(TupleDescAttr(tupDesc, attnum - 1)->attname);

if (cstate->opts.csv_mode)
if (CopyOptsIsCsvMode(cstate->opts))
CopyAttributeOutCSV(cstate, colname, false,
list_length(cstate->attnumlist) == 1);
else
Expand Down Expand Up @@ -731,7 +733,7 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
MemoryContextReset(cstate->rowcontext);
oldcontext = MemoryContextSwitchTo(cstate->rowcontext);

if (cstate->opts.binary)
if (CopyOptsIsBinary(cstate->opts))
{
/* Binary per-tuple header */
CopySendInt16(cstate, list_length(cstate->attnumlist));
Expand All @@ -746,7 +748,7 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
Datum value = slot->tts_values[attnum - 1];
bool isnull = slot->tts_isnull[attnum - 1];

if (!cstate->opts.binary)
if (!CopyOptsIsBinary(cstate->opts))
{
if (need_delim)
CopySendChar(cstate, cstate->opts.delim[0]);
Expand All @@ -755,14 +757,14 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)

if (isnull)
{
if (!cstate->opts.binary)
if (!CopyOptsIsBinary(cstate->opts))
CopySendString(cstate, cstate->opts.null_print_client);
else
CopySendInt32(cstate, -1);
}
else
{
if (!cstate->opts.binary)
if (!CopyOptsIsBinary(cstate->opts))
{
/*
* Lookup the underlying tuple's attribute so we can pass in
Expand Down Expand Up @@ -802,7 +804,7 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
}


if (cstate->opts.csv_mode)
if (CopyOptsIsCsvMode(cstate->opts))
CopyAttributeOutCSV(cstate, string,
cstate->opts.force_quote_flags[attnum - 1],
list_length(cstate->attnumlist) == 1);
Expand Down
1 change: 1 addition & 0 deletions pg_lake_engine/src/data_file/data_file_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "postgres.h"
#include "catalog/pg_type_d.h"

#include "executor/executor.h"
#include "pg_lake/data_file/data_files.h"
Expand Down
Loading
Loading