Skip to content

Commit 578b229

Browse files
committed
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/[email protected]
1 parent 0999ac4 commit 578b229

File tree

343 files changed

+2292
-4291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

343 files changed

+2292
-4291
lines changed

contrib/adminpack/adminpack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ pg_logdir_ls_internal(FunctionCallInfo fcinfo)
502502

503503
fctx = palloc(sizeof(directory_fctx));
504504

505-
tupdesc = CreateTemplateTupleDesc(2, false);
505+
tupdesc = CreateTemplateTupleDesc(2);
506506
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "starttime",
507507
TIMESTAMPOID, -1, 0);
508508
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "filename",

contrib/btree_gist/expected/cash.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- money check
2-
CREATE TABLE moneytmp (a money) WITH OIDS;
2+
CREATE TABLE moneytmp (a money);
33
\copy moneytmp from 'data/cash.data'
44
SET enable_seqscan=on;
55
SELECT count(*) FROM moneytmp WHERE a < '22649.64';

contrib/btree_gist/expected/oid.out

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,66 @@
11
-- oid check
22
SET enable_seqscan=on;
3-
SELECT count(*) FROM moneytmp WHERE oid < ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
3+
CREATE TEMPORARY TABLE oidtmp (oid oid);
4+
INSERT INTO oidtmp SELECT g.i::oid FROM generate_series(1, 1000) g(i);
5+
SELECT count(*) FROM oidtmp WHERE oid < 17;
46
count
57
-------
6-
372
8+
16
79
(1 row)
810

9-
SELECT count(*) FROM moneytmp WHERE oid <= ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
11+
SELECT count(*) FROM oidtmp WHERE oid <= 17;
1012
count
1113
-------
12-
373
14+
17
1315
(1 row)
1416

15-
SELECT count(*) FROM moneytmp WHERE oid = ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
17+
SELECT count(*) FROM oidtmp WHERE oid = 17;
1618
count
1719
-------
1820
1
1921
(1 row)
2022

21-
SELECT count(*) FROM moneytmp WHERE oid >= ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
23+
SELECT count(*) FROM oidtmp WHERE oid >= 17;
2224
count
2325
-------
24-
228
26+
984
2527
(1 row)
2628

27-
SELECT count(*) FROM moneytmp WHERE oid > ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
29+
SELECT count(*) FROM oidtmp WHERE oid > 17;
2830
count
2931
-------
30-
227
32+
983
3133
(1 row)
3234

33-
CREATE INDEX oididx ON moneytmp USING gist ( oid );
35+
CREATE INDEX oididx ON oidtmp USING gist ( oid );
3436
SET enable_seqscan=off;
35-
SELECT count(*) FROM moneytmp WHERE oid < ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
37+
SELECT count(*) FROM oidtmp WHERE oid < 17;
3638
count
3739
-------
38-
372
40+
16
3941
(1 row)
4042

41-
SELECT count(*) FROM moneytmp WHERE oid <= ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
43+
SELECT count(*) FROM oidtmp WHERE oid <= 17;
4244
count
4345
-------
44-
373
46+
17
4547
(1 row)
4648

47-
SELECT count(*) FROM moneytmp WHERE oid = ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
49+
SELECT count(*) FROM oidtmp WHERE oid = 17;
4850
count
4951
-------
5052
1
5153
(1 row)
5254

53-
SELECT count(*) FROM moneytmp WHERE oid >= ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
55+
SELECT count(*) FROM oidtmp WHERE oid >= 17;
5456
count
5557
-------
56-
228
58+
984
5759
(1 row)
5860

59-
SELECT count(*) FROM moneytmp WHERE oid > ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
61+
SELECT count(*) FROM oidtmp WHERE oid > 17;
6062
count
6163
-------
62-
227
64+
983
6365
(1 row)
6466

contrib/btree_gist/sql/cash.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- money check
22

3-
CREATE TABLE moneytmp (a money) WITH OIDS;
3+
CREATE TABLE moneytmp (a money);
44

55
\copy moneytmp from 'data/cash.data'
66

contrib/btree_gist/sql/oid.sql

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@
22

33
SET enable_seqscan=on;
44

5-
SELECT count(*) FROM moneytmp WHERE oid < ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
5+
CREATE TEMPORARY TABLE oidtmp (oid oid);
6+
INSERT INTO oidtmp SELECT g.i::oid FROM generate_series(1, 1000) g(i);
67

7-
SELECT count(*) FROM moneytmp WHERE oid <= ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
8+
SELECT count(*) FROM oidtmp WHERE oid < 17;
89

9-
SELECT count(*) FROM moneytmp WHERE oid = ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
10+
SELECT count(*) FROM oidtmp WHERE oid <= 17;
1011

11-
SELECT count(*) FROM moneytmp WHERE oid >= ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
12+
SELECT count(*) FROM oidtmp WHERE oid = 17;
1213

13-
SELECT count(*) FROM moneytmp WHERE oid > ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
14+
SELECT count(*) FROM oidtmp WHERE oid >= 17;
1415

15-
CREATE INDEX oididx ON moneytmp USING gist ( oid );
16+
SELECT count(*) FROM oidtmp WHERE oid > 17;
17+
18+
CREATE INDEX oididx ON oidtmp USING gist ( oid );
1619

1720
SET enable_seqscan=off;
1821

19-
SELECT count(*) FROM moneytmp WHERE oid < ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
22+
SELECT count(*) FROM oidtmp WHERE oid < 17;
2023

21-
SELECT count(*) FROM moneytmp WHERE oid <= ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
24+
SELECT count(*) FROM oidtmp WHERE oid <= 17;
2225

23-
SELECT count(*) FROM moneytmp WHERE oid = ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
26+
SELECT count(*) FROM oidtmp WHERE oid = 17;
2427

25-
SELECT count(*) FROM moneytmp WHERE oid >= ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
28+
SELECT count(*) FROM oidtmp WHERE oid >= 17;
2629

27-
SELECT count(*) FROM moneytmp WHERE oid > ( SELECT oid FROM moneytmp WHERE a = '22649.64' );
30+
SELECT count(*) FROM oidtmp WHERE oid > 17;

contrib/dblink/dblink.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ materializeResult(FunctionCallInfo fcinfo, PGconn *conn, PGresult *res)
849849
* need a tuple descriptor representing one TEXT column to return
850850
* the command status string as our result tuple
851851
*/
852-
tupdesc = CreateTemplateTupleDesc(1, false);
852+
tupdesc = CreateTemplateTupleDesc(1);
853853
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "status",
854854
TEXTOID, -1, 0);
855855
ntuples = 1;
@@ -1032,7 +1032,7 @@ materializeQueryResult(FunctionCallInfo fcinfo,
10321032
* need a tuple descriptor representing one TEXT column to return
10331033
* the command status string as our result tuple
10341034
*/
1035-
tupdesc = CreateTemplateTupleDesc(1, false);
1035+
tupdesc = CreateTemplateTupleDesc(1);
10361036
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "status",
10371037
TEXTOID, -1, 0);
10381038
attinmeta = TupleDescGetAttInMetadata(tupdesc);
@@ -1526,7 +1526,7 @@ dblink_get_pkey(PG_FUNCTION_ARGS)
15261526
/*
15271527
* need a tuple descriptor representing one INT and one TEXT column
15281528
*/
1529-
tupdesc = CreateTemplateTupleDesc(2, false);
1529+
tupdesc = CreateTemplateTupleDesc(2);
15301530
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "position",
15311531
INT4OID, -1, 0);
15321532
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "colname",
@@ -1904,7 +1904,7 @@ dblink_get_notify(PG_FUNCTION_ARGS)
19041904
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
19051905
oldcontext = MemoryContextSwitchTo(per_query_ctx);
19061906

1907-
tupdesc = CreateTemplateTupleDesc(DBLINK_NOTIFY_COLS, false);
1907+
tupdesc = CreateTemplateTupleDesc(DBLINK_NOTIFY_COLS);
19081908
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "notify_name",
19091909
TEXTOID, -1, 0);
19101910
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "be_pid",

contrib/file_fdw/file_fdw.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,7 @@ fileIterateForeignScan(ForeignScanState *node)
727727
*/
728728
ExecClearTuple(slot);
729729
found = NextCopyFrom(festate->cstate, NULL,
730-
slot->tts_values, slot->tts_isnull,
731-
NULL);
730+
slot->tts_values, slot->tts_isnull);
732731
if (found)
733732
ExecStoreVirtualTuple(slot);
734733

@@ -1148,7 +1147,7 @@ file_acquire_sample_rows(Relation onerel, int elevel,
11481147
MemoryContextReset(tupcontext);
11491148
MemoryContextSwitchTo(tupcontext);
11501149

1151-
found = NextCopyFrom(cstate, NULL, values, nulls, NULL);
1150+
found = NextCopyFrom(cstate, NULL, values, nulls);
11521151

11531152
MemoryContextSwitchTo(oldcontext);
11541153

contrib/pageinspect/heapfuncs.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@
3535
#include "utils/builtins.h"
3636
#include "utils/rel.h"
3737

38+
/*
39+
* It's not supported to create tuples with oids anymore, but when pg_upgrade
40+
* was used to upgrade from an older version, tuples might still have an
41+
* oid. Seems worthwhile to display that.
42+
*/
43+
#define HeapTupleHeaderGetOidOld(tup) \
44+
( \
45+
((tup)->t_infomask & HEAP_HASOID_OLD) ? \
46+
*((Oid *) ((char *)(tup) + (tup)->t_hoff - sizeof(Oid))) \
47+
: \
48+
InvalidOid \
49+
)
50+
3851

3952
/*
4053
* bits_to_text
@@ -241,8 +254,8 @@ heap_page_items(PG_FUNCTION_ARGS)
241254
else
242255
nulls[11] = true;
243256

244-
if (tuphdr->t_infomask & HEAP_HASOID)
245-
values[12] = HeapTupleHeaderGetOid(tuphdr);
257+
if (tuphdr->t_infomask & HEAP_HASOID_OLD)
258+
values[12] = HeapTupleHeaderGetOidOld(tuphdr);
246259
else
247260
nulls[12] = true;
248261
}

contrib/pg_buffercache/pg_buffercache_pages.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
9999
elog(ERROR, "incorrect number of output arguments");
100100

101101
/* Construct a tuple descriptor for the result rows. */
102-
tupledesc = CreateTemplateTupleDesc(expected_tupledesc->natts, false);
102+
tupledesc = CreateTemplateTupleDesc(expected_tupledesc->natts);
103103
TupleDescInitEntry(tupledesc, (AttrNumber) 1, "bufferid",
104104
INT4OID, -1, 0);
105105
TupleDescInitEntry(tupledesc, (AttrNumber) 2, "relfilenode",

contrib/pg_visibility/pg_visibility.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
292292
ReleaseBuffer(vmbuffer);
293293
relation_close(rel, AccessShareLock);
294294

295-
tupdesc = CreateTemplateTupleDesc(2, false);
295+
tupdesc = CreateTemplateTupleDesc(2);
296296
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "all_visible", INT8OID, -1, 0);
297297
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "all_frozen", INT8OID, -1, 0);
298298
tupdesc = BlessTupleDesc(tupdesc);
@@ -447,7 +447,7 @@ pg_visibility_tupdesc(bool include_blkno, bool include_pd)
447447
++maxattr;
448448
if (include_pd)
449449
++maxattr;
450-
tupdesc = CreateTemplateTupleDesc(maxattr, false);
450+
tupdesc = CreateTemplateTupleDesc(maxattr);
451451
if (include_blkno)
452452
TupleDescInitEntry(tupdesc, ++a, "blkno", INT8OID, -1, 0);
453453
TupleDescInitEntry(tupdesc, ++a, "all_visible", BOOLOID, -1, 0);

0 commit comments

Comments
 (0)