Skip to content

Commit

Permalink
redo
Browse files Browse the repository at this point in the history
  • Loading branch information
icefairy committed Apr 29, 2024
1 parent 7e12c7d commit 21c831f
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 20 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions src/backend/distributed/sql/udfs/create_time_partitions/12.1-1.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ BEGIN
SELECT *
FROM get_missing_time_partition_ranges(table_name, partition_interval, end_at, start_from)
LOOP
EXECUTE format('CREATE TABLE %I.%I (LIKE %I INCLUDING DEFAULTS INCLUDING CONSTRAINTS)',
EXECUTE format('CREATE TABLE %I.%I PARTITION OF %I.%I FOR VALUES FROM (%L) TO (%L)',
schema_name_text,
missing_partition_record.partition_name,
table_name_text);
EXECUTE format('ALTER TABLE %I.%I ATTACH PARTITION %I.%I FOR VALUES FROM (%L) TO (%L)',
schema_name_text,
table_name_text,
schema_name_text,
missing_partition_record.partition_name,
missing_partition_record.range_from_value,
missing_partition_record.range_to_value);
RAISE NOTICE 'created partition % for table %', missing_partition_record.partition_name, table_name_text;

partition_created := true;
END LOOP;

Expand All @@ -55,4 +51,4 @@ COMMENT ON FUNCTION pg_catalog.create_time_partitions(
partition_interval INTERVAL,
end_at timestamptz,
start_from timestamptz)
IS 'create time partitions for the given range';
IS 'create time partitions for the given range';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ BEGIN
ORDER BY to_value%1$s::timestamptz', custom_cast);
FOR r IN EXECUTE older_partitions_query USING table_name, older_than
LOOP
RAISE NOTICE 'dropping % with start time % and end time % using DETACH PARTITION partition_name AND THEN DROP IT. ', r.partition, r.from_value, r.to_value;
EXECUTE format('ALTER TABLE %I.%I DETACH PARTITION %I',r.schema_name, r.table_name, r.partition);
RAISE NOTICE 'dropping % with start time % and end time %', r.partition, r.from_value, r.to_value;
EXECUTE format('DROP TABLE %I.%I', r.schema_name, r.table_name);
END LOOP;
END;
$$;
COMMENT ON PROCEDURE pg_catalog.drop_old_time_partitions(
table_name regclass,
older_than timestamptz)
IS 'drop old partitions of a time-partitioned table';
IS 'drop old partitions of a time-partitioned table';

0 comments on commit 21c831f

Please sign in to comment.