Skip to content

Commit 558bdb5

Browse files
committed
Support splitting compressed chunks
Add support for splitting compressed chunks when calling split_chunk(). Only 2-way splits are supported, as before. When splitting a compressed chunk, the same rewrite-approach is taken as when splitting a non-compressed chunk. The main difference is that the internal compressed relation is split in a separate step, similar to the non-compressed relation. One complication is that the split might end up in the middle of a compressed segment, in which case the segment needs to be split as well. This is done by decompressing the segment in memory and creating two new segments that get written to the resulting split relations. Since the non-compressed and compressed relations are split separetely, the non-compressed data remains non-compressed after the split. Special care is also taken to handle compression stats. In particular, instead of computing new stats, the existing stats are divided across the result relations depending on the amount of data received. This means that the sum of the stats after a split is the same as before the split. Computing new stats is not feasible given that the current approach requires knowing the pre-compressed relation sizes, which is not possible without first decompressing everything.
1 parent 27fd9aa commit 558bdb5

File tree

9 files changed

+1810
-395
lines changed

9 files changed

+1810
-395
lines changed

.unreleased/pr_8100

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implements: #8100 Support splitting compressed chunks

src/chunk.c

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,18 @@ copy_hypertable_acl_to_relid(const Hypertable *ht, const Oid owner_id, const Oid
711711
* instead needs the proper permissions on the database to create the schema.
712712
*/
713713
Oid
714-
ts_chunk_create_table(const Chunk *chunk, const Hypertable *ht, const char *tablespacename)
714+
ts_chunk_create_table(const Chunk *chunk, const Hypertable *ht, const char *tablespacename,
715+
Oid amoid)
715716
{
716717
Relation rel;
717718
ObjectAddress address;
718719
int sec_ctx;
720+
char *amname = NULL;
721+
722+
if (OidIsValid(amoid))
723+
amname = get_am_name(amoid);
724+
else if (chunk->relkind == RELKIND_RELATION)
725+
amname = get_am_name(ts_get_rel_am(chunk->hypertable_relid));
719726

720727
/*
721728
* CreateStmt node to create the chunk table
@@ -731,9 +738,7 @@ ts_chunk_create_table(const Chunk *chunk, const Hypertable *ht, const char *tabl
731738
.tablespacename = tablespacename ? (char *) tablespacename : NULL,
732739
.options =
733740
(chunk->relkind == RELKIND_RELATION) ? ts_get_reloptions(ht->main_table_relid) : NIL,
734-
.accessMethod = (chunk->relkind == RELKIND_RELATION) ?
735-
get_am_name(ts_get_rel_am(chunk->hypertable_relid)) :
736-
NULL,
741+
.accessMethod = amname,
737742
};
738743
Oid uid, saved_uid;
739744

@@ -950,12 +955,12 @@ chunk_create_table_constraints(const Hypertable *ht, const Chunk *chunk)
950955
}
951956

952957
static Oid
953-
chunk_create_table(Chunk *chunk, const Hypertable *ht)
958+
chunk_create_table(Chunk *chunk, const Hypertable *ht, Oid amoid)
954959
{
955960
/* Create the actual table relation for the chunk */
956961
const char *tablespace = ts_hypertable_select_tablespace_name(ht, chunk);
957962

958-
chunk->table_id = ts_chunk_create_table(chunk, ht, tablespace);
963+
chunk->table_id = ts_chunk_create_table(chunk, ht, tablespace, amoid);
959964

960965
Assert(OidIsValid(chunk->table_id));
961966

@@ -968,7 +973,8 @@ chunk_create_table(Chunk *chunk, const Hypertable *ht)
968973
*/
969974
static Chunk *
970975
chunk_create_only_table_after_lock(const Hypertable *ht, Hypercube *cube, const char *schema_name,
971-
const char *table_name, const char *prefix, int32 chunk_id)
976+
const char *table_name, const char *prefix, Oid amoid,
977+
int32 chunk_id)
972978
{
973979
Chunk *chunk;
974980

@@ -977,15 +983,15 @@ chunk_create_only_table_after_lock(const Hypertable *ht, Hypercube *cube, const
977983
chunk = chunk_create_object(ht, cube, schema_name, table_name, prefix, chunk_id);
978984
Assert(chunk != NULL);
979985

980-
chunk_create_table(chunk, ht);
986+
chunk_create_table(chunk, ht, amoid);
981987

982988
return chunk;
983989
}
984990

985991
static Chunk *
986992
chunk_create_from_hypercube_after_lock(const Hypertable *ht, Hypercube *cube,
987993
const char *schema_name, const char *table_name,
988-
const char *prefix)
994+
const char *prefix, Oid amoid)
989995
{
990996
chunk_insert_check_hook_type osm_chunk_insert_hook = ts_get_osm_chunk_insert_hook();
991997

@@ -1033,6 +1039,7 @@ chunk_create_from_hypercube_after_lock(const Hypertable *ht, Hypercube *cube,
10331039
schema_name,
10341040
table_name,
10351041
prefix,
1042+
amoid,
10361043
get_next_chunk_id());
10371044

10381045
/* Insert any new chunk column stats entries into the catalog */
@@ -1083,7 +1090,8 @@ chunk_add_inheritance(Chunk *chunk, const Hypertable *ht)
10831090
static Chunk *
10841091
chunk_create_from_hypercube_and_table_after_lock(const Hypertable *ht, Hypercube *cube,
10851092
Oid chunk_table_relid, const char *schema_name,
1086-
const char *table_name, const char *prefix)
1093+
const char *table_name, const char *prefix,
1094+
Oid amoid)
10871095
{
10881096
Oid current_chunk_schemaid = get_rel_namespace(chunk_table_relid);
10891097
Oid new_chunk_schemaid = InvalidOid;
@@ -1172,12 +1180,18 @@ chunk_create_from_point_after_lock(const Hypertable *ht, const Point *p, const c
11721180
/* Resolve collisions with other chunks by cutting the new hypercube */
11731181
chunk_collision_resolve(ht, cube, p);
11741182

1175-
return chunk_create_from_hypercube_after_lock(ht, cube, schema_name, table_name, prefix);
1183+
return chunk_create_from_hypercube_after_lock(ht,
1184+
cube,
1185+
schema_name,
1186+
table_name,
1187+
prefix,
1188+
InvalidOid);
11761189
}
11771190

11781191
Chunk *
11791192
ts_chunk_find_or_create_without_cuts(const Hypertable *ht, Hypercube *hc, const char *schema_name,
1180-
const char *table_name, Oid chunk_table_relid, bool *created)
1193+
const char *table_name, Oid chunk_table_relid, Oid amoid,
1194+
bool *created)
11811195
{
11821196
ChunkStub *stub;
11831197
Chunk *chunk = NULL;
@@ -1211,10 +1225,15 @@ ts_chunk_find_or_create_without_cuts(const Hypertable *ht, Hypercube *hc, const
12111225
chunk_table_relid,
12121226
schema_name,
12131227
table_name,
1214-
NULL);
1228+
NULL,
1229+
amoid);
12151230
else
1216-
chunk =
1217-
chunk_create_from_hypercube_after_lock(ht, hc, schema_name, table_name, NULL);
1231+
chunk = chunk_create_from_hypercube_after_lock(ht,
1232+
hc,
1233+
schema_name,
1234+
table_name,
1235+
NULL,
1236+
amoid);
12181237

12191238
if (NULL != created)
12201239
*created = true;
@@ -1812,7 +1831,7 @@ chunk_resurrect(const Hypertable *ht, int chunk_id)
18121831
/* Create data table and related objects */
18131832
chunk->hypertable_relid = ht->main_table_relid;
18141833
chunk->relkind = RELKIND_RELATION;
1815-
chunk->table_id = chunk_create_table(chunk, ht);
1834+
chunk->table_id = chunk_create_table(chunk, ht, InvalidOid);
18161835
chunk_create_table_constraints(ht, chunk);
18171836

18181837
/* Finally, update the chunk tuple to no longer be a tombstone */

src/chunk.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ extern TSDLLEXPORT Chunk *ts_chunk_get_by_name_with_memory_context(const char *s
171171
extern TSDLLEXPORT void ts_chunk_insert_lock(const Chunk *chunk, LOCKMODE lock);
172172

173173
extern TSDLLEXPORT Oid ts_chunk_create_table(const Chunk *chunk, const Hypertable *ht,
174-
const char *tablespacename);
174+
const char *tablespacename, Oid amoid);
175175
extern TSDLLEXPORT Chunk *ts_chunk_get_by_id(int32 id, bool fail_if_not_found);
176176
extern TSDLLEXPORT Chunk *ts_chunk_get_by_relid(Oid relid, bool fail_if_not_found);
177177
extern TSDLLEXPORT void ts_chunk_free(Chunk *chunk);
@@ -212,9 +212,11 @@ extern TSDLLEXPORT void ts_chunk_drop_preserve_catalog_row(const Chunk *chunk,
212212
extern TSDLLEXPORT List *ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than,
213213
int32 log_level, Oid time_type, Oid arg_type,
214214
bool older_newer);
215-
extern TSDLLEXPORT Chunk *
216-
ts_chunk_find_or_create_without_cuts(const Hypertable *ht, Hypercube *hc, const char *schema_name,
217-
const char *table_name, Oid chunk_table_relid, bool *created);
215+
extern TSDLLEXPORT Chunk *ts_chunk_find_or_create_without_cuts(const Hypertable *ht, Hypercube *hc,
216+
const char *schema_name,
217+
const char *table_name,
218+
Oid chunk_table_relid, Oid amoid,
219+
bool *created);
218220
extern TSDLLEXPORT Chunk *ts_chunk_get_compressed_chunk_parent(const Chunk *chunk);
219221
extern TSDLLEXPORT bool ts_chunk_is_unordered(const Chunk *chunk);
220222
extern TSDLLEXPORT bool ts_chunk_is_partial(const Chunk *chunk);

0 commit comments

Comments
 (0)