-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix args validation in invoke_on_partition_created_callback(), introd…
…uce pathman_calamity regression test
- Loading branch information
1 parent
ba7b036
commit f603e6c
Showing
4 changed files
with
416 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,298 @@ | ||
\set VERBOSITY terse | ||
CREATE EXTENSION pg_pathman; | ||
CREATE SCHEMA calamity; | ||
/* call for coverage test */ | ||
set client_min_messages = ERROR; | ||
SELECT debug_capture(); | ||
debug_capture | ||
--------------- | ||
|
||
(1 row) | ||
|
||
set client_min_messages = NOTICE; | ||
/* create table to be partitioned */ | ||
CREATE TABLE calamity.part_test(val serial); | ||
/* check function validate_relname() */ | ||
SELECT validate_relname('calamity.part_test'); | ||
validate_relname | ||
-------------------- | ||
calamity.part_test | ||
(1 row) | ||
|
||
/* SELECT validate_relname(NULL); -- FIXME: %s */ | ||
/* check function get_parent_of_partition() */ | ||
SELECT get_parent_of_partition('calamity.part_test'); | ||
ERROR: "part_test" is not a partition | ||
SELECT get_parent_of_partition(NULL) IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
/* check function get_base_type() */ | ||
CREATE DOMAIN calamity.test_domain AS INT4; | ||
SELECT get_base_type('int4'::regtype); | ||
get_base_type | ||
--------------- | ||
integer | ||
(1 row) | ||
|
||
SELECT get_base_type('calamity.test_domain'::regtype); | ||
get_base_type | ||
--------------- | ||
integer | ||
(1 row) | ||
|
||
SELECT get_base_type(NULL) IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
/* check function get_attribute_type() */ | ||
SELECT get_attribute_type('calamity.part_test', 'val'); | ||
get_attribute_type | ||
-------------------- | ||
integer | ||
(1 row) | ||
|
||
SELECT get_attribute_type('calamity.part_test', NULL) IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
SELECT get_attribute_type(NULL, 'val') IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
SELECT get_attribute_type(NULL, NULL) IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
/* check function build_check_constraint_name_attnum() */ | ||
SELECT build_check_constraint_name('calamity.part_test', 1::int2); | ||
build_check_constraint_name | ||
----------------------------- | ||
pathman_part_test_1_check | ||
(1 row) | ||
|
||
SELECT build_check_constraint_name('calamity.part_test', NULL::int2) IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
SELECT build_check_constraint_name(NULL, 1::int2) IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
SELECT build_check_constraint_name(NULL, NULL::int2) IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
/* check function build_check_constraint_name_attname() */ | ||
SELECT build_check_constraint_name('calamity.part_test', 'val'); | ||
build_check_constraint_name | ||
----------------------------- | ||
pathman_part_test_1_check | ||
(1 row) | ||
|
||
SELECT build_check_constraint_name('calamity.part_test', NULL::text) IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
SELECT build_check_constraint_name(NULL, 'val') IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
SELECT build_check_constraint_name(NULL, NULL::text) IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
/* check function build_update_trigger_name() */ | ||
SELECT build_update_trigger_name('calamity.part_test'); | ||
build_update_trigger_name | ||
--------------------------- | ||
part_test_upd_trig | ||
(1 row) | ||
|
||
SELECT build_update_trigger_name(NULL) IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
/* check function build_update_trigger_func_name() */ | ||
SELECT build_update_trigger_func_name('calamity.part_test'); | ||
build_update_trigger_func_name | ||
---------------------------------- | ||
calamity.part_test_upd_trig_func | ||
(1 row) | ||
|
||
SELECT build_update_trigger_func_name(NULL) IS NULL; | ||
?column? | ||
---------- | ||
t | ||
(1 row) | ||
|
||
/* check invoke_on_partition_created_callback() for RANGE */ | ||
SELECT invoke_on_partition_created_callback('calamity.part_test', 'calamity.part_test', 1, NULL, NULL::int); | ||
ERROR: both bounds must be provided for RANGE partition | ||
SELECT invoke_on_partition_created_callback('calamity.part_test', 'calamity.part_test', 1, 1, NULL); | ||
ERROR: both bounds must be provided for RANGE partition | ||
SELECT invoke_on_partition_created_callback('calamity.part_test', 'calamity.part_test', 1, NULL, 1); | ||
ERROR: both bounds must be provided for RANGE partition | ||
/* check invoke_on_partition_created_callback() for HASH */ | ||
SELECT invoke_on_partition_created_callback('calamity.part_test', 'calamity.part_test', NULL); | ||
invoke_on_partition_created_callback | ||
-------------------------------------- | ||
|
||
(1 row) | ||
|
||
SELECT invoke_on_partition_created_callback('calamity.part_test', 'calamity.part_test', 0); | ||
invoke_on_partition_created_callback | ||
-------------------------------------- | ||
|
||
(1 row) | ||
|
||
SELECT invoke_on_partition_created_callback(NULL, 'calamity.part_test', 1); | ||
ERROR: parent_relid should not be null | ||
SELECT invoke_on_partition_created_callback('calamity.part_test', NULL, 1); | ||
ERROR: partition should not be null | ||
/* check function add_to_pathman_config() -- PHASE #1 */ | ||
SELECT add_to_pathman_config('calamity.part_test', NULL); | ||
ERROR: attname should not be null | ||
SELECT add_to_pathman_config('calamity.part_test', 'val'); | ||
add_to_pathman_config | ||
----------------------- | ||
t | ||
(1 row) | ||
|
||
SELECT disable_pathman_for('calamity.part_test'); | ||
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping | ||
disable_pathman_for | ||
--------------------- | ||
|
||
(1 row) | ||
|
||
SELECT add_to_pathman_config('calamity.part_test', 'val', '10'); | ||
add_to_pathman_config | ||
----------------------- | ||
t | ||
(1 row) | ||
|
||
SELECT disable_pathman_for('calamity.part_test'); | ||
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping | ||
disable_pathman_for | ||
--------------------- | ||
|
||
(1 row) | ||
|
||
/* check function add_to_pathman_config() -- PHASE #2 */ | ||
CREATE TABLE calamity.part_ok(val serial); | ||
INSERT INTO calamity.part_ok SELECT generate_series(1, 2); | ||
SELECT create_hash_partitions('calamity.part_ok', 'val', 4); | ||
create_hash_partitions | ||
------------------------ | ||
4 | ||
(1 row) | ||
|
||
CREATE TABLE calamity.wrong_partition (LIKE calamity.part_test) INHERITS (calamity.part_test); /* wrong partition w\o constraints */ | ||
NOTICE: merging column "val" with inherited definition | ||
SELECT add_to_pathman_config('calamity.part_test', 'val'); | ||
ERROR: constraint "pathman_wrong_partition_1_check" for partition "wrong_partition" does not exist | ||
EXPLAIN (COSTS OFF) SELECT * FROM calamity.part_ok; /* check that pathman is enabled */ | ||
QUERY PLAN | ||
----------------------------- | ||
Append | ||
-> Seq Scan on part_ok_0 | ||
-> Seq Scan on part_ok_1 | ||
-> Seq Scan on part_ok_2 | ||
-> Seq Scan on part_ok_3 | ||
(5 rows) | ||
|
||
SELECT add_to_pathman_config('calamity.part_test', 'val', '10'); | ||
ERROR: constraint "pathman_wrong_partition_1_check" for partition "wrong_partition" does not exist | ||
EXPLAIN (COSTS OFF) SELECT * FROM calamity.part_ok; /* check that pathman is enabled */ | ||
QUERY PLAN | ||
----------------------------- | ||
Append | ||
-> Seq Scan on part_ok_0 | ||
-> Seq Scan on part_ok_1 | ||
-> Seq Scan on part_ok_2 | ||
-> Seq Scan on part_ok_3 | ||
(5 rows) | ||
|
||
ALTER TABLE calamity.wrong_partition | ||
ADD CONSTRAINT pathman_wrong_partition_1_check | ||
CHECK (val < 10); /* wrong constraint */ | ||
SELECT add_to_pathman_config('calamity.part_test', 'val', '10'); | ||
ERROR: Wrong constraint format for RANGE partition "wrong_partition" | ||
EXPLAIN (COSTS OFF) SELECT * FROM calamity.part_ok; /* check that pathman is enabled */ | ||
QUERY PLAN | ||
----------------------------- | ||
Append | ||
-> Seq Scan on part_ok_0 | ||
-> Seq Scan on part_ok_1 | ||
-> Seq Scan on part_ok_2 | ||
-> Seq Scan on part_ok_3 | ||
(5 rows) | ||
|
||
ALTER TABLE calamity.wrong_partition DROP CONSTRAINT pathman_wrong_partition_1_check; | ||
ALTER TABLE calamity.wrong_partition | ||
ADD CONSTRAINT pathman_wrong_partition_1_check | ||
CHECK (val = 1 OR val = 2); /* wrong constraint */ | ||
SELECT add_to_pathman_config('calamity.part_test', 'val', '10'); | ||
ERROR: Wrong constraint format for RANGE partition "wrong_partition" | ||
EXPLAIN (COSTS OFF) SELECT * FROM calamity.part_ok; /* check that pathman is enabled */ | ||
QUERY PLAN | ||
----------------------------- | ||
Append | ||
-> Seq Scan on part_ok_0 | ||
-> Seq Scan on part_ok_1 | ||
-> Seq Scan on part_ok_2 | ||
-> Seq Scan on part_ok_3 | ||
(5 rows) | ||
|
||
ALTER TABLE calamity.wrong_partition DROP CONSTRAINT pathman_wrong_partition_1_check; | ||
ALTER TABLE calamity.wrong_partition | ||
ADD CONSTRAINT pathman_wrong_partition_1_check | ||
CHECK (val >= 10 AND val = 2); /* wrong constraint */ | ||
SELECT add_to_pathman_config('calamity.part_test', 'val', '10'); | ||
ERROR: Wrong constraint format for RANGE partition "wrong_partition" | ||
EXPLAIN (COSTS OFF) SELECT * FROM calamity.part_ok; /* check that pathman is enabled */ | ||
QUERY PLAN | ||
----------------------------- | ||
Append | ||
-> Seq Scan on part_ok_0 | ||
-> Seq Scan on part_ok_1 | ||
-> Seq Scan on part_ok_2 | ||
-> Seq Scan on part_ok_3 | ||
(5 rows) | ||
|
||
ALTER TABLE calamity.wrong_partition DROP CONSTRAINT pathman_wrong_partition_1_check; | ||
/* check GUC variable */ | ||
SHOW pg_pathman.enable; | ||
pg_pathman.enable | ||
------------------- | ||
on | ||
(1 row) | ||
|
||
DROP SCHEMA calamity CASCADE; | ||
NOTICE: drop cascades to 8 other objects | ||
DROP EXTENSION pg_pathman; |
Oops, something went wrong.