Skip to content

Conversation

@mrkaye97
Copy link
Contributor

@mrkaye97 mrkaye97 commented Sep 3, 2025

Description

Partitioning v1_dag_to_task - this one was much simpler, since we can just create a partition using all of the existing data and attach it to the new table

Type of change

  • Bug fix (non-breaking change which fixes an issue)

@vercel
Copy link

vercel bot commented Sep 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hatchet-docs Ready Ready Preview Comment Sep 12, 2025 2:07pm
hatchet-v0-docs Ready Ready Preview Comment Sep 12, 2025 2:07pm

Comment on lines 42 to 64
CREATE TABLE v1_dag_to_task_original (
dag_id BIGINT NOT NULL,
dag_inserted_at TIMESTAMPTZ NOT NULL,
task_id BIGINT NOT NULL,
task_inserted_at TIMESTAMPTZ NOT NULL,
PRIMARY KEY (dag_id, dag_inserted_at, task_id, task_inserted_at)
);

INSERT INTO v1_dag_to_task_original
SELECT * FROM v1_dag_to_task;

DROP TABLE v1_dag_to_task;
ALTER TABLE v1_dag_to_task_original RENAME TO v1_dag_to_task;
ALTER INDEX v1_dag_to_task_original_pkey RENAME TO v1_dag_to_task_pkey;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is mostly just for me testing on local

@mrkaye97 mrkaye97 requested a review from Copilot September 3, 2025 16:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR partitions the v1_dag_to_task table by range on the dag_inserted_at column to improve performance for time-based queries. The migration creates a new partitioned table, preserves existing data as the first partition, and updates the schema definition.

  • Converts v1_dag_to_task from a regular table to a partitioned table using dag_inserted_at as the partition key
  • Creates a migration that preserves all existing data by making it the first partition
  • Updates the schema definition to reflect the new partitioned structure

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
sql/schema/v1-core.sql Updates table definition to add PARTITION BY RANGE(dag_inserted_at)
cmd/hatchet-migrate/migrate/migrations/20250903152758_v1_0_41.sql Migration script to convert existing table to partitioned format with data preservation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@mrkaye97
Copy link
Contributor Author

mrkaye97 commented Sep 3, 2025

@abelanger5 any idea how long ATTACH PARTITION might take? I didn't find much online about it - I think it'll need to revalidate any constraints, so I'm not 100% sure this is safe to do

Comment on lines 11 to 12
SELECT create_v1_range_partition('v1_dag_to_task_partitioned', NOW()::DATE);
SELECT create_v1_range_partition('v1_dag_to_task_partitioned', (NOW() + INTERVAL '1 day')::DATE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be corresponding code changes to maintain this partition?

Also: would weekly partitions make sense here, or daily?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, thanks 🤦 keep forgetting this when going from cloud to the oss

re: weekly vs daily - I guess weekly is fine? it'd be easier on the planner

@mrkaye97 mrkaye97 force-pushed the mk/partition-core-dag-to-task branch from 5c28693 to 92f771d Compare September 12, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants