Remove some useless code

In commit 8b08f7d482 I added member relationId to IndexStmt struct.
I'm now not sure why; DefineIndex doesn't need it, since the relation
OID is passed as a separate argument anyway.  Remove it.

Also remove a redundant assignment to the relationId argument (it wasn't
redundant when added by commit e093dcdd28, but should have been removed
in commit 5f173040e3), and use relationId instead of stmt->relation when
locking the relation in the second phase of CREATE INDEX CONCURRENTLY,
which is not only confusing but it means we resolve the name twice for
no reason.
This commit is contained in:
Alvaro Herrera 2018-12-31 14:40:33 -03:00
parent b2edbbd02d
commit e439c6f0c3
7 changed files with 2 additions and 10 deletions

View File

@ -415,7 +415,6 @@ DefineIndex(Oid relationId,
lockmode = stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock;
rel = heap_open(relationId, lockmode);
relationId = RelationGetRelid(rel);
namespaceId = RelationGetNamespace(rel);
/* Ensure that it makes sense to index this kind of relation */
@ -1032,7 +1031,7 @@ DefineIndex(Oid relationId,
elog(ERROR, "cannot convert whole-row table reference");
childStmt->idxname = NULL;
childStmt->relationId = childRelid;
childStmt->relation = NULL;
DefineIndex(childRelid, childStmt,
InvalidOid, /* no predefined OID */
indexRelationId, /* this is our child */
@ -1154,7 +1153,7 @@ DefineIndex(Oid relationId,
*/
/* Open and lock the parent heap relation */
rel = heap_openrv(stmt->relation, ShareUpdateExclusiveLock);
rel = heap_open(relationId, ShareUpdateExclusiveLock);
/* And the target index relation */
indexRelation = index_open(indexRelationId, RowExclusiveLock);

View File

@ -3442,7 +3442,6 @@ _copyIndexStmt(const IndexStmt *from)
COPY_STRING_FIELD(idxname);
COPY_NODE_FIELD(relation);
COPY_SCALAR_FIELD(relationId);
COPY_STRING_FIELD(accessMethod);
COPY_STRING_FIELD(tableSpace);
COPY_NODE_FIELD(indexParams);

View File

@ -1325,7 +1325,6 @@ _equalIndexStmt(const IndexStmt *a, const IndexStmt *b)
{
COMPARE_STRING_FIELD(idxname);
COMPARE_NODE_FIELD(relation);
COMPARE_SCALAR_FIELD(relationId);
COMPARE_STRING_FIELD(accessMethod);
COMPARE_STRING_FIELD(tableSpace);
COMPARE_NODE_FIELD(indexParams);

View File

@ -2611,7 +2611,6 @@ _outIndexStmt(StringInfo str, const IndexStmt *node)
WRITE_STRING_FIELD(idxname);
WRITE_NODE_FIELD(relation);
WRITE_OID_FIELD(relationId);
WRITE_STRING_FIELD(accessMethod);
WRITE_STRING_FIELD(tableSpace);
WRITE_NODE_FIELD(indexParams);

View File

@ -7338,7 +7338,6 @@ IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
n->concurrent = $4;
n->idxname = $5;
n->relation = $7;
n->relationId = InvalidOid;
n->accessMethod = $8;
n->indexParams = $10;
n->indexIncludingParams = $12;
@ -7366,7 +7365,6 @@ IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
n->concurrent = $4;
n->idxname = $8;
n->relation = $10;
n->relationId = InvalidOid;
n->accessMethod = $11;
n->indexParams = $13;
n->indexIncludingParams = $15;

View File

@ -1313,7 +1313,6 @@ generateClonedIndexStmt(RangeVar *heapRel, Oid heapRelid, Relation source_idx,
/* Begin building the IndexStmt */
index = makeNode(IndexStmt);
index->relation = heapRel;
index->relationId = heapRelid;
index->accessMethod = pstrdup(NameStr(amrec->amname));
if (OidIsValid(idxrelrec->reltablespace))
index->tableSpace = get_tablespace_name(idxrelrec->reltablespace);

View File

@ -2726,7 +2726,6 @@ typedef struct IndexStmt
NodeTag type;
char *idxname; /* name of new index, or NULL for default */
RangeVar *relation; /* relation to build index on */
Oid relationId; /* OID of relation to build index on */
char *accessMethod; /* name of access method (eg. btree) */
char *tableSpace; /* tablespace, or NULL for default */
List *indexParams; /* columns to index: a list of IndexElem */