Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita455c94

Browse files
committed
Prevent clustering on incomplete indexes: partial indexes are verboten,
as are non-amindexnulls AMs unless first column is attnotnull.
1 parentd28cd22 commita455c94

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

‎src/backend/commands/cluster.c

Lines changed: 30 additions & 1 deletion
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.105 2003/02/09 06:56:26 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.106 2003/03/03 04:37:37 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -160,6 +160,7 @@ cluster(ClusterStmt *stmt)
160160
stmt->indexname,stmt->relation->relname);
161161
}
162162

163+
/* All other checks are done in cluster_rel() */
163164
rvtc.tableOid=tableOid;
164165
rvtc.indexOid=indexOid;
165166

@@ -313,6 +314,34 @@ cluster_rel(RelToCluster *rvtc, bool recheck)
313314
RelationGetRelationName(OldIndex),
314315
RelationGetRelationName(OldHeap));
315316

317+
/*
318+
* Disallow clustering on incomplete indexes (those that might not index
319+
* every row of the relation). We could relax this by making a separate
320+
* seqscan pass over the table to copy the missing rows, but that seems
321+
* expensive and tedious.
322+
*/
323+
if (VARSIZE(&OldIndex->rd_index->indpred)>VARHDRSZ)/* partial? */
324+
elog(ERROR,"CLUSTER: cannot cluster on partial index");
325+
if (!OldIndex->rd_am->amindexnulls)
326+
{
327+
AttrNumbercolno;
328+
329+
/*
330+
* If the AM doesn't index nulls, then it's a partial index unless
331+
* we can prove all the rows are non-null. Note we only need look
332+
* at the first column; multicolumn-capable AMs are *required* to
333+
* index nulls in columns after the first.
334+
*/
335+
if (OidIsValid(OldIndex->rd_index->indproc))
336+
elog(ERROR,"CLUSTER: cannot cluster on functional index when index access method does not handle nulls");
337+
colno=OldIndex->rd_index->indkey[0];
338+
if (colno>0)/* system columns are non-null */
339+
if (!OldHeap->rd_att->attrs[colno-1]->attnotnull)
340+
elog(ERROR,"CLUSTER: cannot cluster when index access method does not handle nulls"
341+
"\n\tYou may be able to work around this by marking column \"%s\" NOT NULL",
342+
NameStr(OldHeap->rd_att->attrs[colno-1]->attname));
343+
}
344+
316345
/*
317346
* Disallow clustering system relations. This will definitely NOT
318347
* work for shared relations (we have no way to update pg_class rows

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp