Fix crashes with currtid() and currtid2()
authorMichael Paquier <michael@paquier.xyz>
Mon, 1 Jun 2020 01:32:06 +0000 (10:32 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 1 Jun 2020 01:32:06 +0000 (10:32 +0900)
commite786be5fcb257a09b05bd8e509c8d1b82e626352
treecd43a679b38124397ad468c8845594d808419d61
parentaf4ea507c3d9217579a8d75fc17f4796a9bab0bb
Fix crashes with currtid() and currtid2()

A relation that has no storage initializes rd_tableam to NULL, which
caused those two functions to crash because of a pointer dereference.
Note that in 11 and older versions, this has always failed with a
confusing error "could not open file".

These two functions are used by the Postgres ODBC driver, which requires
them only when connecting to a backend strictly older than 8.1.  When
connected to 8.2 or a newer version, the driver uses a RETURNING clause
instead whose support has been added in 8.2, so it should be possible to
just remove both functions in the future.  This is left as an issue to
address later.

While on it, add more regression tests for those functions as we never
really had coverage for them, and for aggregates of TIDs.

Reported-by: Jaime Casanova, via sqlsmith
Author: Michael Paquier
Reviewed-by: Álvaro Herrera
Discussion: https://postgr.es/m/CAJGNTeO93u-5APMga6WH41eTZ3Uee9f3s8dCpA-GSSqNs1b=Ug@mail.gmail.com
Backpatch-through: 12
src/backend/utils/adt/tid.c
src/test/regress/expected/tid.out [new file with mode: 0644]
src/test/regress/parallel_schedule
src/test/regress/serial_schedule
src/test/regress/sql/tid.sql [new file with mode: 0644]