Skip to content

Commit 6fd437c

Browse files
committed
Change signature of ts_chunk_tuple_routing_create
Change signature of ts_chunk_tuple_routing_create in preparation for ChunkDispatch removal. This patch extracts the COPY specific changes.
1 parent 24ceeb9 commit 6fd437c

4 files changed

Lines changed: 55 additions & 52 deletions

File tree

src/chunk_tuple_routing.c

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
#include "debug_point.h"
1111
#include "hypercube.h"
1212
#include "nodes/chunk_dispatch/chunk_insert_state.h"
13+
#include "nodes/modify_hypertable.h"
1314
#include "subspace_store.h"
1415

1516
static ChunkInsertState *chunk_insert_state_create(Oid chunk_relid, ChunkTupleRouting *ctr);
1617

1718
ChunkTupleRouting *
18-
ts_chunk_tuple_routing_create(EState *estate, Relation rel)
19+
ts_chunk_tuple_routing_create(EState *estate, ResultRelInfo *rri)
1920
{
2021
ChunkTupleRouting *ctr;
2122

@@ -27,14 +28,16 @@ ts_chunk_tuple_routing_create(EState *estate, Relation rel)
2728
* single tuple into a partitioned table and this must be fast.
2829
*/
2930
ctr = (ChunkTupleRouting *) palloc0(sizeof(ChunkTupleRouting));
30-
ctr->partition_root = rel;
31+
ctr->hypertable_rri = rri;
32+
ctr->partition_root = rri->ri_RelationDesc;
3133
ctr->memcxt = CurrentMemoryContext;
3234
ctr->estate = estate;
3335
ctr->counters = palloc0(sizeof(SharedCounters));
3436

35-
ctr->hypertable = ts_hypertable_cache_get_cache_and_entry(RelationGetRelid(rel),
36-
CACHE_FLAG_NONE,
37-
&ctr->hypertable_cache);
37+
ctr->hypertable =
38+
ts_hypertable_cache_get_cache_and_entry(RelationGetRelid(rri->ri_RelationDesc),
39+
CACHE_FLAG_NONE,
40+
&ctr->hypertable_cache);
3841
ctr->subspace = ts_subspace_store_init(ctr->hypertable->space,
3942
estate->es_query_cxt,
4043
ts_guc_max_open_chunks_per_insert);
@@ -248,3 +251,42 @@ chunk_insert_state_create(Oid chunk_relid, ChunkTupleRouting *ctr)
248251

249252
return state;
250253
}
254+
255+
extern void
256+
ts_chunk_tuple_routing_decompress_for_insert(ChunkInsertState *cis, TupleTableSlot *slot,
257+
EState *estate, bool update_counter)
258+
{
259+
if (!cis->chunk_compressed || (cis->cached_decompression_state &&
260+
!cis->cached_decompression_state->has_primary_or_unique_index))
261+
return;
262+
263+
/*
264+
* If this is an INSERT into a compressed chunk with UNIQUE or
265+
* PRIMARY KEY constraints we need to make sure any batches that could
266+
* potentially lead to a conflict are in the decompressed chunk so
267+
* postgres can do proper constraint checking.
268+
*/
269+
270+
ts_cm_functions->init_decompress_state_for_insert(cis, slot);
271+
ts_cm_functions->decompress_batches_for_insert(cis, slot);
272+
273+
/* mark rows visible */
274+
if (update_counter)
275+
estate->es_output_cid = GetCurrentCommandId(true);
276+
277+
if (ts_guc_max_tuples_decompressed_per_dml > 0)
278+
{
279+
if (cis->counters->tuples_decompressed > ts_guc_max_tuples_decompressed_per_dml)
280+
{
281+
ereport(ERROR,
282+
(errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
283+
errmsg("tuple decompression limit exceeded by operation"),
284+
errdetail("current limit: %d, tuples decompressed: %lld",
285+
ts_guc_max_tuples_decompressed_per_dml,
286+
(long long int) cis->counters->tuples_decompressed),
287+
errhint("Consider increasing "
288+
"timescaledb.max_tuples_decompressed_per_dml_transaction or set "
289+
"to 0 (unlimited).")));
290+
}
291+
}
292+
}

src/chunk_tuple_routing.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ typedef struct ChunkTupleRouting
2929
SharedCounters *counters; /* shared counters for the current statement */
3030
} ChunkTupleRouting;
3131

32-
ChunkTupleRouting *ts_chunk_tuple_routing_create(EState *estate, Relation rel);
32+
ChunkTupleRouting *ts_chunk_tuple_routing_create(EState *estate, ResultRelInfo *rri);
3333
void ts_chunk_tuple_routing_destroy(ChunkTupleRouting *ctr);
3434
ChunkInsertState *ts_chunk_tuple_routing_find_chunk(ChunkTupleRouting *ctr, Point *point);
35+
extern void ts_chunk_tuple_routing_decompress_for_insert(ChunkInsertState *cis,
36+
TupleTableSlot *slot, EState *estate,
37+
bool update_counter);

src/copy.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ copy_chunk_state_create(Hypertable *ht, Relation rel, CopyFromFunc from_func, Co
161161
ccstate = palloc(sizeof(CopyChunkState));
162162
ccstate->rel = rel;
163163
ccstate->estate = estate;
164-
ccstate->ctr = ts_chunk_tuple_routing_create(estate, rel);
165164
ccstate->cstate = cstate;
166165
ccstate->scandesc = scandesc;
167166
ccstate->next_copy_from = from_func;
@@ -890,7 +889,7 @@ copyfrom(CopyChunkState *ccstate, ParseState *pstate, Hypertable *ht, MemoryCont
890889

891890
ExecOpenIndices(resultRelInfo, false);
892891

893-
ccstate->ctr->hypertable_rri = resultRelInfo;
892+
ccstate->ctr = ts_chunk_tuple_routing_create(estate, resultRelInfo);
894893

895894
singleslot = table_slot_create(resultRelInfo->ri_RelationDesc, &estate->es_tupleTable);
896895

@@ -1036,7 +1035,7 @@ copyfrom(CopyChunkState *ccstate, ParseState *pstate, Hypertable *ht, MemoryCont
10361035

10371036
Assert(cis != NULL);
10381037

1039-
ts_chunk_dispatch_decompress_batches_for_insert(cis, myslot, ccstate->ctr->estate, false);
1038+
ts_chunk_tuple_routing_decompress_for_insert(cis, myslot, ccstate->ctr->estate, false);
10401039

10411040
/* Triggers and stuff need to be invoked in query context. */
10421041
MemoryContextSwitchTo(oldcontext);

src/nodes/chunk_dispatch/chunk_dispatch.c

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "compat/compat.h"
2121
#include "chunk_dispatch.h"
2222
#include "chunk_insert_state.h"
23+
#include "chunk_tuple_routing.h"
2324
#include "dimension.h"
2425
#include "errors.h"
2526
#include "guc.h"
@@ -173,45 +174,6 @@ ts_chunk_dispatch_get_chunk_insert_state(ChunkDispatch *dispatch, Point *point,
173174
return cis;
174175
}
175176

176-
extern void
177-
ts_chunk_dispatch_decompress_batches_for_insert(ChunkInsertState *cis, TupleTableSlot *slot,
178-
EState *estate, bool update_counter)
179-
{
180-
if (!cis->chunk_compressed || (cis->cached_decompression_state &&
181-
!cis->cached_decompression_state->has_primary_or_unique_index))
182-
return;
183-
184-
/*
185-
* If this is an INSERT into a compressed chunk with UNIQUE or
186-
* PRIMARY KEY constraints we need to make sure any batches that could
187-
* potentially lead to a conflict are in the decompressed chunk so
188-
* postgres can do proper constraint checking.
189-
*/
190-
191-
ts_cm_functions->init_decompress_state_for_insert(cis, slot);
192-
ts_cm_functions->decompress_batches_for_insert(cis, slot);
193-
194-
/* mark rows visible */
195-
if (update_counter)
196-
estate->es_output_cid = GetCurrentCommandId(true);
197-
198-
if (ts_guc_max_tuples_decompressed_per_dml > 0)
199-
{
200-
if (cis->counters->tuples_decompressed > ts_guc_max_tuples_decompressed_per_dml)
201-
{
202-
ereport(ERROR,
203-
(errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
204-
errmsg("tuple decompression limit exceeded by operation"),
205-
errdetail("current limit: %d, tuples decompressed: %lld",
206-
ts_guc_max_tuples_decompressed_per_dml,
207-
(long long int) cis->counters->tuples_decompressed),
208-
errhint("Consider increasing "
209-
"timescaledb.max_tuples_decompressed_per_dml_transaction or set "
210-
"to 0 (unlimited).")));
211-
}
212-
}
213-
}
214-
215177
static CustomScanMethods chunk_dispatch_plan_methods = {
216178
.CustomName = "ChunkDispatch",
217179
.CreateCustomScanState = chunk_dispatch_state_create,
@@ -433,10 +395,7 @@ chunk_dispatch_exec(CustomScanState *node)
433395
bool update_counter =
434396
ts_chunk_dispatch_get_on_conflict_action(dispatch) == ONCONFLICT_UPDATE;
435397

436-
ts_chunk_dispatch_decompress_batches_for_insert(cis,
437-
slot,
438-
dispatch->estate,
439-
update_counter);
398+
ts_chunk_tuple_routing_decompress_for_insert(cis, slot, dispatch->estate, update_counter);
440399
}
441400

442401
MemoryContextSwitchTo(old);

0 commit comments

Comments
 (0)