Commit a54075a6 authored by Tom Lane's avatar Tom Lane

Update GiST for new pg_opclass arrangement (finally a clean solution

for haskeytype).  Update GiST contrib modules too.  Add linear-time split
algorithm for R-tree GiST opclass.
From Oleg Bartunov and Teodor Sigaev.
parent 38a4c351
...@@ -86,7 +86,7 @@ CREATE FUNCTION g_int_decompress(opaque) RETURNS opaque ...@@ -86,7 +86,7 @@ CREATE FUNCTION g_int_decompress(opaque) RETURNS opaque
AS 'MODULE_PATHNAME' LANGUAGE 'c'; AS 'MODULE_PATHNAME' LANGUAGE 'c';
CREATE FUNCTION g_int_penalty(opaque,opaque,opaque) RETURNS opaque CREATE FUNCTION g_int_penalty(opaque,opaque,opaque) RETURNS opaque
AS 'MODULE_PATHNAME' LANGUAGE 'c'; AS 'MODULE_PATHNAME' LANGUAGE 'c' with (isstrict);
CREATE FUNCTION g_int_picksplit(opaque, opaque) RETURNS opaque CREATE FUNCTION g_int_picksplit(opaque, opaque) RETURNS opaque
AS 'MODULE_PATHNAME' LANGUAGE 'c'; AS 'MODULE_PATHNAME' LANGUAGE 'c';
...@@ -105,7 +105,7 @@ INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype) ...@@ -105,7 +105,7 @@ INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype)
'gist__int_ops', 'gist__int_ops',
(SELECT oid FROM pg_type WHERE typname = '_int4'), (SELECT oid FROM pg_type WHERE typname = '_int4'),
true, true,
(SELECT oid FROM pg_type WHERE typname = '_int4')); 0);
-- get the comparators for _intments and store them in a tmp table -- get the comparators for _intments and store them in a tmp table
...@@ -252,7 +252,7 @@ INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype) ...@@ -252,7 +252,7 @@ INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype)
'gist__intbig_ops', 'gist__intbig_ops',
(SELECT oid FROM pg_type WHERE typname = '_int4'), (SELECT oid FROM pg_type WHERE typname = '_int4'),
false, false,
(SELECT oid FROM pg_type WHERE typname = '_int4')); 0);
-- get the comparators for _intments and store them in a tmp table -- get the comparators for _intments and store them in a tmp table
......
...@@ -19,7 +19,7 @@ select count(*) from boxtmp where b && '(1000,1000,0,0)'::box; ...@@ -19,7 +19,7 @@ select count(*) from boxtmp where b && '(1000,1000,0,0)'::box;
(1 row) (1 row)
drop index bix; drop index bix;
create index bix on boxtmp using gist (b gist_box_ops); create index bix on boxtmp using gist (b);
select count(*) from boxtmp where b && '(1000,1000,0,0)'::box; select count(*) from boxtmp where b && '(1000,1000,0,0)'::box;
count count
------- -------
...@@ -36,7 +36,7 @@ select count(*) from polytmp where p && '(1000,1000),(0,0)'::polygon; ...@@ -36,7 +36,7 @@ select count(*) from polytmp where p && '(1000,1000),(0,0)'::polygon;
(1 row) (1 row)
drop index pix; drop index pix;
create index pix on polytmp using gist (p gist_poly_ops); create index pix on polytmp using gist (p);
select count(*) from polytmp where p && '(1000,1000),(0,0)'::polygon; select count(*) from polytmp where p && '(1000,1000),(0,0)'::polygon;
count count
------- -------
......
This diff is collapsed.
...@@ -27,7 +27,7 @@ INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype) ...@@ -27,7 +27,7 @@ INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype)
(SELECT oid FROM pg_am WHERE amname = 'gist'), (SELECT oid FROM pg_am WHERE amname = 'gist'),
'gist_box_ops', 'gist_box_ops',
(SELECT oid FROM pg_type WHERE typname = 'box'), (SELECT oid FROM pg_type WHERE typname = 'box'),
false, true,
0); 0);
-- get the comparators for boxes and store them in a tmp table -- get the comparators for boxes and store them in a tmp table
...@@ -183,22 +183,14 @@ create function gpoly_consistent(opaque,polygon,int4) returns bool as 'MODULE_PA ...@@ -183,22 +183,14 @@ create function gpoly_consistent(opaque,polygon,int4) returns bool as 'MODULE_PA
create function gpoly_compress(opaque) returns opaque as 'MODULE_PATHNAME' language 'C'; create function gpoly_compress(opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
create function gpoly_penalty(opaque,opaque,opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
create function gpoly_picksplit(opaque, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
create function gpoly_union(bytea, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
create function gpoly_same(opaque, opaque, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
-- add a new opclass (non-default) -- add a new opclass (non-default)
INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype) INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype)
VALUES ( VALUES (
(SELECT oid FROM pg_am WHERE amname = 'gist'), (SELECT oid FROM pg_am WHERE amname = 'gist'),
'gist_poly_ops', 'gist_poly_ops',
(SELECT oid FROM pg_type WHERE typname = 'polygon'), (SELECT oid FROM pg_type WHERE typname = 'polygon'),
false, true,
0); (SELECT oid FROM pg_type WHERE typname = 'box'));
-- get the comparators for polygons and store them in a tmp table -- get the comparators for polygons and store them in a tmp table
-- hack for 757 (poly_contain_pt) Teodor -- hack for 757 (poly_contain_pt) Teodor
...@@ -211,7 +203,7 @@ WHERE o.oprleft = t.oid and o.oid <> 757 ...@@ -211,7 +203,7 @@ WHERE o.oprleft = t.oid and o.oid <> 757
-- using the tmp table, generate the amop entries -- using the tmp table, generate the amop entries
-- poly_left -- poly_left
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 1, false, c.opoid SELECT opcl.oid, 1, true, c.opoid
FROM pg_opclass opcl, rt_ops_tmp c FROM pg_opclass opcl, rt_ops_tmp c
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
...@@ -220,7 +212,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) ...@@ -220,7 +212,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
-- poly_overleft -- poly_overleft
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 2, false, c.opoid SELECT opcl.oid, 2, true, c.opoid
FROM pg_opclass opcl, rt_ops_tmp c FROM pg_opclass opcl, rt_ops_tmp c
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
...@@ -229,7 +221,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) ...@@ -229,7 +221,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
-- poly_overlap -- poly_overlap
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 3, false, c.opoid SELECT opcl.oid, 3, true, c.opoid
FROM pg_opclass opcl, rt_ops_tmp c FROM pg_opclass opcl, rt_ops_tmp c
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
...@@ -238,7 +230,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) ...@@ -238,7 +230,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
-- poly_overright -- poly_overright
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 4, false, c.opoid SELECT opcl.oid, 4, true, c.opoid
FROM pg_opclass opcl, rt_ops_tmp c FROM pg_opclass opcl, rt_ops_tmp c
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
...@@ -247,7 +239,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) ...@@ -247,7 +239,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
-- poly_right -- poly_right
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 5, false, c.opoid SELECT opcl.oid, 5, true, c.opoid
FROM pg_opclass opcl, rt_ops_tmp c FROM pg_opclass opcl, rt_ops_tmp c
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
...@@ -256,7 +248,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) ...@@ -256,7 +248,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
-- poly_same -- poly_same
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 6, false, c.opoid SELECT opcl.oid, 6, true, c.opoid
FROM pg_opclass opcl, rt_ops_tmp c FROM pg_opclass opcl, rt_ops_tmp c
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
...@@ -265,7 +257,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) ...@@ -265,7 +257,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
-- poly_contains -- poly_contains
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 7, false, c.opoid SELECT opcl.oid, 7, true, c.opoid
FROM pg_opclass opcl, rt_ops_tmp c FROM pg_opclass opcl, rt_ops_tmp c
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
...@@ -274,7 +266,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) ...@@ -274,7 +266,7 @@ INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
-- poly_contained -- poly_contained
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 8, false, c.opoid SELECT opcl.oid, 8, true, c.opoid
FROM pg_opclass opcl, rt_ops_tmp c FROM pg_opclass opcl, rt_ops_tmp c
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
...@@ -300,7 +292,7 @@ INSERT INTO pg_amproc (amopclaid, amprocnum, amproc) ...@@ -300,7 +292,7 @@ INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist_poly_ops' and opcname = 'gist_poly_ops'
and proname = 'gpoly_union'; and proname = 'gbox_union';
INSERT INTO pg_amproc (amopclaid, amprocnum, amproc) INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
SELECT opcl.oid, 3, pro.oid SELECT opcl.oid, 3, pro.oid
...@@ -324,7 +316,7 @@ INSERT INTO pg_amproc (amopclaid, amprocnum, amproc) ...@@ -324,7 +316,7 @@ INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist_poly_ops' and opcname = 'gist_poly_ops'
and proname = 'gpoly_penalty'; and proname = 'gbox_penalty';
INSERT INTO pg_amproc (amopclaid, amprocnum, amproc) INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
SELECT opcl.oid, 6, pro.oid SELECT opcl.oid, 6, pro.oid
...@@ -332,7 +324,7 @@ INSERT INTO pg_amproc (amopclaid, amprocnum, amproc) ...@@ -332,7 +324,7 @@ INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist_poly_ops' and opcname = 'gist_poly_ops'
and proname = 'gpoly_picksplit'; and proname = 'gbox_picksplit';
INSERT INTO pg_amproc (amopclaid, amprocnum, amproc) INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
SELECT opcl.oid, 7, pro.oid SELECT opcl.oid, 7, pro.oid
...@@ -340,7 +332,7 @@ INSERT INTO pg_amproc (amopclaid, amprocnum, amproc) ...@@ -340,7 +332,7 @@ INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
WHERE WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist_poly_ops' and opcname = 'gist_poly_ops'
and proname = 'gpoly_same'; and proname = 'gbox_same';
end transaction; end transaction;
...@@ -18,7 +18,7 @@ select count(*) from boxtmp where b && '(1000,1000,0,0)'::box; ...@@ -18,7 +18,7 @@ select count(*) from boxtmp where b && '(1000,1000,0,0)'::box;
drop index bix; drop index bix;
create index bix on boxtmp using gist (b gist_box_ops); create index bix on boxtmp using gist (b);
select count(*) from boxtmp where b && '(1000,1000,0,0)'::box; select count(*) from boxtmp where b && '(1000,1000,0,0)'::box;
...@@ -32,7 +32,7 @@ select count(*) from polytmp where p && '(1000,1000),(0,0)'::polygon; ...@@ -32,7 +32,7 @@ select count(*) from polytmp where p && '(1000,1000),(0,0)'::polygon;
drop index pix; drop index pix;
create index pix on polytmp using gist (p gist_poly_ops); create index pix on polytmp using gist (p);
select count(*) from polytmp where p && '(1000,1000),(0,0)'::polygon; select count(*) from polytmp where p && '(1000,1000),(0,0)'::polygon;
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/gist/gistget.c,v 1.29 2001/08/10 14:34:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/gist/gistget.c,v 1.30 2001/08/22 18:24:26 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -239,7 +239,7 @@ gistindex_keytest(IndexTuple tuple, ...@@ -239,7 +239,7 @@ gistindex_keytest(IndexTuple tuple,
{ {
datum = index_getattr(tuple, datum = index_getattr(tuple,
key[0].sk_attno, key[0].sk_attno,
tupdesc, giststate->tupdesc,
&isNull); &isNull);
if (isNull) if (isNull)
{ {
...@@ -271,7 +271,7 @@ gistindex_keytest(IndexTuple tuple, ...@@ -271,7 +271,7 @@ gistindex_keytest(IndexTuple tuple,
ObjectIdGetDatum(key[0].sk_procedure)); ObjectIdGetDatum(key[0].sk_procedure));
} }
if ( de.key != datum ) if ( de.key != datum && ! isAttByVal( giststate, key[0].sk_attno-1 ) )
if ( DatumGetPointer(de.key) != NULL ) if ( DatumGetPointer(de.key) != NULL )
pfree( DatumGetPointer(de.key) ); pfree( DatumGetPointer(de.key) );
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/gist/gistscan.c,v 1.38 2001/07/15 22:48:15 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/gist/gistscan.c,v 1.39 2001/08/22 18:24:26 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -234,6 +234,8 @@ gistendscan(PG_FUNCTION_ARGS) ...@@ -234,6 +234,8 @@ gistendscan(PG_FUNCTION_ARGS)
{ {
gistfreestack(p->s_stack); gistfreestack(p->s_stack);
gistfreestack(p->s_markstk); gistfreestack(p->s_markstk);
if ( p->giststate != NULL )
freeGISTstate( p->giststate );
pfree(s->opaque); pfree(s->opaque);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.161 2001/08/21 16:36:00 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.162 2001/08/22 18:24:26 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "catalog/index.h" #include "catalog/index.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/pg_index.h" #include "catalog/pg_index.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "commands/comment.h" #include "commands/comment.h"
...@@ -62,9 +63,11 @@ ...@@ -62,9 +63,11 @@
/* non-export function prototypes */ /* non-export function prototypes */
static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName, static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName,
bool istemp); bool istemp);
static TupleDesc BuildFuncTupleDesc(Oid funcOid); static TupleDesc BuildFuncTupleDesc(Oid funcOid,
Oid *classObjectId);
static TupleDesc ConstructTupleDescriptor(Relation heapRelation, static TupleDesc ConstructTupleDescriptor(Relation heapRelation,
int numatts, AttrNumber *attNums); int numatts, AttrNumber *attNums,
Oid *classObjectId);
static void ConstructIndexReldesc(Relation indexRelation, Oid amoid); static void ConstructIndexReldesc(Relation indexRelation, Oid amoid);
static Oid UpdateRelationRelation(Relation indexRelation, char *temp_relname); static Oid UpdateRelationRelation(Relation indexRelation, char *temp_relname);
static void InitializeAttributeOids(Relation indexRelation, static void InitializeAttributeOids(Relation indexRelation,
...@@ -124,11 +127,14 @@ GetHeapRelationOid(char *heapRelationName, char *indexRelationName, bool istemp) ...@@ -124,11 +127,14 @@ GetHeapRelationOid(char *heapRelationName, char *indexRelationName, bool istemp)
} }
static TupleDesc static TupleDesc
BuildFuncTupleDesc(Oid funcOid) BuildFuncTupleDesc(Oid funcOid,
Oid *classObjectId)
{ {
TupleDesc funcTupDesc; TupleDesc funcTupDesc;
HeapTuple tuple; HeapTuple tuple;
Oid keyType;
Oid retType; Oid retType;
Form_pg_type typeTup;
/* /*
* Allocate and zero a tuple descriptor for a one-column tuple. * Allocate and zero a tuple descriptor for a one-column tuple.
...@@ -156,25 +162,41 @@ BuildFuncTupleDesc(Oid funcOid) ...@@ -156,25 +162,41 @@ BuildFuncTupleDesc(Oid funcOid)
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
/* /*
* Lookup the return type in pg_type for the type length etc. * Check the opclass to see if it provides a keytype (overriding the
* function result type).
*/
tuple = SearchSysCache(CLAOID,
ObjectIdGetDatum(classObjectId[0]),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "Opclass %u does not exist", classObjectId[0]);
keyType = ((Form_pg_opclass) GETSTRUCT(tuple))->opckeytype;
ReleaseSysCache(tuple);
if (!OidIsValid(keyType))
keyType = retType;
/*
* Lookup the key type in pg_type for the type length etc.
*/ */
tuple = SearchSysCache(TYPEOID, tuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(retType), ObjectIdGetDatum(keyType),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "Type %u does not exist", retType); elog(ERROR, "Type %u does not exist", keyType);
typeTup = (Form_pg_type) GETSTRUCT(tuple);
/* /*
* Assign some of the attributes values. Leave the rest as 0. * Assign some of the attributes values. Leave the rest as 0.
*/ */
funcTupDesc->attrs[0]->attlen = ((Form_pg_type) GETSTRUCT(tuple))->typlen;
funcTupDesc->attrs[0]->atttypid = retType;
funcTupDesc->attrs[0]->attnum = 1; funcTupDesc->attrs[0]->attnum = 1;
funcTupDesc->attrs[0]->attbyval = ((Form_pg_type) GETSTRUCT(tuple))->typbyval; funcTupDesc->attrs[0]->atttypid = keyType;
funcTupDesc->attrs[0]->attlen = typeTup->typlen;
funcTupDesc->attrs[0]->attbyval = typeTup->typbyval;
funcTupDesc->attrs[0]->attcacheoff = -1; funcTupDesc->attrs[0]->attcacheoff = -1;
funcTupDesc->attrs[0]->atttypmod = -1; funcTupDesc->attrs[0]->atttypmod = -1;
funcTupDesc->attrs[0]->attstorage = ((Form_pg_type) GETSTRUCT(tuple))->typstorage; funcTupDesc->attrs[0]->attstorage = typeTup->typstorage;
funcTupDesc->attrs[0]->attalign = ((Form_pg_type) GETSTRUCT(tuple))->typalign; funcTupDesc->attrs[0]->attalign = typeTup->typalign;
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
...@@ -190,7 +212,8 @@ BuildFuncTupleDesc(Oid funcOid) ...@@ -190,7 +212,8 @@ BuildFuncTupleDesc(Oid funcOid)
static TupleDesc static TupleDesc
ConstructTupleDescriptor(Relation heapRelation, ConstructTupleDescriptor(Relation heapRelation,
int numatts, int numatts,
AttrNumber *attNums) AttrNumber *attNums,
Oid *classObjectId)
{ {
TupleDesc heapTupDesc; TupleDesc heapTupDesc;
TupleDesc indexTupDesc; TupleDesc indexTupDesc;
...@@ -217,6 +240,8 @@ ConstructTupleDescriptor(Relation heapRelation, ...@@ -217,6 +240,8 @@ ConstructTupleDescriptor(Relation heapRelation,
AttrNumber atnum; /* attributeNumber[attributeOffset] */ AttrNumber atnum; /* attributeNumber[attributeOffset] */
Form_pg_attribute from; Form_pg_attribute from;
Form_pg_attribute to; Form_pg_attribute to;
HeapTuple tuple;
Oid keyType;
/* /*
* get the attribute number and make sure it's valid; determine * get the attribute number and make sure it's valid; determine
...@@ -269,6 +294,40 @@ ConstructTupleDescriptor(Relation heapRelation, ...@@ -269,6 +294,40 @@ ConstructTupleDescriptor(Relation heapRelation,
* fix it later. * fix it later.
*/ */
to->attrelid = InvalidOid; to->attrelid = InvalidOid;
/*
* Check the opclass to see if it provides a keytype (overriding
* the attribute type).
*/
tuple = SearchSysCache(CLAOID,
ObjectIdGetDatum(classObjectId[i]),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "Opclass %u does not exist", classObjectId[i]);
keyType = ((Form_pg_opclass) GETSTRUCT(tuple))->opckeytype;
ReleaseSysCache(tuple);
if (OidIsValid(keyType) && keyType != to->atttypid)
{
/* index value and heap value have different types */
Form_pg_type typeTup;
tuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(keyType),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "Type %u does not exist", keyType);
typeTup = (Form_pg_type) GETSTRUCT(tuple);
to->atttypid = keyType;
to->atttypmod = -1;
to->attlen = typeTup->typlen;
to->attbyval = typeTup->typbyval;
to->attalign = typeTup->typalign;
to->attstorage = typeTup->typstorage;
ReleaseSysCache(tuple);
}
} }
return indexTupDesc; return indexTupDesc;
...@@ -703,19 +762,21 @@ index_create(char *heapRelationName, ...@@ -703,19 +762,21 @@ index_create(char *heapRelationName,
heapRelation = heap_open(heapoid, ShareLock); heapRelation = heap_open(heapoid, ShareLock);
/* /*
* construct new tuple descriptor * construct tuple descriptor for index tuples
*/ */
if (OidIsValid(indexInfo->ii_FuncOid)) if (OidIsValid(indexInfo->ii_FuncOid))
indexTupDesc = BuildFuncTupleDesc(indexInfo->ii_FuncOid); indexTupDesc = BuildFuncTupleDesc(indexInfo->ii_FuncOid,
classObjectId);
else else
indexTupDesc = ConstructTupleDescriptor(heapRelation, indexTupDesc = ConstructTupleDescriptor(heapRelation,
indexInfo->ii_NumKeyAttrs, indexInfo->ii_NumKeyAttrs,
indexInfo->ii_KeyAttrNumbers); indexInfo->ii_KeyAttrNumbers,
classObjectId);
if (istemp) if (istemp)
{ {
/* save user relation name because heap_create changes it */ /* save user relation name because heap_create changes it */
temp_relname = pstrdup(indexRelationName); /* save original value */ temp_relname = pstrdup(indexRelationName); /* save original */
indexRelationName = palloc(NAMEDATALEN); indexRelationName = palloc(NAMEDATALEN);
strcpy(indexRelationName, temp_relname); /* heap_create will strcpy(indexRelationName, temp_relname); /* heap_create will
* change this */ * change this */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: gist.h,v 1.31 2001/08/21 16:36:05 tgl Exp $ * $Id: gist.h,v 1.32 2001/08/22 18:24:26 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -72,11 +72,11 @@ typedef struct GISTSTATE ...@@ -72,11 +72,11 @@ typedef struct GISTSTATE
FmgrInfo penaltyFn[INDEX_MAX_KEYS]; FmgrInfo penaltyFn[INDEX_MAX_KEYS];
FmgrInfo picksplitFn[INDEX_MAX_KEYS]; FmgrInfo picksplitFn[INDEX_MAX_KEYS];
FmgrInfo equalFn[INDEX_MAX_KEYS]; FmgrInfo equalFn[INDEX_MAX_KEYS];
bool attbyval[INDEX_MAX_KEYS];
bool haskeytype[INDEX_MAX_KEYS]; TupleDesc tupdesc;
bool keytypbyval[INDEX_MAX_KEYS];
} GISTSTATE; } GISTSTATE;
#define isAttByVal( gs, anum ) (gs)->tupdesc->attrs[anum]->attbyval
/* /*
* When we're doing a scan, we need to keep track of the parent stack * When we're doing a scan, we need to keep track of the parent stack
...@@ -169,6 +169,7 @@ extern Datum gistbulkdelete(PG_FUNCTION_ARGS); ...@@ -169,6 +169,7 @@ extern Datum gistbulkdelete(PG_FUNCTION_ARGS);
extern void _gistdump(Relation r); extern void _gistdump(Relation r);
extern void gistfreestack(GISTSTACK *s); extern void gistfreestack(GISTSTACK *s);
extern void initGISTstate(GISTSTATE *giststate, Relation index); extern void initGISTstate(GISTSTATE *giststate, Relation index);
extern void freeGISTstate(GISTSTATE *giststate);
extern void gistdentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e, extern void gistdentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e,
Datum k, Relation r, Page pg, OffsetNumber o, Datum k, Relation r, Page pg, OffsetNumber o,
int b, bool l, bool isNull); int b, bool l, bool isNull);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment