postgresql/src/interfaces/ecpg/preproc
Andres Freund 578b229718 Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.

This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row.  Neither pg_dump nor COPY included the contents of the
oid column by default.

The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.

WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.

Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
  WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
  issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
  restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
  OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
  plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.

The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.

The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such.  This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.

The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.

Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).

The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.

While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.

Catversion bump, for obvious reasons.

Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
2018-11-20 16:00:17 -08:00
..
po Translation updates 2018-06-25 12:37:18 +02:00
.gitignore Move keywords.c/kwlookup.c into src/common/. 2016-03-23 20:22:08 -04:00
c_keywords.c pgindent run for 9.4 2014-05-06 12:12:18 -04:00
check_rules.pl Fix spelling errors and typos in comments 2018-11-02 13:56:52 +01:00
descriptor.c Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
ecpg_keywords.c SQL procedures 2017-11-30 11:03:20 -05:00
ecpg.addons Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
ecpg.c ecpg: Change --version output to common style 2018-09-12 14:33:15 +02:00
ecpg.header Fixed ECPG to correctly handle out-of-scope cursor declarations with pointers 2017-09-12 04:53:36 +02:00
ecpg.tokens SQL procedures 2017-11-30 11:03:20 -05:00
ecpg.trailer SQL procedures 2017-11-30 11:03:20 -05:00
ecpg.type Changed ecpg parser to allow RETURNING clauses without attached C variables. 2017-08-14 11:29:34 +02:00
extern.h Remove unused code in ECPG. 2018-11-13 13:04:15 -05:00
keywords.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
Makefile Remove unwanted "garbage cleanup" logic in Makefiles. 2018-08-08 14:32:29 -04:00
nls.mk Translation updates 2018-05-21 12:29:52 -04:00
output.c Set connection back to NULL after freeing it. 2018-03-13 16:22:28 +01:00
parse.pl Fix spelling errors and typos in comments 2018-11-02 13:56:52 +01:00
parser.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
pgc.l Fix realfailN lexer rules to not make assumptions about input format. 2018-11-13 14:54:41 -05:00
README.parser Move parse2.pl to parse.pl 2011-06-14 07:34:00 +03:00
type.c Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
type.h Add some const decorations to prototypes 2017-11-10 13:38:57 -05:00
variable.c Remove unnecessary parentheses in return statements 2017-09-05 14:52:55 -04:00

ECPG modifies and extends the core grammar in a way that
1) every token in ECPG is <str> type. New tokens are
   defined in ecpg.tokens, types are defined in ecpg.type
2) most tokens from the core grammar are simply converted
   to literals concatenated together to form the SQL string
   passed to the server, this is done by parse.pl.
3) some rules need side-effects, actions are either added
   or completely overridden (compared to the basic token
   concatenation) for them, these are defined in ecpg.addons,
   the rules for ecpg.addons are explained below.
4) new grammar rules are needed for ECPG metacommands.
   These are in ecpg.trailer.
5) ecpg.header contains common functions, etc. used by
   actions for grammar rules.

In "ecpg.addons", every modified rule follows this pattern:
       ECPG: dumpedtokens postfix
where "dumpedtokens" is simply tokens from core gram.y's
rules concatenated together. e.g. if gram.y has this:
       ruleA: tokenA tokenB tokenC {...}
then "dumpedtokens" is "ruleAtokenAtokenBtokenC".
"postfix" above can be:
a) "block" - the automatic rule created by parse.pl is completely
    overridden, the code block has to be written completely as
    it were in a plain bison grammar
b) "rule" - the automatic rule is extended on, so new syntaxes
    are accepted for "ruleA". E.g.:
      ECPG: ruleAtokenAtokenBtokenC rule
          | tokenD tokenE { action_code; }
          ...
    It will be substituted with:
      ruleA: <original syntax forms and actions up to and including
                    "tokenA tokenB tokenC">
             | tokenD tokenE { action_code; }
             ...
c) "addon" - the automatic action for the rule (SQL syntax constructed
    from the tokens concatenated together) is prepended with a new
    action code part. This code part is written as is's already inside
    the { ... }

Multiple "addon" or "block" lines may appear together with the
new code block if the code block is common for those rules.