Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support postgresql 14 #178

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ SRCS = src/scan/heap_reader.cpp \
OBJS = $(subst .cpp,.o, $(SRCS))


C_SRCS = src/vendor/pg_ruleutils_16.c \
C_SRCS = src/vendor/pg_ruleutils_14.c \
src/vendor/pg_ruleutils_16.c \
src/vendor/pg_ruleutils_17.c
OBJS += $(subst .c,.o, $(C_SRCS))

Expand Down
2 changes: 2 additions & 0 deletions src/pgduckdb_detoast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
extern "C" {
#include "postgres.h"
#include "pg_config.h"
#if PG_VERSION_NUM >= 160000
#include "varatt.h"
#endif

#ifdef USE_LZ4
#include <lz4.h>
Expand Down
15 changes: 13 additions & 2 deletions src/pgduckdb_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ ContainsDuckdbFunctions(Node *node, void *context) {

if (IsA(node, Query)) {
Query *query = (Query *)node;
return query_tree_walker(query, ContainsDuckdbFunctions, context, 0);
#if PG_VERSION_NUM >= 160000
return query_tree_walker(query, ContainsDuckdbFunctions, context, 0);
#else
return query_tree_walker(query, (bool (*)()) ((void *) ContainsDuckdbFunctions), context, 0);
#endif
}

if (IsA(node, FuncExpr)) {
Expand All @@ -61,13 +65,20 @@ ContainsDuckdbFunctions(Node *node, void *context) {
return true;
}
}

#if PG_VERSION_NUM >= 160000
return expression_tree_walker(node, ContainsDuckdbFunctions, context);
#else
return expression_tree_walker(node, (bool (*)()) ((void *) ContainsDuckdbFunctions), context);
#endif
}

static bool
NeedsDuckdbExecution(Query *query) {
#if PG_VERSION_NUM >= 160000
return query_tree_walker(query, ContainsDuckdbFunctions, NULL, 0);
#else
return query_tree_walker(query, (bool (*)()) ((void *) ContainsDuckdbFunctions), NULL, 0);
#endif
}

static bool
Expand Down
5 changes: 4 additions & 1 deletion src/pgduckdb_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ PlanQuery(Query *parse, ParamListInfo bound_params) {
glob->subroots = NIL;
glob->rewindPlanIDs = NULL;
glob->finalrtable = NIL;
#if PG_VERSION_NUM >= 160000
glob->finalrteperminfos = NIL;
#endif
glob->finalrowmarks = NIL;
glob->resultRelations = NIL;
glob->appendRelations = NIL;
Expand Down Expand Up @@ -66,7 +68,6 @@ CreatePlan(Query *query, const char *query_string, ParamListInfo bound_params) {
auto context = duckdb_connection->context;

auto prepared_query = context->Prepare(query_string);

if (prepared_query->HasError()) {
elog(WARNING, "(DuckDB) %s", prepared_query->GetError().c_str());
return nullptr;
Expand Down Expand Up @@ -135,7 +136,9 @@ DuckdbPlanNode(Query *parse, int cursor_options, ParamListInfo bound_params) {
result->parallelModeNeeded = false;
result->planTree = duckdb_plan;
result->rtable = NULL;
#if PG_VERSION_NUM >= 160000
result->permInfos = NULL;
#endif
result->resultRelations = NULL;
result->appendRelations = NULL;
result->subplans = NIL;
Expand Down
6 changes: 5 additions & 1 deletion src/scan/postgres_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ PostgresScanGlobalState::InitGlobalState(duckdb::TableFunctionInitInput &input)

static Oid
FindMatchingRelation(const duckdb::string &to_find) {
#if PG_VERSION_NUM >= 160000
RangeVar *table_range_var = makeRangeVarFromNameList(stringToQualifiedNameList(to_find.c_str(), NULL));
#else
RangeVar *table_range_var = makeRangeVarFromNameList(stringToQualifiedNameList(to_find.c_str()));
#endif
Oid rel_oid = RangeVarGetRelid(table_range_var, AccessShareLock, true);
if (rel_oid != InvalidOid) {
return rel_oid;
Expand Down Expand Up @@ -201,7 +205,7 @@ PostgresReplacementScan(duckdb::ClientContext &context, duckdb::ReplacementScanI
}

/* SELECT query will have nodePath so we can return cardinality estimate of scan */
Cardinality nodeCardinality = node_path ? node_path->rows : 1;
uint64_t nodeCardinality = node_path ? node_path->rows : 1;

if ((node_path != nullptr && (node_path->pathtype == T_IndexScan || node_path->pathtype == T_IndexOnlyScan))) {
auto children = CreateFunctionIndexScanArguments(nodeCardinality, node_path, scan_data->m_query_planner_info,
Expand Down
35 changes: 33 additions & 2 deletions src/utility/copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ static constexpr char r2_filename_prefix[] = "r2://";
static bool
CreateRelationCopyParseState(ParseState *pstate, const CopyStmt *stmt, List **vars, int stmt_location, int stmt_len) {
ParseNamespaceItem *nsitem;
#if PG_VERSION_NUM >= 160000
RTEPermissionInfo *perminfo;
#else
RangeTblEntry *rte;
ListCell *cur;
#endif
TupleDesc tuple_desc;
List *attnums;
Relation rel;
Expand All @@ -43,12 +48,18 @@ CreateRelationCopyParseState(ParseState *pstate, const CopyStmt *stmt, List **va

nsitem = addRangeTableEntryForRelation(pstate, rel, AccessShareLock, NULL, false, false);

#if PG_VERSION_NUM >= 160000
perminfo = nsitem->p_perminfo;
perminfo->requiredPerms = ACL_SELECT;
#else
rte = nsitem->p_rte;
rte->requiredPerms = ACL_SELECT;
#endif

tuple_desc = RelationGetDescr(rel);
attnums = CopyGetAttnums(tuple_desc, rel, stmt->attlist);

#if PG_VERSION_NUM >= 160000
foreach_int(cur, attnums) {
int attno;
Bitmapset **bms;
Expand All @@ -59,12 +70,27 @@ CreateRelationCopyParseState(ParseState *pstate, const CopyStmt *stmt, List **va
lappend(*vars, makeVar(1, cur, tuple_desc->attrs[cur - 1].atttypid, tuple_desc->attrs[cur - 1].atttypmod,
tuple_desc->attrs[cur - 1].attcollation, 0));
}
#else
foreach(cur, attnums)
{
int attno = lfirst_int(cur) -
FirstLowInvalidHeapAttributeNumber;

rte->selectedCols = bms_add_member(rte->selectedCols, attno);
}
#endif

#if PG_VERSION_NUM >= 160000
if (!ExecCheckPermissions(pstate->p_rtable, list_make1(perminfo), false)) {
ereport(WARNING, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("(Duckdb) Failed Permission \"%s\"", RelationGetRelationName(rel))));
}

#else
if (!ExecCheckRTPerms(pstate->p_rtable, true)) {
ereport(WARNING, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("(Duckdb) Failed Permission \"%s\"", RelationGetRelationName(rel))));
}
#endif
table_close(rel, AccessShareLock);

/*
Expand Down Expand Up @@ -108,7 +134,12 @@ DuckdbCopy(PlannedStmt *pstmt, const char *query_string, struct QueryEnvironment
raw_stmt->stmt_location = pstmt->stmt_location;
raw_stmt->stmt_len = pstmt->stmt_len;

rewritten = pg_analyze_and_rewrite_fixedparams(raw_stmt, query_string, NULL, 0, NULL);
#if PG_VERSION_NUM >= 150000
rewritten = pg_analyze_and_rewrite_fixedparams(raw_stmt, query_string, NULL, 0, NULL);
#else
rewritten = pg_analyze_and_rewrite(raw_stmt, query_string, NULL, 0, NULL);
#endif

query = linitial_node(Query, rewritten);

/* Extract required vars for table */
Expand Down
Loading