Skip to content

Commit

Permalink
PG17: Regression Tests
Browse files Browse the repository at this point in the history
Added missing template output tests and also converted others to
template due to output changes.

Also fixed some small pieces of code to properly run in all current
supported Postgres versions (14, 15, 16 and 17)
  • Loading branch information
fabriziomello committed Sep 5, 2024
1 parent d2a2498 commit a627861
Show file tree
Hide file tree
Showing 66 changed files with 22,933 additions and 409 deletions.
3 changes: 2 additions & 1 deletion .github/gh_matrix_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def macos_config(overrides):
"pg": "17",
"snapshot": "snapshot",
"tsdb_build_args": "-DEXPERIMENTAL=ON",
"skipped_tests": "merge_compress merge_dml merge size_utils ts_merge-17",
# @TODO: those skipped tests should be revisited later
"skipped_tests": "merge_compress merge_dml merge ts_merge-17 repair 001_job_crash_log",
}
)
)
Expand Down
3 changes: 3 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,9 @@ ts_try_relation_cached_size(Relation rel, bool verbose)
ForkNumber forkNum;
bool cached = true;

if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
return (int64) nblocks;

/* Get heap size, including FSM and VM */
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
{
Expand Down
File renamed without changes.
2,507 changes: 2,507 additions & 0 deletions test/expected/agg_bookends-15.out

Large diffs are not rendered by default.

2,507 changes: 2,507 additions & 0 deletions test/expected/agg_bookends-16.out

Large diffs are not rendered by default.

2,458 changes: 2,458 additions & 0 deletions test/expected/agg_bookends-17.out

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions test/expected/alter.out
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SELECT * FROM alter_before;
-- Show that deleted column is marked as dropped and that attnums are
-- now different for the root table and the chunk
-- PG17 made attstattarget NULLABLE and changed the default from -1 to NULL
SELECT c.relname, a.attname, a.attnum, a.attoptions, CASE WHEN a.attstattarget = -1 THEN NULL ELSE a.attstattarget END attstattarget, a.attstorage FROM pg_attribute a, pg_class c
SELECT c.relname, a.attname, a.attnum, a.attoptions, CASE WHEN a.attstattarget = -1 OR (a.attisdropped AND a.attstattarget = 0) THEN NULL ELSE a.attstattarget END attstattarget, a.attstorage FROM pg_attribute a, pg_class c
WHERE a.attrelid = c.oid
AND (c.relname LIKE '_hyper_1%_chunk' OR c.relname = 'alter_before')
AND a.attnum > 0
Expand All @@ -42,7 +42,7 @@ ORDER BY c.relname, a.attnum;
_hyper_1_1_chunk | colorid | 3 | | | p
_hyper_1_1_chunk | notes | 4 | | | e
_hyper_1_1_chunk | notes_2 | 5 | | | x
alter_before | ........pg.dropped.1........ | 1 | | 0 | p
alter_before | ........pg.dropped.1........ | 1 | | | p
alter_before | time | 2 | | | p
alter_before | temp | 3 | {n_distinct=10} | 100 | p
alter_before | colorid | 4 | | | p
Expand Down Expand Up @@ -128,14 +128,14 @@ ALTER TABLE _timescaledb_internal._hyper_2_4_chunk ALTER COLUMN temp SET (n_dis
ALTER TABLE _timescaledb_internal._hyper_2_4_chunk ALTER COLUMN temp SET STATISTICS 201;
ALTER TABLE _timescaledb_internal._hyper_2_4_chunk ALTER COLUMN notes SET STORAGE EXTERNAL;
-- PG17 made attstattarget NULLABLE and changed the default from -1 to NULL
SELECT c.relname, a.attname, a.attnum, a.attoptions, CASE WHEN a.attstattarget = -1 THEN NULL ELSE a.attstattarget END attstattarget, a.attstorage FROM pg_attribute a, pg_class c
SELECT c.relname, a.attname, a.attnum, a.attoptions, CASE WHEN a.attstattarget = -1 OR (a.attisdropped AND a.attstattarget = 0) THEN NULL ELSE a.attstattarget END attstattarget, a.attstorage FROM pg_attribute a, pg_class c
WHERE a.attrelid = c.oid
AND (c.relname LIKE '_hyper_2%_chunk' OR c.relname = 'alter_after')
AND a.attnum > 0
ORDER BY c.relname, a.attnum;
relname | attname | attnum | attoptions | attstattarget | attstorage
------------------+------------------------------+--------+-----------------+---------------+------------
_hyper_2_2_chunk | ........pg.dropped.1........ | 1 | | 0 | p
_hyper_2_2_chunk | ........pg.dropped.1........ | 1 | | | p
_hyper_2_2_chunk | time | 2 | | | p
_hyper_2_2_chunk | temp | 3 | {n_distinct=10} | | p
_hyper_2_2_chunk | colorid | 4 | | 101 | p
Expand All @@ -154,7 +154,7 @@ ORDER BY c.relname, a.attnum;
_hyper_2_4_chunk | notes | 4 | | | e
_hyper_2_4_chunk | notes_2 | 5 | | | e
_hyper_2_4_chunk | id | 6 | | | p
alter_after | ........pg.dropped.1........ | 1 | | 0 | p
alter_after | ........pg.dropped.1........ | 1 | | | p
alter_after | time | 2 | | | p
alter_after | temp | 3 | {n_distinct=10} | | p
alter_after | colorid | 4 | | 101 | p
Expand Down
File renamed without changes.
194 changes: 194 additions & 0 deletions test/expected/drop_owned-15.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
\c :TEST_DBNAME :ROLE_SUPERUSER
CREATE SCHEMA hypertable_schema;
GRANT ALL ON SCHEMA hypertable_schema TO :ROLE_DEFAULT_PERM_USER;
SET ROLE :ROLE_DEFAULT_PERM_USER;
CREATE TABLE hypertable_schema.default_perm_user (time timestamptz, temp float, location int);
SELECT create_hypertable('hypertable_schema.default_perm_user', 'time', 'location', 2);
NOTICE: adding not-null constraint to column "time"
create_hypertable
-------------------------------------------
(1,hypertable_schema,default_perm_user,t)
(1 row)

INSERT INTO hypertable_schema.default_perm_user VALUES ('2001-01-01 01:01:01', 23.3, 1);
RESET ROLE;
CREATE TABLE hypertable_schema.superuser (time timestamptz, temp float, location int);
SELECT create_hypertable('hypertable_schema.superuser', 'time', 'location', 2);
NOTICE: adding not-null constraint to column "time"
create_hypertable
-----------------------------------
(2,hypertable_schema,superuser,t)
(1 row)

INSERT INTO hypertable_schema.superuser VALUES ('2001-01-01 01:01:01', 23.3, 1);
SELECT * FROM _timescaledb_catalog.hypertable ORDER BY id;
id | schema_name | table_name | associated_schema_name | associated_table_prefix | num_dimensions | chunk_sizing_func_schema | chunk_sizing_func_name | chunk_target_size | compression_state | compressed_hypertable_id | status
----+-------------------+-------------------+------------------------+-------------------------+----------------+--------------------------+--------------------------+-------------------+-------------------+--------------------------+--------
1 | hypertable_schema | default_perm_user | _timescaledb_internal | _hyper_1 | 2 | _timescaledb_functions | calculate_chunk_interval | 0 | 0 | | 0
2 | hypertable_schema | superuser | _timescaledb_internal | _hyper_2 | 2 | _timescaledb_functions | calculate_chunk_interval | 0 | 0 | | 0
(2 rows)

SELECT id, hypertable_id, schema_name, table_name, compressed_chunk_id, dropped, status, osm_chunk FROM _timescaledb_catalog.chunk;
id | hypertable_id | schema_name | table_name | compressed_chunk_id | dropped | status | osm_chunk
----+---------------+-----------------------+------------------+---------------------+---------+--------+-----------
1 | 1 | _timescaledb_internal | _hyper_1_1_chunk | | f | 0 | f
2 | 2 | _timescaledb_internal | _hyper_2_2_chunk | | f | 0 | f
(2 rows)

DROP OWNED BY :ROLE_DEFAULT_PERM_USER;
SELECT * FROM _timescaledb_catalog.hypertable ORDER BY id;
id | schema_name | table_name | associated_schema_name | associated_table_prefix | num_dimensions | chunk_sizing_func_schema | chunk_sizing_func_name | chunk_target_size | compression_state | compressed_hypertable_id | status
----+-------------------+------------+------------------------+-------------------------+----------------+--------------------------+--------------------------+-------------------+-------------------+--------------------------+--------
2 | hypertable_schema | superuser | _timescaledb_internal | _hyper_2 | 2 | _timescaledb_functions | calculate_chunk_interval | 0 | 0 | | 0
(1 row)

SELECT id, hypertable_id, schema_name, table_name, compressed_chunk_id, dropped, status, osm_chunk FROM _timescaledb_catalog.chunk;
id | hypertable_id | schema_name | table_name | compressed_chunk_id | dropped | status | osm_chunk
----+---------------+-----------------------+------------------+---------------------+---------+--------+-----------
2 | 2 | _timescaledb_internal | _hyper_2_2_chunk | | f | 0 | f
(1 row)

DROP TABLE hypertable_schema.superuser;
--everything should be cleaned up
SELECT * FROM _timescaledb_catalog.hypertable GROUP BY id;
id | schema_name | table_name | associated_schema_name | associated_table_prefix | num_dimensions | chunk_sizing_func_schema | chunk_sizing_func_name | chunk_target_size | compression_state | compressed_hypertable_id | status
----+-------------+------------+------------------------+-------------------------+----------------+--------------------------+------------------------+-------------------+-------------------+--------------------------+--------
(0 rows)

SELECT id, hypertable_id, schema_name, table_name, compressed_chunk_id, dropped, status, osm_chunk FROM _timescaledb_catalog.chunk;
id | hypertable_id | schema_name | table_name | compressed_chunk_id | dropped | status | osm_chunk
----+---------------+-------------+------------+---------------------+---------+--------+-----------
(0 rows)

SELECT * FROM _timescaledb_catalog.dimension;
id | hypertable_id | column_name | column_type | aligned | num_slices | partitioning_func_schema | partitioning_func | interval_length | compress_interval_length | integer_now_func_schema | integer_now_func
----+---------------+-------------+-------------+---------+------------+--------------------------+-------------------+-----------------+--------------------------+-------------------------+------------------
(0 rows)

SELECT * FROM _timescaledb_catalog.dimension_slice;
id | dimension_id | range_start | range_end
----+--------------+-------------+-----------
(0 rows)

SELECT * FROM _timescaledb_catalog.chunk_index;
chunk_id | index_name | hypertable_id | hypertable_index_name
----------+------------+---------------+-----------------------
(0 rows)

SELECT * FROM _timescaledb_catalog.chunk_constraint;
chunk_id | dimension_slice_id | constraint_name | hypertable_constraint_name
----------+--------------------+-----------------+----------------------------
(0 rows)

-- test drop owned in database without extension installed
\c :TEST_DBNAME :ROLE_SUPERUSER
CREATE database test_drop_owned;
\c test_drop_owned
DROP OWNED BY :ROLE_SUPERUSER;
\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE test_drop_owned WITH (FORCE);
-- Test that dependencies on roles are added to chunks when creating
-- new chunks. If that is not done, DROP OWNED BY will not revoke the
-- privilege on the chunk.
CREATE TABLE sensor_data(time timestamptz not null, cpu double precision null);
SELECT * FROM create_hypertable('sensor_data','time');
hypertable_id | schema_name | table_name | created
---------------+-------------+-------------+---------
3 | public | sensor_data | t
(1 row)

INSERT INTO sensor_data
SELECT time,
random() AS cpu
FROM generate_series('2020-01-01'::timestamptz, '2020-01-24'::timestamptz, INTERVAL '10 minute') AS g1(time);
\dp sensor_data
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+-------------+-------+-------------------+-------------------+----------
public | sensor_data | table | | |
(1 row)

\dp _timescaledb_internal._hyper_3*
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
-----------------------+------------------+-------+-------------------+-------------------+----------
_timescaledb_internal | _hyper_3_3_chunk | table | | |
_timescaledb_internal | _hyper_3_4_chunk | table | | |
_timescaledb_internal | _hyper_3_5_chunk | table | | |
_timescaledb_internal | _hyper_3_6_chunk | table | | |
_timescaledb_internal | _hyper_3_7_chunk | table | | |
(5 rows)

GRANT SELECT ON sensor_data TO :ROLE_DEFAULT_PERM_USER;
\dp sensor_data
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+-------------+-------+--------------------------------+-------------------+----------
public | sensor_data | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
(1 row)

\dp _timescaledb_internal._hyper_3*
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
-----------------------+------------------+-------+--------------------------------+-------------------+----------
_timescaledb_internal | _hyper_3_3_chunk | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
_timescaledb_internal | _hyper_3_4_chunk | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
_timescaledb_internal | _hyper_3_5_chunk | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
_timescaledb_internal | _hyper_3_6_chunk | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
_timescaledb_internal | _hyper_3_7_chunk | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
(5 rows)

-- Insert more chunks after adding the user to the hypertable. These
-- will now get the privileges of the hypertable.
INSERT INTO sensor_data
SELECT time,
random() AS cpu
FROM generate_series('2020-01-20'::timestamptz, '2020-02-05'::timestamptz, INTERVAL '10 minute') AS g1(time);
\dp _timescaledb_internal._hyper_3*
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
-----------------------+------------------+-------+--------------------------------+-------------------+----------
_timescaledb_internal | _hyper_3_3_chunk | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
_timescaledb_internal | _hyper_3_4_chunk | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
_timescaledb_internal | _hyper_3_5_chunk | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
_timescaledb_internal | _hyper_3_6_chunk | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
_timescaledb_internal | _hyper_3_7_chunk | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
_timescaledb_internal | _hyper_3_8_chunk | table | super_user=arwdDxt/super_user +| |
| | | default_perm_user=r/super_user | |
(6 rows)

-- This should revoke the privileges on both the hypertable and the chunks.
DROP OWNED BY :ROLE_DEFAULT_PERM_USER;
\dp sensor_data
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+-------------+-------+-------------------------------+-------------------+----------
public | sensor_data | table | super_user=arwdDxt/super_user | |
(1 row)

\dp _timescaledb_internal._hyper_3*
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
-----------------------+------------------+-------+-------------------------------+-------------------+----------
_timescaledb_internal | _hyper_3_3_chunk | table | super_user=arwdDxt/super_user | |
_timescaledb_internal | _hyper_3_4_chunk | table | super_user=arwdDxt/super_user | |
_timescaledb_internal | _hyper_3_5_chunk | table | super_user=arwdDxt/super_user | |
_timescaledb_internal | _hyper_3_6_chunk | table | super_user=arwdDxt/super_user | |
_timescaledb_internal | _hyper_3_7_chunk | table | super_user=arwdDxt/super_user | |
_timescaledb_internal | _hyper_3_8_chunk | table | super_user=arwdDxt/super_user | |
(6 rows)

Loading

0 comments on commit a627861

Please sign in to comment.