Skip to content

Commit 896bd12

Browse files
committed
Code review for transaction-safe-TRUNCATE patch: minor cleanups.
1 parent a03c0d9 commit 896bd12

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

doc/src/sgml/release.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.173 2002/12/20 00:24:00 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.174 2002/12/30 19:45:11 tgl Exp $
33
-->
44

55
<appendix id="release">
@@ -29,6 +29,7 @@ Information schema
2929
Domains now support CHECK constraints
3030
psql backslash commands for listing conversions, casts, and schemas
3131
TRUNCATE TABLE is transaction-safe
32+
CLUSTER can re-cluster a previously clustered table, or all such tables
3233
Statement-level triggers
3334
System can use either hash- or sort-based strategy for grouped aggregation
3435
ON COMMIT options for temp tables

src/backend/commands/cluster.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.103 2002/12/30 18:42:13 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.104 2002/12/30 19:45:15 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -26,7 +26,6 @@
2626
#include "catalog/index.h"
2727
#include "catalog/indexing.h"
2828
#include "catalog/namespace.h"
29-
#include "catalog/pg_constraint.h"
3029
#include "commands/cluster.h"
3130
#include "commands/tablecmds.h"
3231
#include "miscadmin.h"
@@ -111,9 +110,9 @@ cluster(ClusterStmt *stmt)
111110
RelToCluster rvtc;
112111

113112
/* Find and lock the table */
114-
tableOid = RangeVarGetRelid(stmt->relation, false);
113+
rel = heap_openrv(stmt->relation, AccessExclusiveLock);
115114

116-
rel = heap_open(tableOid, AccessExclusiveLock);
115+
tableOid = RelationGetRelid(rel);
117116

118117
/* Check permissions */
119118
if (!check_cluster_permitted(tableOid))
@@ -325,6 +324,13 @@ cluster_rel(RelToCluster *rvtc, bool recheck)
325324
elog(ERROR, "CLUSTER: cannot cluster system relation \"%s\"",
326325
RelationGetRelationName(OldHeap));
327326

327+
/*
328+
* Don't allow cluster on temp tables of other backends ... their
329+
* local buffer manager is not going to cope.
330+
*/
331+
if (isOtherTempNamespace(RelationGetNamespace(OldHeap)))
332+
elog(ERROR, "CLUSTER cannot be used on temp tables of other processes");
333+
328334
/* Drop relcache refcnt on OldIndex, but keep lock */
329335
index_close(OldIndex);
330336

src/backend/commands/tablecmds.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.63 2002/12/30 18:42:14 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.64 2002/12/30 19:45:17 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -423,8 +423,7 @@ TruncateRelation(const RangeVar *relation)
423423
Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tuple);
424424

425425
if (con->contype == 'f' && con->conrelid != relid)
426-
elog(ERROR, "TRUNCATE cannot be used as table %s references "
427-
"this one via foreign key constraint %s",
426+
elog(ERROR, "TRUNCATE cannot be used as table %s references this one via foreign key constraint %s",
428427
get_rel_name(con->conrelid),
429428
NameStr(con->conname));
430429
}
@@ -439,6 +438,11 @@ TruncateRelation(const RangeVar *relation)
439438
rebuild_relation(rel, InvalidOid);
440439

441440
/* NB: rebuild_relation does heap_close() */
441+
442+
/*
443+
* You might think we need to truncate the rel's toast table here too,
444+
* but actually we don't; it will have been rebuilt in an empty state.
445+
*/
442446
}
443447

444448
/*----------

0 commit comments

Comments
 (0)