summaryrefslogtreecommitdiff
path: root/src/pl
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2018-11-20 15:36:57 -0800
committerAndres Freund <andres@anarazel.de>2018-11-20 16:00:17 -0800
commit578b229718e8f15fa779e20f086c4b6bb3776106 (patch)
tree701869752158d27daa080d292befeb2e52f19037 /src/pl
parent0999ac479292c12a7c373e612b15e1ff47077990 (diff)
downloadpostgresql-578b229718e8f15fa779e20f086c4b6bb3776106.tar.gz
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
Diffstat (limited to 'src/pl')
-rw-r--r--src/pl/plperl/plperl.c2
-rw-r--r--src/pl/plpgsql/src/pl_comp.c4
-rw-r--r--src/pl/plpgsql/src/pl_exec.c10
-rw-r--r--src/pl/plpgsql/src/pl_funcs.c2
-rw-r--r--src/pl/plpgsql/src/pl_gram.y6
-rw-r--r--src/pl/plpgsql/src/pl_scanner.c1
-rw-r--r--src/pl/plpgsql/src/plpgsql.h2
-rw-r--r--src/pl/tcl/expected/pltcl_queries.out15
-rw-r--r--src/pl/tcl/expected/pltcl_setup.out4
-rw-r--r--src/pl/tcl/pltcl.c26
-rw-r--r--src/pl/tcl/sql/pltcl_queries.sql6
-rw-r--r--src/pl/tcl/sql/pltcl_setup.sql5
12 files changed, 3 insertions, 80 deletions
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index 4cfc506253..fe54b20903 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -2825,7 +2825,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger, bool is_event_trigger)
elog(ERROR, "cache lookup failed for language %u",
procStruct->prolang);
langStruct = (Form_pg_language) GETSTRUCT(langTup);
- prodesc->lang_oid = HeapTupleGetOid(langTup);
+ prodesc->lang_oid = langStruct->oid;
prodesc->lanpltrusted = langStruct->lanpltrusted;
ReleaseSysCache(langTup);
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c
index 59460d2643..8bacc74cce 100644
--- a/src/pl/plpgsql/src/pl_comp.c
+++ b/src/pl/plpgsql/src/pl_comp.c
@@ -1898,7 +1898,7 @@ build_row_from_vars(PLpgSQL_variable **vars, int numvars)
row->dtype = PLPGSQL_DTYPE_ROW;
row->refname = "(unnamed row)";
row->lineno = -1;
- row->rowtupdesc = CreateTemplateTupleDesc(numvars, false);
+ row->rowtupdesc = CreateTemplateTupleDesc(numvars);
row->nfields = numvars;
row->fieldnames = palloc(numvars * sizeof(char *));
row->varnos = palloc(numvars * sizeof(int));
@@ -2031,7 +2031,7 @@ build_datatype(HeapTuple typeTup, int32 typmod, Oid collation)
typ = (PLpgSQL_type *) palloc(sizeof(PLpgSQL_type));
typ->typname = pstrdup(NameStr(typeStruct->typname));
- typ->typoid = HeapTupleGetOid(typeTup);
+ typ->typoid = typeStruct->oid;
switch (typeStruct->typtype)
{
case TYPTYPE_BASE:
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index d5694d3d08..39ea925820 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -2332,12 +2332,6 @@ exec_stmt_getdiag(PLpgSQL_execstate *estate, PLpgSQL_stmt_getdiag *stmt)
false, INT8OID, -1);
break;
- case PLPGSQL_GETDIAG_RESULT_OID:
- exec_assign_value(estate, var,
- ObjectIdGetDatum(estate->eval_lastoid),
- false, OIDOID, -1);
- break;
-
case PLPGSQL_GETDIAG_ERROR_CONTEXT:
exec_assign_c_string(estate, var,
estate->cur_error->context);
@@ -3936,7 +3930,6 @@ plpgsql_estate_setup(PLpgSQL_execstate *estate,
estate->eval_tuptable = NULL;
estate->eval_processed = 0;
- estate->eval_lastoid = InvalidOid;
estate->eval_econtext = NULL;
estate->err_stmt = NULL;
@@ -4180,7 +4173,6 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
/* All variants should save result info for GET DIAGNOSTICS */
estate->eval_processed = SPI_processed;
- estate->eval_lastoid = SPI_lastoid;
/* Process INTO if present */
if (stmt->into)
@@ -4371,7 +4363,6 @@ exec_stmt_dynexecute(PLpgSQL_execstate *estate,
/* Save result info for GET DIAGNOSTICS */
estate->eval_processed = SPI_processed;
- estate->eval_lastoid = SPI_lastoid;
/* Process INTO if present */
if (stmt->into)
@@ -5841,7 +5832,6 @@ exec_run_select(PLpgSQL_execstate *estate,
Assert(estate->eval_tuptable == NULL);
estate->eval_tuptable = SPI_tuptable;
estate->eval_processed = SPI_processed;
- estate->eval_lastoid = SPI_lastoid;
return rc;
}
diff --git a/src/pl/plpgsql/src/pl_funcs.c b/src/pl/plpgsql/src/pl_funcs.c
index b93f866223..4266e6cee7 100644
--- a/src/pl/plpgsql/src/pl_funcs.c
+++ b/src/pl/plpgsql/src/pl_funcs.c
@@ -307,8 +307,6 @@ plpgsql_getdiag_kindname(PLpgSQL_getdiag_kind kind)
{
case PLPGSQL_GETDIAG_ROW_COUNT:
return "ROW_COUNT";
- case PLPGSQL_GETDIAG_RESULT_OID:
- return "RESULT_OID";
case PLPGSQL_GETDIAG_CONTEXT:
return "PG_CONTEXT";
case PLPGSQL_GETDIAG_ERROR_CONTEXT:
diff --git a/src/pl/plpgsql/src/pl_gram.y b/src/pl/plpgsql/src/pl_gram.y
index 68e399f9cf..a979a5109d 100644
--- a/src/pl/plpgsql/src/pl_gram.y
+++ b/src/pl/plpgsql/src/pl_gram.y
@@ -327,7 +327,6 @@ static void check_raise_parameters(PLpgSQL_stmt_raise *stmt);
%token <keyword> K_RAISE
%token <keyword> K_RELATIVE
%token <keyword> K_RESET
-%token <keyword> K_RESULT_OID
%token <keyword> K_RETURN
%token <keyword> K_RETURNED_SQLSTATE
%token <keyword> K_REVERSE
@@ -977,7 +976,6 @@ stmt_getdiag : K_GET getdiag_area_opt K_DIAGNOSTICS getdiag_list ';'
{
/* these fields are disallowed in stacked case */
case PLPGSQL_GETDIAG_ROW_COUNT:
- case PLPGSQL_GETDIAG_RESULT_OID:
if (new->is_stacked)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
@@ -1061,9 +1059,6 @@ getdiag_item :
K_ROW_COUNT, "row_count"))
$$ = PLPGSQL_GETDIAG_ROW_COUNT;
else if (tok_is_keyword(tok, &yylval,
- K_RESULT_OID, "result_oid"))
- $$ = PLPGSQL_GETDIAG_RESULT_OID;
- else if (tok_is_keyword(tok, &yylval,
K_PG_CONTEXT, "pg_context"))
$$ = PLPGSQL_GETDIAG_CONTEXT;
else if (tok_is_keyword(tok, &yylval,
@@ -2518,7 +2513,6 @@ unreserved_keyword :
| K_RAISE
| K_RELATIVE
| K_RESET
- | K_RESULT_OID
| K_RETURN
| K_RETURNED_SQLSTATE
| K_REVERSE
diff --git a/src/pl/plpgsql/src/pl_scanner.c b/src/pl/plpgsql/src/pl_scanner.c
index fc4ba3054a..ab18946847 100644
--- a/src/pl/plpgsql/src/pl_scanner.c
+++ b/src/pl/plpgsql/src/pl_scanner.c
@@ -158,7 +158,6 @@ static const ScanKeyword unreserved_keywords[] = {
PG_KEYWORD("raise", K_RAISE, UNRESERVED_KEYWORD)
PG_KEYWORD("relative", K_RELATIVE, UNRESERVED_KEYWORD)
PG_KEYWORD("reset", K_RESET, UNRESERVED_KEYWORD)
- PG_KEYWORD("result_oid", K_RESULT_OID, UNRESERVED_KEYWORD)
PG_KEYWORD("return", K_RETURN, UNRESERVED_KEYWORD)
PG_KEYWORD("returned_sqlstate", K_RETURNED_SQLSTATE, UNRESERVED_KEYWORD)
PG_KEYWORD("reverse", K_REVERSE, UNRESERVED_KEYWORD)
diff --git a/src/pl/plpgsql/src/plpgsql.h b/src/pl/plpgsql/src/plpgsql.h
index f6c35a5049..42177ccaa6 100644
--- a/src/pl/plpgsql/src/plpgsql.h
+++ b/src/pl/plpgsql/src/plpgsql.h
@@ -148,7 +148,6 @@ enum
typedef enum PLpgSQL_getdiag_kind
{
PLPGSQL_GETDIAG_ROW_COUNT,
- PLPGSQL_GETDIAG_RESULT_OID,
PLPGSQL_GETDIAG_CONTEXT,
PLPGSQL_GETDIAG_ERROR_CONTEXT,
PLPGSQL_GETDIAG_ERROR_DETAIL,
@@ -1043,7 +1042,6 @@ typedef struct PLpgSQL_execstate
/* temporary state for results from evaluation of query or expr */
SPITupleTable *eval_tuptable;
uint64 eval_processed;
- Oid eval_lastoid;
ExprContext *eval_econtext; /* for executing simple expressions */
/* status information for error context reporting */
diff --git a/src/pl/tcl/expected/pltcl_queries.out b/src/pl/tcl/expected/pltcl_queries.out
index 736671cc1b..17e821bb4c 100644
--- a/src/pl/tcl/expected/pltcl_queries.out
+++ b/src/pl/tcl/expected/pltcl_queries.out
@@ -402,21 +402,6 @@ NOTICE: args: {42 {statement trigger}}
ERROR: argisnull cannot be used in triggers
select trigger_data();
ERROR: trigger functions can only be called as triggers
--- Test spi_lastoid primitive
-create temp table t1 (f1 int);
-select tcl_lastoid('t1');
- tcl_lastoid
--------------
- 0
-(1 row)
-
-create temp table t2 (f1 int) with oids;
-select tcl_lastoid('t2') > 0;
- ?column?
-----------
- t
-(1 row)
-
-- test some error cases
create function tcl_error(out a int, out b int) as $$return {$$ language pltcl;
select tcl_error();
diff --git a/src/pl/tcl/expected/pltcl_setup.out b/src/pl/tcl/expected/pltcl_setup.out
index f1958c3a98..b10cf4e47d 100644
--- a/src/pl/tcl/expected/pltcl_setup.out
+++ b/src/pl/tcl/expected/pltcl_setup.out
@@ -431,10 +431,6 @@ create function tcl_composite_arg_ref2(T_dta1) returns text as '
create function tcl_argisnull(text) returns bool as '
argisnull 1
' language pltcl;
-create function tcl_lastoid(tabname text) returns int8 as '
- spi_exec "insert into $1 default values"
- spi_lastoid
-' language pltcl;
create function tcl_int4add(int4,int4) returns int4 as '
return [expr $1 + $2]
' language pltcl;
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index e2fa43b890..3b1454f833 100644
--- a/src/pl/tcl/pltcl.c
+++ b/src/pl/tcl/pltcl.c
@@ -307,8 +307,6 @@ static int pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[]);
static int pltcl_SPI_execute_plan(ClientData cdata, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[]);
-static int pltcl_SPI_lastoid(ClientData cdata, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
static int pltcl_subtransaction(ClientData cdata, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[]);
static int pltcl_commit(ClientData cdata, Tcl_Interp *interp,
@@ -523,8 +521,6 @@ pltcl_init_interp(pltcl_interp_desc *interp_desc, Oid prolang, bool pltrusted)
pltcl_SPI_prepare, NULL, NULL);
Tcl_CreateObjCommand(interp, "spi_execp",
pltcl_SPI_execute_plan, NULL, NULL);
- Tcl_CreateObjCommand(interp, "spi_lastoid",
- pltcl_SPI_lastoid, NULL, NULL);
Tcl_CreateObjCommand(interp, "subtransaction",
pltcl_subtransaction, NULL, NULL);
Tcl_CreateObjCommand(interp, "commit",
@@ -2874,28 +2870,6 @@ pltcl_SPI_execute_plan(ClientData cdata, Tcl_Interp *interp,
/**********************************************************************
- * pltcl_SPI_lastoid() - return the last oid. To
- * be used after insert queries
- **********************************************************************/
-static int
-pltcl_SPI_lastoid(ClientData cdata, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[])
-{
- /*
- * Check call syntax
- */
- if (objc != 1)
- {
- Tcl_WrongNumArgs(interp, 1, objv, "");
- return TCL_ERROR;
- }
-
- Tcl_SetObjResult(interp, Tcl_NewWideIntObj(SPI_lastoid));
- return TCL_OK;
-}
-
-
-/**********************************************************************
* pltcl_subtransaction() - Execute some Tcl code in a subtransaction
*
* The subtransaction is aborted if the Tcl code fragment returns TCL_ERROR,
diff --git a/src/pl/tcl/sql/pltcl_queries.sql b/src/pl/tcl/sql/pltcl_queries.sql
index 71c1238bd2..7390de6bd6 100644
--- a/src/pl/tcl/sql/pltcl_queries.sql
+++ b/src/pl/tcl/sql/pltcl_queries.sql
@@ -117,12 +117,6 @@ select tcl_argisnull(null);
insert into trigger_test(test_argisnull) values(true);
select trigger_data();
--- Test spi_lastoid primitive
-create temp table t1 (f1 int);
-select tcl_lastoid('t1');
-create temp table t2 (f1 int) with oids;
-select tcl_lastoid('t2') > 0;
-
-- test some error cases
create function tcl_error(out a int, out b int) as $$return {$$ language pltcl;
select tcl_error();
diff --git a/src/pl/tcl/sql/pltcl_setup.sql b/src/pl/tcl/sql/pltcl_setup.sql
index 56a90dc844..0ea46134c7 100644
--- a/src/pl/tcl/sql/pltcl_setup.sql
+++ b/src/pl/tcl/sql/pltcl_setup.sql
@@ -465,11 +465,6 @@ create function tcl_argisnull(text) returns bool as '
argisnull 1
' language pltcl;
-create function tcl_lastoid(tabname text) returns int8 as '
- spi_exec "insert into $1 default values"
- spi_lastoid
-' language pltcl;
-
create function tcl_int4add(int4,int4) returns int4 as '
return [expr $1 + $2]