From: Marc G. Fournier Date: Mon, 26 Aug 1996 06:32:06 +0000 (+0000) Subject: There, now we support GiST...now what? :) X-Git-Tag: REL2_0~623 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2740a455f558a1b8b9cd1962f92980efa4a984a;p=postgresql There, now we support GiST...now what? :) --- diff --git a/src/backend/access/Makefile.inc b/src/backend/access/Makefile.inc index 6adc2c692b..eeff8b43be 100644 --- a/src/backend/access/Makefile.inc +++ b/src/backend/access/Makefile.inc @@ -7,18 +7,19 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/backend/access/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:08 scrappy Exp $ +# $Header: /cvsroot/pgsql/src/backend/access/Attic/Makefile.inc,v 1.2 1996/08/26 06:26:37 scrappy Exp $ # #------------------------------------------------------------------------- accdir=$(CURDIR)/access VPATH:=$(VPATH):$(accdir):\ - $(accdir)/common:$(accdir)/hash:$(accdir)/heap:$(accdir)/index:\ - $(accdir)/rtree:$(accdir)/nbtree:$(accdir)/transam + $(accdir)/common:$(accdir)/gist:$(accdir)/hash:$(accdir)/heap:\ + $(accdir)/index:$(accdir)/rtree:$(accdir)/nbtree:$(accdir)/transam SUBSRCS= include $(accdir)/common/Makefile.inc +include $(accdir)/gist/Makefile.inc include $(accdir)/hash/Makefile.inc include $(accdir)/heap/Makefile.inc include $(accdir)/index/Makefile.inc @@ -27,7 +28,7 @@ include $(accdir)/nbtree/Makefile.inc include $(accdir)/transam/Makefile.inc SRCS_ACCESS:= $(SUBSRCS) -HEADERS+= attnum.h funcindex.h genam.h hash.h \ +HEADERS+= attnum.h funcindex.h genam.h gist.h hash.h \ heapam.h hio.h htup.h ibit.h iqual.h istrat.h \ itup.h nbtree.h printtup.h relscan.h rtree.h \ sdir.h skey.h strat.h transam.h tupdesc.h tupmacs.h \ diff --git a/src/backend/access/genam.h b/src/backend/access/genam.h index b2544650de..8b2ac52e73 100644 --- a/src/backend/access/genam.h +++ b/src/backend/access/genam.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: genam.h,v 1.1.1.1 1996/07/09 06:21:08 scrappy Exp $ + * $Id: genam.h,v 1.2 1996/08/26 06:26:40 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -32,7 +32,8 @@ extern Relation index_open(Oid relationId); extern Relation index_openr(char *relationName); extern void index_close(Relation relation); extern InsertIndexResult index_insert(Relation relation, - IndexTuple indexTuple); + Datum *datum, char *nulls, + ItemPointer heap_t_ctid); extern void index_delete(Relation relation, ItemPointer indexItem); extern IndexScanDesc index_beginscan(Relation relation, bool scanFromEnd, uint16 numberOfKeys, ScanKey key); diff --git a/src/backend/access/hash.h b/src/backend/access/hash.h index 21407696b4..461e7232e6 100644 --- a/src/backend/access/hash.h +++ b/src/backend/access/hash.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: hash.h,v 1.1.1.1 1996/07/09 06:21:08 scrappy Exp $ + * $Id: hash.h,v 1.2 1996/08/26 06:26:42 scrappy Exp $ * * NOTES * modeled after Margo Seltzer's hash implementation for unix. @@ -250,7 +250,8 @@ typedef HashItemData *HashItem; extern void hashbuild(Relation heap, Relation index, int natts, AttrNumber *attnum, IndexStrategy istrat, uint16 pcount, Datum *params, FuncIndexInfo *finfo, PredInfo *predInfo); -extern InsertIndexResult hashinsert(Relation rel, IndexTuple itup); +extern InsertIndexResult hashinsert(Relation rel, Datum *datum, char *nulls, + ItemPointer ht_ctid); extern char *hashgettuple(IndexScanDesc scan, ScanDirection dir); extern char *hashbeginscan(Relation rel, bool fromEnd, uint16 keysz, ScanKey scankey); diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c index a4a4e16e59..bd3b8cd73c 100644 --- a/src/backend/access/hash/hash.c +++ b/src/backend/access/hash/hash.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.1.1.1 1996/07/09 06:21:10 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.2 1996/08/26 06:27:28 scrappy Exp $ * * NOTES * This file contains only the public interface routines. @@ -252,11 +252,17 @@ hashbuild(Relation heap, * to the caller. */ InsertIndexResult -hashinsert(Relation rel, IndexTuple itup) +hashinsert(Relation rel, Datum *datum, char *nulls, ItemPointer ht_ctid) { HashItem hitem; + IndexTuple itup; InsertIndexResult res; + + /* generate an index tuple */ + itup = index_formtuple(RelationGetTupleDescriptor(rel), datum, nulls); + itup->t_tid = *ht_ctid; + if (itup->t_info & INDEX_NULL_MASK) return ((InsertIndexResult) NULL); @@ -265,6 +271,7 @@ hashinsert(Relation rel, IndexTuple itup) res = _hash_doinsert(rel, hitem); pfree(hitem); + pfree(itup); return (res); } diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c index bffe3a41f3..32e4201119 100644 --- a/src/backend/access/index/indexam.c +++ b/src/backend/access/index/indexam.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.1.1.1 1996/07/09 06:21:11 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.2 1996/08/26 06:27:48 scrappy Exp $ * * INTERFACE ROUTINES * index_open - open an index relation by relationId @@ -179,7 +179,9 @@ index_close(Relation relation) */ InsertIndexResult index_insert(Relation relation, - IndexTuple indexTuple) + Datum *datum, + char *nulls, + ItemPointer heap_t_ctid) { RegProcedure procedure; InsertIndexResult specificResult; @@ -192,7 +194,7 @@ index_insert(Relation relation, * ---------------- */ specificResult = (InsertIndexResult) - fmgr(procedure, relation, indexTuple, NULL); + fmgr(procedure, relation, datum, nulls, heap_t_ctid, NULL); /* ---------------- * the insert proc is supposed to return a "specific result" and diff --git a/src/backend/access/nbtree.h b/src/backend/access/nbtree.h index 051fb8f6eb..4dfcf3dbae 100644 --- a/src/backend/access/nbtree.h +++ b/src/backend/access/nbtree.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: nbtree.h,v 1.2 1996/07/30 07:55:10 scrappy Exp $ + * $Id: nbtree.h,v 1.3 1996/08/26 06:26:44 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -201,7 +201,8 @@ extern bool BuildingBtree; /* in nbtree.c */ extern void btbuild(Relation heap, Relation index, int natts, AttrNumber *attnum, IndexStrategy istrat, uint16 pcount, Datum *params, FuncIndexInfo *finfo, PredInfo *predInfo); -extern InsertIndexResult btinsert(Relation rel, IndexTuple itup); +extern InsertIndexResult btinsert(Relation rel, Datum *datum, char *nulls, + ItemPointer ht_ctid); extern char *btgettuple(IndexScanDesc scan, ScanDirection dir); extern char *btbeginscan(Relation rel, bool fromEnd, uint16 keysz, ScanKey scankey); diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c index 5829e8afe0..90afe6b363 100644 --- a/src/backend/access/nbtree/nbtree.c +++ b/src/backend/access/nbtree/nbtree.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.2 1996/07/30 07:56:00 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.3 1996/08/26 06:28:21 scrappy Exp $ * * NOTES * This file contains only the public interface routines. @@ -285,11 +285,16 @@ btbuild(Relation heap, * return an InsertIndexResult to the caller. */ InsertIndexResult -btinsert(Relation rel, IndexTuple itup) +btinsert(Relation rel, Datum *datum, char *nulls, ItemPointer ht_ctid) { BTItem btitem; + IndexTuple itup; InsertIndexResult res; + /* generate an index tuple */ + itup = index_formtuple(RelationGetTupleDescriptor(rel), datum, nulls); + itup->t_tid = *ht_ctid; + if (itup->t_info & INDEX_NULL_MASK) return ((InsertIndexResult) NULL); @@ -297,6 +302,7 @@ btinsert(Relation rel, IndexTuple itup) res = _bt_doinsert(rel, btitem); pfree(btitem); + pfree(itup); return (res); } diff --git a/src/backend/access/rtree/rtree.c b/src/backend/access/rtree/rtree.c index 96efc3bc90..1edec246bc 100644 --- a/src/backend/access/rtree/rtree.c +++ b/src/backend/access/rtree/rtree.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.1.1.1 1996/07/09 06:21:13 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.2 1996/08/26 06:29:10 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -273,11 +273,15 @@ rtbuild(Relation heap, * It doesn't do any work; just locks the relation and passes the buck. */ InsertIndexResult -rtinsert(Relation r, IndexTuple itup) +rtinsert(Relation r, Datum *datum, char *nulls, ItemPointer ht_ctid) { InsertIndexResult res; + IndexTuple itup; RTSTATE rtState; + /* generate an index tuple */ + itup = index_formtuple(RelationGetTupleDescriptor(r), datum, nulls); + itup->t_tid = *ht_ctid; initRtstate(&rtState, r); RelationSetLockForWrite(r); diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index d950ee8680..2400ad0d14 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.2 1996/08/19 13:32:07 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.3 1996/08/26 06:29:32 scrappy Exp $ * * * INTERFACE ROUTINES @@ -86,6 +86,7 @@ static Oid RelationNameGetObjectId(char *relationName, Relation pg_class, static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName); static TupleDesc BuildFuncTupleDesc(FuncIndexInfo *funcInfo); static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation, + TypeName *IndexKeyType, int numatts, AttrNumber attNums[]); static void ConstructIndexReldesc(Relation indexRelation, Oid amoid); @@ -97,7 +98,8 @@ static void AppendAttributeTuples(Relation indexRelation, int numatts); static void UpdateIndexRelation(Oid indexoid, Oid heapoid, FuncIndexInfo *funcInfo, int natts, - AttrNumber attNums[], Oid classOids[], Node *predicate); + AttrNumber attNums[], Oid classOids[], Node *predicate, + TypeName *indexKeyType, bool islossy); static void DefaultBuild(Relation heapRelation, Relation indexRelation, int numberOfAttributes, AttrNumber attributeNumber[], IndexStrategy indexStrategy, uint16 parameterCount, @@ -341,6 +343,7 @@ BuildFuncTupleDesc(FuncIndexInfo *funcInfo) static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation, + TypeName *IndexKeyType, int numatts, AttrNumber attNums[]) { @@ -424,7 +427,28 @@ ConstructTupleDescriptor(Oid heapoid, to = (char *) (indexTupDesc->attrs[ i ]); memcpy(to, from, ATTRIBUTE_TUPLE_SIZE); - + + /* if the keytype is defined, we need to change the tuple form's + atttypid & attlen field to match that of the key's type */ + if (IndexKeyType != NULL) { + HeapTuple tup; + + tup = SearchSysCacheTuple(TYPNAME, + PointerGetDatum(IndexKeyType->name), + 0,0,0); + if(!HeapTupleIsValid(tup)) + elog(WARN, "create index: type '%s' undefined", + IndexKeyType->name); + ((AttributeTupleForm) to)->atttypid = tup->t_oid; + ((AttributeTupleForm) to)->attbyval = + ((TypeTupleForm) ((char *)tup + tup->t_hoff))->typbyval; + if (IndexKeyType->typlen > 0) + ((AttributeTupleForm) to)->attlen = IndexKeyType->typlen; + else ((AttributeTupleForm) to)->attlen = + ((TypeTupleForm) ((char *)tup + tup->t_hoff))->typlen; + } + + /* ---------------- * now we have to drop in the proper relation descriptor * into the copied tuple form's attrelid and we should be @@ -734,7 +758,9 @@ UpdateIndexRelation(Oid indexoid, int natts, AttrNumber attNums[], Oid classOids[], - Node *predicate) + Node *predicate, + TypeName *indexKeyType, + bool islossy) { IndexTupleForm indexForm; char *predString; @@ -770,6 +796,11 @@ UpdateIndexRelation(Oid indexoid, indexForm->indexrelid = indexoid; indexForm->indproc = (PointerIsValid(funcInfo)) ? FIgetProcOid(funcInfo) : InvalidOid; + indexForm->indislossy = islossy; + if (indexKeyType != NULL) + indexForm->indhaskeytype = 1; + else + indexForm->indhaskeytype = 0; memset((char *)& indexForm->indkey[0], 0, sizeof indexForm->indkey); memset((char *)& indexForm->indclass[0], 0, sizeof indexForm->indclass); @@ -987,13 +1018,15 @@ void index_create(char *heapRelationName, char *indexRelationName, FuncIndexInfo *funcInfo, + TypeName *IndexKeyType, Oid accessMethodObjectId, int numatts, AttrNumber attNums[], Oid classObjectId[], uint16 parameterCount, Datum *parameter, - Node *predicate) + Node *predicate, + bool islossy) { Relation heapRelation; Relation indexRelation; @@ -1034,6 +1067,7 @@ index_create(char *heapRelationName, else indexTupDesc = ConstructTupleDescriptor(heapoid, heapRelation, + IndexKeyType, numatts, attNums); @@ -1105,7 +1139,8 @@ index_create(char *heapRelationName, * ---------------- */ UpdateIndexRelation(indexoid, heapoid, funcInfo, - numatts, attNums, classObjectId, predicate); + numatts, attNums, classObjectId, predicate, + IndexKeyType, islossy); predInfo = (PredInfo*)palloc(sizeof(PredInfo)); predInfo->pred = predicate; @@ -1568,7 +1603,8 @@ DefaultBuild(Relation heapRelation, indexTuple->t_tid = heapTuple->t_ctid; - insertResult = index_insert(indexRelation, indexTuple); + insertResult = index_insert(indexRelation, datum, nullv, + &(heapTuple->t_ctid)); if (insertResult) pfree(insertResult); pfree(indexTuple); diff --git a/src/backend/catalog/index.h b/src/backend/catalog/index.h index ef211ab951..3aba53b6a9 100644 --- a/src/backend/catalog/index.h +++ b/src/backend/catalog/index.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: index.h,v 1.2 1996/08/19 13:32:08 scrappy Exp $ + * $Id: index.h,v 1.3 1996/08/26 06:29:36 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -16,6 +16,7 @@ #include "access/funcindex.h" #include "access/itup.h" #include "nodes/execnodes.h" +#include "nodes/parsenodes.h" extern Form_pg_am @@ -31,13 +32,15 @@ extern void InitIndexStrategy(int numatts, extern void index_create(char *heapRelationName, char* indexRelationName, FuncIndexInfo *funcInfo, + TypeName *IndexKeyType, Oid accessMethodObjectId, int numatts, AttrNumber attNums[], Oid classObjectId[], uint16 parameterCount, Datum *parameter, - Node *predicate); + Node *predicate, + bool islossy); extern void index_destroy(Oid indexId); diff --git a/src/backend/catalog/indexing.c b/src/backend/catalog/indexing.c index 74bf48a443..52fb9a68c0 100644 --- a/src/backend/catalog/indexing.c +++ b/src/backend/catalog/indexing.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.1.1.1 1996/07/09 06:21:15 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.2 1996/08/26 06:29:38 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -193,16 +193,8 @@ CatalogIndexInsert(Relation *idescs, nulls, finfoP); - newIndxTup = (IndexTuple)index_formtuple(indexDescriptor, - &datum,nulls); - Assert(newIndxTup); - /* - * Doing this structure assignment makes me quake in my boots when I - * think about portability. - */ - newIndxTup->t_tid = heapTuple->t_ctid; - - indexRes = index_insert(idescs[i], newIndxTup); + indexRes = index_insert(idescs[i], &datum, nulls, + &(heapTuple->t_ctid)); if (indexRes) pfree(indexRes); } } diff --git a/src/backend/catalog/pg_am.h b/src/backend/catalog/pg_am.h index 0f36e7c433..89331a09b8 100644 --- a/src/backend/catalog/pg_am.h +++ b/src/backend/catalog/pg_am.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_am.h,v 1.1.1.1 1996/07/09 06:21:16 scrappy Exp $ + * $Id: pg_am.h,v 1.2 1996/08/26 06:29:40 scrappy Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -103,6 +103,7 @@ DATA(insert OID = 405 ( hash PGUID "o" 1 1 hashgettuple hashinsert hashdelete DATA(insert OID = 402 ( rtree PGUID "o" 8 3 rtgettuple rtinsert rtdelete - - - - rtbeginscan rtrescan rtendscan rtmarkpos rtrestrpos - - rtbuild - - )); DATA(insert OID = 403 ( btree PGUID "o" 5 1 btgettuple btinsert btdelete - - - - btbeginscan btrescan btendscan btmarkpos btrestrpos - - btbuild - - )); #define BTREE_AM_OID 403 +DATA(insert OID = 783 ( gist PGUID "o" 100 7 gistgettuple gistinsert gistdelete - - - - gistbeginscan gistrescan gistendscan gistmarkpos gistrestrpos - - gistbuild - - )); BKI_BEGIN #ifdef NOBTREE diff --git a/src/backend/catalog/pg_index.h b/src/backend/catalog/pg_index.h index da75b025bc..e99b5682f0 100644 --- a/src/backend/catalog/pg_index.h +++ b/src/backend/catalog/pg_index.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_index.h,v 1.1.1.1 1996/07/09 06:21:17 scrappy Exp $ + * $Id: pg_index.h,v 1.2 1996/08/26 06:29:43 scrappy Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -42,6 +42,8 @@ CATALOG(pg_index) { bool indisclustered; bool indisarchived; text indpred; /* query plan for partial index predicate */ + bool indislossy; /* do we fetch false tuples (lossy compression)? */ + bool indhaskeytype; /* does key type != attribute type? */ } FormData_pg_index; #define INDEX_MAX_KEYS 8 /* maximum number of keys in an index definition */ @@ -57,7 +59,7 @@ typedef FormData_pg_index *IndexTupleForm; * compiler constants for pg_index * ---------------- */ -#define Natts_pg_index 8 +#define Natts_pg_index 10 #define Anum_pg_index_indexrelid 1 #define Anum_pg_index_indrelid 2 #define Anum_pg_index_indproc 3 @@ -66,6 +68,8 @@ typedef FormData_pg_index *IndexTupleForm; #define Anum_pg_index_indisclustered 6 #define Anum_pg_index_indisarchived 7 #define Anum_pg_index_indpred 8 +#define Anum_pg_index_indislossy 9 +#define Anum_pg_index_indhaskeytype 10 #endif /* PG_INDEX_H */ diff --git a/src/backend/catalog/pg_proc.h b/src/backend/catalog/pg_proc.h index f282839419..e2165faa98 100644 --- a/src/backend/catalog/pg_proc.h +++ b/src/backend/catalog/pg_proc.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_proc.h,v 1.1.1.1 1996/07/09 06:21:18 scrappy Exp $ + * $Id: pg_proc.h,v 1.2 1996/08/26 06:29:46 scrappy Exp $ * * NOTES * The script catalog/genbki.sh reads this file and generates .bki @@ -385,7 +385,7 @@ DATA(insert OID = 313 ( i2toi4 PGUID 11 f t f 2 f 23 "21" 100 0 0 10 DATA(insert OID = 314 ( i4toi2 PGUID 11 f t f 2 f 21 "23" 100 0 0 100 foo bar )); DATA(insert OID = 315 ( keyfirsteq PGUID 11 f t f 2 f 16 "0 21" 100 0 0 100 foo bar )); -DATA(insert OID = 320 ( rtinsert PGUID 11 f t f 2 f 23 "0" 100 0 0 100 foo bar )); +DATA(insert OID = 320 ( rtinsert PGUID 11 f t f 4 f 23 "0" 100 0 0 100 foo bar )); DATA(insert OID = 321 ( rtdelete PGUID 11 f t f 2 f 23 "0" 100 0 0 100 foo bar )); DATA(insert OID = 322 ( rtgettuple PGUID 11 f t f 2 f 23 "0" 100 0 0 100 foo bar )); DATA(insert OID = 323 ( rtbuild PGUID 11 f t f 9 f 23 "0" 100 0 0 100 foo bar )); @@ -396,7 +396,7 @@ DATA(insert OID = 327 ( rtrestrpos PGUID 11 f t f 1 f 23 "0" 100 0 0 100 DATA(insert OID = 328 ( rtrescan PGUID 11 f t f 3 f 23 "0" 100 0 0 100 foo bar )); DATA(insert OID = 330 ( btgettuple PGUID 11 f t f 2 f 23 "0" 100 0 0 100 foo bar )); -DATA(insert OID = 331 ( btinsert PGUID 11 f t f 2 f 23 "0" 100 0 0 100 foo bar )); +DATA(insert OID = 331 ( btinsert PGUID 11 f t f 4 f 23 "0" 100 0 0 100 foo bar )); DATA(insert OID = 332 ( btdelete PGUID 11 f t f 2 f 23 "0" 100 0 0 100 foo bar )); DATA(insert OID = 333 ( btbeginscan PGUID 11 f t f 4 f 23 "0" 100 0 0 100 foo bar )); DATA(insert OID = 334 ( btrescan PGUID 11 f t f 3 f 23 "0" 100 0 0 100 foo bar )); @@ -448,7 +448,7 @@ DATA(insert OID = 438 ( hashsel PGUID 11 f t t 7 f 701 "26 26 21 0 23 DATA(insert OID = 439 ( hashnpage PGUID 11 f t t 7 f 701 "26 26 21 0 23 23 26" 100 0 0 100 foo bar )); DATA(insert OID = 440 ( hashgettuple PGUID 11 f t f 2 f 23 "0" 100 0 0 100 foo bar )); -DATA(insert OID = 441 ( hashinsert PGUID 11 f t f 2 f 23 "0" 100 0 0 100 foo bar )); +DATA(insert OID = 441 ( hashinsert PGUID 11 f t f 4 f 23 "0" 100 0 0 100 foo bar )); DATA(insert OID = 442 ( hashdelete PGUID 11 f t f 2 f 23 "0" 100 0 0 100 foo bar )); DATA(insert OID = 443 ( hashbeginscan PGUID 11 f t f 4 f 23 "0" 100 0 0 100 foo bar )); DATA(insert OID = 444 ( hashrescan PGUID 11 f t f 3 f 23 "0" 100 0 0 100 foo bar )); @@ -574,6 +574,17 @@ DATA(insert OID = 768 ( int4larger PGUID 11 f t f 2 f 23 "23 23" 100 0 0 DATA(insert OID = 769 ( int4smaller PGUID 11 f t f 2 f 23 "23 23" 100 0 0 100 foo bar )); DATA(insert OID = 770 ( int2larger PGUID 11 f t f 2 f 23 "21 21" 100 0 0 100 foo bar )); DATA(insert OID = 771 ( int2smaller PGUID 11 f t f 2 f 23 "21 21" 100 0 0 100 foo bar )); +DATA(insert OID = 772 ( gistsel PGUID 11 f t t 7 f 701 "26 26 21 0 23 23 26" 100 0 0 100 foo bar )); +DATA(insert OID = 773 ( gistnpage PGUID 11 f t t 7 f 701 "26 26 21 0 23 23 26" 100 0 0 100 foo bar )); +DATA(insert OID = 774 ( gistgettuple PGUID 11 f t f 2 f 23 "0" 100 0 0 100 foo bar )); +DATA(insert OID = 775 ( gistinsert PGUID 11 f t f 4 f 23 "0" 100 0 0 100 foo bar )); +DATA(insert OID = 776 ( gistdelete PGUID 11 f t f 2 f 23 "0" 100 0 0 100 foo bar )); +DATA(insert OID = 777 ( gistbeginscan PGUID 11 f t f 4 f 23 "0" 100 0 0 100 foo bar )); +DATA(insert OID = 778 ( gistrescan PGUID 11 f t f 3 f 23 "0" 100 0 0 100 foo bar )); +DATA(insert OID = 779 ( gistendscan PGUID 11 f t f 1 f 23 "0" 100 0 0 100 foo bar )); +DATA(insert OID = 780 ( gistmarkpos PGUID 11 f t f 1 f 23 "0" 100 0 0 100 foo bar )); +DATA(insert OID = 781 ( gistrestrpos PGUID 11 f t f 1 f 23 "0" 100 0 0 100 foo bar )); +DATA(insert OID = 782 ( gistbuild PGUID 11 f t f 9 f 23 "0" 100 0 0 100 foo bar )); /* OIDS 800 - 899 */ DATA(insert OID = 820 ( oidint2in PGUID 11 f t f 1 f 810 "0" 100 0 0 100 foo bar)); diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index e575e80ef9..0f393aa346 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.2 1996/08/15 07:39:24 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.3 1996/08/26 06:30:19 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -316,11 +316,12 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap) index_create((NewHeap->rd_rel->relname).data, NewIndexName, finfo, +- NULL, /* type info is in the old index */ Old_pg_index_relation_Form->relam, natts, Old_pg_index_Form->indkey, Old_pg_index_Form->indclass, - (uint16)0, (Datum) NULL, NULL); + (uint16)0, (Datum) NULL, NULL, Old_pg_index_Form->indislossy); heap_close(OldIndex); heap_close(NewHeap); diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 109f36f3e5..d0c2a6223e 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.4 1996/08/24 20:48:14 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.5 1996/08/26 06:30:21 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -527,11 +527,9 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim) &idatum, index_nulls, finfoP[i]); - ituple = index_formtuple(itupdescArr[i], &idatum, index_nulls); - ituple->t_tid = tuple->t_ctid; - indexRes = index_insert(index_rels[i], ituple); + indexRes = index_insert(index_rels[i], &idatum, index_nulls, + &(tuple->t_ctid)); if (indexRes) pfree(indexRes); - pfree(ituple); } } diff --git a/src/backend/commands/defind.c b/src/backend/commands/defind.c index e350927da0..48d1aa4f87 100644 --- a/src/backend/commands/defind.c +++ b/src/backend/commands/defind.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.3 1996/08/19 01:53:38 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.4 1996/08/26 06:30:23 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -86,8 +86,9 @@ DefineIndex(char *heapRelationName, Datum *parameterA = NULL; FuncIndexInfo fInfo; List *cnfPred = NULL; - - + bool lossy = FALSE; + List *pl; + /* * Handle attributes */ @@ -123,7 +124,19 @@ DefineIndex(char *heapRelationName, /* * Handle parameters * [param list is now different (NOT USED, really) - ay 10/94] + * + * WITH clause reinstated to handle lossy indices. + * -- JMH, 7/22/96 */ + foreach(pl, parameterList) { + int count; + char *ptr; + ParamString *param = (ParamString*)lfirst(pl); + + if (!strcasecmp(param->name, "islossy")) + lossy = TRUE; + } + /* @@ -167,9 +180,10 @@ DefineIndex(char *heapRelationName, index_create(heapRelationName, indexRelationName, - &fInfo, accessMethodId, + &fInfo, NULL, accessMethodId, numberOfAttributes, attributeNumberA, - classObjectId, parameterCount, parameterA, (Node*)cnfPred); + classObjectId, parameterCount, parameterA, (Node*)cnfPred, + lossy); }else { attributeNumberA = (AttrNumber *)palloc(numberOfAttributes * @@ -182,8 +196,10 @@ DefineIndex(char *heapRelationName, classObjectId, relationId); index_create(heapRelationName, indexRelationName, NULL, + ((IndexElem*)lfirst(attributeList))->tname, accessMethodId, numberOfAttributes, attributeNumberA, - classObjectId, parameterCount, parameterA, (Node*)cnfPred); + classObjectId, parameterCount, parameterA, (Node*)cnfPred, + lossy); } } diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index 8d1108aca2..ce05dc6f99 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.1.1.1 1996/07/09 06:21:25 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.2 1996/08/26 06:30:33 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -1025,11 +1025,17 @@ ExecInsertIndexTuples(TupleTableSlot *slot, RelationPtr relationDescs; Relation heapRelation; IndexInfo **indexInfoArray; + IndexInfo *indexInfo; Node *predicate; bool satisfied; ExprContext *econtext; - IndexTuple indexTuple; InsertIndexResult result; + int numberOfAttributes; + AttrNumber *keyAttributeNumbers; + FuncIndexInfoPtr fInfoP; + TupleDesc heapDescriptor; + Datum *datum; + char *nulls; heapTuple = slot->val; @@ -1050,8 +1056,9 @@ ExecInsertIndexTuples(TupleTableSlot *slot, econtext = NULL; for (i=0; iii_Predicate; + + indexInfo = indexInfoArray[i]; + predicate = indexInfo->ii_Predicate; if (predicate != NULL) { if (econtext == NULL) { econtext = makeNode(ExprContext); @@ -1063,16 +1070,32 @@ ExecInsertIndexTuples(TupleTableSlot *slot, if (satisfied == false) continue; } + + /* ---------------- + * get information from index info structure + * ---------------- + */ + numberOfAttributes = indexInfo->ii_NumKeyAttributes; + keyAttributeNumbers = indexInfo->ii_KeyAttributeNumbers; + fInfoP = indexInfo->ii_FuncIndexInfo; + datum = (Datum *) palloc(numberOfAttributes * sizeof *datum); + nulls = (char *) palloc(numberOfAttributes * sizeof *nulls); + heapDescriptor = (TupleDesc)RelationGetTupleDescriptor(heapRelation); + + FormIndexDatum(numberOfAttributes, /* num attributes */ + keyAttributeNumbers, /* array of att nums to extract */ + heapTuple, /* tuple from base relation */ + heapDescriptor, /* heap tuple's descriptor */ + InvalidBuffer, /* buffer associated with heap tuple */ + datum, /* return: array of attributes */ + nulls, /* return: array of char's */ + fInfoP); /* functional index information */ - indexTuple = ExecFormIndexTuple(heapTuple, - heapRelation, - relationDescs[i], - indexInfoArray[i]); - - indexTuple->t_tid = (*tupleid); /* structure assignment */ result = index_insert(relationDescs[i], /* index relation */ - indexTuple); /* index tuple */ + datum, /* array of heaptuple Datums */ + nulls, /* info on nulls */ + &(heapTuple->t_ctid)); /* oid of heap tuple */ /* ---------------- * keep track of index inserts for debugging @@ -1085,7 +1108,6 @@ ExecInsertIndexTuples(TupleTableSlot *slot, * ---------------- */ if (result) pfree(result); - pfree(indexTuple); } if (econtext != NULL) pfree(econtext); } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index d2dbef2bea..54cafe47dc 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.1.1.1 1996/07/09 06:21:32 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.2 1996/08/26 06:30:51 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -523,6 +523,19 @@ _equalEState(EState *a, EState *b) return (true); } +static bool +_equalTargetEntry(TargetEntry *a, TargetEntry *b) +{ + if (!equal(a->resdom,b->resdom)) + return(false); + if (!equal(a->fjoin,b->fjoin)) + return(false); + if (!equal(a->expr,b->expr)) + return(false); + + return(true); +} + /* * equal -- are two lists equal? @@ -582,6 +595,9 @@ equal(void *a, void *b) case T_Expr: retval = _equalExpr(a, b); break; + case T_TargetEntry: + retval = _equalTargetEntry(a,b); + break; case T_Iter: retval = _equalIter(a, b); break; diff --git a/src/backend/nodes/parsenodes.h b/src/backend/nodes/parsenodes.h index f2c7c59109..d8ca5b9243 100644 --- a/src/backend/nodes/parsenodes.h +++ b/src/backend/nodes/parsenodes.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: parsenodes.h,v 1.4 1996/08/24 20:48:31 scrappy Exp $ + * $Id: parsenodes.h,v 1.5 1996/08/26 06:30:54 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -218,6 +218,7 @@ typedef struct IndexStmt { Node *whereClause; /* qualifications */ List *rangetable; /* range table, filled in by transformStmt() */ + bool *lossy; /* is index lossy? */ } IndexStmt; /* ---------------------- @@ -655,6 +656,7 @@ typedef struct IndexElem { char *name; /* name of index */ List *args; /* if not NULL, function index */ char *class; + TypeName *tname; /* type of index's keys (optional) */ } IndexElem; /* diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 70a5e6461b..341e6080d6 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.1.1.1 1996/07/09 06:21:37 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.2 1996/08/26 06:31:15 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -316,8 +316,11 @@ create_indexscan_node(IndexPath *best_path, List *indxqual = NIL; List *qpqual = NIL; List *fixed_indxqual = NIL; + List *ixid; IndexScan *scan_node = (IndexScan*)NULL; - + bool lossy = FALSE; + HeapTuple indexTuple; + IndexTupleForm index; /* * If an 'or' clause is to be used with this index, the indxqual @@ -340,15 +343,42 @@ create_indexscan_node(IndexPath *best_path, NIL); } + /* check and see if any indices are lossy */ + foreach (ixid, best_path->indexid) { + indexTuple = SearchSysCacheTuple(INDEXRELID, + ObjectIdGetDatum(lfirsti(ixid)), + 0,0,0); + if (!HeapTupleIsValid(indexTuple)) + elog(WARN, "create_plan: index %d not found", + lfirsti(ixid)); + index = (IndexTupleForm)GETSTRUCT(indexTuple); + if (index->indislossy) + lossy = TRUE; + } + + /* - * The qpqual field contains all restrictions except the indxqual. + * The qpqual field contains all restrictions not automatically handled + * by the index. Note that for non-lossy indices, the predicates + * in the indxqual are handled by the index, while for lossy indices + * the indxqual predicates need to be double-checked after the + * index fetches the best-guess tuples. */ - if(or_clause((Node*)index_clause)) + if(or_clause((Node*)index_clause)) { qpqual = set_difference(scan_clauses, lcons(index_clause,NIL)); - else + + if (lossy) + qpqual = nconc(qpqual, + lcons((List *)copyObject(index_clause),NIL)); + } + else { qpqual = set_difference(scan_clauses, lfirst(indxqual)); - + if (lossy) + qpqual = nconc(qpqual, + (List *)copyObject(lfirst(indxqual))); + } + fixed_indxqual = (List*)fix_indxqual_references((Node*)indxqual,(Path*)best_path); diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 96dbc55cb7..46268abd2f 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.8 1996/08/24 20:48:44 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.9 1996/08/26 06:31:31 scrappy Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -140,7 +140,7 @@ static Node *makeA_Expr(int op, char *opname, Node *lexpr, Node *rexpr); %type purge_quals %type insert_rest -%type Typename, typname +%type Typename, typname, opt_type %type columnDef %type def_elem %type def_arg, columnElem, exprElem, where_clause, @@ -658,7 +658,7 @@ opt_portal_name: IN name { $$ = $2;} *****************************************************************************/ IndexStmt: CREATE INDEX index_name ON relation_name - access_method_clause '(' index_params ')' + access_method_clause '(' index_params ')' opt_with { /* should check that access_method is valid, etc ... but doesn't */ @@ -667,7 +667,7 @@ IndexStmt: CREATE INDEX index_name ON relation_name n->relname = $5; n->accessMethod = $6; n->indexParams = $8; - n->withClause = NIL; + n->withClause = $11; n->whereClause = NULL; $$ = (Node *)n; } @@ -1473,24 +1473,30 @@ index_params: index_elem { $$ = lcons($1,NIL); } { $$ = lcons($1, NIL); } ;*/ -func_index: name '(' name_list ')' opt_class +func_index: name '(' name_list ')' opt_type opt_class { $$ = makeNode(IndexElem); $$->name = $1; $$->args = $3; - $$->class = $5; + $$->class = $6; + $$->tname = $5; } ; -index_elem: attr_name opt_class +index_elem: attr_name opt_type opt_class { $$ = makeNode(IndexElem); $$->name = $1; $$->args = NIL; - $$->class = $2; + $$->class = $3; + $$->tname = $2; } ; +opt_type: ':' Typename { $$ = $2;} + | /*EMPTY*/ { $$ = NULL;} + ; + opt_class: class | WITH class { $$ = $2; } | /*EMPTY*/ { $$ = NULL; } diff --git a/src/backend/storage/large_object/inv_api.c b/src/backend/storage/large_object/inv_api.c index ae57032f94..c61eead748 100644 --- a/src/backend/storage/large_object/inv_api.c +++ b/src/backend/storage/large_object/inv_api.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.1.1.1 1996/07/09 06:21:55 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.2 1996/08/26 06:31:45 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -157,9 +157,9 @@ inv_create(int flags) attNums[0] = 1; classObjectId[0] = INT4_OPS_OID; - index_create(objname, indname, NULL, BTREE_AM_OID, + index_create(objname, indname, NULL, NULL, BTREE_AM_OID, 1, &attNums[0], &classObjectId[0], - 0, (Datum) NULL, NULL); + 0, (Datum) NULL, NULL, FALSE); /* make the index visible in this transaction */ CommandCounterIncrement(); @@ -996,23 +996,16 @@ inv_newtuple(LargeObjectDesc *obj_desc, static void inv_indextup(LargeObjectDesc *obj_desc, HeapTuple htup) { - IndexTuple itup; InsertIndexResult res; Datum v[1]; char n[1]; n[0] = ' '; v[0] = Int32GetDatum(obj_desc->highbyte); - itup = index_formtuple(obj_desc->idesc, &v[0], &n[0]); - memmove((char *)&(itup->t_tid), - (char *)&(htup->t_ctid), - sizeof(ItemPointerData)); - res = index_insert(obj_desc->index_r, itup); + res = index_insert(obj_desc->index_r, &v[0], &n[0], &(htup->t_ctid)); if (res) pfree(res); - - pfree(itup); } /* diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index d1d5daae9f..5807808fcd 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.2 1996/07/31 18:48:16 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.3 1996/08/26 06:32:06 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -583,3 +583,29 @@ rtnpage(Oid operatorObjectId, return (btreenpage(operatorObjectId, indrelid, attributeNumber, constValue, constFlag, nIndexKeys, indexrelid)); } + +float64 +gistsel(Oid operatorObjectId, + Oid indrelid, + AttrNumber attributeNumber, + char *constValue, + int32 constFlag, + int32 nIndexKeys, + Oid indexrelid) +{ + return (btreesel(operatorObjectId, indrelid, attributeNumber, + constValue, constFlag, nIndexKeys, indexrelid)); +} + +float64 +gistnpage(Oid operatorObjectId, + Oid indrelid, + AttrNumber attributeNumber, + char *constValue, + int32 constFlag, + int32 nIndexKeys, + Oid indexrelid) +{ + return (btreenpage(operatorObjectId, indrelid, attributeNumber, + constValue, constFlag, nIndexKeys, indexrelid)); +}