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

Commit301f6d2

Browse files
committed
fix bugs in create_hash_partitions_internal() and deconstruct_text_array(), tests
1 parent4468ae8 commit301f6d2

File tree

5 files changed

+54
-33
lines changed

5 files changed

+54
-33
lines changed

‎expected/pathman_basic.out

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,9 +2178,6 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.index_on_childs WHERE c1 > 100 AND c1 < 2
21782178
/* Test create_range_partitions() + relnames */
21792179
CREATE TABLE test.provided_part_names(id INT NOT NULL);
21802180
INSERT INTO test.provided_part_names SELECT generate_series(1, 10);
2181-
SELECT create_hash_partitions('test.provided_part_names', 'id', 2,
2182-
relnames := ARRAY[]::TEXT[]);/* not ok */
2183-
ERROR: size of array 'relnames' must be equal to 'partitions_count'
21842181
SELECT create_hash_partitions('test.provided_part_names', 'id', 2,
21852182
relnames := ARRAY['p1', 'p2']::TEXT[]);/* ok */
21862183
create_hash_partitions

‎expected/pathman_calamity.out

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,20 @@ SELECT count(*) FROM calamity.part_test;
102102
DELETE FROM calamity.part_test;
103103
/* test function create_hash_partitions() */
104104
SELECT create_hash_partitions('calamity.part_test', 'val', 2,
105-
relnames := ARRAY['calamity.p1']::TEXT[]);
106-
ERROR:size of array'relnames'must be equal to 'partitions_count'
105+
relnames := ARRAY[]::TEXT[]); /* not ok */
106+
ERROR: 'relnames'and 'tablespaces' may not be empty
107107
SELECT create_hash_partitions('calamity.part_test', 'val', 2,
108-
tablespaces := ARRAY['abcd']::TEXT[]);
109-
ERROR: size of array 'tablespaces' must be equal to 'partitions_count'
108+
relnames := ARRAY[ 'p1', NULL ]::TEXT[]); /* not ok */
109+
ERROR: 'relnames' and 'tablespaces' may not contain NULLs
110+
SELECT create_hash_partitions('calamity.part_test', 'val', 2,
111+
relnames := ARRAY[ ['p1'], ['p2'] ]::TEXT[]); /* not ok */
112+
ERROR: 'relnames' and 'tablespaces' may contain only 1 dimension
113+
SELECT create_hash_partitions('calamity.part_test', 'val', 2,
114+
relnames := ARRAY['calamity.p1']::TEXT[]); /* not ok */
115+
ERROR: size of 'relnames' must be equal to 'partitions_count'
116+
SELECT create_hash_partitions('calamity.part_test', 'val', 2,
117+
tablespaces := ARRAY['abcd']::TEXT[]); /* not ok */
118+
ERROR: size of 'tablespaces' must be equal to 'partitions_count'
110119
/* test stub 'enable_parent' value for PATHMAN_CONFIG_PARAMS */
111120
INSERT INTO calamity.part_test SELECT generate_series(1, 30);
112121
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);

‎sql/pathman_basic.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,6 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.index_on_childs WHERE c1 > 100 AND c1 < 2
587587
/* Test create_range_partitions() + relnames*/
588588
CREATETABLEtest.provided_part_names(idINTNOT NULL);
589589
INSERT INTOtest.provided_part_namesSELECT generate_series(1,10);
590-
SELECT create_hash_partitions('test.provided_part_names','id',2,
591-
relnames := ARRAY[]::TEXT[]);/* not ok*/
592590
SELECT create_hash_partitions('test.provided_part_names','id',2,
593591
relnames := ARRAY['p1','p2']::TEXT[]);/* ok*/
594592
/* list partitions*/

‎sql/pathman_calamity.sql

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,19 @@ DELETE FROM calamity.part_test;
3737

3838
/* test function create_hash_partitions()*/
3939
SELECT create_hash_partitions('calamity.part_test','val',2,
40-
relnames := ARRAY['calamity.p1']::TEXT[]);
40+
relnames := ARRAY[]::TEXT[]);/* not ok*/
41+
42+
SELECT create_hash_partitions('calamity.part_test','val',2,
43+
relnames := ARRAY['p1',NULL ]::TEXT[]);/* not ok*/
44+
45+
SELECT create_hash_partitions('calamity.part_test','val',2,
46+
relnames := ARRAY[ ['p1'], ['p2'] ]::TEXT[]);/* not ok*/
47+
48+
SELECT create_hash_partitions('calamity.part_test','val',2,
49+
relnames := ARRAY['calamity.p1']::TEXT[]);/* not ok*/
50+
4151
SELECT create_hash_partitions('calamity.part_test','val',2,
42-
tablespaces := ARRAY['abcd']::TEXT[]);
52+
tablespaces := ARRAY['abcd']::TEXT[]);/* not ok*/
4353

