Skip to content

PGPRO-8546: Create targetlist in partition filter and partition route… #272

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

Merged
merged 2 commits into from
Oct 3, 2023
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ The `pg_pathman` module provides optimized partitioning mechanism and functions

The extension is compatible with:

* PostgreSQL 11, 12, 13;
* PostgreSQL with core-patch: 14, 15;
* PostgreSQL 12, 13;
* PostgreSQL with core-patch: 11, 14, 15;
* Postgres Pro Standard 11, 12, 13, 14, 15;
* Postgres Pro Enterprise;

Expand Down
53 changes: 53 additions & 0 deletions patches/REL_11_STABLE-pg_pathman-core.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
diff --git a/src/backend/jit/llvm/llvmjit_deform.c b/src/backend/jit/llvm/llvmjit_deform.c
index 6384ac940d8..8b4f731e7a8 100644
--- a/src/backend/jit/llvm/llvmjit_deform.c
+++ b/src/backend/jit/llvm/llvmjit_deform.c
@@ -104,6 +104,10 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, int natts)

int attnum;

+ /* don't generate code for tuples without user attributes */
+ if (desc->natts == 0)
+ return NULL;
+
mod = llvm_mutable_module(context);

funcname = llvm_expand_funcname(context, "deform");
diff --git a/src/backend/jit/llvm/llvmjit_expr.c b/src/backend/jit/llvm/llvmjit_expr.c
index 12138e49577..8638ebc4ba1 100644
--- a/src/backend/jit/llvm/llvmjit_expr.c
+++ b/src/backend/jit/llvm/llvmjit_expr.c
@@ -274,6 +274,7 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef v_slot;
LLVMBasicBlockRef b_fetch;
LLVMValueRef v_nvalid;
+ LLVMValueRef l_jit_deform = NULL;

b_fetch = l_bb_before_v(opblocks[i + 1],
"op.%d.fetch", i);
@@ -336,17 +337,20 @@ llvm_compile_expr(ExprState *state)
*/
if (desc && (context->base.flags & PGJIT_DEFORM))
{
- LLVMValueRef params[1];
- LLVMValueRef l_jit_deform;
-
l_jit_deform =
- slot_compile_deform(context, desc,
+ slot_compile_deform(context,
+ desc,
op->d.fetch.last_var);
+ }
+
+ if (l_jit_deform)
+ {
+ LLVMValueRef params[1];
+
params[0] = v_slot;

LLVMBuildCall(b, l_jit_deform,
params, lengthof(params), "");
-
}
else
{
4 changes: 1 addition & 3 deletions src/include/partition_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ TupleConversionMap * build_part_tuple_map_child(Relation child_rel);

void destroy_tuple_map(TupleConversionMap *tuple_map);

List * pfilter_build_tlist(Plan *subplan);

void pfilter_tlist_fix_resjunk(CustomScan *subplan);
List * pfilter_build_tlist(Plan *subplan, Index varno);

/* Find suitable partition using 'value' */
Oid * find_partitions_for_value(Datum value, Oid value_type,
Expand Down
39 changes: 3 additions & 36 deletions src/partition_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,12 +812,7 @@ make_partition_filter(Plan *subplan,
cscan->scan.scanrelid = 0;

/* Build an appropriate target list */
cscan->scan.plan.targetlist = pfilter_build_tlist(subplan);

/* Prepare 'custom_scan_tlist' for EXPLAIN (VERBOSE) */
cscan->custom_scan_tlist = copyObject(cscan->scan.plan.targetlist);
ChangeVarNodes((Node *) cscan->custom_scan_tlist, INDEX_VAR, parent_rti, 0);
pfilter_tlist_fix_resjunk(cscan);
cscan->scan.plan.targetlist = pfilter_build_tlist(subplan, parent_rti);

/* Pack partitioned table's Oid and conflict_action */
cscan->custom_private = list_make4(makeInteger(parent_relid),
Expand Down Expand Up @@ -1076,7 +1071,7 @@ partition_filter_explain(CustomScanState *node, List *ancestors, ExplainState *e
* Build partition filter's target list pointing to subplan tuple's elements.
*/
List *
pfilter_build_tlist(Plan *subplan)
pfilter_build_tlist(Plan *subplan, Index varno)
{
List *result_tlist = NIL;
ListCell *lc;
Expand All @@ -1096,7 +1091,7 @@ pfilter_build_tlist(Plan *subplan)
}
else
{
Var *var = makeVar(INDEX_VAR, /* point to subplan's elements */
Var *var = makeVar(varno, /* point to subplan's elements */
tle->resno,
exprType((Node *) tle->expr),
exprTypmod((Node *) tle->expr),
Expand All @@ -1115,34 +1110,6 @@ pfilter_build_tlist(Plan *subplan)
return result_tlist;
}

/*
* resjunk Vars had its varattnos being set on nonexisting relation columns.
* For future processing service attributes should be indicated correctly.
*/
void
pfilter_tlist_fix_resjunk(CustomScan *css)
{
ListCell *lc;

foreach(lc, css->custom_scan_tlist)
{
TargetEntry *tle = (TargetEntry *) lfirst(lc);

if (!IsA(tle->expr, Const))
{
Var *var = (Var *) tle->expr;

if (tle->resjunk)
{
/* To make Var recognizable as service attribute. */
var->varattno = -1;
}
}
}

return;
}

/*
* ----------------------------------------------
* Additional init steps for ResultPartsStorage
Expand Down
2 changes: 1 addition & 1 deletion src/partition_overseer.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ make_partition_overseer(Plan *subplan)
cscan->scan.scanrelid = 0;

/* Build an appropriate target list */
cscan->scan.plan.targetlist = pfilter_build_tlist(subplan);
cscan->scan.plan.targetlist = pfilter_build_tlist(subplan, INDEX_VAR);
cscan->custom_scan_tlist = subplan->targetlist;

return &cscan->scan.plan;
Expand Down
7 changes: 1 addition & 6 deletions src/partition_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,7 @@ make_partition_router(Plan *subplan, int epq_param, Index parent_rti)
cscan->scan.scanrelid = 0;

/* Build an appropriate target list */
cscan->scan.plan.targetlist = pfilter_build_tlist(subplan);

/* Fix 'custom_scan_tlist' for EXPLAIN (VERBOSE) */
cscan->custom_scan_tlist = copyObject(cscan->scan.plan.targetlist);
ChangeVarNodes((Node *) cscan->custom_scan_tlist, INDEX_VAR, parent_rti, 0);
pfilter_tlist_fix_resjunk(cscan);
cscan->scan.plan.targetlist = pfilter_build_tlist(subplan, parent_rti);

return &cscan->scan.plan;
}
Expand Down