Skip to content

Commit

Permalink
Implement policies based on chunk creation time
Browse files Browse the repository at this point in the history
- The idea with these changes is to support INTERVAL boundaries for
  INTEGER type columns in policy APIs. The boundary calculation will
  be done using chunk creation time metadata.
- Updated show_chunks, drop_chunks and retention policy APIs to get the
  affected chunks using chunk creation time metadata based on the
  INTERVAL boundary specified for the INTEGER columns.
- Honor "integer_now" function if it's specified so as to keep backwards
  compatibility with the existing behavior

Co-authored-by: Dipesh Pandit <[email protected]>
  • Loading branch information
nikkhils and pdipesh02 committed Oct 9, 2023
1 parent 0b87a06 commit 3ce3ccb
Show file tree
Hide file tree
Showing 23 changed files with 618 additions and 119 deletions.
13 changes: 12 additions & 1 deletion sql/policy_internal.sql
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ DECLARE
dimtypeinput REGPROC;
compress_after TEXT;
lag_value TEXT;
lag_bigint_value BIGINT;
htid INTEGER;
htoid REGCLASS;
chunk_rec RECORD;
Expand Down Expand Up @@ -193,9 +194,19 @@ BEGIN

lag_value := jsonb_object_field_text(config, 'compress_after');

-- We now allow INTERVAL lag values for INT-like dimensions. So
-- try to typecast to BIGINT (since it should be able to handle
-- INT/SMALLINT/BIGINT). If the typecasting fails then we know
-- it's an interval
BEGIN
lag_bigint_value := lag_value::BIGINT;
EXCEPTION WHEN OTHERS THEN
dimtype := 'INTERVAL' ::regtype;
END;

-- execute the properly type casts for the lag value
CASE dimtype
WHEN 'TIMESTAMP'::regtype, 'TIMESTAMPTZ'::regtype, 'DATE'::regtype THEN
WHEN 'TIMESTAMP'::regtype, 'TIMESTAMPTZ'::regtype, 'DATE'::regtype, 'INTERVAL' ::regtype THEN
CALL _timescaledb_functions.policy_compression_execute(
job_id, htid, lag_value::INTERVAL,
maxchunks, verbose_log, recompress_enabled
Expand Down
Loading

0 comments on commit 3ce3ccb

Please sign in to comment.