4454

4555
/* test stub 'enable_parent' value for PATHMAN_CONFIG_PARAMS*/

‎src/pl_hash_funcs.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include"utils/array.h"
2323

2424

25-
staticchar**deconstruct_text_array(Datumarr,int*num_elems);
25+
staticchar**deconstruct_text_array(Datumarray,int*array_size);
2626

2727

2828
/* Function declarations */
@@ -80,17 +80,13 @@ create_hash_partitions_internal(PG_FUNCTION_ARGS)
8080
if (!PG_ARGISNULL(4))
8181
tablespaces=deconstruct_text_array(PG_GETARG_DATUM(4),&tablespaces_size);
8282

83-
/* If both arrays are present, check that their lengths are equal */
84-
if (relnames&&tablespaces&&relnames_size!=tablespaces_size)
85-
elog(ERROR,"sizes of arrays 'relnames' and 'tablespaces' are different");
86-
8783
/* Validate size of 'relnames' */
8884
if (relnames&&relnames_size!=partitions_count)
89-
elog(ERROR,"size ofarray'relnames' must be equal to 'partitions_count'");
85+
elog(ERROR,"size of 'relnames' must be equal to 'partitions_count'");
9086

9187
/* Validate size of 'tablespaces' */
9288
if (tablespaces&&tablespaces_size!=partitions_count)
93-
elog(ERROR,"size ofarray'tablespaces' must be equal to 'partitions_count'");
89+
elog(ERROR,"size of 'tablespaces' must be equal to 'partitions_count'");
9490

9591
/* Convert partition names into RangeVars */
9692
if (relnames)
@@ -195,43 +191,54 @@ build_hash_condition(PG_FUNCTION_ARGS)
195191

196192
/* Convert Datum into CSTRING array */
197193
staticchar**
198-
deconstruct_text_array(Datumarr,int*num_elems)
194+
deconstruct_text_array(Datumarray,int*array_size)
199195
{
200-
ArrayType*arrayval;
196+
ArrayType*array_ptr=DatumGetArrayTypeP(array);
201197
int16elemlen;
202198
boolelembyval;
203199
charelemalign;
200+
204201
Datum*elem_values;
205202
bool*elem_nulls;
206-
int16i;
207203

208-
arrayval=DatumGetArrayTypeP(arr);
204+
intarr_size=0;
209205

210-
Assert(ARR_ELEMTYPE(arrayval)==TEXTOID);
206+
/* Check type invariant */
207+
Assert(ARR_ELEMTYPE(array_ptr)==TEXTOID);
211208

212-
get_typlenbyvalalign(ARR_ELEMTYPE(arrayval),
209+
/* Check number of dimensions */
210+
if (ARR_NDIM(array_ptr)>1)
211+
elog(ERROR,"'relnames' and 'tablespaces' may contain only 1 dimension");
212+
213+
get_typlenbyvalalign(ARR_ELEMTYPE(array_ptr),
213214
&elemlen,&elembyval,&elemalign);
214-
deconstruct_array(arrayval,
215-
ARR_ELEMTYPE(arrayval),
215+
216+
deconstruct_array(array_ptr,
217+
ARR_ELEMTYPE(array_ptr),
216218
elemlen,elembyval,elemalign,
217-
&elem_values,&elem_nulls,num_elems);
219+
&elem_values,&elem_nulls,&arr_size);
218220

219-
/* If there are actual values then convert them into CSTRINGs */
220-
if (num_elems>0)
221+
/* If there are actual values, convert them into CSTRINGs */
222+
if (arr_size>0)
221223
{
222-
char**strings=palloc(sizeof(char*)**num_elems);
224+
char**strings=palloc(arr_size*sizeof(char*));
225+
inti;
223226

224-
for (i=0;i<*num_elems;i++)
227+
for (i=0;i<arr_size;i++)
225228
{
226229
if (elem_nulls[i])
227-
elog(ERROR,"partition name and tablespace arrays "
228-
"may not contain nulls");
230+
elog(ERROR,"'relnames' and 'tablespaces' may not contain NULLs");
229231

230232
strings[i]=TextDatumGetCString(elem_values[i]);
231233
}
232234

235+
/* Return an array and it's size */
236+
*array_size=arr_size;
233237
returnstrings;
234238
}
239+
/* Else emit ERROR */
240+
elseelog(ERROR,"'relnames' and 'tablespaces' may not be empty");
235241

242+
/* Keep compiler happy */
236243
returnNULL;
237244
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp