Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa5c8a0

Browse files
committed
Cross-data-type comparisons are now indexable by btrees, pursuant to my
pghackers proposal of 8-Nov. All the existing cross-type comparisonoperators (int2/int4/int8 and float4/float8) have appropriate support.The original proposal of storing the right-hand-side datatype as part ofthe primary key for pg_amop and pg_amproc got modified a bit in the event;it is easier to store zero as the 'default' case and only store a nonzerowhen the operator is actually cross-type. Along the way, remove thelong-since-defunct bigbox_ops operator class.
1 parent49f98fa commitfa5c8a0

File tree

76 files changed

+2238
-1493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2238
-1493
lines changed

‎contrib/dblink/dblink.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,10 +1357,10 @@ get_pkey_attnames(Oid relid, int16 *numatts)
13571357

13581358
/* use relid to get all related indexes */
13591359
indexRelation=heap_openr(IndexRelationName,AccessShareLock);
1360-
ScanKeyEntryInitialize(&entry,0,
1361-
Anum_pg_index_indrelid,
1362-
BTEqualStrategyNumber,F_OIDEQ,
1363-
ObjectIdGetDatum(relid),OIDOID);
1360+
ScanKeyInit(&entry,
1361+
Anum_pg_index_indrelid,
1362+
BTEqualStrategyNumber,F_OIDEQ,
1363+
ObjectIdGetDatum(relid));
13641364
scan=heap_beginscan(indexRelation,SnapshotNow,1,&entry);
13651365

13661366
while ((indexTuple=heap_getnext(scan,ForwardScanDirection))!=NULL)

‎contrib/miscutil/misc_utils.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include"access/tupdesc.h"
2222
#include"catalog/catname.h"
2323
#include"catalog/pg_listener.h"
24-
#include"catalog/pg_type.h"
2524
#include"commands/async.h"
2625
#include"fmgr.h"
2726
#include"storage/lmgr.h"
@@ -87,10 +86,10 @@ active_listeners(text *relname)
8786
MemSet(listen_name,0,NAMEDATALEN);
8887
len=MIN(VARSIZE(relname)-VARHDRSZ,NAMEDATALEN-1);
8988
memcpy(listen_name,VARDATA(relname),len);
90-
ScanKeyEntryInitialize(&key,0,
91-
Anum_pg_listener_relname,
92-
BTEqualStrategyNumber,F_NAMEEQ,
93-
PointerGetDatum(listen_name),NAMEOID);
89+
ScanKeyInit(&key,
90+
Anum_pg_listener_relname,
91+
BTEqualStrategyNumber,F_NAMEEQ,
92+
PointerGetDatum(listen_name));
9493
sRel=heap_beginscan(lRel,SnapshotNow,1,&key);
9594
}
9695
else

‎doc/src/sgml/catalogs.sgml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.78 2003/11/02 12:53:57 petere Exp $
3+
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.79 2003/11/12 21:15:42 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -499,6 +499,14 @@
499499
<entry>The index operator class this entry is for</entry>
500500
</row>
501501

502+
<row>
503+
<entry><structfield>amopsubtype</structfield></entry>
504+
<entry><type>oid</type></entry>
505+
<entry><literal><link linkend="catalog-pg-type"><structname>pg_type</structname></link>.oid</literal></entry>
506+
<entry>Subtype to distinguish multiple entries for one strategy;
507+
zero for default</entry>
508+
</row>
509+
502510
<row>
503511
<entry><structfield>amopstrategy</structfield></entry>
504512
<entry><type>int2</type></entry>
@@ -562,6 +570,13 @@
562570
<entry>The index operator class this entry is for</entry>
563571
</row>
564572

573+
<row>
574+
<entry><structfield>amprocsubtype</structfield></entry>
575+
<entry><type>oid</type></entry>
576+
<entry><literal><link linkend="catalog-pg-type"><structname>pg_type</structname></link>.oid</literal></entry>
577+
<entry>Subtype, if cross-type routine, else zero</entry>
578+
</row>
579+
565580
<row>
566581
<entry><structfield>amprocnum</structfield></entry>
567582
<entry><type>int2</type></entry>
@@ -2435,7 +2450,7 @@
24352450
<entry><structfield>opcintype</structfield></entry>
24362451
<entry><type>oid</type></entry>
24372452
<entry><literal><link linkend="catalog-pg-type"><structname>pg_type</structname></link>.oid</literal></entry>
2438-
<entry>Input datatypeof the operator class</entry>
2453+
<entry>Datatypethat the operator class indexes</entry>
24392454
</row>
24402455

24412456
<row>
@@ -2449,7 +2464,7 @@
24492464
<entry><structfield>opckeytype</structfield></entry>
24502465
<entry><type>oid</type></entry>
24512466
<entry><literal><link linkend="catalog-pg-type"><structname>pg_type</structname></link>.oid</literal></entry>
2452-
<entry>Type ofindexdata, or zero if same as <structfield>opcintype</></entry>
2467+
<entry>Type of data stored in index, or zero if same as <structfield>opcintype</></entry>
24532468
</row>
24542469

24552470
</tbody>

‎doc/src/sgml/xindex.sgml

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.34 2003/11/01 01:56:29 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.35 2003/11/12 21:15:45 tgl Exp $
33
-->
44

55
<sect1 id="xindex">
@@ -80,7 +80,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.34 2003/11/01 01:56:29 pete
8080
The same operator class name
8181
can be used for several different index methods (for example, both B-tree
8282
and hash index methods have operator classes named
83-
<literal>oid_ops</literal>), but each such class is an independent
83+
<literal>int4_ops</literal>), but each such class is an independent
8484
entity and must be defined separately.
8585
</para>
8686
</sect2>
@@ -589,6 +589,71 @@ CREATE OPERATOR CLASS complex_abs_ops
589589
</para>
590590
</sect2>
591591

592+
<sect2 id="xindex-opclass-crosstype">
593+
<title>Cross-Data-Type Operator Classes</title>
594+
595+
<para>
596+
So far we have implicitly assumed that an operator class deals with
597+
only one data type. While there certainly can be only one data type in
598+
a particular index column, it is often useful to index operations that
599+
compare an indexed column to a value of a different data type. This is
600+
presently supported by the B-tree and GiST index methods.
601+
</para>
602+
603+
<para>
604+
B-trees require the left-hand operand of each operator to be the indexed
605+
data type, but the right-hand operand can be of a different type. There
606+
must be a support function having a matching signature. For example,
607+
the built-in operator class for type <type>bigint</> (<type>int8</>)
608+
allows cross-type comparisons to <type>int4</> and <type>int2</>. It
609+
could be duplicated by this definition:
610+
611+
<programlisting>
612+
CREATE OPERATOR CLASS int8_ops
613+
DEFAULT FOR TYPE int8 USING btree AS
614+
-- standard int8 comparisons
615+
OPERATOR 1 &lt; ,
616+
OPERATOR 2 &lt;= ,
617+
OPERATOR 3 = ,
618+
OPERATOR 4 &gt;= ,
619+
OPERATOR 5 &gt; ,
620+
FUNCTION 1 btint8cmp(int8, int8) ,
621+
622+
-- cross-type comparisons to int2 (smallint)
623+
OPERATOR 1 &lt; (int8, int2) ,
624+
OPERATOR 2 &lt;= (int8, int2) ,
625+
OPERATOR 3 = (int8, int2) ,
626+
OPERATOR 4 &gt;= (int8, int2) ,
627+
OPERATOR 5 &gt; (int8, int2) ,
628+
FUNCTION 1 btint82cmp(int8, int2) ,
629+
630+
-- cross-type comparisons to int4 (integer)
631+
OPERATOR 1 &lt; (int8, int4) ,
632+
OPERATOR 2 &lt;= (int8, int4) ,
633+
OPERATOR 3 = (int8, int4) ,
634+
OPERATOR 4 &gt;= (int8, int4) ,
635+
OPERATOR 5 &gt; (int8, int4) ,
636+
FUNCTION 1 btint84cmp(int8, int4) ;
637+
</programlisting>
638+
639+
Notice that this definition <quote>overloads</> the operator strategy and
640+
support function numbers. This is allowed (for B-tree operator classes
641+
only) so long as each instance of a particular number has a different
642+
right-hand data type. The instances that are not cross-type are the
643+
default or primary operators of the operator class.
644+
</para>
645+
646+
<para>
647+
GiST indexes do not allow overloading of strategy or support function
648+
numbers, but it is still possible to get the effect of supporting
649+
multiple right-hand data types, by assigning a distinct strategy number
650+
to each operator that needs to be supported. The <literal>consistent</>
651+
support function must determine what it needs to do based on the strategy
652+
number, and must be prepared to accept comparison values of the appropriate
653+
data types.
654+
</para>
655+
</sect2>
656+
592657
<sect2 id="xindex-opclass-dependencies">
593658
<title>System Dependencies on Operator Classes</title>
594659

‎src/backend/access/common/scankey.c

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/scankey.c,v 1.23 2003/11/09 21:30:35 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/scankey.c,v 1.24 2003/11/12 21:15:46 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -31,15 +31,43 @@ ScanKeyEntryInitialize(ScanKey entry,
3131
intflags,
3232
AttrNumberattributeNumber,
3333
StrategyNumberstrategy,
34+
Oidsubtype,
3435
RegProcedureprocedure,
35-
Datumargument,
36-
Oidargtype)
36+
Datumargument)
3737
{
3838
entry->sk_flags=flags;
3939
entry->sk_attno=attributeNumber;
4040
entry->sk_strategy=strategy;
41+
entry->sk_subtype=subtype;
42+
entry->sk_argument=argument;
43+
fmgr_info(procedure,&entry->sk_func);
44+
}
45+
46+
/*
47+
* ScanKeyInit
48+
*Shorthand version of ScanKeyEntryInitialize: flags and subtype
49+
*are assumed to be zero (the usual value).
50+
*
51+
* This is the recommended version for hardwired lookups in system catalogs.
52+
* It cannot handle NULL arguments, unary operators, or nondefault operators,
53+
* but we need none of those features for most hardwired lookups.
54+
*
55+
* Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
56+
* itself, because that's what will be used for any subsidiary info attached
57+
* to the ScanKey's FmgrInfo record.
58+
*/
59+
void
60+
ScanKeyInit(ScanKeyentry,
61+
AttrNumberattributeNumber,
62+
StrategyNumberstrategy,
63+
RegProcedureprocedure,
64+
Datumargument)
65+
{
66+
entry->sk_flags=0;
67+
entry->sk_attno=attributeNumber;
68+
entry->sk_strategy=strategy;
69+
entry->sk_subtype=InvalidOid;
4170
entry->sk_argument=argument;
42-
entry->sk_argtype=argtype;
4371
fmgr_info(procedure,&entry->sk_func);
4472
}
4573

@@ -57,14 +85,14 @@ ScanKeyEntryInitializeWithInfo(ScanKey entry,
5785
intflags,
5886
AttrNumberattributeNumber,
5987
StrategyNumberstrategy,
88+
Oidsubtype,
6089
FmgrInfo*finfo,
61-
Datumargument,
62-
Oidargtype)
90+
Datumargument)
6391
{
6492
entry->sk_flags=flags;
6593
entry->sk_attno=attributeNumber;
6694
entry->sk_strategy=strategy;
95+
entry->sk_subtype=subtype;
6796
entry->sk_argument=argument;
68-
entry->sk_argtype=argtype;
6997
fmgr_info_copy(&entry->sk_func,finfo,CurrentMemoryContext);
7098
}

‎src/backend/access/gist/gistget.c

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/gist/gistget.c,v 1.37 2003/11/09 21:30:35 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/gist/gistget.c,v 1.38 2003/11/12 21:15:46 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -221,40 +221,50 @@ gistindex_keytest(IndexTuple tuple,
221221
Pagep,
222222
OffsetNumberoffset)
223223
{
224-
boolisNull;
225-
Datumdatum;
226-
Datumtest;
227-
GISTENTRYde;
228-
229224
IncrIndexProcessed();
230225

231226
while (scanKeySize>0)
232227
{
228+
Datumdatum;
229+
boolisNull;
230+
Datumtest;
231+
GISTENTRYde;
232+
233233
datum=index_getattr(tuple,
234-
key[0].sk_attno,
234+
key->sk_attno,
235235
giststate->tupdesc,
236236
&isNull);
237+
/* is the index entry NULL? */
237238
if (isNull)
238239
{
239240
/* XXX eventually should check if SK_ISNULL */
240241
return false;
241242
}
242-
243-
/* this code from backend/access/common/indexvalid.c. But why and what???
244-
if (key[0].sk_flags & SK_ISNULL)
243+
/* is the compared-to datum NULL? */
244+
if (key->sk_flags&SK_ISNULL)
245245
return false;
246-
*/
247-
gistdentryinit(giststate,key[0].sk_attno-1,&de,
246+
247+
gistdentryinit(giststate,key->sk_attno-1,&de,
248248
datum,r,p,offset,
249249
IndexTupleSize(tuple)-sizeof(IndexTupleData),
250250
FALSE,isNull);
251251

252-
test=FunctionCall3(&key[0].sk_func,
252+
/*
253+
* Call the Consistent function to evaluate the test. The arguments
254+
* are the index datum (as a GISTENTRY*), the comparison datum, and
255+
* the comparison operator's strategy number and subtype from pg_amop.
256+
*
257+
* (Presently there's no need to pass the subtype since it'll always
258+
* be zero, but might as well pass it for possible future use.)
259+
*/
260+
test=FunctionCall4(&key->sk_func,
253261
PointerGetDatum(&de),
254-
key[0].sk_argument,
255-
Int32GetDatum(key[0].sk_strategy));
262+
key->sk_argument,
263+
Int32GetDatum(key->sk_strategy),
264+
ObjectIdGetDatum(key->sk_subtype));
256265

257-
if (de.key!=datum&& !isAttByVal(giststate,key[0].sk_attno-1))
266+
/* if index datum had to be decompressed, free it */
267+
if (de.key!=datum&& !isAttByVal(giststate,key->sk_attno-1))
258268
if (DatumGetPointer(de.key)!=NULL)
259269
pfree(DatumGetPointer(de.key));
260270

@@ -264,6 +274,7 @@ gistindex_keytest(IndexTuple tuple,
264274
scanKeySize--;
265275
key++;
266276
}
277+
267278
return true;
268279
}
269280

‎src/backend/access/gist/gistscan.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/gist/gistscan.c,v 1.48 2003/11/09 21:30:35 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/gist/gistscan.c,v 1.49 2003/11/12 21:15:46 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -109,7 +109,8 @@ gistrescan(PG_FUNCTION_ARGS)
109109
* Modify the scan key so that the Consistent function is called
110110
* for all comparisons. The original operator is passed to the
111111
* Consistent function in the form of its strategy number, which
112-
* is available from the sk_strategy field.
112+
* is available from the sk_strategy field, and its subtype from
113+
* the sk_subtype field.
113114
*/
114115
for (i=0;i<s->numberOfKeys;i++)
115116
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp