Skip to content

Commit a2740a4

Browse files
committed
There, now we support GiST...now what? :)
1 parent fe87dbb commit a2740a4

File tree

24 files changed

+279
-99
lines changed

24 files changed

+279
-99
lines changed

src/backend/access/Makefile.inc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
#
88
#
99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/backend/access/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:08 scrappy Exp $
10+
# $Header: /cvsroot/pgsql/src/backend/access/Attic/Makefile.inc,v 1.2 1996/08/26 06:26:37 scrappy Exp $
1111
#
1212
#-------------------------------------------------------------------------
1313

1414
accdir=$(CURDIR)/access
1515
VPATH:=$(VPATH):$(accdir):\
16-
$(accdir)/common:$(accdir)/hash:$(accdir)/heap:$(accdir)/index:\
17-
$(accdir)/rtree:$(accdir)/nbtree:$(accdir)/transam
16+
$(accdir)/common:$(accdir)/gist:$(accdir)/hash:$(accdir)/heap:\
17+
$(accdir)/index:$(accdir)/rtree:$(accdir)/nbtree:$(accdir)/transam
1818

1919

2020
SUBSRCS=
2121
include $(accdir)/common/Makefile.inc
22+
include $(accdir)/gist/Makefile.inc
2223
include $(accdir)/hash/Makefile.inc
2324
include $(accdir)/heap/Makefile.inc
2425
include $(accdir)/index/Makefile.inc
@@ -27,7 +28,7 @@ include $(accdir)/nbtree/Makefile.inc
2728
include $(accdir)/transam/Makefile.inc
2829
SRCS_ACCESS:= $(SUBSRCS)
2930

30-
HEADERS+= attnum.h funcindex.h genam.h hash.h \
31+
HEADERS+= attnum.h funcindex.h genam.h gist.h hash.h \
3132
heapam.h hio.h htup.h ibit.h iqual.h istrat.h \
3233
itup.h nbtree.h printtup.h relscan.h rtree.h \
3334
sdir.h skey.h strat.h transam.h tupdesc.h tupmacs.h \

src/backend/access/genam.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: genam.h,v 1.1.1.1 1996/07/09 06:21:08 scrappy Exp $
9+
* $Id: genam.h,v 1.2 1996/08/26 06:26:40 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -32,7 +32,8 @@ extern Relation index_open(Oid relationId);
3232
extern Relation index_openr(char *relationName);
3333
extern void index_close(Relation relation);
3434
extern InsertIndexResult index_insert(Relation relation,
35-
IndexTuple indexTuple);
35+
Datum *datum, char *nulls,
36+
ItemPointer heap_t_ctid);
3637
extern void index_delete(Relation relation, ItemPointer indexItem);
3738
extern IndexScanDesc index_beginscan(Relation relation, bool scanFromEnd,
3839
uint16 numberOfKeys, ScanKey key);

src/backend/access/hash.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: hash.h,v 1.1.1.1 1996/07/09 06:21:08 scrappy Exp $
9+
* $Id: hash.h,v 1.2 1996/08/26 06:26:42 scrappy Exp $
1010
*
1111
* NOTES
1212
* modeled after Margo Seltzer's hash implementation for unix.
@@ -250,7 +250,8 @@ typedef HashItemData *HashItem;
250250
extern void hashbuild(Relation heap, Relation index, int natts,
251251
AttrNumber *attnum, IndexStrategy istrat, uint16 pcount,
252252
Datum *params, FuncIndexInfo *finfo, PredInfo *predInfo);
253-
extern InsertIndexResult hashinsert(Relation rel, IndexTuple itup);
253+
extern InsertIndexResult hashinsert(Relation rel, Datum *datum, char *nulls,
254+
ItemPointer ht_ctid);
254255
extern char *hashgettuple(IndexScanDesc scan, ScanDirection dir);
255256
extern char *hashbeginscan(Relation rel, bool fromEnd, uint16 keysz,
256257
ScanKey scankey);

