mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Modify the relcache to record the temp status of both local and nonlocal
temp relations; this is no more expensive than before, now that we have pg_class.relistemp. Insert tests into bufmgr.c to prevent attempting to fetch pages from nonlocal temp relations. This provides a low-level defense against bugs-of-omission allowing temp pages to be loaded into shared buffers, as in the contrib/pgstattuple problem reported by Stuart Bishop. While at it, tweak a bunch of places to use new relcache tests (instead of expensive probes into pg_namespace) to detect local or nonlocal temp tables.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.134 2009/03/24 20:17:13 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.135 2009/03/31 22:12:46 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -213,7 +213,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt,
|
||||
* probably not up-to-date on disk. (We don't throw a warning here; it
|
||||
* would just lead to chatter during a database-wide ANALYZE.)
|
||||
*/
|
||||
if (isOtherTempNamespace(RelationGetNamespace(onerel)))
|
||||
if (RELATION_IS_OTHER_TEMP(onerel))
|
||||
{
|
||||
relation_close(onerel, ShareUpdateExclusiveLock);
|
||||
return;
|
||||
|
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.182 2009/02/02 19:31:38 alvherre Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.183 2009/03/31 22:12:46 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -117,7 +117,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
|
||||
* Reject clustering a remote temp table ... their local buffer
|
||||
* manager is not going to cope.
|
||||
*/
|
||||
if (isOtherTempNamespace(RelationGetNamespace(rel)))
|
||||
if (RELATION_IS_OTHER_TEMP(rel))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot cluster temporary tables of other sessions")));
|
||||
@@ -302,7 +302,7 @@ cluster_rel(RelToCluster *rvtc, bool recheck, bool verbose)
|
||||
* check_index_is_clusterable which is redundant, but we leave it for
|
||||
* extra safety.
|
||||
*/
|
||||
if (isOtherTempNamespace(RelationGetNamespace(OldHeap)))
|
||||
if (RELATION_IS_OTHER_TEMP(OldHeap))
|
||||
{
|
||||
relation_close(OldHeap, AccessExclusiveLock);
|
||||
return;
|
||||
@@ -465,7 +465,7 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid, bool recheck)
|
||||
* Don't allow cluster on temp tables of other backends ... their local
|
||||
* buffer manager is not going to cope.
|
||||
*/
|
||||
if (isOtherTempNamespace(RelationGetNamespace(OldHeap)))
|
||||
if (RELATION_IS_OTHER_TEMP(OldHeap))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot cluster temporary tables of other sessions")));
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.306 2009/03/26 19:24:54 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.307 2009/03/31 22:12:46 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1001,8 +1001,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
}
|
||||
|
||||
/* check read-only transaction */
|
||||
if (XactReadOnly && is_from &&
|
||||
!isTempNamespace(RelationGetNamespace(cstate->rel)))
|
||||
if (XactReadOnly && is_from && !cstate->rel->rd_islocaltemp)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
|
||||
errmsg("transaction is read-only")));
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.182 2009/02/02 19:31:38 alvherre Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.183 2009/03/31 22:12:47 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -175,7 +175,7 @@ DefineIndex(RangeVar *heapRelation,
|
||||
/*
|
||||
* Don't try to CREATE INDEX on temp tables of other backends.
|
||||
*/
|
||||
if (isOtherTempNamespace(namespaceId))
|
||||
if (RELATION_IS_OTHER_TEMP(rel))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot create indexes on temporary tables of other sessions")));
|
||||
@@ -1404,7 +1404,8 @@ ReindexDatabase(const char *databaseName, bool do_system, bool do_user)
|
||||
continue;
|
||||
|
||||
/* Skip temp tables of other backends; we can't reindex them at all */
|
||||
if (isOtherTempNamespace(classtuple->relnamespace))
|
||||
if (classtuple->relistemp &&
|
||||
!isTempNamespace(classtuple->relnamespace))
|
||||
continue;
|
||||
|
||||
/* Check user/system classification, and optionally skip */
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.280 2009/02/11 21:11:16 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.281 2009/03/31 22:12:47 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1056,7 +1056,7 @@ truncate_check_rel(Relation rel)
|
||||
* Don't allow truncate on temp tables of other backends ... their local
|
||||
* buffer manager is not going to cope.
|
||||
*/
|
||||
if (isOtherTempNamespace(RelationGetNamespace(rel)))
|
||||
if (RELATION_IS_OTHER_TEMP(rel))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot truncate temporary tables of other sessions")));
|
||||
@@ -1203,7 +1203,7 @@ MergeAttributes(List *schema, List *supers, bool istemp,
|
||||
errmsg("inherited relation \"%s\" is not a table",
|
||||
parent->relname)));
|
||||
/* Permanent rels cannot inherit from temporary ones */
|
||||
if (!istemp && isTempNamespace(RelationGetNamespace(relation)))
|
||||
if (!istemp && relation->rd_istemp)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("cannot inherit from temporary relation \"%s\"",
|
||||
@@ -2793,7 +2793,7 @@ ATRewriteTables(List **wqueue)
|
||||
* Don't allow rewrite on temp tables of other backends ... their
|
||||
* local buffer manager is not going to cope.
|
||||
*/
|
||||
if (isOtherTempNamespace(RelationGetNamespace(OldHeap)))
|
||||
if (RELATION_IS_OTHER_TEMP(OldHeap))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot rewrite temporary tables of other sessions")));
|
||||
@@ -4603,16 +4603,16 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel,
|
||||
* backend has created in the temp table, because non-shared buffers are
|
||||
* used for temp tables.)
|
||||
*/
|
||||
if (isTempNamespace(RelationGetNamespace(pkrel)))
|
||||
if (pkrel->rd_istemp)
|
||||
{
|
||||
if (!isTempNamespace(RelationGetNamespace(rel)))
|
||||
if (!rel->rd_istemp)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
|
||||
errmsg("cannot reference temporary table from permanent table constraint")));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isTempNamespace(RelationGetNamespace(rel)))
|
||||
if (rel->rd_istemp)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
|
||||
errmsg("cannot reference permanent table from temporary table constraint")));
|
||||
@@ -6690,7 +6690,7 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace)
|
||||
* Don't allow moving temp tables of other backends ... their local buffer
|
||||
* manager is not going to cope.
|
||||
*/
|
||||
if (isOtherTempNamespace(RelationGetNamespace(rel)))
|
||||
if (RELATION_IS_OTHER_TEMP(rel))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot move temporary tables of other sessions")));
|
||||
@@ -6901,8 +6901,7 @@ ATExecAddInherit(Relation child_rel, RangeVar *parent)
|
||||
ATSimplePermissions(parent_rel, false);
|
||||
|
||||
/* Permanent rels cannot inherit from temporary ones */
|
||||
if (!isTempNamespace(RelationGetNamespace(child_rel)) &&
|
||||
isTempNamespace(RelationGetNamespace(parent_rel)))
|
||||
if (parent_rel->rd_istemp && !child_rel->rd_istemp)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("cannot inherit from temporary relation \"%s\"",
|
||||
|
@@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.386 2009/03/24 20:17:13 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.387 2009/03/31 22:12:48 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1147,7 +1147,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, bool do_toast, bool for_wraparound,
|
||||
* warning here; it would just lead to chatter during a database-wide
|
||||
* VACUUM.)
|
||||
*/
|
||||
if (isOtherTempNamespace(RelationGetNamespace(onerel)))
|
||||
if (RELATION_IS_OTHER_TEMP(onerel))
|
||||
{
|
||||
relation_close(onerel, lmode);
|
||||
PopActiveSnapshot();
|
||||
|
Reference in New Issue
Block a user