From cb9bf6aa22200401c8964c8e451b27d56b577067 Mon Sep 17 00:00:00 2001 From: Mehmet Yilmaz Date: Thu, 7 Nov 2024 13:16:50 +0000 Subject: [PATCH] alter_index test update --- src/test/regress/expected/alter_index.out | 6 ++ src/test/regress/expected/alter_index_0.out | 72 +++++++++++++++++++++ src/test/regress/sql/alter_index.sql | 6 ++ 3 files changed, 84 insertions(+) create mode 100644 src/test/regress/expected/alter_index_0.out diff --git a/src/test/regress/expected/alter_index.out b/src/test/regress/expected/alter_index.out index 4d4a725b3..047be84c3 100644 --- a/src/test/regress/expected/alter_index.out +++ b/src/test/regress/expected/alter_index.out @@ -1,3 +1,9 @@ +-- Two alternative test outputs: +-- alter_index.out for PG16 and before +-- alter_index_0.out for PG17 +-- related commit +-- Changed `attstattarget` in `pg_attribute` to use `NullableDatum`, allowing null representation for default statistics target in PostgreSQL 17. +-- https://github.com/postgres/postgres/commit/6a004f1be87d34cfe51acf2fe2552d2b08a79273 CREATE SCHEMA alterindex; SET search_path TO "alterindex"; SET citus.next_shard_id TO 980000; diff --git a/src/test/regress/expected/alter_index_0.out b/src/test/regress/expected/alter_index_0.out new file mode 100644 index 000000000..c793579de --- /dev/null +++ b/src/test/regress/expected/alter_index_0.out @@ -0,0 +1,72 @@ +-- Two alternative test outputs: +-- alter_index.out for PG16 and before +-- alter_index_0.out for PG17 +-- related commit +-- Changed `attstattarget` in `pg_attribute` to use `NullableDatum`, allowing null representation for default statistics target in PostgreSQL 17. +-- https://github.com/postgres/postgres/commit/6a004f1be87d34cfe51acf2fe2552d2b08a79273 +CREATE SCHEMA alterindex; +SET search_path TO "alterindex"; +SET citus.next_shard_id TO 980000; +SET client_min_messages TO WARNING; +SET citus.shard_count TO 4; +SET citus.shard_replication_factor TO 1; +-- test alter index set statistics +CREATE TABLE t1 (a int, b int); +SELECT create_distributed_table('t1','a'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +CREATE INDEX test_idx on t1 ((a+b)); +ALTER INDEX test_idx ALTER COLUMN 1 SET STATISTICS 4646; +ALTER INDEX test_idx ALTER COLUMN 1 SET STATISTICS -4646; +ERROR: statistics target -4646 is too low +ALTER INDEX test_idx ALTER COLUMN 3 SET STATISTICS 4646; +ERROR: column number 3 of relation "test_idx" does not exist +-- test alter index set statistics before distribution +CREATE TABLE t2 (a int, b int); +CREATE INDEX test_idx2 on t2 ((a+b), (a-b), (a*b)); +ALTER INDEX test_idx2 ALTER COLUMN 2 SET STATISTICS 3737; +ALTER INDEX test_idx2 ALTER COLUMN 3 SET STATISTICS 3737; +ALTER INDEX test_idx2 ALTER COLUMN 2 SET STATISTICS 99999; +WARNING: lowering statistics target to 10000 +SELECT create_distributed_table('t2','a'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +-- verify statistics is set +SELECT c.relname, a.attstattarget +FROM pg_attribute a +JOIN pg_class c ON a.attrelid = c.oid AND c.relname LIKE 'test\_idx%' +ORDER BY c.relname, a.attnum; + relname | attstattarget +--------------------------------------------------------------------- + test_idx | 4646 + test_idx2 | + test_idx2 | 10000 + test_idx2 | 3737 +(4 rows) + +\c - - - :worker_1_port +SELECT c.relname, a.attstattarget +FROM pg_attribute a +JOIN pg_class c ON a.attrelid = c.oid AND c.relname SIMILAR TO 'test\_idx%\_\d%' +ORDER BY c.relname, a.attnum; + relname | attstattarget +--------------------------------------------------------------------- + test_idx2_980004 | + test_idx2_980004 | 10000 + test_idx2_980004 | 3737 + test_idx2_980006 | + test_idx2_980006 | 10000 + test_idx2_980006 | 3737 + test_idx_980000 | 4646 + test_idx_980002 | 4646 +(8 rows) + +\c - - - :master_port +SET client_min_messages TO WARNING; +DROP SCHEMA alterindex CASCADE; diff --git a/src/test/regress/sql/alter_index.sql b/src/test/regress/sql/alter_index.sql index 3531bad18..224442600 100644 --- a/src/test/regress/sql/alter_index.sql +++ b/src/test/regress/sql/alter_index.sql @@ -1,3 +1,9 @@ +-- Two alternative test outputs: +-- alter_index.out for PG16 and before +-- alter_index_0.out for PG17 +-- related commit +-- Changed `attstattarget` in `pg_attribute` to use `NullableDatum`, allowing null representation for default statistics target in PostgreSQL 17. +-- https://github.com/postgres/postgres/commit/6a004f1be87d34cfe51acf2fe2552d2b08a79273 CREATE SCHEMA alterindex; SET search_path TO "alterindex";