Skip to content

Fix dump/restore when chunk skipping is enabled #8211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

erimatnor
Copy link
Member

@erimatnor erimatnor commented Jun 3, 2025

The chunk skipping feature uses a "special" entry in the catalog table chunk_column_stats to indicate that chunk skipping is enabled for that column. The special entry has the chunk_id column set to 0. However, at the same time the table schema defines a foreign key on the chunk_id column where the 0 entry violates that constraint. This prevents a dump/restore from working when such an entry is present.

As a temporary solution, remove the foreign key constraint. A longer term solution should probably use a different way to indicate that chunk skipping is enabled.

Fixes: #8130

@erimatnor erimatnor force-pushed the remove-column-stats-fk branch 3 times, most recently from b91f94d to f5efdaa Compare June 3, 2025 10:25
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.36%. Comparing base (4c701e0) to head (2305074).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8211      +/-   ##
==========================================
+ Coverage   82.30%   82.36%   +0.06%     
==========================================
  Files         256      256              
  Lines       48016    47988      -28     
  Branches    12113    12109       -4     
==========================================
+ Hits        39518    39524       +6     
- Misses       3638     3658      +20     
+ Partials     4860     4806      -54     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The chunk skipping feature uses a "special" entry in the catalog table
chunk_column_stats to indicate that chunk skipping is enabled for that
column. The special entry has the chunk_id column set to 0. However,
at the same time the table schema defines a foreign key on the
chunk_id column where the 0 entry violates that constraint. This
prevents a dump/restore from working when such an entry is present.

As a temporary solution, remove the foreign key constraint. A longer
term solution should probably use a different way to indicate that
chunk skipping is enabled.
@erimatnor erimatnor force-pushed the remove-column-stats-fk branch from f5efdaa to 2305074 Compare June 3, 2025 11:52
@erimatnor erimatnor marked this pull request as ready for review June 3, 2025 11:56
@github-actions github-actions bot requested review from gayyappan and svenklemm June 3, 2025 11:57
Copy link

github-actions bot commented Jun 3, 2025

@gayyappan, @svenklemm: please review this pull request.

Powered by pull-review

Copy link
Member

@mkindahl mkindahl left a comment

Choose a reason for hiding this comment

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

We should probably use NULL to represent this, since NULL means "no association with the referenced table", which is essentially what "invalid hypertable" means.

@erimatnor
Copy link
Member Author

We should probably use NULL to represent this, since NULL means "no association with the referenced table", which is essentially what "invalid hypertable" means.

@mkindahl do you think that is a better solution than removing the FK constraint? Perhaps we should do this directly in this PR?

@mkindahl
Copy link
Member

mkindahl commented Jun 4, 2025

We should probably use NULL to represent this, since NULL means "no association with the referenced table", which is essentially what "invalid hypertable" means.

@mkindahl do you think that is a better solution than removing the FK constraint? Perhaps we should do this directly in this PR?

IMHO; this is a better alternative since this is this is what the semantics is used for.

@@ -239,8 +239,8 @@ CREATE TABLE _timescaledb_catalog.chunk_column_stats (
CONSTRAINT chunk_column_stats_pkey PRIMARY KEY (id),
CONSTRAINT chunk_column_stats_ht_id_chunk_id_colname_key UNIQUE (hypertable_id, chunk_id, column_name),
CONSTRAINT chunk_column_stats_range_check CHECK (range_start <= range_end),
CONSTRAINT chunk_column_stats_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id),
CONSTRAINT chunk_column_stats_chunk_id_fkey FOREIGN KEY (chunk_id) REFERENCES _timescaledb_catalog.chunk (id)
-- No FK for chunk_id since we allow entries with Invalid chunk ID (0)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be NULL instead of 0 (zero)??

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I am working on a version of the patch to test that.

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.

pg_restore: error: COPY failed for table "chunk_column_stats
4 participants