Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5592c67

Browse files
committed
more calamity tests for coverage
1 parenta3a841b commit5592c67

File tree

4 files changed

+93
-32
lines changed

4 files changed

+93
-32
lines changed

‎expected/pathman_calamity.out‎

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,21 @@ SELECT build_range_condition('calamity.part_test', 'val', NULL, 10);/* OK */
270270
(1 row)
271271

272272
/* check function validate_interval_value() */
273-
SELECT validate_interval_value(1::REGCLASS, 'expr', 2, '1 mon', 'cooked_expr');/* not ok */
273+
SELECT validate_interval_value(1::REGCLASS, 'expr', 2, '1 mon', 'cooked_expr');/* not ok */
274274
ERROR: relation "1" does not exist
275-
SELECT validate_interval_value(NULL, 'expr', 2, '1 mon', 'cooked_expr');/* not ok */
275+
SELECT validate_interval_value(NULL, 'expr', 2, '1 mon', 'cooked_expr');/* not ok */
276276
ERROR: 'partrel' should not be NULL
277-
SELECT validate_interval_value('pg_class', NULL, 2, '1 mon', 'cooked_expr');/* not ok */
277+
SELECT validate_interval_value('pg_class', NULL, 2, '1 mon', 'cooked_expr');/* not ok */
278278
ERROR: 'expression' should not be NULL
279-
SELECT validate_interval_value('pg_class', 'oid', 1, 'HASH', NULL);/* not ok */
279+
SELECT validate_interval_value('pg_class', 'oid', NULL, '1 mon', 'cooked_expr');/* not ok */
280+
ERROR: 'parttype' should not be NULL
281+
SELECT validate_interval_value('pg_class', 'oid', 1, 'HASH', NULL);/* not ok */
280282
ERROR: interval should be NULL for HASH partitioned table
281-
SELECT validate_interval_value('pg_class', 'expr', 2, '1 mon', NULL);/* not ok */
283+
SELECT validate_interval_value('pg_class', 'expr', 2, '1 mon', NULL);/* not ok */
282284
ERROR: cannot find type name for attribute "expr" of relation "pg_class"
283-
SELECT validate_interval_value('pg_class', 'expr', 2, NULL, 'cooked_expr');/* not ok */
285+
SELECT validate_interval_value('pg_class', 'expr', 2, NULL, 'cooked_expr');/* not ok */
284286
ERROR: unrecognized token: "cooked_expr"
285-
SELECT validate_interval_value('pg_class', 'EXPR', 1, 'HASH', NULL);/* not ok */
287+
SELECT validate_interval_value('pg_class', 'EXPR', 1, 'HASH', NULL);/* not ok */
286288
ERROR: cannot find type name for attribute "expr" of relation "pg_class"
287289
/* check function validate_relname() */
288290
SELECT validate_relname('calamity.part_test');
@@ -749,8 +751,46 @@ SELECT get_part_range('calamity.test_range_oid_1', NULL::INT4);/* OK */
749751

750752
DROP TABLE calamity.test_range_oid CASCADE;
751753
NOTICE: drop cascades to table calamity.test_range_oid_1
754+
/* check function merge_range_partitions() */
755+
SELECT merge_range_partitions('{pg_class}');/* not ok */
756+
ERROR: cannot merge partitions
757+
\errverbose
758+
ERROR: XX000: cannot merge partitions
759+
DETAIL: there must be at least two partitions
760+
LOCATION: merge_range_partitions, pl_range_funcs.c:625
761+
SELECT merge_range_partitions('{pg_class, pg_inherits}');/* not ok */
762+
ERROR: cannot merge partitions
763+
\errverbose
764+
ERROR: XX000: cannot merge partitions
765+
DETAIL: relation "pg_class" is not a partition
766+
LOCATION: merge_range_partitions, pl_range_funcs.c:636
767+
CREATE TABLE calamity.merge_test_a(val INT4 NOT NULL);
768+
CREATE TABLE calamity.merge_test_b(val INT4 NOT NULL);
769+
SELECT create_range_partitions('calamity.merge_test_a', 'val', 1, 10, 2);
770+
NOTICE: sequence "merge_test_a_seq" does not exist, skipping
771+
create_range_partitions
772+
-------------------------
773+
2
774+
(1 row)
775+
776+
SELECT create_range_partitions('calamity.merge_test_b', 'val', 1, 10, 2);
777+
NOTICE: sequence "merge_test_b_seq" does not exist, skipping
778+
create_range_partitions
779+
-------------------------
780+
2
781+
(1 row)
782+
783+
SELECT merge_range_partitions('{calamity.merge_test_a_1,
784+
calamity.merge_test_b_1}');/* not ok */
785+
ERROR: cannot merge partitions
786+
\errverbose
787+
ERROR: XX000: cannot merge partitions
788+
DETAIL: all relations must share the same parent
789+
LOCATION: merge_range_partitions, pl_range_funcs.c:645
790+
DROP TABLE calamity.merge_test_a,calamity.merge_test_b CASCADE;
791+
NOTICE: drop cascades to 4 other objects
752792
DROP SCHEMA calamity CASCADE;
753-
NOTICE: drop cascades to18 other objects
793+
NOTICE: drop cascades to20 other objects
754794
DROP EXTENSION pg_pathman;
755795
/*
756796
* -------------------------------------

‎sql/pathman_calamity.sql‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ SELECT build_range_condition('calamity.part_test', 'val', 10, NULL);/* OK */
126126
SELECT build_range_condition('calamity.part_test','val',NULL,10);/* OK*/
127127

128128
/* check function validate_interval_value()*/
129-
SELECT validate_interval_value(1::REGCLASS,'expr',2,'1 mon','cooked_expr');/* not ok*/
130-
SELECT validate_interval_value(NULL,'expr',2,'1 mon','cooked_expr');/* not ok*/
131-
SELECT validate_interval_value('pg_class',NULL,2,'1 mon','cooked_expr');/* not ok*/
132-
SELECT validate_interval_value('pg_class','oid',1,'HASH',NULL);/* not ok*/
133-
SELECT validate_interval_value('pg_class','expr',2,'1 mon',NULL);/* not ok*/
134-
SELECT validate_interval_value('pg_class','expr',2,NULL,'cooked_expr');/* not ok*/
135-
SELECT validate_interval_value('pg_class','EXPR',1,'HASH',NULL);/* not ok*/
129+
SELECT validate_interval_value(1::REGCLASS,'expr',2,'1 mon','cooked_expr');/* not ok*/
130+
SELECT validate_interval_value(NULL,'expr',2,'1 mon','cooked_expr');/* not ok*/
131+
SELECT validate_interval_value('pg_class',NULL,2,'1 mon','cooked_expr');/* not ok*/
132+
SELECT validate_interval_value('pg_class','oid',NULL,'1 mon','cooked_expr');/* not ok*/
133+
SELECT validate_interval_value('pg_class','oid',1,'HASH',NULL);/* not ok*/
134+
SELECT validate_interval_value('pg_class','expr',2,'1 mon',NULL);/* not ok*/
135+
SELECT validate_interval_value('pg_class','expr',2,NULL,'cooked_expr');/* not ok*/
136+
SELECT validate_interval_value('pg_class','EXPR',1,'HASH',NULL);/* not ok*/
136137

137138
/* check function validate_relname()*/
138139
SELECT validate_relname('calamity.part_test');
@@ -315,6 +316,26 @@ SELECT get_part_range('calamity.test_range_oid_1', NULL::INT4);/* OK */
315316

316317
DROPTABLEcalamity.test_range_oid CASCADE;
317318

