pgsql: Replace uses of SPI_modifytuple that intend to allocate in curre

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Replace uses of SPI_modifytuple that intend to allocate in curre
Date: 2016-11-08 20:36:53
Message-ID: E1c4D8X-0002wP-TD@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Replace uses of SPI_modifytuple that intend to allocate in current context.

Invent a new function heap_modify_tuple_by_cols() that is functionally
equivalent to SPI_modifytuple except that it always allocates its result
by simple palloc. I chose however to make the API details a bit more
like heap_modify_tuple: pass a tupdesc rather than a Relation, and use
bool convention for the isnull array.

Use this function in place of SPI_modifytuple at all call sites where the
intended behavior is to allocate in current context. (There actually are
only two call sites left that depend on the old behavior, which makes me
wonder if we should just drop this function rather than keep it.)

This new function is easier to use than heap_modify_tuple() for purposes
of replacing a single column (or, really, any fixed number of columns).
There are a number of places where it would simplify the code to change
over, but I resisted that temptation for the moment ... everywhere except
in plpgsql's exec_assign_value(); changing that might offer some small
performance benefit, so I did it.

This is on the way to removing SPI_push/SPI_pop, but it seems like
good code cleanup in its own right.

Discussion: <9633(dot)1478552022(at)sss(dot)pgh(dot)pa(dot)us>

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/9257f0787257022e31c61cd77449127adfccf37f

Modified Files
--------------
contrib/spi/autoinc.c | 13 ++++---
contrib/spi/insert_username.c | 12 +++----
contrib/spi/moddatetime.c | 21 ++++-------
contrib/spi/timetravel.c | 25 ++++++-------
doc/src/sgml/spi.sgml | 5 +--
src/backend/access/common/heaptuple.c | 66 +++++++++++++++++++++++++++++++++++
src/backend/utils/adt/tsvector_op.c | 16 ++++-----
src/include/access/htup_details.h | 6 ++++
src/pl/plpgsql/src/pl_exec.c | 57 ++++++++++--------------------
src/test/regress/regress.c | 11 ++----
10 files changed, 137 insertions(+), 95 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2016-11-08 21:31:50 pgsql: psql: Tab completion for renaming enum values.
Previous Message Robert Haas 2016-11-08 20:35:51 pgsql: Fix typo.