Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e16ba23

Browse files
committed
Merge branch 'PGPROEE10_PGPRO-1658' into PGPROEE10
2 parents 7fad4f3 + 80a7a1b commit e16ba23

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

contrib/test_partition/expected/partition.out

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,16 @@ SELECT count(*) FROM conc_pt;
321321

322322
DROP TABLE conc_pt CASCADE;
323323
NOTICE: drop cascades to 10 other objects
324+
/* Create table with non-scalar key */
325+
CREATE TABLE abc (id NUMERIC NOT NULL) PARTITION BY RANGE (id) USING pg_pathman;
326+
ALTER TABLE abc ADD PARTITION abc_0 VALUES LESS THAN (0);
327+
ALTER TABLE abc ADD PARTITION abc_100 VALUES LESS THAN (100);
328+
INSERT INTO abc SELECT generate_series(-99, 99);
329+
SELECT tableoid::regclass, * FROM abc WHERE id BETWEEN -1 AND 1;
330+
tableoid | id
331+
----------+----
332+
abc_0 | -1
333+
abc_100 | 0
334+
abc_100 | 1
335+
(3 rows)
336+

contrib/test_partition/sql/partition.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,10 @@ SELECT count(*) FROM ONLY conc_pt;
190190
SELECT count(*) FROM conc_pt;
191191

192192
DROP TABLE conc_pt CASCADE;
193+
194+
/* Create table with non-scalar key */
195+
CREATE TABLE abc (id NUMERIC NOT NULL) PARTITION BY RANGE (id) USING pg_pathman;
196+
ALTER TABLE abc ADD PARTITION abc_0 VALUES LESS THAN (0);
197+
ALTER TABLE abc ADD PARTITION abc_100 VALUES LESS THAN (100);
198+
INSERT INTO abc SELECT generate_series(-99, 99);
199+
SELECT tableoid::regclass, * FROM abc WHERE id BETWEEN -1 AND 1;

src/backend/commands/partition.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ create_range_partitions(PartitionSpec *partspec,
220220
Oid key_type;
221221
int32 key_typmod;
222222
Datum start_value;
223+
bool start_value_isnull;
223224

224225
/* parameters */
225226
Datum interval_datum;
@@ -244,9 +245,13 @@ create_range_partitions(PartitionSpec *partspec,
244245
if (!IsA(n, Const))
245246
elog(ERROR, "Start value should be a constant expression");
246247
start_value = ((Const *) n)->constvalue;
248+
start_value_isnull = false;
247249
}
248250
else
251+
{
249252
start_value = (Datum) 0;
253+
start_value_isnull = true;
254+
}
250255

251256
context = deparse_context_for(get_rel_name(relid), relid);
252257
expr_str = deparse_expression(expr, context, false, false);
@@ -256,6 +261,7 @@ create_range_partitions(PartitionSpec *partspec,
256261
expr_str,
257262
key_type,
258263
start_value,
264+
start_value_isnull,
259265
interval_datum,
260266
interval_type,
261267
partspec->interval == NULL,

src/backend/commands/pathman_wrapper.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ pathman_invoke_return_value_omit_errors(const char *func,
152152
static void
153153
InitFuncArgs(FuncArgs *funcargs, uint32 size)
154154
{
155-
funcargs->types = palloc(sizeof(Oid) * size);
156-
funcargs->values = palloc(sizeof(Datum) * size);
155+
funcargs->types = palloc0(sizeof(Oid) * size);
156+
funcargs->values = palloc0(sizeof(Datum) * size);
157157
funcargs->nulls = palloc(sizeof(char) * size);
158158
funcargs->nargs = size;
159159

@@ -396,6 +396,7 @@ pm_create_range_partitions(Oid relid,
396396
const char *attname,
397397
Oid atttype,
398398
Datum start_from,
399+
bool start_value_isnull,
399400
Datum interval,
400401
Oid interval_type,
401402
bool interval_isnull,
@@ -408,7 +409,10 @@ pm_create_range_partitions(Oid relid,
408409
InitFuncArgs(&args, 6);
409410
PG_SETARG_DATUM(&args, 0, OIDOID, relid);
410411
PG_SETARG_DATUM(&args, 1, TEXTOID, PointerGetDatum(cstring_to_text(attname)));
411-
PG_SETARG_DATUM(&args, 2, atttype, start_from);
412+
if (!start_value_isnull)
413+
PG_SETARG_DATUM(&args, 2, atttype, start_from);
414+
else
415+
PG_SETARG_NULL(&args, 2, atttype);
412416

413417
if (!interval_isnull)
414418
PG_SETARG_DATUM(&args, 3, interval_type, interval);

src/include/commands/pathman_wrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void pm_create_range_partitions(Oid relid,
2929
const char *attname,
3030
Oid atttype,
3131
Datum start_from,
32+
bool start_value_isnull,
3233
Datum interval,
3334
Oid interval_type,
3435
bool interval_isnull,

0 commit comments

Comments
 (0)