summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/datum.c13
-rw-r--r--src/test/regress/expected/select_parallel.out27
-rw-r--r--src/test/regress/sql/select_parallel.sql16
3 files changed, 55 insertions, 1 deletions
diff --git a/src/backend/utils/adt/datum.c b/src/backend/utils/adt/datum.c
index d02e3c81106..76e99ccf4ee 100644
--- a/src/backend/utils/adt/datum.c
+++ b/src/backend/utils/adt/datum.c
@@ -334,8 +334,19 @@ datumSerialize(Datum value, bool isnull, bool typByVal, int typLen,
}
else if (eoh)
{
- EOH_flatten_into(eoh, (void *) *start_address, header);
+ char *tmp;
+
+ /*
+ * EOH_flatten_into expects the target address to be maxaligned,
+ * so we can't store directly to *start_address.
+ */
+ tmp = (char *) palloc(header);
+ EOH_flatten_into(eoh, (void *) tmp, header);
+ memcpy(*start_address, tmp, header);
*start_address += header;
+
+ /* be tidy. */
+ pfree(tmp);
}
else
{
diff --git a/src/test/regress/expected/select_parallel.out b/src/test/regress/expected/select_parallel.out
index 07fd37e720e..5655997e056 100644
--- a/src/test/regress/expected/select_parallel.out
+++ b/src/test/regress/expected/select_parallel.out
@@ -235,6 +235,33 @@ explain (costs off)
Index Cond: (unique1 = 1)
(5 rows)
+-- test passing expanded-value representations to workers
+CREATE FUNCTION make_some_array(int,int) returns int[] as
+$$declare x int[];
+ begin
+ x[1] := $1;
+ x[2] := $2;
+ return x;
+ end$$ language plpgsql parallel safe;
+CREATE TABLE fooarr(f1 text, f2 int[], f3 text);
+INSERT INTO fooarr VALUES('1', ARRAY[1,2], 'one');
+PREPARE pstmt(text, int[]) AS SELECT * FROM fooarr WHERE f1 = $1 AND f2 = $2;
+EXPLAIN (COSTS OFF) EXECUTE pstmt('1', make_some_array(1,2));
+ QUERY PLAN
+------------------------------------------------------------------
+ Gather
+ Workers Planned: 3
+ -> Parallel Seq Scan on fooarr
+ Filter: ((f1 = '1'::text) AND (f2 = '{1,2}'::integer[]))
+(4 rows)
+
+EXECUTE pstmt('1', make_some_array(1,2));
+ f1 | f2 | f3
+----+-------+-----
+ 1 | {1,2} | one
+(1 row)
+
+DEALLOCATE pstmt;
do $$begin
-- Provoke error, possibly in worker. If this error happens to occur in
-- the worker, there will be a CONTEXT line which must be hidden.
diff --git a/src/test/regress/sql/select_parallel.sql b/src/test/regress/sql/select_parallel.sql
index a7e2a61cffd..627a7b2dd2c 100644
--- a/src/test/regress/sql/select_parallel.sql
+++ b/src/test/regress/sql/select_parallel.sql
@@ -96,6 +96,22 @@ explain (costs off)
explain (costs off)
select stringu1::int2 from tenk1 where unique1 = 1;
+-- test passing expanded-value representations to workers
+CREATE FUNCTION make_some_array(int,int) returns int[] as
+$$declare x int[];
+ begin
+ x[1] := $1;
+ x[2] := $2;
+ return x;
+ end$$ language plpgsql parallel safe;
+CREATE TABLE fooarr(f1 text, f2 int[], f3 text);
+INSERT INTO fooarr VALUES('1', ARRAY[1,2], 'one');
+
+PREPARE pstmt(text, int[]) AS SELECT * FROM fooarr WHERE f1 = $1 AND f2 = $2;
+EXPLAIN (COSTS OFF) EXECUTE pstmt('1', make_some_array(1,2));
+EXECUTE pstmt('1', make_some_array(1,2));
+DEALLOCATE pstmt;
+
do $$begin
-- Provoke error, possibly in worker. If this error happens to occur in
-- the worker, there will be a CONTEXT line which must be hidden.