77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.2 1996/08/19 13:32:07 scrappy Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.3 1996/08/26 06:29:32 scrappy Exp $
1111 *
1212 *
1313 * INTERFACE ROUTINES
@@ -86,6 +86,7 @@ static Oid RelationNameGetObjectId(char *relationName, Relation pg_class,
8686static Oid GetHeapRelationOid (char * heapRelationName ,char * indexRelationName );
8787static TupleDesc BuildFuncTupleDesc (FuncIndexInfo * funcInfo );
8888static TupleDesc ConstructTupleDescriptor (Oid heapoid ,Relation heapRelation ,
89+ TypeName * IndexKeyType ,
8990int numatts ,AttrNumber attNums []);
9091
9192static void ConstructIndexReldesc (Relation indexRelation ,Oid amoid );
@@ -97,7 +98,8 @@ static void
9798AppendAttributeTuples (Relation indexRelation ,int numatts );
9899static void UpdateIndexRelation (Oid indexoid ,Oid heapoid ,
99100FuncIndexInfo * funcInfo ,int natts ,
100- AttrNumber attNums [],Oid classOids [],Node * predicate );
101+ AttrNumber attNums [],Oid classOids [],Node * predicate ,
102+ TypeName * indexKeyType ,bool islossy );
101103static void DefaultBuild (Relation heapRelation ,Relation indexRelation ,
102104int numberOfAttributes ,AttrNumber attributeNumber [],
103105IndexStrategy indexStrategy ,uint16 parameterCount ,
@@ -341,6 +343,7 @@ BuildFuncTupleDesc(FuncIndexInfo *funcInfo)
341343static TupleDesc
342344ConstructTupleDescriptor (Oid heapoid ,
343345Relation heapRelation ,
346+ TypeName * IndexKeyType ,
344347int numatts ,
345348AttrNumber attNums [])
346349{
@@ -424,7 +427,28 @@ ConstructTupleDescriptor(Oid heapoid,
424427
425428to = (char * ) (indexTupDesc -> attrs [i ]);
426429memcpy (to ,from ,ATTRIBUTE_TUPLE_SIZE );
427-
430+
431+ /* if the keytype is defined, we need to change the tuple form's
432+ atttypid & attlen field to match that of the key's type */
433+ if (IndexKeyType != NULL ) {
434+ HeapTuple tup ;
435+
436+ tup = SearchSysCacheTuple (TYPNAME ,
437+ PointerGetDatum (IndexKeyType -> name ),
438+ 0 ,0 ,0 );
439+ if (!HeapTupleIsValid (tup ))
440+ elog (WARN ,"create index: type '%s' undefined" ,
441+ IndexKeyType -> name );
442+ ((AttributeTupleForm )to )-> atttypid = tup -> t_oid ;
443+ ((AttributeTupleForm )to )-> attbyval =
444+ ((TypeTupleForm ) ((char * )tup + tup -> t_hoff ))-> typbyval ;
445+ if (IndexKeyType -> typlen > 0 )
446+ ((AttributeTupleForm )to )-> attlen = IndexKeyType -> typlen ;
447+ else ((AttributeTupleForm )to )-> attlen =
448+ ((TypeTupleForm ) ((char * )tup + tup -> t_hoff ))-> typlen ;
449+ }
450+
451+
428452/* ----------------
429453 * now we have to drop in the proper relation descriptor
430454 * into the copied tuple form's attrelid and we should be
@@ -734,7 +758,9 @@ UpdateIndexRelation(Oid indexoid,
734758int natts ,
735759AttrNumber attNums [],
736760Oid classOids [],
737- Node * predicate )
761+ Node * predicate ,
762+ TypeName * indexKeyType ,
763+ bool islossy )
738764{
739765IndexTupleForm indexForm ;
740766char * predString ;
@@ -770,6 +796,11 @@ UpdateIndexRelation(Oid indexoid,
770796indexForm -> indexrelid = indexoid ;
771797indexForm -> indproc = (PointerIsValid (funcInfo )) ?
772798FIgetProcOid (funcInfo ) :InvalidOid ;
799+ indexForm -> indislossy = islossy ;
800+ if (indexKeyType != NULL )
801+ indexForm -> indhaskeytype = 1 ;
802+ else
803+ indexForm -> indhaskeytype = 0 ;
773804
774805memset ((char * )& indexForm -> indkey [0 ],0 ,sizeof indexForm -> indkey );
775806memset ((char * )& indexForm -> indclass [0 ],0 ,sizeof indexForm -> indclass );
@@ -987,13 +1018,15 @@ void
9871018index_create (char * heapRelationName ,
9881019char * indexRelationName ,
9891020FuncIndexInfo * funcInfo ,
1021+ TypeName * IndexKeyType ,
9901022Oid accessMethodObjectId ,
9911023int numatts ,
9921024AttrNumber attNums [],
9931025Oid classObjectId [],
9941026uint16 parameterCount ,
9951027Datum * parameter ,
996- Node * predicate )
1028+ Node * predicate ,
1029+ bool islossy )
9971030{
9981031Relation heapRelation ;
9991032Relation indexRelation ;
@@ -1034,6 +1067,7 @@ index_create(char *heapRelationName,
10341067else
10351068indexTupDesc = ConstructTupleDescriptor (heapoid ,
10361069heapRelation ,
1070+ IndexKeyType ,
10371071numatts ,
10381072attNums );
10391073
@@ -1105,7 +1139,8 @@ index_create(char *heapRelationName,
11051139 * ----------------
11061140 */
11071141UpdateIndexRelation (indexoid ,heapoid ,funcInfo ,
1108- numatts ,attNums ,classObjectId ,predicate );
1142+ numatts ,attNums ,classObjectId ,predicate ,
1143+ IndexKeyType ,islossy );
11091144
11101145predInfo = (PredInfo * )palloc (sizeof (PredInfo ));
11111146predInfo -> pred = predicate ;
@@ -1568,7 +1603,8 @@ DefaultBuild(Relation heapRelation,
15681603
15691604indexTuple -> t_tid = heapTuple -> t_ctid ;
15701605
1571- insertResult = index_insert (indexRelation ,indexTuple );
1606+ insertResult = index_insert (indexRelation ,datum ,nullv ,
1607+ & (heapTuple -> t_ctid ));
15721608
15731609if (insertResult )pfree (insertResult );
15741610pfree (indexTuple );