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

Commit8ef9451

Browse files
committed
Refactor cluster.c to use new routine get_index_isclustered()
This new cache lookup routine has been introduced in a40caf5, and morecode paths can directly use it.Note that in cluster_rel(), the code was returning immediately if thetuple's entry in pg_index for the clustered index was not valid. Thiscommit changes the code so as a lookup error is raised instead,something that could not happen from the start as we check for theexistence of the index beforehand, while holding an exclusive lock onthe parent table.Author: Justin PryzbyReviewed-by: Álvaro Herrera, Michael PaquierDiscussion:https://postgr.es/m/20200202161718.GI13621@telsasoft.com
1 parent33e05f8 commit8ef9451

File tree

1 file changed

+3
-38
lines changed

1 file changed

+3
-38
lines changed

‎src/backend/commands/cluster.c

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,9 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
139139
/* We need to find the index that has indisclustered set. */
140140
foreach(index,RelationGetIndexList(rel))
141141
{
142-
HeapTupleidxtuple;
143-
Form_pg_indexindexForm;
144-
145142
indexOid=lfirst_oid(index);
146-
idxtuple=SearchSysCache1(INDEXRELID,
147-
ObjectIdGetDatum(indexOid));
148-
if (!HeapTupleIsValid(idxtuple))
149-
elog(ERROR,"cache lookup failed for index %u",indexOid);
150-
indexForm= (Form_pg_index)GETSTRUCT(idxtuple);
151-
if (indexForm->indisclustered)
152-
{
153-
ReleaseSysCache(idxtuple);
143+
if (get_index_isclustered(indexOid))
154144
break;
155-
}
156-
ReleaseSysCache(idxtuple);
157145
indexOid=InvalidOid;
158146
}
159147

@@ -304,9 +292,6 @@ cluster_rel(Oid tableOid, Oid indexOid, int options)
304292
*/
305293
if (recheck)
306294
{
307-
HeapTupletuple;
308-
Form_pg_indexindexForm;
309-
310295
/* Check that the user still owns the relation */
311296
if (!pg_class_ownercheck(tableOid,GetUserId()))
312297
{
@@ -345,22 +330,12 @@ cluster_rel(Oid tableOid, Oid indexOid, int options)
345330
/*
346331
* Check that the index is still the one with indisclustered set.
347332
*/
348-
tuple=SearchSysCache1(INDEXRELID,ObjectIdGetDatum(indexOid));
349-
if (!HeapTupleIsValid(tuple))/* probably can't happen */
350-
{
351-
relation_close(OldHeap,AccessExclusiveLock);
352-
pgstat_progress_end_command();
353-
return;
354-
}
355-
indexForm= (Form_pg_index)GETSTRUCT(tuple);
356-
if (!indexForm->indisclustered)
333+
if (!get_index_isclustered(indexOid))
357334
{
358-
ReleaseSysCache(tuple);
359335
relation_close(OldHeap,AccessExclusiveLock);
360336
pgstat_progress_end_command();
361337
return;
362338
}
363-
ReleaseSysCache(tuple);
364339
}
365340
}
366341

@@ -519,18 +494,8 @@ mark_index_clustered(Relation rel, Oid indexOid, bool is_internal)
519494
*/
520495
if (OidIsValid(indexOid))
521496
{
522-
indexTuple=SearchSysCache1(INDEXRELID,ObjectIdGetDatum(indexOid));
523-
if (!HeapTupleIsValid(indexTuple))
524-
elog(ERROR,"cache lookup failed for index %u",indexOid);
525-
indexForm= (Form_pg_index)GETSTRUCT(indexTuple);
526-
527-
if (indexForm->indisclustered)
528-
{
529-
ReleaseSysCache(indexTuple);
497+
if (get_index_isclustered(indexOid))
530498
return;
531-
}
532-
533-
ReleaseSysCache(indexTuple);
534499
}
535500

536501
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp