Remove some useless code
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 31 Dec 2018 17:40:33 +0000 (14:40 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 31 Dec 2018 17:50:48 +0000 (14:50 -0300)
In commit 8b08f7d4820f 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 e093dcdd285, 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.

src/backend/commands/indexcmds.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/outfuncs.c
src/backend/parser/gram.y
src/backend/parser/parse_utilcmd.c
src/include/nodes/parsenodes.h

index 62ec387486e0a3c12c648d2f2fff7aa429a431ca..816c73a36a5aa972cafae31218a2951c589133a2 100644 (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);
index db49968409688c6212e3f53ab86b36bdc6e13679..144cd7a047063f0e1e261a552b2d8d184ee220c9 100644 (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);
index 273e2756614caf8aaaf0e7e8c3d8279af4d9ddd9..c4579fbcc613899fb0678b4ba3610b105d69a733 100644 (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);
index be6b4ca2f4256c5cd367aa11cd2b336167fd29a3..2dd8ed3a46c064c53654a3af7553f7ca677c13e3 100644 (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);
index 2c2208ffb724d7f6864f8ad020bb128c253b3324..5bcaf42205e33d1e2680cc8c8a421830dac2d3a2 100644 (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;
index 807bb9bae21e6d3a26ae4a3d3665c5d9cb54b0a1..ce89e4e86522021cb18f93810379916e7562f03a 100644 (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);
index e5bdc1cec576d052f6ea436f24ccde802605c5fd..d3dd3d03395707ed0a0b6611a21d206205091342 100644 (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 */