src/backend/access/hash/hash.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.1.1.1 1996/07/09 06:21:10 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.2 1996/08/26 06:27:28 scrappy Exp $
1111
*
1212
* NOTES
1313
* This file contains only the public interface routines.
@@ -252,11 +252,17 @@ hashbuild(Relation heap,
252252
* to the caller.
253253
*/
254254
InsertIndexResult
255-
hashinsert(Relation rel, IndexTuple itup)
255+
hashinsert(Relation rel, Datum *datum, char *nulls, ItemPointer ht_ctid)
256256
{
257257
HashItem hitem;
258+
IndexTuple itup;
258259
InsertIndexResult res;
259260

261+
262+
/* generate an index tuple */
263+
itup = index_formtuple(RelationGetTupleDescriptor(rel), datum, nulls);
264+
itup->t_tid = *ht_ctid;
265+
260266
if (itup->t_info & INDEX_NULL_MASK)
261267
return ((InsertIndexResult) NULL);
262268

@@ -265,6 +271,7 @@ hashinsert(Relation rel, IndexTuple itup)
265271
res = _hash_doinsert(rel, hitem);
266272

267273
pfree(hitem);
274+
pfree(itup);
268275

269276
return (res);
270277
}

src/backend/access/index/indexam.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.1.1.1 1996/07/09 06:21:11 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.2 1996/08/26 06:27:48 scrappy Exp $
1111
*
1212
* INTERFACE ROUTINES
1313
* index_open - open an index relation by relationId
@@ -179,7 +179,9 @@ index_close(Relation relation)
179179
*/
180180
InsertIndexResult
181181
index_insert(Relation relation,
182-
IndexTuple indexTuple)
182+
Datum *datum,
183+
char *nulls,
184+
ItemPointer heap_t_ctid)
183185
{
184186
RegProcedure procedure;
185187
InsertIndexResult specificResult;
@@ -192,7 +194,7 @@ index_insert(Relation relation,
192194
* ----------------
193195
*/
194196
specificResult = (InsertIndexResult)
195-
fmgr(procedure, relation, indexTuple, NULL);
197+
fmgr(procedure, relation, datum, nulls, heap_t_ctid, NULL);
196198

197199
/* ----------------
198200
* the insert proc is supposed to return a "specific result" and

src/backend/access/nbtree.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: nbtree.h,v 1.2 1996/07/30 07:55:10 scrappy Exp $
9+
* $Id: nbtree.h,v 1.3 1996/08/26 06:26:44 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -201,7 +201,8 @@ extern bool BuildingBtree; /* in nbtree.c */
201201
extern void btbuild(Relation heap, Relation index, int natts,
202202
AttrNumber *attnum, IndexStrategy istrat, uint16 pcount,
203203
Datum *params, FuncIndexInfo *finfo, PredInfo *predInfo);
204-
extern InsertIndexResult btinsert(Relation rel, IndexTuple itup);
204+
extern InsertIndexResult btinsert(Relation rel, Datum *datum, char *nulls,
205+
ItemPointer ht_ctid);
205206
extern char *btgettuple(IndexScanDesc scan, ScanDirection dir);
206207
extern char *btbeginscan(Relation rel, bool fromEnd, uint16 keysz,
207208
ScanKey scankey);

src/backend/access/nbtree/nbtree.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.2 1996/07/30 07:56:00 scrappy Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.3 1996/08/26 06:28:21 scrappy Exp $
1212
*
1313
* NOTES
1414
* This file contains only the public interface routines.
@@ -285,18 +285,24 @@ btbuild(Relation heap,
285285
* return an InsertIndexResult to the caller.
286286
*/
287287
InsertIndexResult
288-
btinsert(Relation rel, IndexTuple itup)
288+
btinsert(Relation rel, Datum *datum, char *nulls, ItemPointer ht_ctid)
289289
{
290290
BTItem btitem;
291+
IndexTuple itup;
291292
InsertIndexResult res;
292293

294+
/* generate an index tuple */
295+
itup = index_formtuple(RelationGetTupleDescriptor(rel), datum, nulls);
296+
itup->t_tid = *ht_ctid;
297+
293298
if (itup->t_info & INDEX_NULL_MASK)
294299
return ((InsertIndexResult) NULL);
295300

296301
btitem = _bt_formitem(itup);
297302

298303
res = _bt_doinsert(rel, btitem);
299304
pfree(btitem);
305+
pfree(itup);
300306

301307
return (res);
302308
}

src/backend/access/rtree/rtree.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.1.1.1 1996/07/09 06:21:13 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.2 1996/08/26 06:29:10 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -273,11 +273,15 @@ rtbuild(Relation heap,
273273
* It doesn't do any work; just locks the relation and passes the buck.
274274
*/
275275
InsertIndexResult
276-
rtinsert(Relation r, IndexTuple itup)
276+
rtinsert(Relation r, Datum *datum, char *nulls, ItemPointer ht_ctid)
277277
{
278278
InsertIndexResult res;
279+
IndexTuple itup;
279280
RTSTATE rtState;
280281

282+
/* generate an index tuple */
283+
itup = index_formtuple(RelationGetTupleDescriptor(r), datum, nulls);
284+
itup->t_tid = *ht_ctid;
281285
initRtstate(&rtState, r);
282286

283287
RelationSetLockForWrite(r);

src/backend/catalog/index.c

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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,
8686
static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName);
8787
static TupleDesc BuildFuncTupleDesc(FuncIndexInfo *funcInfo);
8888
static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation,
89+
TypeName *IndexKeyType,
8990
int numatts, AttrNumber attNums[]);
9091

9192
static void ConstructIndexReldesc(Relation indexRelation, Oid amoid);
@@ -97,7 +98,8 @@ static void
9798
AppendAttributeTuples(Relation indexRelation, int numatts);
9899
static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
99100
FuncIndexInfo *funcInfo, int natts,
100-
AttrNumber attNums[], Oid classOids[], Node *predicate);
101+
AttrNumber attNums[], Oid classOids[], Node *predicate,
102+
TypeName *indexKeyType, bool islossy);
101103
static void DefaultBuild(Relation heapRelation, Relation indexRelation,
102104
int numberOfAttributes, AttrNumber attributeNumber[],
103105
IndexStrategy indexStrategy, uint16 parameterCount,
@@ -341,6 +343,7 @@ BuildFuncTupleDesc(FuncIndexInfo *funcInfo)
341343
static TupleDesc
342344
ConstructTupleDescriptor(Oid heapoid,
343345
Relation heapRelation,
346+
TypeName *IndexKeyType,
344347
int numatts,
345348
AttrNumber attNums[])
346349
{
@@ -424,7 +427,28 @@ ConstructTupleDescriptor(Oid heapoid,
424427

425428
to = (char *) (indexTupDesc->attrs[ i ]);
426429
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+
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,
734758
int natts,
735759
AttrNumber attNums[],
736760
Oid classOids[],
737-
Node *predicate)
761+
Node *predicate,
762+
TypeName *indexKeyType,
763+
bool islossy)
738764
{
739765
IndexTupleForm indexForm;
740766
char *predString;
@@ -770,6 +796,11 @@ UpdateIndexRelation(Oid indexoid,
770796
indexForm->indexrelid = indexoid;
771797
indexForm->indproc = (PointerIsValid(funcInfo)) ?
772798
FIgetProcOid(funcInfo) : InvalidOid;
799+
indexForm->indislossy = islossy;
800+
if (indexKeyType != NULL)
801+
indexForm->indhaskeytype = 1;
802+
else
803+
indexForm->indhaskeytype = 0;
773804

774805
memset((char *)& indexForm->indkey[0], 0, sizeof indexForm->indkey);
775806
memset((char *)& indexForm->indclass[0], 0, sizeof indexForm->indclass);
@@ -987,13 +1018,15 @@ void
9871018
index_create(char *heapRelationName,
9881019
char *indexRelationName,
9891020
FuncIndexInfo *funcInfo,
1021+
TypeName *IndexKeyType,
9901022
Oid accessMethodObjectId,
9911023
int numatts,
9921024
AttrNumber attNums[],
9931025
Oid classObjectId[],
9941026
uint16 parameterCount,
9951027
Datum *parameter,
996-
Node *predicate)
1028+
Node *predicate,
1029+
bool islossy)
9971030
{
9981031
Relation heapRelation;
9991032
Relation indexRelation;
@@ -1034,6 +1067,7 @@ index_create(char *heapRelationName,
10341067
else
10351068
indexTupDesc = ConstructTupleDescriptor(heapoid,
10361069
heapRelation,
1070+
IndexKeyType,
10371071
numatts,
10381072
attNums);
10391073

@@ -1105,7 +1139,8 @@ index_create(char *heapRelationName,
11051139
* ----------------
11061140
*/
11071141
UpdateIndexRelation(indexoid, heapoid, funcInfo,
1108-
numatts, attNums, classObjectId, predicate);
1142+
numatts, attNums, classObjectId, predicate,
1143+
IndexKeyType, islossy);
11091144

11101145
predInfo = (PredInfo*)palloc(sizeof(PredInfo));
11111146
predInfo->pred = predicate;
@@ -1568,7 +1603,8 @@ DefaultBuild(Relation heapRelation,
15681603

15691604
indexTuple->t_tid = heapTuple->t_ctid;
15701605

1571-
insertResult = index_insert(indexRelation, indexTuple);
1606+
insertResult = index_insert(indexRelation, datum, nullv,
1607+
&(heapTuple->t_ctid));
15721608

15731609
if (insertResult) pfree(insertResult);
15741610
pfree(indexTuple);

src/backend/catalog/index.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: index.h,v 1.2 1996/08/19 13:32:08 scrappy Exp $
9+
* $Id: index.h,v 1.3 1996/08/26 06:29:36 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -16,6 +16,7 @@
1616
#include "access/funcindex.h"
1717
#include "access/itup.h"
1818
#include "nodes/execnodes.h"
19+
#include "nodes/parsenodes.h"
1920

2021

2122
extern Form_pg_am
@@ -31,13 +32,15 @@ extern void InitIndexStrategy(int numatts,
3132
extern void index_create(char *heapRelationName,
3233
char* indexRelationName,
3334
FuncIndexInfo *funcInfo,
35+
TypeName *IndexKeyType,
3436
Oid accessMethodObjectId,
3537
int numatts,
3638
AttrNumber attNums[],
3739
Oid classObjectId[],
3840
uint16 parameterCount,
3941
Datum *parameter,
40-
Node *predicate);
42+
Node *predicate,
43+
bool islossy);
4144

4245
extern void index_destroy(Oid indexId);
4346

0 commit comments

Comments
 (0)