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/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
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

+1-1
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

+1-1
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

+21-19
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

+1-1
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

+14-11
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

+4-4
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

+2-3
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

+15-2
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

+1-1
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

+2-2
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);

contrib/postgres_fdw/deparse.c

+6-29
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,13 @@ foreign_expr_walker(Node *node,
332332
/* Var belongs to foreign table */
333333

334334
/*
335-
* System columns other than ctid and oid should not be
336-
* sent to the remote, since we don't make any effort to
337-
* ensure that local and remote values match (tableoid, in
335+
* System columns other than ctid should not be sent to
336+
* the remote, since we don't make any effort to ensure
337+
* that local and remote values match (tableoid, in
338338
* particular, almost certainly doesn't match).
339339
*/
340340
if (var->varattno < 0 &&
341-
var->varattno != SelfItemPointerAttributeNumber &&
342-
var->varattno != ObjectIdAttributeNumber)
341+
var->varattno != SelfItemPointerAttributeNumber)
343342
return false;
344343

345344
/* Else check the collation */
@@ -1145,8 +1144,8 @@ deparseTargetList(StringInfo buf,
11451144
}
11461145

11471146
/*
1148-
* Add ctid and oid if needed. We currently don't support retrieving any
1149-
* other system columns.
1147+
* Add ctid if needed. We currently don't support retrieving any other
1148+
* system columns.
11501149
*/
11511150
if (bms_is_member(SelfItemPointerAttributeNumber - FirstLowInvalidHeapAttributeNumber,
11521151
attrs_used))
@@ -1164,22 +1163,6 @@ deparseTargetList(StringInfo buf,
11641163
*retrieved_attrs = lappend_int(*retrieved_attrs,
11651164
SelfItemPointerAttributeNumber);
11661165
}
1167-
if (bms_is_member(ObjectIdAttributeNumber - FirstLowInvalidHeapAttributeNumber,
1168-
attrs_used))
1169-
{
1170-
if (!first)
1171-
appendStringInfoString(buf, ", ");
1172-
else if (is_returning)
1173-
appendStringInfoString(buf, " RETURNING ");
1174-
first = false;
1175-
1176-
if (qualify_col)
1177-
ADD_REL_QUALIFIER(buf, rtindex);
1178-
appendStringInfoString(buf, "oid");
1179-
1180-
*retrieved_attrs = lappend_int(*retrieved_attrs,
1181-
ObjectIdAttributeNumber);
1182-
}
11831166

11841167
/* Don't generate bad syntax if no undropped columns */
11851168
if (first && !is_returning)
@@ -2079,12 +2062,6 @@ deparseColumnRef(StringInfo buf, int varno, int varattno, RangeTblEntry *rte,
20792062
ADD_REL_QUALIFIER(buf, varno);
20802063
appendStringInfoString(buf, "ctid");
20812064
}
2082-
else if (varattno == ObjectIdAttributeNumber)
2083-
{
2084-
if (qualify_col)
2085-
ADD_REL_QUALIFIER(buf, varno);
2086-
appendStringInfoString(buf, "oid");
2087-
}
20882065
else if (varattno < 0)
20892066
{
20902067
/*

contrib/postgres_fdw/expected/postgres_fdw.out

+9-32
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,6 @@ CREATE FOREIGN TABLE ft6 (
129129
c2 int NOT NULL,
130130
c3 text
131131
) SERVER loopback2 OPTIONS (schema_name 'S 1', table_name 'T 4');
132-
-- A table with oids. CREATE FOREIGN TABLE doesn't support the
133-
-- WITH OIDS option, but ALTER does.
134-
CREATE FOREIGN TABLE ft_pg_type (
135-
typname name,
136-
typlen smallint
137-
) SERVER loopback OPTIONS (schema_name 'pg_catalog', table_name 'pg_type');
138-
ALTER TABLE ft_pg_type SET WITH OIDS;
139132
-- ===================================================================
140133
-- tests for validator
141134
-- ===================================================================
@@ -185,16 +178,15 @@ ALTER FOREIGN TABLE ft2 OPTIONS (schema_name 'S 1', table_name 'T 1');
185178
ALTER FOREIGN TABLE ft1 ALTER COLUMN c1 OPTIONS (column_name 'C 1');
186179
ALTER FOREIGN TABLE ft2 ALTER COLUMN c1 OPTIONS (column_name 'C 1');
187180
\det+
188-
List of foreign tables
189-
Schema | Table | Server | FDW options | Description
190-
--------+------------+-----------+--------------------------------------------------+-------------
191-
public | ft1 | loopback | (schema_name 'S 1', table_name 'T 1') |
192-
public | ft2 | loopback | (schema_name 'S 1', table_name 'T 1') |
193-
public | ft4 | loopback | (schema_name 'S 1', table_name 'T 3') |
194-
public | ft5 | loopback | (schema_name 'S 1', table_name 'T 4') |
195-
public | ft6 | loopback2 | (schema_name 'S 1', table_name 'T 4') |
196-
public | ft_pg_type | loopback | (schema_name 'pg_catalog', table_name 'pg_type') |
197-
(6 rows)
181+
List of foreign tables
182+
Schema | Table | Server | FDW options | Description
183+
--------+-------+-----------+---------------------------------------+-------------
184+
public | ft1 | loopback | (schema_name 'S 1', table_name 'T 1') |
185+
public | ft2 | loopback | (schema_name 'S 1', table_name 'T 1') |
186+
public | ft4 | loopback | (schema_name 'S 1', table_name 'T 3') |
187+
public | ft5 | loopback | (schema_name 'S 1', table_name 'T 4') |
188+
public | ft6 | loopback2 | (schema_name 'S 1', table_name 'T 4') |
189+
(5 rows)
198190

199191
-- Test that alteration of server options causes reconnection
200192
-- Remote's errors might be non-English, so hide them to ensure stable results
@@ -4048,21 +4040,6 @@ SELECT ctid, * FROM ft1 t1 LIMIT 1;
40484040
(0,1) | 1 | 1 | 00001 | Fri Jan 02 00:00:00 1970 PST | Fri Jan 02 00:00:00 1970 | 1 | 1 | foo
40494041
(1 row)
40504042

4051-
EXPLAIN (VERBOSE, COSTS OFF)
4052-
SELECT oid, * FROM ft_pg_type WHERE typname = 'int4';
4053-
QUERY PLAN
4054-
----------------------------------------------------------------------------------------------------
4055-
Foreign Scan on public.ft_pg_type
4056-
Output: oid, typname, typlen
4057-
Remote SQL: SELECT typname, typlen, oid FROM pg_catalog.pg_type WHERE ((typname = 'int4'::name))
4058-
(3 rows)
4059-
4060-
SELECT oid, * FROM ft_pg_type WHERE typname = 'int4';
4061-
oid | typname | typlen
4062-
-----+---------+--------
4063-
23 | int4 | 4
4064-
(1 row)
4065-
40664043
-- ===================================================================
40674044
-- used in PL/pgSQL function
40684045
-- ===================================================================

0 commit comments

Comments
 (0)