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

Commitd9e7edb

Browse files
committed
even more regression tests, fix in function create_range_partitions_internal()
1 parent068f0da commitd9e7edb

File tree

5 files changed

+74
-16
lines changed

5 files changed

+74
-16
lines changed

‎expected/pathman_basic.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ INSERT INTO test.hash_rel VALUES (1, 1);
1010
INSERT INTO test.hash_rel VALUES (2, 2);
1111
INSERT INTO test.hash_rel VALUES (3, 3);
1212
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3);
13-
ERROR: partitioning key "value" must be NOT NULL
13+
ERROR: partitioning key "value" must bemarkedNOT NULL
1414
ALTER TABLE test.hash_rel ALTER COLUMN value SET NOT NULL;
1515
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3, partition_data:=false);
1616
create_hash_partitions
@@ -130,7 +130,7 @@ CREATE INDEX ON test.range_rel (dt);
130130
INSERT INTO test.range_rel (dt, txt)
131131
SELECT g, md5(g::TEXT) FROM generate_series('2015-01-01', '2015-04-30', '1 day'::interval) as g;
132132
SELECT pathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 2);
133-
ERROR: partitioning key "dt" must be NOT NULL
133+
ERROR: partitioning key "dt" must bemarkedNOT NULL
134134
ALTER TABLE test.range_rel ALTER COLUMN dt SET NOT NULL;
135135
SELECT pathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 2);
136136
ERROR: not enough partitions to fit all values of "dt"

‎expected/pathman_calamity.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ SELECT count(*) FROM calamity.part_test;
102102
(1 row)
103103

104104
DELETE FROM calamity.part_test;
105+
/* test function create_range_partitions_internal() */
106+
SELECT create_range_partitions_internal(NULL, '{}'::INT[], NULL, NULL);/* not ok */
107+
ERROR: 'parent_relid' should not be NULL
108+
SELECT create_range_partitions_internal('calamity.part_test',
109+
NULL::INT[], NULL, NULL);/* not ok */
110+
ERROR: 'bounds' should not be NULL
111+
SELECT create_range_partitions_internal('calamity.part_test', '{1}'::INT[],
112+
'{part_1}'::TEXT[], NULL);/* not ok */
113+
ERROR: wrong length of 'relnames' array
114+
SELECT create_range_partitions_internal('calamity.part_test', '{1}'::INT[],
115+
NULL, '{tblspc_1}'::TEXT[]);/* not ok */
116+
ERROR: wrong length of 'tablespaces' array
117+
SELECT create_range_partitions_internal('calamity.part_test',
118+
'{1, NULL}'::INT[], NULL, NULL);/* not ok */
119+
ERROR: only first bound can be NULL
120+
SELECT create_range_partitions_internal('calamity.part_test',
121+
'{2, 1}'::INT[], NULL, NULL);/* not ok */
122+
ERROR: 'bounds' array must be ascending
105123
/* test function create_hash_partitions() */
106124
SELECT create_hash_partitions('calamity.part_test', 'val', 2,
107125
partition_names := ARRAY[]::TEXT[]); /* not ok */
@@ -415,6 +433,8 @@ SELECT generate_range_bounds(0, 100, NULL) IS NULL;
415433
t
416434
(1 row)
417435

436+
SELECT generate_range_bounds(0, 100, 0);/* not ok */
437+
ERROR: 'p_count' must be greater than zero
418438
SELECT generate_range_bounds('a'::TEXT, 'test'::TEXT, 10);/* not ok */
419439
ERROR: cannot find operator +(text, text)
420440
SELECT generate_range_bounds('a'::TEXT, '1 mon'::INTERVAL, 10);/* not ok */

‎init.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ BEGIN
469469
END IF;
470470

471471
IF @extschema@.is_attribute_nullable(relation, p_attribute) THEN
472-
RAISE EXCEPTION'partitioning key "%" must be NOT NULL', p_attribute;
472+
RAISE EXCEPTION'partitioning key "%" must bemarkedNOT NULL', p_attribute;
473473
END IF;
474474

475475
/* Check if there are foreign keys that reference the relation*/

‎sql/pathman_calamity.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ SELECT count(*) FROM calamity.part_test;
3636
DELETEFROMcalamity.part_test;
3737

3838

39+
/* test function create_range_partitions_internal()*/
40+
SELECT create_range_partitions_internal(NULL,'{}'::INT[],NULL,NULL);/* not ok*/
41+
42+
SELECT create_range_partitions_internal('calamity.part_test',
43+
NULL::INT[],NULL,NULL);/* not ok*/
44+
45+
SELECT create_range_partitions_internal('calamity.part_test','{1}'::INT[],
46+
'{part_1}'::TEXT[],NULL);/* not ok*/
47+
48+
SELECT create_range_partitions_internal('calamity.part_test','{1}'::INT[],
49+
NULL,'{tblspc_1}'::TEXT[]);/* not ok*/
50+
51+
SELECT create_range_partitions_internal('calamity.part_test',
52+
'{1, NULL}'::INT[],NULL,NULL);/* not ok*/
53+
54+
SELECT create_range_partitions_internal('calamity.part_test',
55+
'{2, 1}'::INT[],NULL,NULL);/* not ok*/
56+
3957
/* test function create_hash_partitions()*/
4058
SELECT create_hash_partitions('calamity.part_test','val',2,
4159
partition_names := ARRAY[]::TEXT[]);/* not ok*/
@@ -157,6 +175,7 @@ SELECT drop_range_partition_expand_next(NULL) IS NULL;
157175
SELECT generate_range_bounds(NULL,100,10) ISNULL;
158176
SELECT generate_range_bounds(0,NULL::INT4,10) ISNULL;
159177
SELECT generate_range_bounds(0,100,NULL) ISNULL;
178+
SELECT generate_range_bounds(0,100,0);/* not ok*/
160179
SELECT generate_range_bounds('a'::TEXT,'test'::TEXT,10);/* not ok*/
161180
SELECT generate_range_bounds('a'::TEXT,'1 mon'::INTERVAL,10);/* not ok*/
162181
SELECT generate_range_bounds(0::NUMERIC,1::NUMERIC,10);/* OK*/

‎src/pl_range_funcs.c

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ create_single_range_partition_pl(PG_FUNCTION_ARGS)
145145
Datum
146146
create_range_partitions_internal(PG_FUNCTION_ARGS)
147147
{
148-
Oidrelid=PG_GETARG_OID(0);
148+
Oidparent_relid;
149149
int16typlen;
150150
booltypbyval;
151151
chartypalign;
@@ -159,13 +159,30 @@ create_range_partitions_internal(PG_FUNCTION_ARGS)
159159
intntablespaces=0;
160160

161161
/* Bounds */
162-
ArrayType*array=PG_GETARG_ARRAYTYPE_P(1);
163-
Oidelemtype=ARR_ELEMTYPE(array);
162+
ArrayType*bounds;
163+
Oidelemtype;
164164
Datum*datums;
165165
bool*nulls;
166166
intndatums;
167167
inti;
168168

169+
/* Extract parent's Oid */
170+
if (!PG_ARGISNULL(0))
171+
{
172+
parent_relid=PG_GETARG_OID(0);
173+
}
174+
elseereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
175+
errmsg("'parent_relid' should not be NULL")));
176+
177+
/* Extract array of bounds */
178+
if (!PG_ARGISNULL(1))
179+
{
180+
bounds=PG_GETARG_ARRAYTYPE_P(1);
181+
elemtype=ARR_ELEMTYPE(bounds);
182+
}
183+
elseereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
184+
errmsg("'bounds' should not be NULL")));
185+
169186
/* Extract partition names */
170187
if (!PG_ARGISNULL(2))
171188
{
@@ -179,27 +196,29 @@ create_range_partitions_internal(PG_FUNCTION_ARGS)
179196

180197
/* Extract bounds */
181198
get_typlenbyvalalign(elemtype,&typlen,&typbyval,&typalign);
182-
deconstruct_array(array,elemtype,
199+
deconstruct_array(bounds,elemtype,
183200
typlen,typbyval,typalign,
184201
&datums,&nulls,&ndatums);
185202

186203
if (partnames&&npartnames!=ndatums-1)
187-
ereport(ERROR, (errmsg("wrong length of relnames array"),
188-
errdetail("relnames number must be less than "
189-
"bounds array length by one")));
204+
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
205+
errmsg("wrong length of 'relnames' array"),
206+
errdetail("number of 'relnames' must be less than "
207+
"'bounds' array length by one")));
190208

191209
if (tablespaces&&ntablespaces!=ndatums-1)
192-
ereport(ERROR, (errmsg("wrong length of tablespaces array"),
193-
errdetail("tablespaces number must be less than "
194-
"bounds array length by one")));
210+
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
211+
errmsg("wrong length of 'tablespaces' array"),
212+
errdetail("number of 'tablespaces' must be less than "
213+
"'bounds' array length by one")));
195214

196215
/* Check if bounds array is ascending */
197216
fill_type_cmp_fmgr_info(&cmp_func,
198217
getBaseType(elemtype),
199218
getBaseType(elemtype));
200219

201220
/* Validate bounds */
202-
for (i=0;i<ndatums-1;i++)
221+
for (i=0;i<ndatums;i++)
203222
{
204223
/* Disregard 1st bound */
205224
if (i==0)continue;
@@ -212,7 +231,7 @@ create_range_partitions_internal(PG_FUNCTION_ARGS)
212231
/* Check that bounds are ascending */
213232
if (!nulls[i-1]&& !check_le(&cmp_func,datums[i-1],datums[i]))
214233
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
215-
errmsg("bounds array must be ascending")));
234+
errmsg("'bounds' array must be ascending")));
216235
}
217236

218237
/* Create partitions using provided bounds */
@@ -230,7 +249,7 @@ create_range_partitions_internal(PG_FUNCTION_ARGS)
230249

231250
char*tablespace=tablespaces ?tablespaces[i] :NULL;
232251

233-
(void)create_single_range_partition_internal(relid,
252+
(void)create_single_range_partition_internal(parent_relid,
234253
&start,
235254
&end,
236255
elemtype,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp