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

Commit9718c93

Browse files
author
Amit Kapila
committed
MAXALIGN the target address where we store flattened value.
The API (EOH_flatten_into) that flattens the expanded value representationexpects the target address to be maxaligned. All it's usage adhere to thatprinciple except when serializing datums for parallel query. Fix thatusage.Diagnosed-by: Tom LaneAuthor: Tom Lane and Amit KapilaBackpatch-through: 9.6Discussion:https://postgr.es/m/11629.1536550032@sss.pgh.pa.us
1 parent6483381 commit9718c93

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

‎src/backend/utils/adt/datum.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,19 @@ datumSerialize(Datum value, bool isnull, bool typByVal, int typLen,
338338
}
339339
elseif (eoh)
340340
{
341-
EOH_flatten_into(eoh, (void*)*start_address,header);
341+
char*tmp;
342+
343+
/*
344+
* EOH_flatten_into expects the target address to be maxaligned,
345+
* so we can't store directly to *start_address.
346+
*/
347+
tmp= (char*)palloc(header);
348+
EOH_flatten_into(eoh, (void*)tmp,header);
349+
memcpy(*start_address,tmp,header);
342350
*start_address+=header;
351+
352+
/* be tidy. */
353+
pfree(tmp);
343354
}
344355
else
345356
{

‎src/test/regress/expected/select_parallel.out

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,33 @@ EXPLAIN (analyze, timing off, summary off, costs off) SELECT * FROM tenk1;
628628
-> Parallel Seq Scan on tenk1 (actual rows=2000 loops=5)
629629
(4 rows)
630630

631+
-- test passing expanded-value representations to workers
632+
CREATE FUNCTION make_some_array(int,int) returns int[] as
633+
$$declare x int[];
634+
begin
635+
x[1] := $1;
636+
x[2] := $2;
637+
return x;
638+
end$$ language plpgsql parallel safe;
639+
CREATE TABLE fooarr(f1 text, f2 int[], f3 text);
640+
INSERT INTO fooarr VALUES('1', ARRAY[1,2], 'one');
641+
PREPARE pstmt(text, int[]) AS SELECT * FROM fooarr WHERE f1 = $1 AND f2 = $2;
642+
EXPLAIN (COSTS OFF) EXECUTE pstmt('1', make_some_array(1,2));
643+
QUERY PLAN
644+
------------------------------------------------------------------
645+
Gather
646+
Workers Planned: 3
647+
-> Parallel Seq Scan on fooarr
648+
Filter: ((f1 = '1'::text) AND (f2 = '{1,2}'::integer[]))
649+
(4 rows)
650+
651+
EXECUTE pstmt('1', make_some_array(1,2));
652+
f1 | f2 | f3
653+
----+-------+-----
654+
1 | {1,2} | one
655+
(1 row)
656+
657+
DEALLOCATE pstmt;
631658
-- provoke error in worker
632659
select stringu1::int2 from tenk1 where unique1 = 1;
633660
ERROR: invalid input syntax for integer: "BAAAAA"

‎src/test/regress/sql/select_parallel.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,22 @@ explain (costs off)
218218
-- to increase the parallel query test coverage
219219
EXPLAIN (analyze, timing off, summary off, costs off)SELECT*FROM tenk1;
220220

221+
-- test passing expanded-value representations to workers
222+
CREATEFUNCTIONmake_some_array(int,int) returnsint[]as
223+
$$declare xint[];
224+
begin
225+
x[1] := $1;
226+
x[2] := $2;
227+
return x;
228+
end$$ language plpgsql parallel safe;
229+
CREATETABLEfooarr(f1text, f2int[], f3text);
230+
INSERT INTO fooarrVALUES('1', ARRAY[1,2],'one');
231+
232+
PREPARE pstmt(text,int[])ASSELECT*FROM fooarrWHERE f1= $1AND f2= $2;
233+
EXPLAIN (COSTS OFF) EXECUTE pstmt('1', make_some_array(1,2));
234+
EXECUTE pstmt('1', make_some_array(1,2));
235+
DEALLOCATE pstmt;
236+
221237
-- provoke error in worker
222238
select stringu1::int2from tenk1where unique1=1;
223239

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp