Skip to content

Commit

Permalink
Fix range covered by osm chunk slices
Browse files Browse the repository at this point in the history
The initial range for the OSM chunk will be from INT64_MAX - 1 to INT64_MAX.
This range was chosen to minimize interference with tuple routing and
occupy a range outside of potential values as there must be no overlap
between the hypercube occupied by the osm chunk and actual chunks.
Previously the range covered by the osm chunk would bucket the start
of the range leading to a dependency on chunk_time_interval and
limiting the range of usable values in the hypertable when an osm chunk
is present.
  • Loading branch information
svenklemm committed Sep 11, 2023
1 parent ef783c4 commit 2c349a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
7 changes: 7 additions & 0 deletions sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,10 @@ ALTER FUNCTION _timescaledb_internal.finalize_agg_ffunc(internal,text,name,name,
ALTER FUNCTION _timescaledb_internal.finalize_agg_sfunc(internal,text,name,name,name[],bytea,anyelement) SET SCHEMA _timescaledb_functions;
ALTER FUNCTION _timescaledb_internal.partialize_agg(anyelement) SET SCHEMA _timescaledb_functions;

-- Fix osm chunk ranges
UPDATE _timescaledb_catalog.dimension_slice ds
SET range_start = 9223372036854775806
FROM _timescaledb_catalog.chunk_constraint cc
INNER JOIN _timescaledb_catalog.chunk c ON c.id = cc.chunk_id AND c.osm_chunk
WHERE cc.dimension_slice_id = ds.id AND ds.range_start <> 9223372036854775806;

17 changes: 10 additions & 7 deletions src/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4517,20 +4517,23 @@ ts_chunk_scan_iterator_set_chunk_id(ScanIterator *it, int32 chunk_id)
}

#include "hypercube.h"
/*
* Create a hypercube for the OSM chunk
* The initial range for the OSM chunk will be from INT64_MAX - 1 to INT64_MAX.
* This range was chosen to minimize interference with tuple routing and
* occupy a range outside of potential values as there must be no overlap
* between the hypercube occupied by the osm chunk and actual chunks.
*/
static Hypercube *
fill_hypercube_for_foreign_table_chunk(Hyperspace *hs)
fill_hypercube_for_osm_chunk(Hyperspace *hs)
{
Hypercube *cube = ts_hypercube_alloc(hs->num_dimensions);
Point *p = ts_point_create(hs->num_dimensions);
Assert(hs->num_dimensions == 1); // does not work with partitioned range
for (int i = 0; i < hs->num_dimensions; i++)
{
const Dimension *dim = &hs->dimensions[i];
Assert(dim->type == DIMENSION_TYPE_OPEN);
Oid dimtype = ts_dimension_get_partition_type(dim);
Datum val = ts_time_datum_get_max(dimtype);
p->coordinates[p->num_coords++] = ts_time_value_to_internal(val, dimtype);
cube->slices[i] = ts_dimension_calculate_default_slice(dim, p->coordinates[i]);
cube->slices[i] = ts_dimension_slice_create(dim->fd.id, PG_INT64_MAX-1,PG_INT64_MAX);
cube->num_slices++;
}
Assert(cube->num_slices == 1);
Expand Down Expand Up @@ -4580,7 +4583,7 @@ add_foreign_table_as_chunk(Oid relid, Hypertable *parent_ht)
/* fill in the correct table_name for the chunk*/
chunk->fd.hypertable_id = hs->hypertable_id;
chunk->fd.osm_chunk = true; /* this is an OSM chunk */
chunk->cube = fill_hypercube_for_foreign_table_chunk(hs);
chunk->cube = fill_hypercube_for_osm_chunk(hs);
chunk->hypertable_relid = parent_ht->main_table_relid;
chunk->constraints = ts_chunk_constraints_alloc(1, CurrentMemoryContext);

Expand Down
14 changes: 7 additions & 7 deletions tsl/test/expected/chunk_utils_internal.out
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,10 @@ SELECT chunk_name, range_start, range_end
FROM chunk_view
WHERE hypertable_name = 'ht_try'
ORDER BY chunk_name;
chunk_name | range_start | range_end
-------------------+--------------------------------+------------------------------
_hyper_5_10_chunk | Wed May 04 17:00:00 2022 PDT | Thu May 05 17:00:00 2022 PDT
child_fdw_table | Thu Dec 31 16:00:00 294246 PST | infinity
chunk_name | range_start | range_end
-------------------+---------------------------------------+------------------------------
_hyper_5_10_chunk | Wed May 04 17:00:00 2022 PDT | Thu May 05 17:00:00 2022 PDT
child_fdw_table | Sat Jan 09 20:00:54.775806 294247 PST | infinity
(2 rows)

SELECT * FROM ht_try ORDER BY 1;
Expand Down Expand Up @@ -802,9 +802,9 @@ SELECT chunk_name, range_start, range_end
FROM chunk_view
WHERE hypertable_name = 'hyper_constr'
ORDER BY chunk_name;
chunk_name | range_start | range_end
--------------------+-------------------------------------+-----------
child_hyper_constr | Sat Jan 09 20:00:54.7758 294247 PST | infinity
chunk_name | range_start | range_end
--------------------+---------------------------------------+-----------
child_hyper_constr | Sat Jan 09 20:00:54.775806 294247 PST | infinity
(1 row)

----- TESTS for copy into frozen chunk ------------
Expand Down

0 comments on commit 2c349a6

Please sign in to comment.