Skip to content

Commit ddbae9d

Browse files
committed
even more calamity tests
1 parent 3b6db77 commit ddbae9d

File tree

6 files changed

+90
-48
lines changed

6 files changed

+90
-48
lines changed

expected/pathman_calamity.out

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,26 @@ SELECT count(*) FROM calamity.part_test;
102102
(1 row)
103103

104104
DELETE FROM calamity.part_test;
105+
/* test function create_single_range_partition() */
106+
SELECT create_single_range_partition(NULL, NULL::INT4, NULL); /* not ok */
107+
ERROR: 'parent_relid' should not be NULL
105108
/* test function create_range_partitions_internal() */
106-
SELECT create_range_partitions_internal(NULL, '{}'::INT[], NULL, NULL); /* not ok */
109+
SELECT create_range_partitions_internal(NULL, '{}'::INT[], NULL, NULL); /* not ok */
107110
ERROR: 'parent_relid' should not be NULL
108111
SELECT create_range_partitions_internal('calamity.part_test',
109-
NULL::INT[], NULL, NULL); /* not ok */
112+
NULL::INT[], NULL, NULL); /* not ok */
110113
ERROR: 'bounds' should not be NULL
111114
SELECT create_range_partitions_internal('calamity.part_test', '{1}'::INT[],
112-
'{part_1}'::TEXT[], NULL); /* not ok */
115+
'{part_1}'::TEXT[], NULL); /* not ok */
113116
ERROR: wrong length of 'partition_names' array
114117
SELECT create_range_partitions_internal('calamity.part_test', '{1}'::INT[],
115-
NULL, '{tblspc_1}'::TEXT[]); /* not ok */
118+
NULL, '{tblspc_1}'::TEXT[]); /* not ok */
116119
ERROR: wrong length of 'tablespaces' array
117120
SELECT create_range_partitions_internal('calamity.part_test',
118-
'{1, NULL}'::INT[], NULL, NULL); /* not ok */
121+
'{1, NULL}'::INT[], NULL, NULL); /* not ok */
119122
ERROR: only first bound can be NULL
120123
SELECT create_range_partitions_internal('calamity.part_test',
121-
'{2, 1}'::INT[], NULL, NULL); /* not ok */
124+
'{2, 1}'::INT[], NULL, NULL); /* not ok */
122125
ERROR: 'bounds' array must be ascending
123126
/* test function create_hash_partitions() */
124127
SELECT create_hash_partitions('calamity.part_test', 'val', 2,
@@ -348,12 +351,16 @@ SELECT get_partition_key_type(NULL) IS NULL;
348351
(1 row)
349352

350353
/* check function build_check_constraint_name_attnum() */
351-
SELECT build_check_constraint_name('calamity.part_test', 1::int2);
354+
SELECT build_check_constraint_name('calamity.part_test', 1::int2); /* OK */
352355
build_check_constraint_name
353356
-----------------------------
354357
pathman_part_test_1_check
355358
(1 row)
356359

360+
SELECT build_check_constraint_name(0::REGCLASS, 1::int2); /* not ok */
361+
ERROR: relation "0" does not exist
362+
SELECT build_check_constraint_name('calamity.part_test', -1::int2); /* not ok */
363+
ERROR: invalid attribute number -1
357364
SELECT build_check_constraint_name('calamity.part_test', NULL::int2) IS NULL;
358365
?column?
359366
----------
@@ -373,12 +380,16 @@ SELECT build_check_constraint_name(NULL, NULL::int2) IS NULL;
373380
(1 row)
374381

375382
/* check function build_check_constraint_name_attname() */
376-
SELECT build_check_constraint_name('calamity.part_test', 'val');
383+
SELECT build_check_constraint_name('calamity.part_test', 'val'); /* OK */
377384
build_check_constraint_name
378385
-----------------------------
379386
pathman_part_test_1_check
380387
(1 row)
381388

389+
SELECT build_check_constraint_name(0::REGCLASS, 'val'); /* not ok */
390+
ERROR: relation "0" does not exist
391+
SELECT build_check_constraint_name('calamity.part_test', 'nocol'); /* not ok */
392+
ERROR: relation "part_test" has no column "nocol"
382393
SELECT build_check_constraint_name('calamity.part_test', NULL::text) IS NULL;
383394
?column?
384395
----------
@@ -398,51 +409,64 @@ SELECT build_check_constraint_name(NULL, NULL::text) IS NULL;
398409
(1 row)
399410

400411
/* check function build_update_trigger_name() */
401-
SELECT build_update_trigger_name('calamity.part_test');
412+
SELECT build_update_trigger_name('calamity.part_test'); /* OK */
402413
build_update_trigger_name
403414
---------------------------
404415
part_test_upd_trig
405416
(1 row)
406417

418+
SELECT build_update_trigger_name(0::REGCLASS); /* not ok */
419+
ERROR: relation "0" does not exist
407420
SELECT build_update_trigger_name(NULL) IS NULL;
408421
?column?
409422
----------
410423
t
411424
(1 row)
412425

413426
/* check function build_update_trigger_func_name() */
414-
SELECT build_update_trigger_func_name('calamity.part_test');
427+
SELECT build_update_trigger_func_name('calamity.part_test'); /* OK */
415428
build_update_trigger_func_name
416429
----------------------------------
417430
calamity.part_test_upd_trig_func
418431
(1 row)
419432

433+
SELECT build_update_trigger_func_name(0::REGCLASS); /* not ok */
434+
ERROR: relation "0" does not exist
420435
SELECT build_update_trigger_func_name(NULL) IS NULL;
421436
?column?
422437
----------
423438
t
424439
(1 row)
425440

426441
/* check function build_sequence_name() */
427-
SELECT build_sequence_name('calamity.part_test'); /* ok */
442+
SELECT build_sequence_name('calamity.part_test'); /* OK */
428443
build_sequence_name
429444
------------------------
430445
calamity.part_test_seq
431446
(1 row)
432447

433-
SELECT build_sequence_name(1::REGCLASS); /* not ok */
448+
SELECT build_sequence_name(1::REGCLASS); /* not ok */
434449
ERROR: relation "1" does not exist
435450
SELECT build_sequence_name(NULL) IS NULL;
436451
?column?
437452
----------
438453
t
439454
(1 row)
440455

456+
/* check function partition_table_concurrently() */
457+
SELECT partition_table_concurrently(1::REGCLASS); /* not ok */
458+
ERROR: relation "1" has no partitions
459+
SELECT partition_table_concurrently('pg_class', 0); /* not ok */
460+
ERROR: 'batch_size' should not be less than 1 or greater than 10000
461+
SELECT partition_table_concurrently('pg_class', 1, 1E-5); /* not ok */
462+
ERROR: 'sleep_time' should not be less than 0.5
463+
SELECT partition_table_concurrently('pg_class'); /* not ok */
464+
ERROR: relation "pg_class" has no partitions
441465
/* check function stop_concurrent_part_task() */
442-
SELECT stop_concurrent_part_task(1::regclass);
466+
SELECT stop_concurrent_part_task(1::REGCLASS); /* not ok */
443467
ERROR: cannot find worker for relation "1"
444468
/* check function drop_range_partition_expand_next() */
445-
SELECT drop_range_partition_expand_next('pg_class');
469+
SELECT drop_range_partition_expand_next('pg_class'); /* not ok */
446470
ERROR: relation "pg_class" is not a partition
447471
SELECT drop_range_partition_expand_next(NULL) IS NULL;
448472
?column?
@@ -572,6 +596,8 @@ DROP FUNCTION calamity.dummy_cb(arg jsonb);
572596
/* check function add_to_pathman_config() -- PHASE #1 */
573597
SELECT add_to_pathman_config(NULL, 'val'); /* no table */
574598
ERROR: 'parent_relid' should not be NULL
599+
SELECT add_to_pathman_config(0::REGCLASS, 'val'); /* no table (oid) */
600+
ERROR: relation "0" does not exist
575601
SELECT add_to_pathman_config('calamity.part_test', NULL); /* no column */
576602
ERROR: 'attname' should not be NULL
577603
SELECT add_to_pathman_config('calamity.part_test', 'V_A_L'); /* wrong column */

sql/pathman_calamity.sql

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,26 @@ SELECT count(*) FROM calamity.part_test;
3636
DELETE FROM calamity.part_test;
3737

3838

39-
40-
39+
/* test function create_single_range_partition() */
40+
SELECT create_single_range_partition(NULL, NULL::INT4, NULL); /* not ok */
4141

4242
/* test function create_range_partitions_internal() */
43-
SELECT create_range_partitions_internal(NULL, '{}'::INT[], NULL, NULL); /* not ok */
43+
SELECT create_range_partitions_internal(NULL, '{}'::INT[], NULL, NULL); /* not ok */
4444

4545
SELECT create_range_partitions_internal('calamity.part_test',
46-
NULL::INT[], NULL, NULL); /* not ok */
46+
NULL::INT[], NULL, NULL); /* not ok */
4747

4848
SELECT create_range_partitions_internal('calamity.part_test', '{1}'::INT[],
49-
'{part_1}'::TEXT[], NULL); /* not ok */
49+
'{part_1}'::TEXT[], NULL); /* not ok */
5050

5151
SELECT create_range_partitions_internal('calamity.part_test', '{1}'::INT[],
52-
NULL, '{tblspc_1}'::TEXT[]); /* not ok */
52+
NULL, '{tblspc_1}'::TEXT[]); /* not ok */
5353

5454
SELECT create_range_partitions_internal('calamity.part_test',
55-
'{1, NULL}'::INT[], NULL, NULL); /* not ok */
55+
'{1, NULL}'::INT[], NULL, NULL); /* not ok */
5656

5757
SELECT create_range_partitions_internal('calamity.part_test',
58-
'{2, 1}'::INT[], NULL, NULL); /* not ok */
58+
'{2, 1}'::INT[], NULL, NULL); /* not ok */
5959

6060
/* test function create_hash_partitions() */
6161
SELECT create_hash_partitions('calamity.part_test', 'val', 2,
@@ -158,35 +158,47 @@ SELECT get_partition_key_type(0::regclass);
158158
SELECT get_partition_key_type(NULL) IS NULL;
159159

160160
/* check function build_check_constraint_name_attnum() */
161-
SELECT build_check_constraint_name('calamity.part_test', 1::int2);
161+
SELECT build_check_constraint_name('calamity.part_test', 1::int2); /* OK */
162+
SELECT build_check_constraint_name(0::REGCLASS, 1::int2); /* not ok */
163+
SELECT build_check_constraint_name('calamity.part_test', -1::int2); /* not ok */
162164
SELECT build_check_constraint_name('calamity.part_test', NULL::int2) IS NULL;
163165
SELECT build_check_constraint_name(NULL, 1::int2) IS NULL;
164166
SELECT build_check_constraint_name(NULL, NULL::int2) IS NULL;
165167

166168
/* check function build_check_constraint_name_attname() */
167-
SELECT build_check_constraint_name('calamity.part_test', 'val');
169+
SELECT build_check_constraint_name('calamity.part_test', 'val'); /* OK */
170+
SELECT build_check_constraint_name(0::REGCLASS, 'val'); /* not ok */
171+
SELECT build_check_constraint_name('calamity.part_test', 'nocol'); /* not ok */
168172
SELECT build_check_constraint_name('calamity.part_test', NULL::text) IS NULL;
169173
SELECT build_check_constraint_name(NULL, 'val') IS NULL;
170174
SELECT build_check_constraint_name(NULL, NULL::text) IS NULL;
171175

172176
/* check function build_update_trigger_name() */
173-
SELECT build_update_trigger_name('calamity.part_test');
177+
SELECT build_update_trigger_name('calamity.part_test'); /* OK */
178+
SELECT build_update_trigger_name(0::REGCLASS); /* not ok */
174179
SELECT build_update_trigger_name(NULL) IS NULL;
175180

176181
/* check function build_update_trigger_func_name() */
177-
SELECT build_update_trigger_func_name('calamity.part_test');
182+
SELECT build_update_trigger_func_name('calamity.part_test'); /* OK */
183+
SELECT build_update_trigger_func_name(0::REGCLASS); /* not ok */
178184
SELECT build_update_trigger_func_name(NULL) IS NULL;
179185

180186
/* check function build_sequence_name() */
181-
SELECT build_sequence_name('calamity.part_test'); /* ok */
182-
SELECT build_sequence_name(1::REGCLASS); /* not ok */
187+
SELECT build_sequence_name('calamity.part_test'); /* OK */
188+
SELECT build_sequence_name(1::REGCLASS); /* not ok */
183189
SELECT build_sequence_name(NULL) IS NULL;
184190

191+
/* check function partition_table_concurrently() */
192+
SELECT partition_table_concurrently(1::REGCLASS); /* not ok */
193+
SELECT partition_table_concurrently('pg_class', 0); /* not ok */
194+
SELECT partition_table_concurrently('pg_class', 1, 1E-5); /* not ok */
195+
SELECT partition_table_concurrently('pg_class'); /* not ok */
196+
185197
/* check function stop_concurrent_part_task() */
186-
SELECT stop_concurrent_part_task(1::regclass);
198+
SELECT stop_concurrent_part_task(1::REGCLASS); /* not ok */
187199

188200
/* check function drop_range_partition_expand_next() */
189-
SELECT drop_range_partition_expand_next('pg_class');
201+
SELECT drop_range_partition_expand_next('pg_class'); /* not ok */
190202
SELECT drop_range_partition_expand_next(NULL) IS NULL;
191203

192204
/* check function generate_range_bounds() */
@@ -235,6 +247,7 @@ DROP FUNCTION calamity.dummy_cb(arg jsonb);
235247

236248
/* check function add_to_pathman_config() -- PHASE #1 */
237249
SELECT add_to_pathman_config(NULL, 'val'); /* no table */
250+
SELECT add_to_pathman_config(0::REGCLASS, 'val'); /* no table (oid) */
238251
SELECT add_to_pathman_config('calamity.part_test', NULL); /* no column */
239252
SELECT add_to_pathman_config('calamity.part_test', 'V_A_L'); /* wrong column */
240253
SELECT add_to_pathman_config('calamity.part_test', 'val'); /* OK */

src/partition_creation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ create_partitions_for_value(Oid relid, Datum value, Oid value_type)
298298
}
299299
}
300300
else
301-
elog(ERROR, "relation \"%s\" is not partitioned by pg_pathman",
301+
elog(ERROR, "relation \"%s\" is not partitioned",
302302
get_rel_name_or_relid(relid));
303303

304304
/* Check that 'last_partition' is valid */

src/pathman_workers.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,14 @@ partition_table_concurrently(PG_FUNCTION_ARGS)
635635

636636
/* Check batch_size */
637637
if (batch_size < 1 || batch_size > 10000)
638-
elog(ERROR, "\"batch_size\" should not be less than 1 "
639-
"or greater than 10000");
638+
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
639+
errmsg("'batch_size' should not be less than 1"
640+
" or greater than 10000")));
640641

641642
/* Check sleep_time */
642643
if (sleep_time < 0.5)
643-
elog(ERROR, "\"sleep_time\" should not be less than 0.5");
644+
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
645+
errmsg("'sleep_time' should not be less than 0.5")));
644646

645647
/* Check if relation is a partitioned table */
646648
shout_if_prel_is_invalid(relid,
@@ -656,7 +658,9 @@ partition_table_concurrently(PG_FUNCTION_ARGS)
656658
ereport(ERROR, (errmsg("cannot start %s", concurrent_part_bgw),
657659
errdetail("table is being partitioned now")));
658660
}
659-
else elog(ERROR, "cannot find relation %d", relid);
661+
else ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
662+
errmsg("relation \"%s\" is not partitioned",
663+
get_rel_name_or_relid(relid))));
660664

661665
/*
662666
* Look for an empty slot and also check that a concurrent

src/pl_funcs.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ get_base_type_pl(PG_FUNCTION_ARGS)
238238
}
239239

240240
/*
241-
* Return partition key type
241+
* Return partition key type.
242242
*/
243243
Datum
244244
get_partition_key_type(PG_FUNCTION_ARGS)
@@ -253,7 +253,7 @@ get_partition_key_type(PG_FUNCTION_ARGS)
253253
}
254254

255255
/*
256-
* Return tablespace name for specified relation
256+
* Return tablespace name of a specified relation.
257257
*/
258258
Datum
259259
get_tablespace_pl(PG_FUNCTION_ARGS)
@@ -755,8 +755,7 @@ build_check_constraint_name_attnum(PG_FUNCTION_ARGS)
755755
/* We explicitly do not support system attributes */
756756
if (attnum == InvalidAttrNumber || attnum < 0)
757757
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_COLUMN),
758-
errmsg("cannot build check constraint name"),
759-
errdetail("invalid attribute number %i", attnum)));
758+
errmsg("invalid attribute number %i", attnum)));
760759

761760
result = build_check_constraint_name_relid_internal(relid, attnum);
762761

@@ -779,10 +778,9 @@ build_check_constraint_name_attname(PG_FUNCTION_ARGS)
779778

780779
if (attnum == InvalidAttrNumber)
781780
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_COLUMN),
782-
errmsg("cannot build check constraint name"),
783-
errdetail("relation \"%s\" has no column \"%s\"",
784-
get_rel_name_or_relid(relid),
785-
text_to_cstring(attname))));
781+
errmsg("relation \"%s\" has no column \"%s\"",
782+
get_rel_name_or_relid(relid),
783+
text_to_cstring(attname))));
786784

787785
result = build_check_constraint_name_relid_internal(relid, attnum);
788786

src/pl_range_funcs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ create_single_range_partition_pl(PG_FUNCTION_ARGS)
105105

106106

107107
/* Handle 'parent_relid' */
108-
if (PG_ARGISNULL(0))
109-
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
110-
errmsg("'parent_relid' should not be NULL")));
108+
if (!PG_ARGISNULL(0))
109+
{
110+
parent_relid = PG_GETARG_OID(0);
111+
}
112+
else ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
113+
errmsg("'parent_relid' should not be NULL")));
111114

112-
/* Fetch mandatory args */
113-
parent_relid = PG_GETARG_OID(0);
114115
value_type = get_fn_expr_argtype(fcinfo->flinfo, 1);
115116

116117
start = PG_ARGISNULL(1) ?

0 commit comments

Comments
 (0)