Skip to content

Commit 6027775

Browse files
committed
pathman: another 32bit systems issue fix
1 parent 3488a71 commit 6027775

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

contrib/pg_pathman/pl_funcs.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,11 @@ get_partition_range(PG_FUNCTION_ARGS)
204204

205205
if (found)
206206
{
207+
bool byVal = rangerel->by_val;
208+
207209
elems = palloc(nelems * sizeof(Datum));
208-
elems[0] = ranges[i].min;
209-
elems[1] = ranges[i].max;
210+
elems[0] = PATHMAN_GET_DATUM(ranges[i].min, byVal);
211+
elems[1] = PATHMAN_GET_DATUM(ranges[i].max, byVal);
210212

211213
arr = construct_array(elems, nelems, prel->atttype,
212214
tce->typlen, tce->typbyval, tce->typalign);
@@ -251,8 +253,8 @@ get_range_by_idx(PG_FUNCTION_ARGS)
251253
re = &ranges[rangerel->ranges.length - 1];
252254

253255
elems = palloc(2 * sizeof(Datum));
254-
elems[0] = re->min;
255-
elems[1] = re->max;
256+
elems[0] = PATHMAN_GET_DATUM(re->min, rangerel->by_val);
257+
elems[1] = PATHMAN_GET_DATUM(re->max, rangerel->by_val);
256258

257259
PG_RETURN_ARRAYTYPE_P(
258260
construct_array(elems, 2, prel->atttype,
@@ -277,7 +279,7 @@ get_min_range_value(PG_FUNCTION_ARGS)
277279
PG_RETURN_NULL();
278280

279281
ranges = dsm_array_get_pointer(&rangerel->ranges);
280-
PG_RETURN_DATUM(ranges[0].min);
282+
PG_RETURN_DATUM(PATHMAN_GET_DATUM(ranges[0].min, rangerel->by_val));
281283
}
282284

283285
/*
@@ -298,7 +300,7 @@ get_max_range_value(PG_FUNCTION_ARGS)
298300
PG_RETURN_NULL();
299301

300302
ranges = dsm_array_get_pointer(&rangerel->ranges);
301-
PG_RETURN_DATUM(ranges[rangerel->ranges.length-1].max);
303+
PG_RETURN_DATUM(PATHMAN_GET_DATUM(ranges[rangerel->ranges.length-1].max, rangerel->by_val));
302304
}
303305

304306
/*

contrib/pg_pathman/worker.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "storage/dsm.h"
77
#include "access/xact.h"
88
#include "utils/snapmgr.h"
9+
#include "utils/typcache.h"
910

1011
/*-------------------------------------------------------------------------
1112
*
@@ -26,11 +27,17 @@ static void bg_worker_main(Datum main_arg);
2627

2728
typedef struct PartitionArgs
2829
{
29-
Oid dbid;
30-
Oid relid;
31-
Datum value;
32-
Oid value_type;
33-
Oid result;
30+
Oid dbid;
31+
Oid relid;
32+
#ifdef HAVE_INT64_TIMESTAMP
33+
int64 value;
34+
#else
35+
double value;
36+
#endif
37+
//Datum value;
38+
Oid value_type;
39+
bool by_val;
40+
Oid result;
3441
} PartitionArgs;
3542

3643
/*
@@ -46,17 +53,25 @@ create_partitions_bg_worker(Oid relid, Datum value, Oid value_type)
4653
dsm_segment *segment;
4754
dsm_handle segment_handle;
4855
pid_t pid;
49-
PartitionArgs *args;
56+
PartitionArgs *args;
5057
Oid child_oid;
58+
TypeCacheEntry *tce;
5159

5260
/* Create a dsm segment for the worker to pass arguments */
5361
segment = dsm_create(sizeof(PartitionArgs), 0);
5462
segment_handle = dsm_segment_handle(segment);
5563

64+
tce = lookup_type_cache(value_type, 0);
65+
66+
/* Fill arguments structure */
5667
args = (PartitionArgs *) dsm_segment_address(segment);
5768
args->dbid = MyDatabaseId;
5869
args->relid = relid;
59-
args->value = value;
70+
if (tce->typbyval)
71+
args->value = value;
72+
else
73+
memcpy(&args->value, DatumGetPointer(value), sizeof(args->value));
74+
args->by_val = tce->typbyval;
6075
args->value_type = value_type;
6176
args->result = 0;
6277

@@ -121,7 +136,7 @@ bg_worker_main(Datum main_arg)
121136
PushActiveSnapshot(GetTransactionSnapshot());
122137

123138
/* Create partitions */
124-
args->result = create_partitions(args->relid, args->value, args->value_type);
139+
args->result = create_partitions(args->relid, PATHMAN_GET_DATUM(args->value, args->by_val), args->value_type);
125140

126141
/* Cleanup */
127142
SPI_finish();

0 commit comments

Comments
 (0)