Re: More refactoring for BuildIndexInfo

2019-08-03 Thread Michael Paquier
On Thu, Aug 01, 2019 at 01:13:22PM +0900, Michael Paquier wrote:
> Any thoughts or objections?

Hearing nothing, done.
--
Michael


signature.asc
Description: PGP signature


More refactoring for BuildIndexInfo

2019-07-31 Thread Michael Paquier
Hi all,

7cce1593 has introduced a new routine makeIndexInfo to create
IndexInfo nodes.  It happens that we can do a bit more refactoring as
per the attached, as BuildIndexInfo can make use of this routine,
removing some duplication on the way (filling in IndexInfo was still
duplicated in a couple of places before 7cce159).

Any thoughts or objections?
--
Michael
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 99ae159f98..5753870158 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -2229,7 +2229,7 @@ index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
 IndexInfo *
 BuildIndexInfo(Relation index)
 {
-	IndexInfo  *ii = makeNode(IndexInfo);
+	IndexInfo  *ii;
 	Form_pg_index indexStruct = index->rd_index;
 	int			i;
 	int			numAtts;
@@ -2239,22 +2239,20 @@ BuildIndexInfo(Relation index)
 	if (numAtts < 1 || numAtts > INDEX_MAX_KEYS)
 		elog(ERROR, "invalid indnatts %d for index %u",
 			 numAtts, RelationGetRelid(index));
-	ii->ii_NumIndexAttrs = numAtts;
-	ii->ii_NumIndexKeyAttrs = indexStruct->indnkeyatts;
-	Assert(ii->ii_NumIndexKeyAttrs != 0);
-	Assert(ii->ii_NumIndexKeyAttrs <= ii->ii_NumIndexAttrs);
 
+	ii = makeIndexInfo(indexStruct->indnatts,
+	   indexStruct->indnkeyatts,
+	   index->rd_rel->relam,
+	   RelationGetIndexExpressions(index),
+	   RelationGetIndexPredicate(index),
+	   indexStruct->indisunique,
+	   indexStruct->indisready,
+	   false);
+
+	/* fill in attribute numbers */
 	for (i = 0; i < numAtts; i++)
 		ii->ii_IndexAttrNumbers[i] = indexStruct->indkey.values[i];
 
-	/* fetch any expressions needed for expressional indexes */
-	ii->ii_Expressions = RelationGetIndexExpressions(index);
-	ii->ii_ExpressionsState = NIL;
-
-	/* fetch index predicate if any */
-	ii->ii_Predicate = RelationGetIndexPredicate(index);
-	ii->ii_PredicateState = NULL;
-
 	/* fetch exclusion constraint info if any */
 	if (indexStruct->indisexclusion)
 	{
@@ -2263,30 +2261,6 @@ BuildIndexInfo(Relation index)
  >ii_ExclusionProcs,
  >ii_ExclusionStrats);
 	}
-	else
-	{
-		ii->ii_ExclusionOps = NULL;
-		ii->ii_ExclusionProcs = NULL;
-		ii->ii_ExclusionStrats = NULL;
-	}
-
-	/* other info */
-	ii->ii_Unique = indexStruct->indisunique;
-	ii->ii_ReadyForInserts = indexStruct->indisready;
-	/* assume not doing speculative insertion for now */
-	ii->ii_UniqueOps = NULL;
-	ii->ii_UniqueProcs = NULL;
-	ii->ii_UniqueStrats = NULL;
-
-	/* initialize index-build state to default */
-	ii->ii_Concurrent = false;
-	ii->ii_BrokenHotChain = false;
-	ii->ii_ParallelWorkers = 0;
-
-	/* set up for possible use by index AM */
-	ii->ii_Am = index->rd_rel->relam;
-	ii->ii_AmCache = NULL;
-	ii->ii_Context = CurrentMemoryContext;
 
 	return ii;
 }


signature.asc
Description: PGP signature