diff options
| author | Alvaro Herrera | 2016-12-09 15:42:17 +0000 |
|---|---|---|
| committer | Alvaro Herrera | 2016-12-09 15:42:17 +0000 |
| commit | a73491e5fee88f5db70d69e81fa45060b6ed3682 (patch) | |
| tree | a2cca864d4556a42659095986505e1071a640806 /src/test | |
| parent | 64bc26f90d342ca343f5ba383a97691a58991204 (diff) | |
Fix crasher bug in array_position(s)
array_position and its cousin array_positions were caching the element
type equality function's FmgrInfo without being careful enough to put it
in a long-lived context. This is obviously broken but it didn't matter
in most cases; only when using arrays of records (involving record_eq)
it becomes a problem. The fix is to ensure that the type's equality
function's FmgrInfo is cached in the array_position's flinfo->fn_mcxt
rather than the current memory context.
Apart from record types, the only other case that seems complex enough
to possibly cause the same problem are range types. I didn't find a way
to reproduce the problem with those, so I only include the test case
submitted with the bug report as regression test.
Bug report and patch: Junseok Yang
Discussion: https://postgr.es/m/CAE+byMupUURYiZ6bKYgMZb9pgV1CYAijJGqWj-90W=nS7uEOeA@mail.gmail.com
Backpatch to 9.5, where array_position appeared.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/arrays.out | 14 | ||||
| -rw-r--r-- | src/test/regress/sql/arrays.sql | 9 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/test/regress/expected/arrays.out b/src/test/regress/expected/arrays.out index baccca14afd..59e4472e4fd 100644 --- a/src/test/regress/expected/arrays.out +++ b/src/test/regress/expected/arrays.out @@ -589,6 +589,20 @@ SELECT array_positions('[2:4]={1,2,3}'::int[], 1); {2} (1 row) +SELECT + array_position(ids, (1, 1)), + array_positions(ids, (1, 1)) + FROM +(VALUES + (ARRAY[(0, 0), (1, 1)]), + (ARRAY[(1, 1)]) +) AS f (ids); + array_position | array_positions +----------------+----------------- + 2 | {2} + 1 | {1} +(2 rows) + -- operators SELECT a FROM arrtest WHERE b = ARRAY[[[113,142],[1,147]]]; a diff --git a/src/test/regress/sql/arrays.sql b/src/test/regress/sql/arrays.sql index a2c3db11274..2fbc699f604 100644 --- a/src/test/regress/sql/arrays.sql +++ b/src/test/regress/sql/arrays.sql @@ -262,6 +262,15 @@ $$ LANGUAGE plpgsql; SELECT array_position('[2:4]={1,2,3}'::int[], 1); SELECT array_positions('[2:4]={1,2,3}'::int[], 1); +SELECT + array_position(ids, (1, 1)), + array_positions(ids, (1, 1)) + FROM +(VALUES + (ARRAY[(0, 0), (1, 1)]), + (ARRAY[(1, 1)]) +) AS f (ids); + -- operators SELECT a FROM arrtest WHERE b = ARRAY[[[113,142],[1,147]]]; SELECT NOT ARRAY[1.1,1.2,1.3] = ARRAY[1.1,1.2,1.3] AS "FALSE"; |
