Skip to content
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

Fix FK constraints for compressed chunks #6797

Merged
merged 1 commit into from
Apr 13, 2024

Conversation

svenklemm
Copy link
Member

@svenklemm svenklemm commented Apr 2, 2024

When foreign key support for compressed chunks was added we moved
the FK constraint from the uncompressed chunk to the compressed chunk as
part of compress_chunk and moved it back as part of decompress_chunk.
With the addition of partially compressed chunks in 2.10.x this approach
was no longer sufficient and the FK constraint needs to be present on
both the uncompressed and the compressed chunk.

While this patch will fix future compressed chunks a migration has to be
run after upgrading timescaledb to migrate existing chunks affected by
this.

The following code will fix any affected hypertables:

CREATE OR REPLACE FUNCTION pg_temp.constraint_columns(regclass, int2[]) RETURNS text[] AS
$$
  SELECT array_agg(attname) FROM unnest($2) un(attnum) LEFT JOIN pg_attribute att ON att.attrelid=$1 AND att.attnum = un.attnum;
$$ LANGUAGE SQL SET search_path TO pg_catalog, pg_temp;

DO $$
DECLARE
  ht_id int;
  ht regclass;
  chunk regclass;
  con_oid oid;
  con_frelid regclass;
  con_name text;
  con_columns text[];
  chunk_id int;

BEGIN

  -- iterate over all hypertables that have foreign key constraints
  FOR ht_id, ht in
    SELECT
      ht.id,
      format('%I.%I',ht.schema_name,ht.table_name)::regclass
    FROM _timescaledb_catalog.hypertable ht
    WHERE
      EXISTS (
        SELECT FROM pg_constraint con
        WHERE
          con.contype='f' AND
          con.conrelid=format('%I.%I',ht.schema_name,ht.table_name)::regclass
      )
  LOOP
    RAISE NOTICE 'Hypertable % has foreign key constraint', ht;

    -- iterate over all foreign key constraints on the hypertable
    -- and check that they are present on every chunk
    FOR con_oid, con_frelid, con_name, con_columns IN
      SELECT con.oid, con.confrelid, con.conname, pg_temp.constraint_columns(con.conrelid,con.conkey)
      FROM pg_constraint con
      WHERE
        con.contype='f' AND
        con.conrelid=ht
    LOOP
      RAISE NOTICE 'Checking constraint % %', con_name, con_columns;
      -- check that the foreign key constraint is present on the chunk

      FOR chunk_id, chunk IN
        SELECT
          ch.id,
          format('%I.%I',ch.schema_name,ch.table_name)::regclass
        FROM _timescaledb_catalog.chunk ch
        WHERE
          ch.hypertable_id=ht_id
      LOOP
        RAISE NOTICE 'Checking chunk %', chunk;
        IF NOT EXISTS (
          SELECT FROM pg_constraint con
          WHERE
            con.contype='f' AND
            con.conrelid=chunk AND
            con.confrelid=con_frelid  AND
            pg_temp.constraint_columns(con.conrelid,con.conkey) = con_columns
        ) THEN
          RAISE WARNING 'Restoring constraint % on chunk %', con_name, chunk;
          PERFORM _timescaledb_functions.constraint_clone(con_oid, chunk);
          INSERT INTO _timescaledb_catalog.chunk_constraint(chunk_id, dimension_slice_id, constraint_name, hypertable_constraint_name) VALUES (chunk_id, NULL, con_name, con_name);
        END IF;

      END LOOP;
    END LOOP;

  END LOOP;

END
$$;

DROP FUNCTION pg_temp.constraint_columns(regclass, int2[]);

Fixes #6759

@svenklemm svenklemm self-assigned this Apr 2, 2024
@svenklemm svenklemm force-pushed the compressed_fk branch 2 times, most recently from e6ef021 to 37ea0fb Compare April 4, 2024 12:05
@svenklemm svenklemm force-pushed the compressed_fk branch 3 times, most recently from d3f8553 to 77e40a7 Compare April 10, 2024 14:03
Copy link
Contributor

@antekresic antekresic left a comment

Choose a reason for hiding this comment

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

LGTM

@svenklemm svenklemm force-pushed the compressed_fk branch 2 times, most recently from bad12ef to efeca06 Compare April 13, 2024 13:44
@svenklemm svenklemm added this to the TimescaleDB 2.15.0 milestone Apr 13, 2024
When foreign key support for compressed chunks was added we moved
the FK constraint from the uncompressed chunk to the compressed chunk as
part of compress_chunk and moved it back as part of decompress_chunk.
With the addition of partially compressed chunks in 2.10.x this approach
was no longer sufficient and the FK constraint needs to be present on
both the uncompressed and the compressed chunk.

While this patch will fix future compressed chunks a migration has to be
run after upgrading timescaledb to migrate existing chunks affected by
this.

The following code will fix any affected hypertables:
```
CREATE OR REPLACE FUNCTION pg_temp.constraint_columns(regclass, int2[]) RETURNS text[] AS
$$
  SELECT array_agg(attname) FROM unnest($2) un(attnum) LEFT JOIN pg_attribute att ON att.attrelid=$1 AND att.attnum = un.attnum;
$$ LANGUAGE SQL SET search_path TO pg_catalog, pg_temp;

DO $$
DECLARE
  ht_id int;
  ht regclass;
  chunk regclass;
  con_oid oid;
  con_frelid regclass;
  con_name text;
  con_columns text[];
  chunk_id int;

BEGIN

  -- iterate over all hypertables that have foreign key constraints
  FOR ht_id, ht in
    SELECT
      ht.id,
      format('%I.%I',ht.schema_name,ht.table_name)::regclass
    FROM _timescaledb_catalog.hypertable ht
    WHERE
      EXISTS (
        SELECT FROM pg_constraint con
        WHERE
          con.contype='f' AND
          con.conrelid=format('%I.%I',ht.schema_name,ht.table_name)::regclass
      )
  LOOP
    RAISE NOTICE 'Hypertable % has foreign key constraint', ht;

    -- iterate over all foreign key constraints on the hypertable
    -- and check that they are present on every chunk
    FOR con_oid, con_frelid, con_name, con_columns IN
      SELECT con.oid, con.confrelid, con.conname, pg_temp.constraint_columns(con.conrelid,con.conkey)
      FROM pg_constraint con
      WHERE
        con.contype='f' AND
        con.conrelid=ht
    LOOP
      RAISE NOTICE 'Checking constraint % %', con_name, con_columns;
      -- check that the foreign key constraint is present on the chunk

      FOR chunk_id, chunk IN
        SELECT
          ch.id,
          format('%I.%I',ch.schema_name,ch.table_name)::regclass
        FROM _timescaledb_catalog.chunk ch
        WHERE
          ch.hypertable_id=ht_id
      LOOP
        RAISE NOTICE 'Checking chunk %', chunk;
        IF NOT EXISTS (
          SELECT FROM pg_constraint con
          WHERE
            con.contype='f' AND
            con.conrelid=chunk AND
            con.confrelid=con_frelid  AND
            pg_temp.constraint_columns(con.conrelid,con.conkey) = con_columns
        ) THEN
          RAISE WARNING 'Restoring constraint % on chunk %', con_name, chunk;
          PERFORM _timescaledb_functions.constraint_clone(con_oid, chunk);
          INSERT INTO _timescaledb_catalog.chunk_constraint(chunk_id, dimension_slice_id, constraint_name, hypertable_constraint_name) VALUES (chunk_id, NULL, con_name, con_name);
        END IF;

      END LOOP;
    END LOOP;

  END LOOP;

END
$$;

DROP FUNCTION pg_temp.constraint_columns(regclass, int2[]);
```
Copy link

codecov bot commented Apr 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.93%. Comparing base (59f50f2) to head (5586d8f).
Report is 110 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6797      +/-   ##
==========================================
+ Coverage   80.06%   80.93%   +0.86%     
==========================================
  Files         190      197       +7     
  Lines       37181    37015     -166     
  Branches     9450     9661     +211     
==========================================
+ Hits        29770    29957     +187     
- Misses       2997     3202     +205     
+ Partials     4414     3856     -558     

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

@svenklemm svenklemm enabled auto-merge (rebase) April 13, 2024 14:26
@svenklemm svenklemm merged commit ecf6bea into timescale:main Apr 13, 2024
41 checks passed
@timescale-automation
Copy link

Automated backport to 2.14.x not done: cherry-pick failed.

Git status

HEAD detached at origin/2.14.x
You are currently cherry-picking commit ecf6beae5.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   .unreleased/pr_6797
	modified:   src/chunk.h
	modified:   tsl/src/compression/api.c
	modified:   tsl/test/expected/compression.out
	new file:   tsl/test/expected/compression_fks.out
	modified:   tsl/test/sql/CMakeLists.txt
	new file:   tsl/test/sql/compression_fks.sql

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/chunk.c


Job log

@timescale-automation timescale-automation added the auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) label Apr 13, 2024
fabriziomello added a commit to fabriziomello/timescaledb that referenced this pull request May 6, 2024
This release contains performance improvements and bug fixes since
the 2.14.2 release. We recommend that you upgrade at the next
available opportunity.

In addition, it includes these noteworthy features:
* Support `time_bucket` with `origin` and/or `offset` on Continuous Aggregate
* Compression improvements:
  - Improve expression pushdown
  - Add minmax sparse indexes when compressing columns with btree indexes
  - Make compression use the defaults functions
  - Vectorize filters in WHERE clause that contain text equality operators and LIKE expressions

**Deprecation warning**
* Starting on this release will not be possible to create Continuous Aggregate using `time_bucket_ng` anymore and it will be completely removed on the upcoming releases.
* Recommend users to [migrate their old Continuous Aggregate format to the new one](https://docs.timescale.com/use-timescale/latest/continuous-aggregates/migrate/) because it support will be completely removed in next releases prevent them to migrate.
* This is the last release supporting PostgreSQL 13.

**For on-premise users and this release only**, you will need to run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql) after running `ALTER EXTENSION`. More details can be found in the pull request [timescale#6786](timescale#6797).

**Features**
* timescale#6382 Support for time_bucket with origin and offset in CAggs
* timescale#6696 Improve defaults for compression segment_by and order_by
* timescale#6705 Add sparse minmax indexes for compressed columns that have uncompressed btree indexes
* timescale#6754 Allow DROP CONSTRAINT on compressed hypertables
* timescale#6767 Add metadata table `_timestaledb_internal.bgw_job_stat_history` for tracking job execution history
* timescale#6798 Prevent usage of deprecated time_bucket_ng in CAgg definition
* timescale#6810 Add telemetry for access methods
* timescale#6811 Remove no longer relevant timescaledb.allow_install_without_preload GUC
* timescale#6837 Add migration path for CAggs using time_bucket_ng
* timescale#6865 Update the watermark when truncating a CAgg

**Bugfixes**
* timescale#6617 Fix error in show_chunks
* timescale#6621 Remove metadata when dropping chunks
* timescale#6677 Fix snapshot usage in CAgg invalidation scanner
* timescale#6698 Define meaning of 0 retries for jobs as no retries
* timescale#6717 Fix handling of compressed tables with primary or unique index in COPY path
* timescale#6726 Fix constify cagg_watermark using window function when querying a CAgg
* timescale#6729 Fix NULL start value handling in CAgg refresh
* timescale#6732 Fix CAgg migration with custom timezone / date format settings
* timescale#6752 Remove custom autovacuum setting from compressed chunks
* timescale#6770 Fix plantime chunk exclusion for OSM chunk
* timescale#6789 Fix deletes with subqueries and compression
* timescale#6796 Fix a crash involving a view on a hypertable
* timescale#6797 Fix foreign key constraint handling on compressed hypertables
* timescale#6816 Fix handling of chunks with no contraints
* timescale#6820 Fix a crash when the ts_hypertable_insert_blocker was called directly
* timescale#6849 Use non-orderby compressed metadata in compressed DML
* timescale#6867 Clean up compression settings when deleting compressed cagg
* timescale#6869 Fix compressed DML with constraints of form value OP column
* timescale#6870 Fix bool expression pushdown for queries on compressed chunks

**Thanks**
* @brasic for reporting a crash when the ts_hypertable_insert_blocker was called directly
* @bvanelli for reporting an issue with the jobs retry count
* @djzurawsk For reporting error when dropping chunks
* @Dzuzepppe for reporting an issue with DELETEs using subquery on compressed chunk working incorrectly.
* @hongquan For reporting a 'timestamp out of range' error during CAgg migrations
* @kevcenteno for reporting an issue with the show_chunks API showing incorrect output when 'created_before/created_after' was used with time-partitioned columns.
* @mahipv For starting working on the job history PR
* @rovo89 For reporting constify cagg_watermark not working using window function when querying a CAgg
fabriziomello added a commit to fabriziomello/timescaledb that referenced this pull request May 6, 2024
This release contains performance improvements and bug fixes since
the 2.14.2 release. We recommend that you upgrade at the next
available opportunity.

In addition, it includes these noteworthy features:
* Support `time_bucket` with `origin` and/or `offset` on Continuous Aggregate
* Compression improvements:
  - Improve expression pushdown
  - Add minmax sparse indexes when compressing columns with btree indexes
  - Make compression use the defaults functions
  - Vectorize filters in WHERE clause that contain text equality operators and LIKE expressions

**Deprecation warning**
* Starting on this release will not be possible to create Continuous Aggregate using `time_bucket_ng` anymore and it will be completely removed on the upcoming releases.
* Recommend users to [migrate their old Continuous Aggregate format to the new one](https://docs.timescale.com/use-timescale/latest/continuous-aggregates/migrate/) because it support will be completely removed in next releases prevent them to migrate.
* This is the last release supporting PostgreSQL 13.

**For on-premise users and this release only**, you will need to run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql) after running `ALTER EXTENSION`. More details can be found in the pull request [timescale#6786](timescale#6797).

**Features**
* timescale#6382 Support for time_bucket with origin and offset in CAggs
* timescale#6696 Improve defaults for compression segment_by and order_by
* timescale#6705 Add sparse minmax indexes for compressed columns that have uncompressed btree indexes
* timescale#6754 Allow DROP CONSTRAINT on compressed hypertables
* timescale#6767 Add metadata table `_timestaledb_internal.bgw_job_stat_history` for tracking job execution history
* timescale#6798 Prevent usage of deprecated time_bucket_ng in CAgg definition
* timescale#6810 Add telemetry for access methods
* timescale#6811 Remove no longer relevant timescaledb.allow_install_without_preload GUC
* timescale#6837 Add migration path for CAggs using time_bucket_ng
* timescale#6865 Update the watermark when truncating a CAgg

**Bugfixes**
* timescale#6617 Fix error in show_chunks
* timescale#6621 Remove metadata when dropping chunks
* timescale#6677 Fix snapshot usage in CAgg invalidation scanner
* timescale#6698 Define meaning of 0 retries for jobs as no retries
* timescale#6717 Fix handling of compressed tables with primary or unique index in COPY path
* timescale#6726 Fix constify cagg_watermark using window function when querying a CAgg
* timescale#6729 Fix NULL start value handling in CAgg refresh
* timescale#6732 Fix CAgg migration with custom timezone / date format settings
* timescale#6752 Remove custom autovacuum setting from compressed chunks
* timescale#6770 Fix plantime chunk exclusion for OSM chunk
* timescale#6789 Fix deletes with subqueries and compression
* timescale#6796 Fix a crash involving a view on a hypertable
* timescale#6797 Fix foreign key constraint handling on compressed hypertables
* timescale#6816 Fix handling of chunks with no contraints
* timescale#6820 Fix a crash when the ts_hypertable_insert_blocker was called directly
* timescale#6849 Use non-orderby compressed metadata in compressed DML
* timescale#6867 Clean up compression settings when deleting compressed cagg
* timescale#6869 Fix compressed DML with constraints of form value OP column
* timescale#6870 Fix bool expression pushdown for queries on compressed chunks

**Thanks**
* @brasic for reporting a crash when the ts_hypertable_insert_blocker was called directly
* @bvanelli for reporting an issue with the jobs retry count
* @djzurawsk For reporting error when dropping chunks
* @Dzuzepppe for reporting an issue with DELETEs using subquery on compressed chunk working incorrectly.
* @hongquan For reporting a 'timestamp out of range' error during CAgg migrations
* @kevcenteno for reporting an issue with the show_chunks API showing incorrect output when 'created_before/created_after' was used with time-partitioned columns.
* @mahipv For starting working on the job history PR
* @rovo89 For reporting constify cagg_watermark not working using window function when querying a CAgg
@fabriziomello fabriziomello mentioned this pull request May 6, 2024
fabriziomello added a commit to fabriziomello/timescaledb that referenced this pull request May 6, 2024
This release contains performance improvements and bug fixes since
the 2.14.2 release. We recommend that you upgrade at the next
available opportunity.

In addition, it includes these noteworthy features:
* Support `time_bucket` with `origin` and/or `offset` on Continuous Aggregate
* Compression improvements:
  - Improve expression pushdown
  - Add minmax sparse indexes when compressing columns with btree indexes
  - Make compression use the defaults functions
  - Vectorize filters in WHERE clause that contain text equality operators and LIKE expressions

**Deprecation warning**
* Starting on this release will not be possible to create Continuous Aggregate using `time_bucket_ng` anymore and it will be completely removed on the upcoming releases.
* Recommend users to [migrate their old Continuous Aggregate format to the new one](https://docs.timescale.com/use-timescale/latest/continuous-aggregates/migrate/) because it support will be completely removed in next releases prevent them to migrate.
* This is the last release supporting PostgreSQL 13.

**For on-premise users and this release only**, you will need to run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql) after running `ALTER EXTENSION`. More details can be found in the pull request [timescale#6786](timescale#6797).

**Features**
* timescale#6382 Support for time_bucket with origin and offset in CAggs
* timescale#6696 Improve defaults for compression segment_by and order_by
* timescale#6705 Add sparse minmax indexes for compressed columns that have uncompressed btree indexes
* timescale#6754 Allow DROP CONSTRAINT on compressed hypertables
* timescale#6767 Add metadata table `_timestaledb_internal.bgw_job_stat_history` for tracking job execution history
* timescale#6798 Prevent usage of deprecated time_bucket_ng in CAgg definition
* timescale#6810 Add telemetry for access methods
* timescale#6811 Remove no longer relevant timescaledb.allow_install_without_preload GUC
* timescale#6837 Add migration path for CAggs using time_bucket_ng
* timescale#6865 Update the watermark when truncating a CAgg

**Bugfixes**
* timescale#6617 Fix error in show_chunks
* timescale#6621 Remove metadata when dropping chunks
* timescale#6677 Fix snapshot usage in CAgg invalidation scanner
* timescale#6698 Define meaning of 0 retries for jobs as no retries
* timescale#6717 Fix handling of compressed tables with primary or unique index in COPY path
* timescale#6726 Fix constify cagg_watermark using window function when querying a CAgg
* timescale#6729 Fix NULL start value handling in CAgg refresh
* timescale#6732 Fix CAgg migration with custom timezone / date format settings
* timescale#6752 Remove custom autovacuum setting from compressed chunks
* timescale#6770 Fix plantime chunk exclusion for OSM chunk
* timescale#6789 Fix deletes with subqueries and compression
* timescale#6796 Fix a crash involving a view on a hypertable
* timescale#6797 Fix foreign key constraint handling on compressed hypertables
* timescale#6816 Fix handling of chunks with no contraints
* timescale#6820 Fix a crash when the ts_hypertable_insert_blocker was called directly
* timescale#6849 Use non-orderby compressed metadata in compressed DML
* timescale#6867 Clean up compression settings when deleting compressed cagg
* timescale#6869 Fix compressed DML with constraints of form value OP column
* timescale#6870 Fix bool expression pushdown for queries on compressed chunks

**Thanks**
* @brasic for reporting a crash when the ts_hypertable_insert_blocker was called directly
* @bvanelli for reporting an issue with the jobs retry count
* @djzurawsk For reporting error when dropping chunks
* @Dzuzepppe for reporting an issue with DELETEs using subquery on compressed chunk working incorrectly.
* @hongquan For reporting a 'timestamp out of range' error during CAgg migrations
* @kevcenteno for reporting an issue with the show_chunks API showing incorrect output when 'created_before/created_after' was used with time-partitioned columns.
* @mahipv For starting working on the job history PR
* @rovo89 For reporting constify cagg_watermark not working using window function when querying a CAgg
fabriziomello added a commit that referenced this pull request May 6, 2024
This release contains performance improvements and bug fixes since
the 2.14.2 release. We recommend that you upgrade at the next
available opportunity.

In addition, it includes these noteworthy features:
* Support `time_bucket` with `origin` and/or `offset` on Continuous Aggregate
* Compression improvements:
  - Improve expression pushdown
  - Add minmax sparse indexes when compressing columns with btree indexes
  - Make compression use the defaults functions
  - Vectorize filters in WHERE clause that contain text equality operators and LIKE expressions

**Deprecation warning**
* Starting on this release will not be possible to create Continuous Aggregate using `time_bucket_ng` anymore and it will be completely removed on the upcoming releases.
* Recommend users to [migrate their old Continuous Aggregate format to the new one](https://docs.timescale.com/use-timescale/latest/continuous-aggregates/migrate/) because it support will be completely removed in next releases prevent them to migrate.
* This is the last release supporting PostgreSQL 13.

**For on-premise users and this release only**, you will need to run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql) after running `ALTER EXTENSION`. More details can be found in the pull request [#6786](#6797).

**Features**
* #6382 Support for time_bucket with origin and offset in CAggs
* #6696 Improve defaults for compression segment_by and order_by
* #6705 Add sparse minmax indexes for compressed columns that have uncompressed btree indexes
* #6754 Allow DROP CONSTRAINT on compressed hypertables
* #6767 Add metadata table `_timestaledb_internal.bgw_job_stat_history` for tracking job execution history
* #6798 Prevent usage of deprecated time_bucket_ng in CAgg definition
* #6810 Add telemetry for access methods
* #6811 Remove no longer relevant timescaledb.allow_install_without_preload GUC
* #6837 Add migration path for CAggs using time_bucket_ng
* #6865 Update the watermark when truncating a CAgg

**Bugfixes**
* #6617 Fix error in show_chunks
* #6621 Remove metadata when dropping chunks
* #6677 Fix snapshot usage in CAgg invalidation scanner
* #6698 Define meaning of 0 retries for jobs as no retries
* #6717 Fix handling of compressed tables with primary or unique index in COPY path
* #6726 Fix constify cagg_watermark using window function when querying a CAgg
* #6729 Fix NULL start value handling in CAgg refresh
* #6732 Fix CAgg migration with custom timezone / date format settings
* #6752 Remove custom autovacuum setting from compressed chunks
* #6770 Fix plantime chunk exclusion for OSM chunk
* #6789 Fix deletes with subqueries and compression
* #6796 Fix a crash involving a view on a hypertable
* #6797 Fix foreign key constraint handling on compressed hypertables
* #6816 Fix handling of chunks with no contraints
* #6820 Fix a crash when the ts_hypertable_insert_blocker was called directly
* #6849 Use non-orderby compressed metadata in compressed DML
* #6867 Clean up compression settings when deleting compressed cagg
* #6869 Fix compressed DML with constraints of form value OP column
* #6870 Fix bool expression pushdown for queries on compressed chunks

**Thanks**
* @brasic for reporting a crash when the ts_hypertable_insert_blocker was called directly
* @bvanelli for reporting an issue with the jobs retry count
* @djzurawsk For reporting error when dropping chunks
* @Dzuzepppe for reporting an issue with DELETEs using subquery on compressed chunk working incorrectly.
* @hongquan For reporting a 'timestamp out of range' error during CAgg migrations
* @kevcenteno for reporting an issue with the show_chunks API showing incorrect output when 'created_before/created_after' was used with time-partitioned columns.
* @mahipv For starting working on the job history PR
* @rovo89 For reporting constify cagg_watermark not working using window function when querying a CAgg
fabriziomello added a commit to fabriziomello/timescaledb that referenced this pull request May 6, 2024
This release contains performance improvements and bug fixes since
the 2.14.2 release. We recommend that you upgrade at the next
available opportunity.

In addition, it includes these noteworthy features:
* Support `time_bucket` with `origin` and/or `offset` on Continuous Aggregate
* Compression improvements:
  - Improve expression pushdown
  - Add minmax sparse indexes when compressing columns with btree indexes
  - Make compression use the defaults functions
  - Vectorize filters in WHERE clause that contain text equality operators and LIKE expressions

**Deprecation warning**
* Starting on this release will not be possible to create Continuous Aggregate using `time_bucket_ng` anymore and it will be completely removed on the upcoming releases.
* Recommend users to [migrate their old Continuous Aggregate format to the new one](https://docs.timescale.com/use-timescale/latest/continuous-aggregates/migrate/) because it support will be completely removed in next releases prevent them to migrate.
* This is the last release supporting PostgreSQL 13.

**For on-premise users and this release only**, you will need to run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql) after running `ALTER EXTENSION`. More details can be found in the pull request [timescale#6786](timescale#6797).

**Features**
* timescale#6382 Support for time_bucket with origin and offset in CAggs
* timescale#6696 Improve defaults for compression segment_by and order_by
* timescale#6705 Add sparse minmax indexes for compressed columns that have uncompressed btree indexes
* timescale#6754 Allow DROP CONSTRAINT on compressed hypertables
* timescale#6767 Add metadata table `_timestaledb_internal.bgw_job_stat_history` for tracking job execution history
* timescale#6798 Prevent usage of deprecated time_bucket_ng in CAgg definition
* timescale#6810 Add telemetry for access methods
* timescale#6811 Remove no longer relevant timescaledb.allow_install_without_preload GUC
* timescale#6837 Add migration path for CAggs using time_bucket_ng
* timescale#6865 Update the watermark when truncating a CAgg

**Bugfixes**
* timescale#6617 Fix error in show_chunks
* timescale#6621 Remove metadata when dropping chunks
* timescale#6677 Fix snapshot usage in CAgg invalidation scanner
* timescale#6698 Define meaning of 0 retries for jobs as no retries
* timescale#6717 Fix handling of compressed tables with primary or unique index in COPY path
* timescale#6726 Fix constify cagg_watermark using window function when querying a CAgg
* timescale#6729 Fix NULL start value handling in CAgg refresh
* timescale#6732 Fix CAgg migration with custom timezone / date format settings
* timescale#6752 Remove custom autovacuum setting from compressed chunks
* timescale#6770 Fix plantime chunk exclusion for OSM chunk
* timescale#6789 Fix deletes with subqueries and compression
* timescale#6796 Fix a crash involving a view on a hypertable
* timescale#6797 Fix foreign key constraint handling on compressed hypertables
* timescale#6816 Fix handling of chunks with no contraints
* timescale#6820 Fix a crash when the ts_hypertable_insert_blocker was called directly
* timescale#6849 Use non-orderby compressed metadata in compressed DML
* timescale#6867 Clean up compression settings when deleting compressed cagg
* timescale#6869 Fix compressed DML with constraints of form value OP column
* timescale#6870 Fix bool expression pushdown for queries on compressed chunks

**Thanks**
* @brasic for reporting a crash when the ts_hypertable_insert_blocker was called directly
* @bvanelli for reporting an issue with the jobs retry count
* @djzurawsk For reporting error when dropping chunks
* @Dzuzepppe for reporting an issue with DELETEs using subquery on compressed chunk working incorrectly.
* @hongquan For reporting a 'timestamp out of range' error during CAgg migrations
* @kevcenteno for reporting an issue with the show_chunks API showing incorrect output when 'created_before/created_after' was used with time-partitioned columns.
* @mahipv For starting working on the job history PR
* @rovo89 For reporting constify cagg_watermark not working using window function when querying a CAgg
fabriziomello added a commit that referenced this pull request May 7, 2024
This release contains performance improvements and bug fixes since
the 2.14.2 release. We recommend that you upgrade at the next
available opportunity.

In addition, it includes these noteworthy features:
* Support `time_bucket` with `origin` and/or `offset` on Continuous Aggregate
* Compression improvements:
  - Improve expression pushdown
  - Add minmax sparse indexes when compressing columns with btree indexes
  - Make compression use the defaults functions
  - Vectorize filters in WHERE clause that contain text equality operators and LIKE expressions

**Deprecation warning**
* Starting on this release will not be possible to create Continuous Aggregate using `time_bucket_ng` anymore and it will be completely removed on the upcoming releases.
* Recommend users to [migrate their old Continuous Aggregate format to the new one](https://docs.timescale.com/use-timescale/latest/continuous-aggregates/migrate/) because it support will be completely removed in next releases prevent them to migrate.
* This is the last release supporting PostgreSQL 13.

**For on-premise users and this release only**, you will need to run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql) after running `ALTER EXTENSION`. More details can be found in the pull request [#6786](#6797).

**Features**
* #6382 Support for time_bucket with origin and offset in CAggs
* #6696 Improve defaults for compression segment_by and order_by
* #6705 Add sparse minmax indexes for compressed columns that have uncompressed btree indexes
* #6754 Allow DROP CONSTRAINT on compressed hypertables
* #6767 Add metadata table `_timestaledb_internal.bgw_job_stat_history` for tracking job execution history
* #6798 Prevent usage of deprecated time_bucket_ng in CAgg definition
* #6810 Add telemetry for access methods
* #6811 Remove no longer relevant timescaledb.allow_install_without_preload GUC
* #6837 Add migration path for CAggs using time_bucket_ng
* #6865 Update the watermark when truncating a CAgg

**Bugfixes**
* #6617 Fix error in show_chunks
* #6621 Remove metadata when dropping chunks
* #6677 Fix snapshot usage in CAgg invalidation scanner
* #6698 Define meaning of 0 retries for jobs as no retries
* #6717 Fix handling of compressed tables with primary or unique index in COPY path
* #6726 Fix constify cagg_watermark using window function when querying a CAgg
* #6729 Fix NULL start value handling in CAgg refresh
* #6732 Fix CAgg migration with custom timezone / date format settings
* #6752 Remove custom autovacuum setting from compressed chunks
* #6770 Fix plantime chunk exclusion for OSM chunk
* #6789 Fix deletes with subqueries and compression
* #6796 Fix a crash involving a view on a hypertable
* #6797 Fix foreign key constraint handling on compressed hypertables
* #6816 Fix handling of chunks with no contraints
* #6820 Fix a crash when the ts_hypertable_insert_blocker was called directly
* #6849 Use non-orderby compressed metadata in compressed DML
* #6867 Clean up compression settings when deleting compressed cagg
* #6869 Fix compressed DML with constraints of form value OP column
* #6870 Fix bool expression pushdown for queries on compressed chunks

**Thanks**
* @brasic for reporting a crash when the ts_hypertable_insert_blocker was called directly
* @bvanelli for reporting an issue with the jobs retry count
* @djzurawsk For reporting error when dropping chunks
* @Dzuzepppe for reporting an issue with DELETEs using subquery on compressed chunk working incorrectly.
* @hongquan For reporting a 'timestamp out of range' error during CAgg migrations
* @kevcenteno for reporting an issue with the show_chunks API showing incorrect output when 'created_before/created_after' was used with time-partitioned columns.
* @mahipv For starting working on the job history PR
* @rovo89 For reporting constify cagg_watermark not working using window function when querying a CAgg
@SystemParadox
Copy link

Why isn't this being done automatically as part of the upgrade? Manual migration like this is a real pain.

@eyadmba
Copy link

eyadmba commented May 18, 2024

Does this script need to be run if I don't have any compressed hypertables? If not, then the docs should mention that. Right now the docs say that the script "must" be run after the ALTER EXTENSION.

@mac866
Copy link

mac866 commented May 24, 2024

Hi,

the script creates and immediately deletes the function constraint_columns.
Where, when and how (parameters?) is constraint_columns called?

Thank you very much!

@adschmu
Copy link

adschmu commented May 28, 2024

@svenklemm Release docs say "for this release only". Does this mean that
A) we will get an upgrade script for this at some point (e.g. with 2.16.x),
or does it mean that
B) we will continue to have to run this whenever we upgrade coming from < 2.15.0 to >= 2.15.0, so we never get it integrated?

@billy-the-fish billy-the-fish mentioned this pull request May 28, 2024
pallavisontakke added a commit that referenced this pull request May 28, 2024
This release contains performance improvements and bug fixes since
the 2.15.0 release. Best practice is to upgrade at the next 
available opportunity.

**Migrating from self-hosted TimescaleDB v2.14.x and earlier**

After you run `ALTER EXTENSION`, you must run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql). For more details, see the following pull request [#6797](#6797).

If you are migrating from TimescaleDB v2.15.0, no changes are required.

**Bugfixes**
* #6540: Segmentation fault when you backfill data using COPY into a compressed chunk.
* #6858: `BEFORE UPDATE` trigger not working correctly. 
* #6908: Fix `time_bucket_gapfill()` with timezone behaviour around daylight savings time (DST) switches.
* #6911: Fix dropped chunk metadata removal in the update script. 
* #6940: Fix `pg_upgrade` failure by removing `regprocedure` from the catalog table.
* #6957: Fix the `segfault` in UNION queries that contain ordering on compressed chunks.

**Thanks**
* @DiAifU, @kiddhombre and @intermittentnrg for reporting the issues with gapfill and daylight saving time.
* @edgarzamora for reporting the issue with update triggers.
* @hongquan for reporting the issue with the update script.
* @iliastsa and @SystemParadox for reporting the issue with COPY into a compressed chunk.
@fabriziomello fabriziomello mentioned this pull request May 28, 2024
fabriziomello added a commit to fabriziomello/timescaledb that referenced this pull request Jun 6, 2024
This release contains performance improvements and bug fixes since
the 2.15.0 release. Best practice is to upgrade at the next
available opportunity.

**Migrating from self-hosted TimescaleDB v2.14.x and earlier**

After you run `ALTER EXTENSION`, you must run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql). For more details, see the following pull request [timescale#6797](timescale#6797).

If you are migrating from TimescaleDB v2.15.0 or v2.15.1, no changes are required.

**Bugfixes**
* timescale#6975: Fix sort pushdown for partially compressed chunks.
* timescale#6976: Fix removal of metadata function and update script.
* timescale#6978: Fix segfault in compress_chunk with primary space partition.
* timescale#6993: Disallow hash partitioning on primary column.

**Thanks**
* @gugu for reporting the issue with catalog corruption due to update.
* @srieding for reporting an issue with partially compressed chunks and ordering on joined columns.
@fabriziomello fabriziomello mentioned this pull request Jun 6, 2024
fabriziomello added a commit to fabriziomello/timescaledb that referenced this pull request Jun 6, 2024
This release contains performance improvements and bug fixes since
the 2.15.0 release. Best practice is to upgrade at the next
available opportunity.

**Migrating from self-hosted TimescaleDB v2.14.x and earlier**

After you run `ALTER EXTENSION`, you must run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql). For more details, see the following pull request [timescale#6797](timescale#6797).

If you are migrating from TimescaleDB v2.15.0 or v2.15.1, no changes are required.

**Bugfixes**
* timescale#6975: Fix sort pushdown for partially compressed chunks.
* timescale#6976: Fix removal of metadata function and update script.
* timescale#6978: Fix segfault in compress_chunk with primary space partition.
* timescale#6993: Disallow hash partitioning on primary column.

**Thanks**
* @gugu for reporting the issue with catalog corruption due to update.
* @srieding for reporting an issue with partially compressed chunks and ordering on joined columns.
fabriziomello added a commit to fabriziomello/timescaledb that referenced this pull request Jun 7, 2024
This release contains performance improvements and bug fixes since
the 2.15.0 release. Best practice is to upgrade at the next
available opportunity.

**Migrating from self-hosted TimescaleDB v2.14.x and earlier**

After you run `ALTER EXTENSION`, you must run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql). For more details, see the following pull request [timescale#6797](timescale#6797).

If you are migrating from TimescaleDB v2.15.0 or v2.15.1, no changes are required.

**Bugfixes**
* timescale#6975: Fix sort pushdown for partially compressed chunks.
* timescale#6976: Fix removal of metadata function and update script.
* timescale#6978: Fix segfault in compress_chunk with primary space partition.
* timescale#6993: Disallow hash partitioning on primary column.

**Thanks**
* @gugu for reporting the issue with catalog corruption due to update.
* @srieding for reporting an issue with partially compressed chunks and ordering on joined columns.
fabriziomello added a commit that referenced this pull request Jun 7, 2024
This release contains performance improvements and bug fixes since
the 2.15.0 release. Best practice is to upgrade at the next
available opportunity.

**Migrating from self-hosted TimescaleDB v2.14.x and earlier**

After you run `ALTER EXTENSION`, you must run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql). For more details, see the following pull request [#6797](#6797).

If you are migrating from TimescaleDB v2.15.0 or v2.15.1, no changes are required.

**Bugfixes**
* #6975: Fix sort pushdown for partially compressed chunks.
* #6976: Fix removal of metadata function and update script.
* #6978: Fix segfault in compress_chunk with primary space partition.
* #6993: Disallow hash partitioning on primary column.

**Thanks**
* @gugu for reporting the issue with catalog corruption due to update.
* @srieding for reporting an issue with partially compressed chunks and ordering on joined columns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) compression migration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Foreign keys on compressed hypertables not working
8 participants