Skip to content

Commit e973eef

Browse files
committed
Rename HypertableModify to ModifyHypertable to align with pg ModifyTable
Use upstream ExecGetUpdateNewTuple instead of our own
1 parent ccd24b5 commit e973eef

27 files changed

+283
-350
lines changed

src/cross_module_fn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef struct Hypertable Hypertable;
3434
typedef struct Chunk Chunk;
3535
typedef struct ChunkInsertState ChunkInsertState;
3636
typedef struct CopyChunkState CopyChunkState;
37-
typedef struct HypertableModifyState HypertableModifyState;
37+
typedef struct ModifyHypertableState ModifyHypertableState;
3838

3939
typedef struct CrossModuleFunctions
4040
{
@@ -130,7 +130,7 @@ typedef struct CrossModuleFunctions
130130
PGFunction compress_chunk;
131131
PGFunction decompress_chunk;
132132
void (*decompress_batches_for_insert)(const ChunkInsertState *state, TupleTableSlot *slot);
133-
bool (*decompress_target_segments)(HypertableModifyState *ht_state);
133+
bool (*decompress_target_segments)(ModifyHypertableState *ht_state);
134134
int (*hypercore_decompress_update_segment)(Relation relation, const ItemPointer ctid,
135135
TupleTableSlot *slot, Snapshot snapshot,
136136
ItemPointer new_tid);

src/import/ht_hypertable_modify.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,6 @@ TupleTableSlot *ExecInsert(ModifyTableContext * context, ResultRelInfo * resultR
382382
ChunkDispatchState* cds,
383383
TupleTableSlot * slot, bool canSetTag);
384384

385-
static TupleTableSlot * mergeGetUpdateNewTuple(ResultRelInfo * relinfo, TupleTableSlot * planSlot,
386-
TupleTableSlot * oldSlot, MergeActionState * relaction);
387-
388385
/*
389386
* Check and execute the first qualifying MATCHED action. The current target
390387
* tuple is identified by tupleid.
@@ -528,7 +525,6 @@ lmerge_matched:;
528525
#else
529526
context->relaction = relaction;
530527
#endif
531-
context->GetUpdateNewTuple = mergeGetUpdateNewTuple;
532528
context->cpUpdateRetrySlot = NULL;
533529

534530
if (!ht_ExecUpdatePrologue(context, resultRelInfo, tupleid, NULL, newslot, &result))
@@ -1061,19 +1057,3 @@ ht_ExecMerge(ModifyTableContext * context, ResultRelInfo * resultRelInfo, ChunkD
10611057
return rslot;
10621058
}
10631059

1064-
/*
1065-
* Callback for ModifyTableContext->GetUpdateNewTuple for use by MERGE. It
1066-
* computes the updated tuple by projecting from the current merge action's
1067-
* projection.
1068-
*/
1069-
static TupleTableSlot *
1070-
mergeGetUpdateNewTuple(ResultRelInfo * relinfo, TupleTableSlot * planSlot, TupleTableSlot * oldSlot,
1071-
MergeActionState * relaction) {
1072-
ExprContext *econtext = relaction->mas_proj->pi_exprContext;
1073-
1074-
econtext->ecxt_scantuple = oldSlot;
1075-
econtext->ecxt_innertuple = planSlot;
1076-
1077-
return ExecProject(relaction->mas_proj);
1078-
}
1079-

src/import/ht_hypertable_modify.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ typedef struct ModifyTableContext {
3434
*/
3535
TupleTableSlot *planSlot;
3636

37-
/*
38-
* During EvalPlanQual, project and return the new version of the new
39-
* tuple
40-
*/
41-
TupleTableSlot *(*GetUpdateNewTuple) (ResultRelInfo * resultRelInfo, TupleTableSlot * epqslot,
42-
TupleTableSlot * oldSlot, MergeActionState * relaction);
43-
4437
/* MERGE specific */
4538
MergeActionState *relaction; /* MERGE action in progress */
4639
/*

src/nodes/hypertable_modify.c

Lines changed: 37 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ get_chunk_dispatch_state(PlanState *substate)
9292
* the ModifyTableState node whenever it inserts into a new chunk.
9393
*/
9494
static void
95-
hypertable_modify_begin(CustomScanState *node, EState *estate, int eflags)
95+
modify_hypertable_begin(CustomScanState *node, EState *estate, int eflags)
9696
{
97-
HypertableModifyState *state = (HypertableModifyState *) node;
97+
ModifyHypertableState *state = (ModifyHypertableState *) node;
9898
ModifyTableState *mtstate;
9999
PlanState *ps;
100100

@@ -116,7 +116,7 @@ hypertable_modify_begin(CustomScanState *node, EState *estate, int eflags)
116116
* Unfortunately that strips off the HypertableInsert node leading to
117117
* tuple routing not working in INSERTs inside CTEs. To make INSERTs
118118
* inside CTEs work we have to fix es_auxmodifytables and add back the
119-
* HypertableModifyState.
119+
* ModifyHypertableState.
120120
*/
121121
if (estate->es_auxmodifytables && linitial(estate->es_auxmodifytables) == mtstate)
122122
linitial(estate->es_auxmodifytables) = node;
@@ -140,28 +140,28 @@ hypertable_modify_begin(CustomScanState *node, EState *estate, int eflags)
140140
}
141141

142142
static TupleTableSlot *
143-
hypertable_modify_exec(CustomScanState *node)
143+
modify_hypertable_exec(CustomScanState *node)
144144
{
145145
ModifyTableState *mtstate = linitial_node(ModifyTableState, node->custom_ps);
146146
return ExecModifyTable(node, &mtstate->ps);
147147
}
148148

149149
static void
150-
hypertable_modify_end(CustomScanState *node)
150+
modify_hypertable_end(CustomScanState *node)
151151
{
152152
ExecEndNode(linitial(node->custom_ps));
153153
}
154154

155155
static void
156-
hypertable_modify_rescan(CustomScanState *node)
156+
modify_hypertable_rescan(CustomScanState *node)
157157
{
158158
ExecReScan(linitial(node->custom_ps));
159159
}
160160

161161
static void
162-
hypertable_modify_explain(CustomScanState *node, List *ancestors, ExplainState *es)
162+
modify_hypertable_explain(CustomScanState *node, List *ancestors, ExplainState *es)
163163
{
164-
HypertableModifyState *state = (HypertableModifyState *) node;
164+
ModifyHypertableState *state = (ModifyHypertableState *) node;
165165
ModifyTableState *mtstate = linitial_node(ModifyTableState, node->custom_ps);
166166

167167
/*
@@ -183,13 +183,13 @@ hypertable_modify_explain(CustomScanState *node, List *ancestors, ExplainState *
183183
}
184184
/*
185185
* Since we hijack the ModifyTable node, instrumentation on ModifyTable will
186-
* be missing so we set it to instrumentation of HypertableModify node.
186+
* be missing so we set it to instrumentation of ModifyHypertable node.
187187
*/
188188
if (mtstate->ps.instrument)
189189
{
190190
/*
191191
* INSERT .. ON CONFLICT statements record few metrics in the ModifyTable node.
192-
* So, copy them into HypertableModify node before replacing them.
192+
* So, copy them into ModifyHypertable node before replacing them.
193193
*/
194194
node->ss.ps.instrument->ntuples2 = mtstate->ps.instrument->ntuples2;
195195
node->ss.ps.instrument->nfiltered1 = mtstate->ps.instrument->nfiltered1;
@@ -220,32 +220,32 @@ hypertable_modify_explain(CustomScanState *node, List *ancestors, ExplainState *
220220
ExplainPropertyInteger("Batches deleted", NULL, state->batches_deleted, es);
221221
}
222222

223-
static CustomExecMethods hypertable_modify_state_methods = {
224-
.CustomName = "HypertableModifyState",
225-
.BeginCustomScan = hypertable_modify_begin,
226-
.EndCustomScan = hypertable_modify_end,
227-
.ExecCustomScan = hypertable_modify_exec,
228-
.ReScanCustomScan = hypertable_modify_rescan,
229-
.ExplainCustomScan = hypertable_modify_explain,
223+
static CustomExecMethods modify_hypertable_state_methods = {
224+
.CustomName = "ModifyHypertableState",
225+
.BeginCustomScan = modify_hypertable_begin,
226+
.EndCustomScan = modify_hypertable_end,
227+
.ExecCustomScan = modify_hypertable_exec,
228+
.ReScanCustomScan = modify_hypertable_rescan,
229+
.ExplainCustomScan = modify_hypertable_explain,
230230
};
231231

232232
static Node *
233-
hypertable_modify_state_create(CustomScan *cscan)
233+
modify_hypertable_state_create(CustomScan *cscan)
234234
{
235-
HypertableModifyState *state;
235+
ModifyHypertableState *state;
236236
ModifyTable *mt = castNode(ModifyTable, linitial(cscan->custom_plans));
237237

238-
state = (HypertableModifyState *) newNode(sizeof(HypertableModifyState), T_CustomScanState);
239-
state->cscan_state.methods = &hypertable_modify_state_methods;
238+
state = (ModifyHypertableState *) newNode(sizeof(ModifyHypertableState), T_CustomScanState);
239+
state->cscan_state.methods = &modify_hypertable_state_methods;
240240
state->mt = mt;
241241
state->mt->arbiterIndexes = linitial(cscan->custom_private);
242242

243243
return (Node *) state;
244244
}
245245

246-
static CustomScanMethods hypertable_modify_plan_methods = {
247-
.CustomName = "HypertableModify",
248-
.CreateCustomScanState = hypertable_modify_state_create,
246+
static CustomScanMethods modify_hypertable_plan_methods = {
247+
.CustomName = "ModifyHypertable",
248+
.CreateCustomScanState = modify_hypertable_state_create,
249249
};
250250

251251
/*
@@ -290,13 +290,13 @@ make_var_targetlist(const List *tlist)
290290
* set_plan_references().
291291
*/
292292
void
293-
ts_hypertable_modify_fixup_tlist(Plan *plan)
293+
ts_modify_hypertable_fixup_tlist(Plan *plan)
294294
{
295295
if (IsA(plan, CustomScan))
296296
{
297297
CustomScan *cscan = (CustomScan *) plan;
298298

299-
if (cscan->methods == &hypertable_modify_plan_methods)
299+
if (cscan->methods == &modify_hypertable_plan_methods)
300300
{
301301
ModifyTable *mt = linitial_node(ModifyTable, cscan->custom_plans);
302302

@@ -344,13 +344,13 @@ ts_replace_rowid_vars(PlannerInfo *root, List *tlist, int varno)
344344
}
345345

346346
static Plan *
347-
hypertable_modify_plan_create(PlannerInfo *root, RelOptInfo *rel, CustomPath *best_path,
347+
modify_hypertable_plan_create(PlannerInfo *root, RelOptInfo *rel, CustomPath *best_path,
348348
List *tlist, List *clauses, List *custom_plans)
349349
{
350350
CustomScan *cscan = makeNode(CustomScan);
351351
ModifyTable *mt = linitial_node(ModifyTable, custom_plans);
352352

353-
cscan->methods = &hypertable_modify_plan_methods;
353+
cscan->methods = &modify_hypertable_plan_methods;
354354
cscan->custom_plans = custom_plans;
355355
cscan->scan.scanrelid = 0;
356356

@@ -427,19 +427,19 @@ hypertable_modify_plan_create(PlannerInfo *root, RelOptInfo *rel, CustomPath *be
427427
return &cscan->scan.plan;
428428
}
429429

430-
static CustomPathMethods hypertable_modify_path_methods = {
431-
.CustomName = "HypertableModifyPath",
432-
.PlanCustomPath = hypertable_modify_plan_create,
430+
static CustomPathMethods modify_hypertable_path_methods = {
431+
.CustomName = "ModifyHypertablePath",
432+
.PlanCustomPath = modify_hypertable_plan_create,
433433
};
434434

435435
Path *
436-
ts_hypertable_modify_path_create(PlannerInfo *root, ModifyTablePath *mtpath, Hypertable *ht,
436+
ts_modify_hypertable_path_create(PlannerInfo *root, ModifyTablePath *mtpath, Hypertable *ht,
437437
RelOptInfo *rel)
438438
{
439439
Path *path = &mtpath->path;
440440
Path *subpath = NULL;
441441
Cache *hcache = ts_hypertable_cache_pin();
442-
HypertableModifyPath *hmpath;
442+
ModifyHypertablePath *hmpath;
443443
int i = 0;
444444

445445
/* PG14 only copies child rows and width if returningLists is not
@@ -459,14 +459,14 @@ ts_hypertable_modify_path_create(PlannerInfo *root, ModifyTablePath *mtpath, Hyp
459459
subpath = ts_chunk_dispatch_path_create(root, mtpath, rti, i);
460460
}
461461

462-
hmpath = palloc0(sizeof(HypertableModifyPath));
462+
hmpath = palloc0(sizeof(ModifyHypertablePath));
463463

464464
/* Copy costs, etc. */
465465
memcpy(&hmpath->cpath.path, path, sizeof(Path));
466466
hmpath->cpath.path.type = T_CustomPath;
467467
hmpath->cpath.path.pathtype = T_CustomScan;
468468
hmpath->cpath.custom_paths = list_make1(mtpath);
469-
hmpath->cpath.methods = &hypertable_modify_path_methods;
469+
hmpath->cpath.methods = &modify_hypertable_path_methods;
470470
path = &hmpath->cpath.path;
471471
if (subpath)
472472
mtpath->subpath = subpath;
@@ -476,22 +476,6 @@ ts_hypertable_modify_path_create(PlannerInfo *root, ModifyTablePath *mtpath, Hyp
476476
return path;
477477
}
478478

479-
/*
480-
* Callback for ModifyTableState->GetUpdateNewTuple for use by regular UPDATE.
481-
*/
482-
static TupleTableSlot *
483-
internalGetUpdateNewTuple(ResultRelInfo *relinfo, TupleTableSlot *planSlot, TupleTableSlot *oldSlot,
484-
MergeActionState *relaction)
485-
{
486-
ProjectionInfo *newProj = relinfo->ri_projectNew;
487-
ExprContext *econtext;
488-
489-
econtext = newProj->pi_exprContext;
490-
econtext->ecxt_outertuple = planSlot;
491-
econtext->ecxt_scantuple = oldSlot;
492-
return ExecProject(newProj);
493-
}
494-
495479
/* ----------------------------------------------------------------
496480
* ExecModifyTable
497481
*
@@ -504,7 +488,7 @@ internalGetUpdateNewTuple(ResultRelInfo *relinfo, TupleTableSlot *planSlot, Tupl
504488
static TupleTableSlot *
505489
ExecModifyTable(CustomScanState *cs_node, PlanState *pstate)
506490
{
507-
HypertableModifyState *ht_state = (HypertableModifyState *) cs_node;
491+
ModifyHypertableState *ht_state = (ModifyHypertableState *) cs_node;
508492
ModifyTableState *node = castNode(ModifyTableState, pstate);
509493
ModifyTableContext context;
510494
EState *estate = node->ps.state;
@@ -893,8 +877,7 @@ ExecModifyTable(CustomScanState *cs_node, PlanState *pstate)
893877
if (!table_tuple_fetch_row_version(relation, tupleid, SnapshotAny, oldSlot))
894878
elog(ERROR, "failed to fetch tuple being updated");
895879
}
896-
slot = internalGetUpdateNewTuple(resultRelInfo, context.planSlot, oldSlot, NULL);
897-
context.GetUpdateNewTuple = internalGetUpdateNewTuple;
880+
slot = ExecGetUpdateNewTuple(resultRelInfo, context.planSlot, oldSlot);
898881
context.relaction = NULL;
899882
/* Now apply the update. */
900883
slot =
@@ -1320,26 +1303,6 @@ ExecGetInsertNewTuple(ResultRelInfo *relinfo, TupleTableSlot *planSlot)
13201303
return ExecProject(newProj);
13211304
}
13221305

1323-
/*
1324-
* ExecGetUpdateNewTuple
1325-
* This prepares a "new" tuple by combining an UPDATE subplan's output
1326-
* tuple (which contains values of changed columns) with unchanged
1327-
* columns taken from the old tuple.
1328-
*
1329-
* The subplan tuple might also contain junk columns, which are ignored.
1330-
* Note that the projection also ensures we have a slot of the right type.
1331-
*/
1332-
TupleTableSlot *
1333-
ExecGetUpdateNewTuple(ResultRelInfo *relinfo, TupleTableSlot *planSlot, TupleTableSlot *oldSlot)
1334-
{
1335-
/* Use a few extra Asserts to protect against outside callers */
1336-
Assert(relinfo->ri_projectNewInfoValid);
1337-
Assert(planSlot != NULL && !TTS_EMPTY(planSlot));
1338-
Assert(oldSlot != NULL && !TTS_EMPTY(oldSlot));
1339-
1340-
return internalGetUpdateNewTuple(relinfo, planSlot, oldSlot, NULL);
1341-
}
1342-
13431306
/* ----------------------------------------------------------------
13441307
* ExecInsert
13451308
*

src/nodes/hypertable_modify.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
/* Forward declarations */
1616
struct ChunkDispatchState;
1717

18-
typedef struct HypertableModifyPath
18+
typedef struct ModifyHypertablePath
1919
{
2020
CustomPath cpath;
21-
} HypertableModifyPath;
21+
} ModifyHypertablePath;
2222

2323
/*
2424
* State for the hypertable_modify custom scan node.
2525
*
2626
* This struct definition is also used in ts_stat_statements, so any new fields
2727
* should only be added at the end of the struct.
2828
*/
29-
typedef struct HypertableModifyState
29+
typedef struct ModifyHypertableState
3030
{
3131
CustomScanState cscan_state;
3232
ModifyTable *mt;
@@ -36,10 +36,10 @@ typedef struct HypertableModifyState
3636
int64 batches_decompressed;
3737
int64 batches_filtered;
3838
int64 batches_deleted;
39-
} HypertableModifyState;
39+
} ModifyHypertableState;
4040

41-
extern void ts_hypertable_modify_fixup_tlist(Plan *plan);
42-
extern Path *ts_hypertable_modify_path_create(PlannerInfo *root, ModifyTablePath *mtpath,
41+
extern void ts_modify_hypertable_fixup_tlist(Plan *plan);
42+
extern Path *ts_modify_hypertable_path_create(PlannerInfo *root, ModifyTablePath *mtpath,
4343
Hypertable *ht, RelOptInfo *input_rel);
4444
extern List *ts_replace_rowid_vars(PlannerInfo *root, List *tlist, int varno);
4545

0 commit comments

Comments
 (0)