7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*
13
13
* INTERFACE ROUTINES
@@ -86,6 +86,7 @@ static Oid RelationNameGetObjectId(char *relationName, Relation pg_class,
86
86
static Oid GetHeapRelationOid (char * heapRelationName ,char * indexRelationName );
87
87
static TupleDesc BuildFuncTupleDesc (FuncIndexInfo * funcInfo );
88
88
static TupleDesc ConstructTupleDescriptor (Oid heapoid ,Relation heapRelation ,
89
+ TypeName * IndexKeyType ,
89
90
int numatts ,AttrNumber attNums []);
90
91
91
92
static void ConstructIndexReldesc (Relation indexRelation ,Oid amoid );
@@ -97,7 +98,8 @@ static void
97
98
AppendAttributeTuples (Relation indexRelation ,int numatts );
98
99
static void UpdateIndexRelation (Oid indexoid ,Oid heapoid ,
99
100
FuncIndexInfo * funcInfo ,int natts ,
100
- AttrNumber attNums [],Oid classOids [],Node * predicate );
101
+ AttrNumber attNums [],Oid classOids [],Node * predicate ,
102
+ TypeName * indexKeyType ,bool islossy );
101
103
static void DefaultBuild (Relation heapRelation ,Relation indexRelation ,
102
104
int numberOfAttributes ,AttrNumber attributeNumber [],
103
105
IndexStrategy indexStrategy ,uint16 parameterCount ,
@@ -341,6 +343,7 @@ BuildFuncTupleDesc(FuncIndexInfo *funcInfo)
341
343
static TupleDesc
342
344
ConstructTupleDescriptor (Oid heapoid ,
343
345
Relation heapRelation ,
346
+ TypeName * IndexKeyType ,
344
347
int numatts ,
345
348
AttrNumber attNums [])
346
349
{
@@ -424,7 +427,28 @@ ConstructTupleDescriptor(Oid heapoid,
424
427
425
428
to = (char * ) (indexTupDesc -> attrs [i ]);
426
429
memcpy (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
+
428
452
/* ----------------
429
453
* now we have to drop in the proper relation descriptor
430
454
* into the copied tuple form's attrelid and we should be
@@ -734,7 +758,9 @@ UpdateIndexRelation(Oid indexoid,
734
758
int natts ,
735
759
AttrNumber attNums [],
736
760
Oid classOids [],
737
- Node * predicate )
761
+ Node * predicate ,
762
+ TypeName * indexKeyType ,
763
+ bool islossy )
738
764
{
739
765
IndexTupleForm indexForm ;
740
766
char * predString ;
@@ -770,6 +796,11 @@ UpdateIndexRelation(Oid indexoid,
770
796
indexForm -> indexrelid = indexoid ;
771
797
indexForm -> indproc = (PointerIsValid (funcInfo )) ?
772
798
FIgetProcOid (funcInfo ) :InvalidOid ;
799
+ indexForm -> indislossy = islossy ;
800
+ if (indexKeyType != NULL )
801
+ indexForm -> indhaskeytype = 1 ;
802
+ else
803
+ indexForm -> indhaskeytype = 0 ;
773
804
774
805
memset ((char * )& indexForm -> indkey [0 ],0 ,sizeof indexForm -> indkey );
775
806
memset ((char * )& indexForm -> indclass [0 ],0 ,sizeof indexForm -> indclass );
@@ -987,13 +1018,15 @@ void
987
1018
index_create (char * heapRelationName ,
988
1019
char * indexRelationName ,
989
1020
FuncIndexInfo * funcInfo ,
1021
+ TypeName * IndexKeyType ,
990
1022
Oid accessMethodObjectId ,
991
1023
int numatts ,
992
1024
AttrNumber attNums [],
993
1025
Oid classObjectId [],
994
1026
uint16 parameterCount ,
995
1027
Datum * parameter ,
996
- Node * predicate )
1028
+ Node * predicate ,
1029
+ bool islossy )
997
1030
{
998
1031
Relation heapRelation ;
999
1032
Relation indexRelation ;
@@ -1034,6 +1067,7 @@ index_create(char *heapRelationName,
1034
1067
else
1035
1068
indexTupDesc = ConstructTupleDescriptor (heapoid ,
1036
1069
heapRelation ,
1070
+ IndexKeyType ,
1037
1071
numatts ,
1038
1072
attNums );
1039
1073
@@ -1105,7 +1139,8 @@ index_create(char *heapRelationName,
1105
1139
* ----------------
1106
1140
*/
1107
1141
UpdateIndexRelation (indexoid ,heapoid ,funcInfo ,
1108
- numatts ,attNums ,classObjectId ,predicate );
1142
+ numatts ,attNums ,classObjectId ,predicate ,
1143
+ IndexKeyType ,islossy );
1109
1144
1110
1145
predInfo = (PredInfo * )palloc (sizeof (PredInfo ));
1111
1146
predInfo -> pred = predicate ;
@@ -1568,7 +1603,8 @@ DefaultBuild(Relation heapRelation,
1568
1603
1569
1604
indexTuple -> t_tid = heapTuple -> t_ctid ;
1570
1605
1571
- insertResult = index_insert (indexRelation ,indexTuple );
1606
+ insertResult = index_insert (indexRelation ,datum ,nullv ,
1607
+ & (heapTuple -> t_ctid ));
1572
1608
1573
1609
if (insertResult )pfree (insertResult );
1574
1610
pfree (indexTuple );