319+
320+
/* check function merge_range_partitions()*/
321+
SELECT merge_range_partitions('{pg_class}');/* not ok*/
322+
\errverbose
323+
SELECT merge_range_partitions('{pg_class, pg_inherits}');/* not ok*/
324+
\errverbose
325+
326+
CREATETABLEcalamity.merge_test_a(val INT4NOT NULL);
327+
CREATETABLEcalamity.merge_test_b(val INT4NOT NULL);
328+
329+
SELECT create_range_partitions('calamity.merge_test_a','val',1,10,2);
330+
SELECT create_range_partitions('calamity.merge_test_b','val',1,10,2);
331+
332+
SELECT merge_range_partitions('{calamity.merge_test_a_1,
333+
calamity.merge_test_b_1}');/* not ok*/
334+
\errverbose
335+
336+
DROPTABLEcalamity.merge_test_a,calamity.merge_test_b CASCADE;
337+
338+
318339
DROPSCHEMA calamity CASCADE;
319340
DROP EXTENSION pg_pathman;
320341

‎src/partition_creation.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,14 +1707,13 @@ build_partitioning_expression(Oid parent_relid,
17071707
List**columns)/* ret val #2 */
17081708
{
17091709
/* Values extracted from PATHMAN_CONFIG */
1710-
Datumvalues[Natts_pathman_config];
1711-
boolisnull[Natts_pathman_config];
1712-
char*expr_cstr;
1713-
Node*expr;
1710+
Datumvalues[Natts_pathman_config];
1711+
boolisnull[Natts_pathman_config];
1712+
char*expr_cstr;
1713+
Node*expr;
17141714

17151715
/* Check that table is registered in PATHMAN_CONFIG */
1716-
if (!pathman_config_contains_relation(parent_relid,values,
1717-
isnull,NULL,NULL))
1716+
if (!pathman_config_contains_relation(parent_relid,values,isnull,NULL,NULL))
17181717
elog(ERROR,"table \"%s\" is not partitioned",
17191718
get_rel_name_or_relid(parent_relid));
17201719

@@ -1732,13 +1731,14 @@ build_partitioning_expression(Oid parent_relid,
17321731
expr_p_cstr=
17331732
TextDatumGetCString(values[Anum_pathman_config_expression_p-1]);
17341733

1734+
/* Finally return expression type */
17351735
*expr_type=exprType(stringToNode(expr_p_cstr));
17361736
}
17371737

17381738
if (columns)
17391739
{
17401740
/* Column list should be empty */
1741-
Assert(*columns==NIL);
1741+
AssertArg(*columns==NIL);
17421742
extract_column_names(expr,columns);
17431743
}
17441744

‎src/pl_range_funcs.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,9 @@ drop_range_partition_expand_next(PG_FUNCTION_ARGS)
803803
}
804804

805805
/*
806-
* Takes text representation of interval value and checks if it is corresponds
807-
*to partitioning key. The function throws an errorif itfails toconvert
808-
* text to Datum
806+
* Takes text representation of interval value and checks
807+
* if itcorresponds topartitioning expression.
808+
*NOTE: throws an ERROR if it fails to converttext to Datum.
809809
*/
810810
Datum
811811
validate_interval_value(PG_FUNCTION_ARGS)
@@ -839,6 +839,13 @@ validate_interval_value(PG_FUNCTION_ARGS)
839839
}
840840
elseexpr_cstr=TextDatumGetCString(PG_GETARG_TEXT_P(ARG_EXPRESSION));
841841

842+
if (PG_ARGISNULL(ARG_PARTTYPE))
843+
{
844+
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
845+
errmsg("'parttype' should not be NULL")));
846+
}
847+
elseparttype=DatumGetPartType(PG_GETARG_DATUM(ARG_PARTTYPE));
848+
842849
/*
843850
* Fetch partitioning expression's type using
844851
* either user's expression or parsed expression.
@@ -867,13 +874,6 @@ validate_interval_value(PG_FUNCTION_ARGS)
867874
pfree(expr_cstr);
868875
}
869876

870-
if (PG_ARGISNULL(ARG_PARTTYPE))
871-
{
872-
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
873-
errmsg("'parttype' should not be NULL")));
874-
}
875-
elseparttype=DatumGetPartType(PG_GETARG_DATUM(ARG_PARTTYPE));
876-
877877
/*
878878
* NULL interval is fine for both HASH and RANGE.
879879
* But for RANGE we need to make some additional checks.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp