Skip to content

Commit

Permalink
fix args validation in invoke_on_partition_created_callback(), introd…
Browse files Browse the repository at this point in the history
…uce pathman_calamity regression test
  • Loading branch information
funbringer committed Oct 19, 2016
1 parent ba7b036 commit f603e6c
Show file tree
Hide file tree
Showing 4 changed files with 416 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ REGRESS = pathman_basic \
pathman_foreign_keys \
pathman_permissions \
pathman_rowmarks \
pathman_copy_stmt_hooking
pathman_copy_stmt_hooking \
pathman_calamity
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
EXTRA_CLEAN = pg_pathman--$(EXTVERSION).sql ./isolation_output

Expand Down
298 changes: 298 additions & 0 deletions expected/pathman_calamity.out
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;
Loading

0 comments on commit f603e6c

Please sign in to comment.