Skip to content

Commit 5f9e2af

Browse files
committed
Revert "TableAM: add relation_reindex"
This reverts commit f8103ed.
1 parent 69f7937 commit 5f9e2af

File tree

7 files changed

+28
-72
lines changed

7 files changed

+28
-72
lines changed

src/backend/access/heap/heapam_handler.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -982,12 +982,6 @@ heapam_relation_nontransactional_truncate(Relation rel)
982982
RelationTruncate(rel, 0);
983983
}
984984

985-
static bool
986-
heapam_relation_reindex(Relation rel, int flags, ReindexParams *params)
987-
{
988-
return reindex_relation(rel, flags, params);
989-
}
990-
991985
static void
992986
heapam_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
993987
{
@@ -2961,7 +2955,6 @@ static const TableAmRoutine heapam_methods = {
29612955

29622956
.relation_set_new_filelocator = heapam_relation_set_new_filelocator,
29632957
.relation_nontransactional_truncate = heapam_relation_nontransactional_truncate,
2964-
.relation_reindex = heapam_relation_reindex,
29652958
.relation_copy_data = heapam_relation_copy_data,
29662959
.relation_copy_for_cluster = heapam_relation_copy_for_cluster,
29672960
.relation_vacuum = heap_vacuum_rel,

src/backend/catalog/index.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3891,15 +3891,25 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
38913891
* index rebuild.
38923892
*/
38933893
bool
3894-
reindex_relation(Relation rel, int flags, ReindexParams *params)
3894+
reindex_relation(Oid relid, int flags, ReindexParams *params)
38953895
{
3896+
Relation rel;
38963897
Oid toast_relid;
38973898
List *indexIds;
38983899
char persistence;
38993900
bool result;
39003901
ListCell *indexId;
39013902
int i;
39023903

3904+
/*
3905+
* Open and lock the relation. ShareLock is sufficient since we only need
3906+
* to prevent schema and data changes in it. The lock level used here
3907+
* should match ReindexTable().
3908+
*/
3909+
if ((params->options & REINDEXOPT_MISSING_OK) != 0)
3910+
rel = try_table_open(relid, ShareLock);
3911+
else
3912+
rel = table_open(relid, ShareLock);
39033913

39043914
/* if relation is gone, leave */
39053915
if (!rel)
@@ -3991,6 +4001,11 @@ reindex_relation(Relation rel, int flags, ReindexParams *params)
39914001
i++;
39924002
}
39934003

4004+
/*
4005+
* Close rel, but continue to hold the lock.
4006+
*/
4007+
table_close(rel, NoLock);
4008+
39944009
result = (indexIds != NIL);
39954010

39964011
/*
@@ -4006,20 +4021,10 @@ reindex_relation(Relation rel, int flags, ReindexParams *params)
40064021
* This rule is enforced by setting tablespaceOid to InvalidOid.
40074022
*/
40084023
ReindexParams newparams = *params;
4009-
/*
4010-
* Open and lock the relation. ShareLock is sufficient since we only need
4011-
* to prevent schema and data changes in it. The lock level used here
4012-
* should match ReindexTable().
4013-
*/
4014-
Relation toast_rel = table_open(toast_relid, ShareLock);
40154024

40164025
newparams.options &= ~(REINDEXOPT_MISSING_OK);
40174026
newparams.tablespaceOid = InvalidOid;
4018-
result |= reindex_relation(toast_rel, flags, &newparams);
4019-
/*
4020-
* Close rel, but continue to hold the lock.
4021-
*/
4022-
table_close(toast_rel, NoLock);
4027+
result |= reindex_relation(toast_relid, flags, &newparams);
40234028
}
40244029

40254030
return result;

src/backend/commands/cluster.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,6 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
14621462
int reindex_flags;
14631463
ReindexParams reindex_params = {0};
14641464
int i;
1465-
Relation oldHeap;
14661465

14671466
/* Report that we are now swapping relation files */
14681467
pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE,
@@ -1518,19 +1517,8 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
15181517
/* Report that we are now reindexing relations */
15191518
pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE,
15201519
PROGRESS_CLUSTER_PHASE_REBUILD_INDEX);
1521-
/*
1522-
* Open and lock the relation. ShareLock is sufficient since we only need
1523-
* to prevent schema and data changes in it. The lock level used here
1524-
* should match ReindexTable().
1525-
*/
1526-
oldHeap = table_open(OIDOldHeap, ShareLock);
1527-
1528-
reindex_relation(oldHeap, reindex_flags, &reindex_params);
1529-
/*
1530-
* Close rel, but continue to hold the lock.
1531-
*/
1532-
table_close(oldHeap, NoLock);
15331520

1521+
reindex_relation(OIDOldHeap, reindex_flags, &reindex_params);
15341522

15351523
/* Report that we are now doing clean up */
15361524
pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE,

src/backend/commands/indexcmds.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,23 +2943,12 @@ ReindexTable(RangeVar *relation, ReindexParams *params, bool isTopLevel)
29432943
else
29442944
{
29452945
ReindexParams newparams = *params;
2946-
Relation rel;
29472946

29482947
newparams.options |= REINDEXOPT_REPORT_PROGRESS;
2949-
if ((newparams.options & REINDEXOPT_MISSING_OK) != 0)
2950-
rel = try_table_open(heapOid, ShareLock);
2951-
else
2952-
rel = table_open(heapOid, ShareLock);
2953-
2954-
result = table_relation_reindex(rel,
2955-
REINDEX_REL_PROCESS_TOAST |
2956-
REINDEX_REL_CHECK_CONSTRAINTS,
2957-
&newparams);
2958-
/*
2959-
* Close rel, but continue to hold the lock.
2960-
*/
2961-
table_close(rel, NoLock);
2962-
2948+
result = reindex_relation(heapOid,
2949+
REINDEX_REL_PROCESS_TOAST |
2950+
REINDEX_REL_CHECK_CONSTRAINTS,
2951+
&newparams);
29632952
if (!result)
29642953
ereport(NOTICE,
29652954
(errmsg("table \"%s\" has no indexes to reindex",
@@ -3387,24 +3376,13 @@ ReindexMultipleInternal(List *relids, ReindexParams *params)
33873376
{
33883377
bool result;
33893378
ReindexParams newparams = *params;
3390-
Relation rel;
33913379

33923380
newparams.options |=
33933381
REINDEXOPT_REPORT_PROGRESS | REINDEXOPT_MISSING_OK;
3394-
/*
3395-
* Open and lock the relation. ShareLock is sufficient since we only need
3396-
* to prevent schema and data changes in it. The lock level used here
3397-
* should match ReindexTable().
3398-
*/
3399-
rel = try_table_open(relid, ShareLock);
3400-
result = table_relation_reindex(rel,
3382+
result = reindex_relation(relid,
34013383
REINDEX_REL_PROCESS_TOAST |
34023384
REINDEX_REL_CHECK_CONSTRAINTS,
34033385
&newparams);
3404-
/*
3405-
* Close rel, but continue to hold the lock.
3406-
*/
3407-
table_close(rel, NoLock);
34083386

34093387
if (result && (params->options & REINDEXOPT_VERBOSE) != 0)
34103388
ereport(INFO,

src/backend/commands/tablecmds.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,7 @@ ExecuteTruncateGuts(List *explicit_rels,
20382038
}
20392039
else
20402040
{
2041+
Oid heap_relid;
20412042
Oid toast_relid;
20422043
ReindexParams reindex_params = {0};
20432044

@@ -2058,6 +2059,8 @@ ExecuteTruncateGuts(List *explicit_rels,
20582059
*/
20592060
RelationSetNewRelfilenumber(rel, rel->rd_rel->relpersistence);
20602061

2062+
heap_relid = RelationGetRelid(rel);
2063+
20612064
/*
20622065
* The same for the toast table, if any.
20632066
*/
@@ -2075,7 +2078,7 @@ ExecuteTruncateGuts(List *explicit_rels,
20752078
/*
20762079
* Reconstruct the indexes to match, and we're done.
20772080
*/
2078-
table_relation_reindex(rel, REINDEX_REL_PROCESS_TOAST,
2081+
reindex_relation(heap_relid, REINDEX_REL_PROCESS_TOAST,
20792082
&reindex_params);
20802083
}
20812084

src/include/access/tableam.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "utils/guc.h"
2828
#include "utils/rel.h"
2929
#include "utils/snapshot.h"
30-
#include "catalog/index.h"
3130

3231

3332
#define DEFAULT_TABLE_ACCESS_METHOD "heap"
@@ -640,9 +639,6 @@ typedef struct TableAmRoutine
640639
*/
641640
void (*relation_nontransactional_truncate) (Relation rel);
642641

643-
/* See reindex_relation for reference about parameters */
644-
bool (*relation_reindex) (Relation rel, int flags, ReindexParams *params);
645-
646642
/*
647643
* See table_relation_copy_data().
648644
*
@@ -1691,13 +1687,6 @@ table_relation_nontransactional_truncate(Relation rel)
16911687
rel->rd_tableam->relation_nontransactional_truncate(rel);
16921688
}
16931689

1694-
/* See reindex_relation for reference about parameters */
1695-
static inline bool
1696-
table_relation_reindex(Relation rel, int flags, ReindexParams *params)
1697-
{
1698-
return rel->rd_tableam->relation_reindex(rel, flags, params);
1699-
}
1700-
17011690
/*
17021691
* Copy data from `rel` into the new relfilelocator `newrlocator`. The new
17031692
* relfilelocator may not have storage associated before this function is

src/include/catalog/index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ extern void reindex_index(Oid indexId, bool skip_constraint_checks,
158158
#define REINDEX_REL_FORCE_INDEXES_UNLOGGED 0x08
159159
#define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10
160160

161-
extern bool reindex_relation(Relation rel, int flags, ReindexParams *params);
161+
extern bool reindex_relation(Oid relid, int flags, ReindexParams *params);
162162

163163
extern bool ReindexIsProcessingHeap(Oid heapOid);
164164
extern bool ReindexIsProcessingIndex(Oid indexOid);

0 commit comments

Comments
 (0)