pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Re-implement pl/pgsql's expression and assignment parsing.
Date: Mon, 04 Jan 2021 17:39:40 +0000
Message-ID: <E1kwTpU-0000yS-Px@gemulon.postgresql.org> (raw)

Re-implement pl/pgsql's expression and assignment parsing.

Invent new RawParseModes that allow the core grammar to handle
pl/pgsql expressions and assignments directly, and thereby get rid
of a lot of hackery in pl/pgsql's parser.  This moves a good deal
of knowledge about pl/pgsql into the core code: notably, we have to
invent a CoercionContext that matches pl/pgsql's (rather dubious)
historical behavior for assignment coercions.  That's getting away
from the original idea of pl/pgsql as an arm's-length extension of
the core, but really we crossed that bridge a long time ago.

The main advantage of doing this is that we can now use the core
parser to generate FieldStore and/or SubscriptingRef nodes to handle
assignments to pl/pgsql variables that are records or arrays.  That
fixes a number of cases that had never been implemented in pl/pgsql
assignment, such as nested records and array slicing, and it allows
pl/pgsql assignment to support the datatype-specific subscripting
behaviors introduced in commit c7aba7c14.

There are cosmetic benefits too: when a syntax error occurs in a
pl/pgsql expression, the error report no longer includes the confusing
"SELECT" keyword that used to get prefixed to the expression text.
Also, there seem to be some small speed gains.

Discussion: https://postgr.es/m/4165684.1607707277@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/c9d5298485b78a37923a23f9af9aa0ade06762db

Modified Files
--------------
contrib/hstore/expected/hstore.out               |   4 +
contrib/hstore/sql/hstore.sql                    |   4 +
doc/src/sgml/plpgsql.sgml                        |  21 +-
src/backend/commands/functioncmds.c              |   1 +
src/backend/executor/spi.c                       |  54 ++++-
src/backend/nodes/copyfuncs.c                    |  17 ++
src/backend/nodes/equalfuncs.c                   |  15 ++
src/backend/nodes/nodeFuncs.c                    |  10 +
src/backend/nodes/outfuncs.c                     |  15 ++
src/backend/parser/analyze.c                     | 240 +++++++++++++++++++++++
src/backend/parser/gram.y                        |  99 +++++++++-
src/backend/parser/parse_coerce.c                |   8 +
src/backend/parser/parse_target.c                |  41 ++--
src/backend/parser/parser.c                      |   6 +-
src/backend/tcop/utility.c                       |   8 +
src/include/nodes/nodes.h                        |   1 +
src/include/nodes/parsenodes.h                   |  19 ++
src/include/nodes/primnodes.h                    |   1 +
src/include/parser/parse_target.h                |  12 ++
src/include/parser/parser.h                      |  13 +-
src/interfaces/ecpg/preproc/parse.pl             |   6 +-
src/pl/plpgsql/src/Makefile                      |   2 +-
src/pl/plpgsql/src/expected/plpgsql_array.out    |  94 +++++++++
src/pl/plpgsql/src/expected/plpgsql_record.out   |  91 ++++++++-
src/pl/plpgsql/src/expected/plpgsql_varprops.out |   2 +-
src/pl/plpgsql/src/pl_comp.c                     |  49 +++--
src/pl/plpgsql/src/pl_exec.c                     |  49 ++++-
src/pl/plpgsql/src/pl_gram.y                     | 196 +++++++++++-------
src/pl/plpgsql/src/plpgsql.h                     |   5 +-
src/pl/plpgsql/src/sql/plpgsql_array.sql         |  79 ++++++++
src/pl/plpgsql/src/sql/plpgsql_record.sql        |  42 ++++
src/test/regress/expected/plpgsql.out            |  36 ++--
32 files changed, 1081 insertions(+), 159 deletions(-)



Message-ID: <E1kwTpU-0000yS-Px@gemulon.postgresql.org>
Permalink:  ../E1kwTpU-0000yS-Px@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kwTpU-0000yS-Px@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Re-implement pl/pgsql's expression and assignment parsing.
  In-Reply-To: <E1kwTpU-0000yS-Px@gemulon.postgresql.org>
  References: <E1kwTpU-0000yS-Px@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox