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

Refactor ts_hypertable_insert_path_create #3762

Merged
merged 1 commit into from Oct 30, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/nodes/chunk_dispatch_state.c
Expand Up @@ -216,7 +216,7 @@ static CustomExecMethods chunk_dispatch_state_methods = {
* Check whether the PlanState is a ChunkDispatchState node.
*/
bool
ts_chunk_dispatch_is_state(PlanState *state)
ts_is_chunk_dispatch_state(PlanState *state)
{
CustomScanState *csstate = (CustomScanState *) state;

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/chunk_dispatch_state.h
Expand Up @@ -35,7 +35,7 @@ typedef struct ChunkDispatchState
ResultRelInfo *rri;
} ChunkDispatchState;

extern bool ts_chunk_dispatch_is_state(PlanState *state);
extern bool ts_is_chunk_dispatch_state(PlanState *state);
extern ChunkDispatchState *ts_chunk_dispatch_state_create(Oid hypertable_oid, Plan *plan);
extern void ts_chunk_dispatch_state_set_parent(ChunkDispatchState *state, ModifyTableState *parent);

Expand Down
43 changes: 16 additions & 27 deletions src/nodes/hypertable_insert.c
Expand Up @@ -70,7 +70,7 @@ get_chunk_dispatch_states(PlanState *substate)
ListCell *lc;
List *result = NIL;

if (ts_chunk_dispatch_is_state(substate))
if (ts_is_chunk_dispatch_state(substate))
return list_make1(substate);

/*
Expand Down Expand Up @@ -490,13 +490,12 @@ static CustomPathMethods hypertable_insert_path_methods = {
};

Path *
ts_hypertable_insert_path_create(PlannerInfo *root, ModifyTablePath *mtpath)
ts_hypertable_insert_path_create(PlannerInfo *root, ModifyTablePath *mtpath, Hypertable *ht)
{
Path *path = &mtpath->path;
Path *subpath;
Cache *hcache = ts_hypertable_cache_pin();
Bitmapset *distributed_insert_plans = NULL;
Hypertable *ht = NULL;
HypertableInsertPath *hipath;
int i = 0;

Expand Down Expand Up @@ -524,34 +523,24 @@ ts_hypertable_insert_path_create(PlannerInfo *root, ModifyTablePath *mtpath)
#endif

Index rti = linitial_int(mtpath->resultRelations);
RangeTblEntry *rte = planner_rt_fetch(rti, root);

ht = ts_hypertable_cache_get_entry(hcache, rte->relid, CACHE_FLAG_MISSING_OK);
if (root->parse->onConflict && OidIsValid(root->parse->onConflict->constraint))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("hypertables do not support ON CONFLICT statements that reference "
"constraints"),
errhint("Use column names to infer indexes instead.")));

if (!ht)
if (hypertable_is_distributed(ht) && ts_guc_max_insert_batch_size > 0)
{
elog(ERROR, "no hypertable found in INSERT plan");
/* Remember that this will become a data node dispatch/copy
* plan. We need to know later whether or not to plan this
* using the FDW API. */
distributed_insert_plans = bms_add_member(distributed_insert_plans, i);
subpath = ts_cm_functions->distributed_insert_path_create(root, mtpath, rti, i);
}
else
{
if (root->parse->onConflict && OidIsValid(root->parse->onConflict->constraint))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("hypertables do not support ON CONFLICT statements that reference "
"constraints"),
errhint("Use column names to infer indexes instead.")));

if (hypertable_is_distributed(ht) && ts_guc_max_insert_batch_size > 0)
{
/* Remember that this will become a data node dispatch/copy
* plan. We need to know later whether or not to plan this
* using the FDW API. */
distributed_insert_plans = bms_add_member(distributed_insert_plans, i);
subpath = ts_cm_functions->distributed_insert_path_create(root, mtpath, rti, i);
}
else
subpath = ts_chunk_dispatch_path_create(root, mtpath, rti, i);
}
subpath = ts_chunk_dispatch_path_create(root, mtpath, rti, i);

hipath = palloc0(sizeof(HypertableInsertPath));

Expand Down Expand Up @@ -638,7 +627,7 @@ ExecModifyTable(PlanState *pstate)
resultRelInfo = node->resultRelInfo + node->mt_lastResultIndex;
subplanstate = outerPlanState(node);

if (ts_chunk_dispatch_is_state(subplanstate))
if (ts_is_chunk_dispatch_state(subplanstate))
cds = (ChunkDispatchState *) subplanstate;
else
cds = linitial(get_chunk_dispatch_states(subplanstate));
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/hypertable_insert.h
Expand Up @@ -30,6 +30,7 @@ typedef struct HypertableInsertState
} HypertableInsertState;

extern void ts_hypertable_insert_fixup_tlist(Plan *plan);
extern Path *ts_hypertable_insert_path_create(PlannerInfo *root, ModifyTablePath *mtpath);
extern Path *ts_hypertable_insert_path_create(PlannerInfo *root, ModifyTablePath *mtpath,
Hypertable *ht);

#endif /* TIMESCALEDB_HYPERTABLE_INSERT_H */
4 changes: 2 additions & 2 deletions src/planner.c
Expand Up @@ -1013,8 +1013,8 @@ replace_hypertable_insert_paths(PlannerInfo *root, List *pathlist)
RangeTblEntry *rte = planner_rt_fetch(linitial_int(mt->resultRelations), root);
Hypertable *ht = get_hypertable(rte->relid, CACHE_FLAG_CHECK);

if (NULL != ht)
path = ts_hypertable_insert_path_create(root, mt);
if (ht)
path = ts_hypertable_insert_path_create(root, mt, ht);
}

new_pathlist = lappend(new_pathlist, path);
Expand Down