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

Commit3a6d8a6

Browse files
committed
improve functions get_part_range_by_idx() and get_part_range_by_oid(), tests
1 parenta5c8cb7 commit3a6d8a6

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

‎expected/pathman_calamity.out‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,56 @@ SELECT count(*) FROM pathman_config_params WHERE partrel = 'calamity.to_be_disab
617617
0
618618
(1 row)
619619

620+
/* check function get_part_range_by_idx() */
621+
CREATE TABLE calamity.test_range_idx(val INT4 NOT NULL);
622+
SELECT create_range_partitions('calamity.test_range_idx', 'val', 1, 10, 1);
623+
NOTICE: sequence "test_range_idx_seq" does not exist, skipping
624+
create_range_partitions
625+
-------------------------
626+
1
627+
(1 row)
628+
629+
SELECT get_part_range(NULL, 1, NULL::INT4);/* not ok */
630+
ERROR: 'parent_relid' should not be NULL
631+
SELECT get_part_range('calamity.test_range_idx', NULL, NULL::INT4);/* not ok */
632+
ERROR: 'partition_idx' should not be NULL
633+
SELECT get_part_range('calamity.test_range_idx', 0, NULL::INT2);/* not ok */
634+
ERROR: pg_typeof(dummy) should be integer
635+
SELECT get_part_range('calamity.test_range_idx', -2, NULL::INT4);/* not ok */
636+
ERROR: negative indices other than -1 (last partition) are not allowed
637+
SELECT get_part_range('calamity.test_range_idx', 4, NULL::INT4);/* not ok */
638+
ERROR: partition #4 does not exist (total amount is 1)
639+
SELECT get_part_range('calamity.test_range_idx', 0, NULL::INT4);/* OK */
640+
get_part_range
641+
----------------
642+
{1,11}
643+
(1 row)
644+
645+
DROP TABLE calamity.test_range_idx CASCADE;
646+
NOTICE: drop cascades to table calamity.test_range_idx_1
647+
/* check function get_part_range_by_oid() */
648+
CREATE TABLE calamity.test_range_oid(val INT4 NOT NULL);
649+
SELECT create_range_partitions('calamity.test_range_oid', 'val', 1, 10, 1);
650+
NOTICE: sequence "test_range_oid_seq" does not exist, skipping
651+
create_range_partitions
652+
-------------------------
653+
1
654+
(1 row)
655+
656+
SELECT get_part_range(NULL, NULL::INT4);/* not ok */
657+
ERROR: 'partition_relid' should not be NULL
658+
SELECT get_part_range('pg_class', NULL::INT4);/* not ok */
659+
ERROR: relation "pg_class" is not a partition
660+
SELECT get_part_range('calamity.test_range_oid_1', NULL::INT2);/* not ok */
661+
ERROR: pg_typeof(dummy) should be integer
662+
SELECT get_part_range('calamity.test_range_oid_1', NULL::INT4);/* OK */
663+
get_part_range
664+
----------------
665+
{1,11}
666+
(1 row)
667+
668+
DROP TABLE calamity.test_range_oid CASCADE;
669+
NOTICE: drop cascades to table calamity.test_range_oid_1
620670
DROP SCHEMA calamity CASCADE;
621-
NOTICE: drop cascades to16 other objects
671+
NOTICE: drop cascades to18 other objects
622672
DROP EXTENSION pg_pathman;

‎sql/pathman_calamity.sql‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,32 @@ SELECT count(*) FROM pathman_config WHERE partrel = 'calamity.to_be_disabled'::R
235235
SELECTcount(*)FROM pathman_config_paramsWHERE partrel='calamity.to_be_disabled'::REGCLASS;
236236

237237

238+
/* check function get_part_range_by_idx()*/
239+
CREATETABLEcalamity.test_range_idx(val INT4NOT NULL);
240+
SELECT create_range_partitions('calamity.test_range_idx','val',1,10,1);
241+
242+
SELECT get_part_range(NULL,1,NULL::INT4);/* not ok*/
243+
SELECT get_part_range('calamity.test_range_idx',NULL,NULL::INT4);/* not ok*/
244+
SELECT get_part_range('calamity.test_range_idx',0,NULL::INT2);/* not ok*/
245+
SELECT get_part_range('calamity.test_range_idx',-2,NULL::INT4);/* not ok*/
246+
SELECT get_part_range('calamity.test_range_idx',4,NULL::INT4);/* not ok*/
247+
SELECT get_part_range('calamity.test_range_idx',0,NULL::INT4);/* OK*/
248+
249+
DROPTABLEcalamity.test_range_idx CASCADE;
250+
251+
252+
/* check function get_part_range_by_oid()*/
253+
CREATETABLEcalamity.test_range_oid(val INT4NOT NULL);
254+
SELECT create_range_partitions('calamity.test_range_oid','val',1,10,1);
255+
256+
SELECT get_part_range(NULL,NULL::INT4);/* not ok*/
257+
SELECT get_part_range('pg_class',NULL::INT4);/* not ok*/
258+
SELECT get_part_range('calamity.test_range_oid_1',NULL::INT2);/* not ok*/
259+
SELECT get_part_range('calamity.test_range_oid_1',NULL::INT4);/* OK*/
260+
261+
DROPTABLEcalamity.test_range_oid CASCADE;
262+
263+
264+
238265
DROPSCHEMA calamity CASCADE;
239266
DROP EXTENSION pg_pathman;

‎src/pl_range_funcs.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ get_part_range_by_oid(PG_FUNCTION_ARGS)
256256
prel=get_pathman_relation_info(parent_relid);
257257
shout_if_prel_is_invalid(parent_relid,prel,PT_RANGE);
258258

259+
/* Check type of 'dummy' (for correct output) */
260+
if (getBaseType(get_fn_expr_argtype(fcinfo->flinfo,1))!=getBaseType(prel->atttype))
261+
elog(ERROR,"pg_typeof(dummy) should be %s",
262+
format_type_be(getBaseType(prel->atttype)));
263+
264+
259265
ranges=PrelGetRangesArray(prel);
260266

261267
/* Look for the specified partition */
@@ -309,6 +315,12 @@ get_part_range_by_idx(PG_FUNCTION_ARGS)
309315
prel=get_pathman_relation_info(parent_relid);
310316
shout_if_prel_is_invalid(parent_relid,prel,PT_RANGE);
311317

318+
/* Check type of 'dummy' (for correct output) */
319+
if (getBaseType(get_fn_expr_argtype(fcinfo->flinfo,2))!=getBaseType(prel->atttype))
320+
elog(ERROR,"pg_typeof(dummy) should be %s",
321+
format_type_be(getBaseType(prel->atttype)));
322+
323+
312324
/* Now we have to deal with 'idx' */
313325
if (partition_idx<-1)
314326
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp