On Fri, Nov 20, 2020 at 09:50:08PM -0500, Tom Lane wrote: > Michael Paquier <[email protected]> writes: >> What about cutting the cake in two and just remove >> currtid() then? > > +1. That'd still let us get rid of setLastTid() which is > the ugliest part of the thing, IMO.
Indeed, this could go. There is a recursive call for views, but in order to maintain compatibility with that we can just remove one function and move the second to use a regclass as argument, like the attached, while removing setLastTid(). Any thoughts? -- Michael
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 92b19dba32..54b2eb7378 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -129,7 +129,6 @@ extern bool heap_hot_search_buffer(ItemPointer tid, Relation relation,
bool *all_dead, bool first_call);
extern void heap_get_latest_tid(TableScanDesc scan, ItemPointer tid);
-extern void setLastTid(const ItemPointer tid);
extern BulkInsertState GetBulkInsertState(void);
extern void FreeBulkInsertState(BulkInsertState);
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index c6da0df868..7d1f6ec234 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 202011191
+#define CATALOG_VERSION_NO 202011211
#endif
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 33dacfd340..63ddfe99d3 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -2549,13 +2549,10 @@
{ oid => '1292',
proname => 'tideq', proleakproof => 't', prorettype => 'bool',
proargtypes => 'tid tid', prosrc => 'tideq' },
-{ oid => '1293', descr => 'latest tid of a tuple',
- proname => 'currtid', provolatile => 'v', proparallel => 'u',
- prorettype => 'tid', proargtypes => 'oid tid', prosrc => 'currtid_byreloid' },
{ oid => '1294', descr => 'latest tid of a tuple',
proname => 'currtid2', provolatile => 'v', proparallel => 'u',
- prorettype => 'tid', proargtypes => 'text tid',
- prosrc => 'currtid_byrelname' },
+ prorettype => 'tid', proargtypes => 'regclass tid',
+ prosrc => 'currtid_byreloid' },
{ oid => '1265',
proname => 'tidne', proleakproof => 't', prorettype => 'bool',
proargtypes => 'tid tid', prosrc => 'tidne' },
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 29e07b7228..e0f24283b8 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -645,10 +645,7 @@ ExecInsert(ModifyTableState *mtstate,
}
if (canSetTag)
- {
(estate->es_processed)++;
- setLastTid(&slot->tts_tid);
- }
/*
* If this insert is the result of a partition key update that moved the
diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c
index 509a0fdffc..4d191d91b6 100644
--- a/src/backend/utils/adt/tid.c
+++ b/src/backend/utils/adt/tid.c
@@ -275,14 +275,6 @@ hashtidextended(PG_FUNCTION_ARGS)
* Maybe these implementations should be moved to another place
*/
-static ItemPointerData Current_last_tid = {{0, 0}, 0};
-
-void
-setLastTid(const ItemPointer tid)
-{
- Current_last_tid = *tid;
-}
-
/*
* Handle CTIDs of views.
* CTID should be defined in the view and it must
@@ -367,11 +359,6 @@ currtid_byreloid(PG_FUNCTION_ARGS)
TableScanDesc scan;
result = (ItemPointer) palloc(sizeof(ItemPointerData));
- if (!reloid)
- {
- *result = Current_last_tid;
- PG_RETURN_ITEMPOINTER(result);
- }
rel = table_open(reloid, AccessShareLock);
@@ -401,46 +388,3 @@ currtid_byreloid(PG_FUNCTION_ARGS)
PG_RETURN_ITEMPOINTER(result);
}
-
-Datum
-currtid_byrelname(PG_FUNCTION_ARGS)
-{
- text *relname = PG_GETARG_TEXT_PP(0);
- ItemPointer tid = PG_GETARG_ITEMPOINTER(1);
- ItemPointer result;
- RangeVar *relrv;
- Relation rel;
- AclResult aclresult;
- Snapshot snapshot;
- TableScanDesc scan;
-
- relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
- rel = table_openrv(relrv, AccessShareLock);
-
- aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
- ACL_SELECT);
- if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind),
- RelationGetRelationName(rel));
-
- if (rel->rd_rel->relkind == RELKIND_VIEW)
- return currtid_for_view(rel, tid);
-
- if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
- elog(ERROR, "cannot look at latest visible tid for relation \"%s.%s\"",
- get_namespace_name(RelationGetNamespace(rel)),
- RelationGetRelationName(rel));
-
- result = (ItemPointer) palloc(sizeof(ItemPointerData));
- ItemPointerCopy(tid, result);
-
- snapshot = RegisterSnapshot(GetLatestSnapshot());
- scan = table_beginscan_tid(rel, snapshot);
- table_tuple_get_latest_tid(scan, result);
- table_endscan(scan);
- UnregisterSnapshot(snapshot);
-
- table_close(rel, AccessShareLock);
-
- PG_RETURN_ITEMPOINTER(result);
-}
diff --git a/src/test/regress/expected/tid.out b/src/test/regress/expected/tid.out
index e7e0d74780..8da1a45576 100644
--- a/src/test/regress/expected/tid.out
+++ b/src/test/regress/expected/tid.out
@@ -15,21 +15,13 @@ SELECT max(ctid) FROM tid_tab;
(1 row)
TRUNCATE tid_tab;
--- Tests for currtid() and currtid2() with various relation kinds
+-- Tests for currtid2() with various relation kinds
-- Materialized view
CREATE MATERIALIZED VIEW tid_matview AS SELECT a FROM tid_tab;
-SELECT currtid('tid_matview'::regclass::oid, '(0,1)'::tid); -- fails
-ERROR: tid (0, 1) is not valid for relation "tid_matview"
SELECT currtid2('tid_matview'::text, '(0,1)'::tid); -- fails
ERROR: tid (0, 1) is not valid for relation "tid_matview"
INSERT INTO tid_tab VALUES (1);
REFRESH MATERIALIZED VIEW tid_matview;
-SELECT currtid('tid_matview'::regclass::oid, '(0,1)'::tid); -- ok
- currtid
----------
- (0,1)
-(1 row)
-
SELECT currtid2('tid_matview'::text, '(0,1)'::tid); -- ok
currtid2
----------
@@ -40,12 +32,6 @@ DROP MATERIALIZED VIEW tid_matview;
TRUNCATE tid_tab;
-- Sequence
CREATE SEQUENCE tid_seq;
-SELECT currtid('tid_seq'::regclass::oid, '(0,1)'::tid); -- ok
- currtid
----------
- (0,1)
-(1 row)
-
SELECT currtid2('tid_seq'::text, '(0,1)'::tid); -- ok
currtid2
----------
@@ -55,39 +41,25 @@ SELECT currtid2('tid_seq'::text, '(0,1)'::tid); -- ok
DROP SEQUENCE tid_seq;
-- Index, fails with incorrect relation type
CREATE INDEX tid_ind ON tid_tab(a);
-SELECT currtid('tid_ind'::regclass::oid, '(0,1)'::tid); -- fails
-ERROR: "tid_ind" is an index
SELECT currtid2('tid_ind'::text, '(0,1)'::tid); -- fails
ERROR: "tid_ind" is an index
DROP INDEX tid_ind;
-- Partitioned table, no storage
CREATE TABLE tid_part (a int) PARTITION BY RANGE (a);
-SELECT currtid('tid_part'::regclass::oid, '(0,1)'::tid); -- fails
-ERROR: cannot look at latest visible tid for relation "public.tid_part"
SELECT currtid2('tid_part'::text, '(0,1)'::tid); -- fails
ERROR: cannot look at latest visible tid for relation "public.tid_part"
DROP TABLE tid_part;
-- Views
-- ctid not defined in the view
CREATE VIEW tid_view_no_ctid AS SELECT a FROM tid_tab;
-SELECT currtid('tid_view_no_ctid'::regclass::oid, '(0,1)'::tid); -- fails
-ERROR: currtid cannot handle views with no CTID
SELECT currtid2('tid_view_no_ctid'::text, '(0,1)'::tid); -- fails
ERROR: currtid cannot handle views with no CTID
DROP VIEW tid_view_no_ctid;
-- ctid fetched directly from the source table.
CREATE VIEW tid_view_with_ctid AS SELECT ctid, a FROM tid_tab;
-SELECT currtid('tid_view_with_ctid'::regclass::oid, '(0,1)'::tid); -- fails
-ERROR: tid (0, 1) is not valid for relation "tid_tab"
SELECT currtid2('tid_view_with_ctid'::text, '(0,1)'::tid); -- fails
ERROR: tid (0, 1) is not valid for relation "tid_tab"
INSERT INTO tid_tab VALUES (1);
-SELECT currtid('tid_view_with_ctid'::regclass::oid, '(0,1)'::tid); -- ok
- currtid
----------
- (0,1)
-(1 row)
-
SELECT currtid2('tid_view_with_ctid'::text, '(0,1)'::tid); -- ok
currtid2
----------
@@ -98,8 +70,6 @@ DROP VIEW tid_view_with_ctid;
TRUNCATE tid_tab;
-- ctid attribute with incorrect data type
CREATE VIEW tid_view_fake_ctid AS SELECT 1 AS ctid, 2 AS a;
-SELECT currtid('tid_view_fake_ctid'::regclass::oid, '(0,1)'::tid); -- fails
-ERROR: ctid isn't of type TID
SELECT currtid2('tid_view_fake_ctid'::text, '(0,1)'::tid); -- fails
ERROR: ctid isn't of type TID
DROP VIEW tid_view_fake_ctid;
diff --git a/src/test/regress/sql/tid.sql b/src/test/regress/sql/tid.sql
index c0d02df34f..34546a3cb7 100644
--- a/src/test/regress/sql/tid.sql
+++ b/src/test/regress/sql/tid.sql
@@ -8,55 +8,46 @@ SELECT min(ctid) FROM tid_tab;
SELECT max(ctid) FROM tid_tab;
TRUNCATE tid_tab;
--- Tests for currtid() and currtid2() with various relation kinds
+-- Tests for currtid2() with various relation kinds
-- Materialized view
CREATE MATERIALIZED VIEW tid_matview AS SELECT a FROM tid_tab;
-SELECT currtid('tid_matview'::regclass::oid, '(0,1)'::tid); -- fails
SELECT currtid2('tid_matview'::text, '(0,1)'::tid); -- fails
INSERT INTO tid_tab VALUES (1);
REFRESH MATERIALIZED VIEW tid_matview;
-SELECT currtid('tid_matview'::regclass::oid, '(0,1)'::tid); -- ok
SELECT currtid2('tid_matview'::text, '(0,1)'::tid); -- ok
DROP MATERIALIZED VIEW tid_matview;
TRUNCATE tid_tab;
-- Sequence
CREATE SEQUENCE tid_seq;
-SELECT currtid('tid_seq'::regclass::oid, '(0,1)'::tid); -- ok
SELECT currtid2('tid_seq'::text, '(0,1)'::tid); -- ok
DROP SEQUENCE tid_seq;
-- Index, fails with incorrect relation type
CREATE INDEX tid_ind ON tid_tab(a);
-SELECT currtid('tid_ind'::regclass::oid, '(0,1)'::tid); -- fails
SELECT currtid2('tid_ind'::text, '(0,1)'::tid); -- fails
DROP INDEX tid_ind;
-- Partitioned table, no storage
CREATE TABLE tid_part (a int) PARTITION BY RANGE (a);
-SELECT currtid('tid_part'::regclass::oid, '(0,1)'::tid); -- fails
SELECT currtid2('tid_part'::text, '(0,1)'::tid); -- fails
DROP TABLE tid_part;
-- Views
-- ctid not defined in the view
CREATE VIEW tid_view_no_ctid AS SELECT a FROM tid_tab;
-SELECT currtid('tid_view_no_ctid'::regclass::oid, '(0,1)'::tid); -- fails
SELECT currtid2('tid_view_no_ctid'::text, '(0,1)'::tid); -- fails
DROP VIEW tid_view_no_ctid;
-- ctid fetched directly from the source table.
CREATE VIEW tid_view_with_ctid AS SELECT ctid, a FROM tid_tab;
-SELECT currtid('tid_view_with_ctid'::regclass::oid, '(0,1)'::tid); -- fails
SELECT currtid2('tid_view_with_ctid'::text, '(0,1)'::tid); -- fails
INSERT INTO tid_tab VALUES (1);
-SELECT currtid('tid_view_with_ctid'::regclass::oid, '(0,1)'::tid); -- ok
SELECT currtid2('tid_view_with_ctid'::text, '(0,1)'::tid); -- ok
DROP VIEW tid_view_with_ctid;
TRUNCATE tid_tab;
-- ctid attribute with incorrect data type
CREATE VIEW tid_view_fake_ctid AS SELECT 1 AS ctid, 2 AS a;
-SELECT currtid('tid_view_fake_ctid'::regclass::oid, '(0,1)'::tid); -- fails
SELECT currtid2('tid_view_fake_ctid'::text, '(0,1)'::tid); -- fails
DROP VIEW tid_view_fake_ctid;
signature.asc
Description: PGP signature
