Skip to content

Commit c1d62bf

Browse files
committed
Add operator strategy and comparison-value datatype fields to ScanKey.
Remove the 'strategy map' code, which was a large amount of mechanism that no longer had any use except reverse-mapping from procedure OID to strategy number. Passing the strategy number to the index AM in the first place is simpler and faster. This is a preliminary step in planned support for cross-datatype index operations. I'm committing it now since the ScanKeyEntryInitialize() API change touches quite a lot of files, and I want to commit those changes before the tree drifts under me.
1 parent 723825a commit c1d62bf

Some content is hidden

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

72 files changed

+950
-2147
lines changed

contrib/dblink/dblink.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,8 +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, Anum_pg_index_indrelid,
1361-
F_OIDEQ, ObjectIdGetDatum(relid));
1360+
ScanKeyEntryInitialize(&entry, 0,
1361+
Anum_pg_index_indrelid,
1362+
BTEqualStrategyNumber, F_OIDEQ,
1363+
ObjectIdGetDatum(relid), OIDOID);
13621364
scan = heap_beginscan(indexRelation, SnapshotNow, 1, &entry);
13631365

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

contrib/miscutil/misc_utils.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "access/tupdesc.h"
2222
#include "catalog/catname.h"
2323
#include "catalog/pg_listener.h"
24+
#include "catalog/pg_type.h"
2425
#include "commands/async.h"
2526
#include "fmgr.h"
2627
#include "storage/lmgr.h"
@@ -88,8 +89,8 @@ active_listeners(text *relname)
8889
memcpy(listen_name, VARDATA(relname), len);
8990
ScanKeyEntryInitialize(&key, 0,
9091
Anum_pg_listener_relname,
91-
F_NAMEEQ,
92-
PointerGetDatum(listen_name));
92+
BTEqualStrategyNumber, F_NAMEEQ,
93+
PointerGetDatum(listen_name), NAMEOID);
9394
sRel = heap_beginscan(lRel, SnapshotNow, 1, &key);
9495
}
9596
else

src/backend/access/common/indexvalid.c

Lines changed: 3 additions & 6 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/Attic/indexvalid.c,v 1.29 2003/08/04 02:39:56 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/Attic/indexvalid.c,v 1.30 2003/11/09 21:30:35 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -57,12 +57,9 @@ index_keytest(IndexTuple tuple,
5757
if (key->sk_flags & SK_ISNULL)
5858
return false;
5959

60-
if (key->sk_flags & SK_COMMUTE)
61-
test = FunctionCall2(&key->sk_func, key->sk_argument, datum);
62-
else
63-
test = FunctionCall2(&key->sk_func, datum, key->sk_argument);
60+
test = FunctionCall2(&key->sk_func, datum, key->sk_argument);
6461

65-
if (DatumGetBool(test) == !!(key->sk_flags & SK_NEGATE))
62+
if (!DatumGetBool(test))
6663
return false;
6764

6865
key++;

src/backend/access/common/scankey.c

Lines changed: 24 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,70 @@
11
/*-------------------------------------------------------------------------
22
*
3-
* scan.c
4-
* scan direction and key code
3+
* scankey.c
4+
* scan key support code
55
*
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/scankey.c,v 1.22 2003/08/04 02:39:56 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/scankey.c,v 1.23 2003/11/09 21:30:35 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
15-
1615
#include "postgres.h"
1716

1817
#include "access/skey.h"
1918

20-
/*
21-
* ScanKeyEntryIsLegal
22-
* True iff the scan key entry is legal.
23-
*/
24-
#define ScanKeyEntryIsLegal(entry) \
25-
( \
26-
AssertMacro(PointerIsValid(entry)), \
27-
AttributeNumberIsValid((entry)->sk_attno) \
28-
)
29-
30-
/*
31-
* ScanKeyEntrySetIllegal
32-
* Marks a scan key entry as illegal.
33-
*/
34-
void
35-
ScanKeyEntrySetIllegal(ScanKey entry)
36-
{
37-
38-
Assert(PointerIsValid(entry));
39-
40-
entry->sk_flags = 0; /* just in case... */
41-
entry->sk_attno = InvalidAttrNumber;
42-
entry->sk_procedure = 0; /* should be InvalidRegProcedure */
43-
entry->sk_func.fn_oid = InvalidOid;
44-
entry->sk_argument = (Datum) 0;
45-
}
4619

4720
/*
4821
* ScanKeyEntryInitialize
49-
* Initializes a scan key entry.
22+
* Initializes a scan key entry given all the field values.
23+
* The target procedure is specified by OID.
5024
*
51-
* Note:
52-
* Assumes the scan key entry is valid.
53-
* Assumes the intialized scan key entry will be legal.
25+
* Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
26+
* itself, because that's what will be used for any subsidiary info attached
27+
* to the ScanKey's FmgrInfo record.
5428
*/
5529
void
5630
ScanKeyEntryInitialize(ScanKey entry,
57-
bits16 flags,
31+
int flags,
5832
AttrNumber attributeNumber,
33+
StrategyNumber strategy,
5934
RegProcedure procedure,
60-
Datum argument)
35+
Datum argument,
36+
Oid argtype)
6137
{
62-
Assert(PointerIsValid(entry));
63-
6438
entry->sk_flags = flags;
6539
entry->sk_attno = attributeNumber;
66-
entry->sk_procedure = procedure;
40+
entry->sk_strategy = strategy;
6741
entry->sk_argument = argument;
42+
entry->sk_argtype = argtype;
6843
fmgr_info(procedure, &entry->sk_func);
69-
70-
Assert(ScanKeyEntryIsLegal(entry));
7144
}
7245

7346
/*
7447
* ScanKeyEntryInitializeWithInfo
7548
* Initializes a scan key entry using an already-completed FmgrInfo
7649
* function lookup record.
7750
*
78-
* mcxt is the memory context holding the scan key; it'll be used for
79-
* any subsidiary info attached to the scankey's FmgrInfo record.
51+
* Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
52+
* itself, because that's what will be used for any subsidiary info attached
53+
* to the ScanKey's FmgrInfo record.
8054
*/
8155
void
8256
ScanKeyEntryInitializeWithInfo(ScanKey entry,
83-
bits16 flags,
57+
int flags,
8458
AttrNumber attributeNumber,
59+
StrategyNumber strategy,
8560
FmgrInfo *finfo,
86-
MemoryContext mcxt,
87-
Datum argument)
61+
Datum argument,
62+
Oid argtype)
8863
{
89-
Assert(PointerIsValid(entry));
90-
Assert(RegProcedureIsValid(finfo->fn_oid));
91-
9264
entry->sk_flags = flags;
9365
entry->sk_attno = attributeNumber;
94-
entry->sk_procedure = finfo->fn_oid;
66+
entry->sk_strategy = strategy;
9567
entry->sk_argument = argument;
96-
fmgr_info_copy(&entry->sk_func, finfo, mcxt);
97-
98-
Assert(ScanKeyEntryIsLegal(entry));
68+
entry->sk_argtype = argtype;
69+
fmgr_info_copy(&entry->sk_func, finfo, CurrentMemoryContext);
9970
}

src/backend/access/gist/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# Makefile for access/gist
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/backend/access/gist/Makefile,v 1.10 2000/08/31 16:09:31 petere Exp $
7+
# $Header: /cvsroot/pgsql/src/backend/access/gist/Makefile,v 1.11 2003/11/09 21:30:35 tgl Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/access/gist
1212
top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
OBJS = gist.o gistget.o gistscan.o giststrat.o
15+
OBJS = gist.o gistget.o gistscan.o
1616

1717
all: SUBSYS.o
1818

src/backend/access/gist/gistget.c

Lines changed: 6 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.36 2003/08/04 02:39:57 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/gist/gistget.c,v 1.37 2003/11/09 21:30:35 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -249,26 +249,16 @@ gistindex_keytest(IndexTuple tuple,
249249
IndexTupleSize(tuple) - sizeof(IndexTupleData),
250250
FALSE, isNull);
251251

252-
if (key[0].sk_flags & SK_COMMUTE)
253-
{
254-
test = FunctionCall3(&key[0].sk_func,
255-
key[0].sk_argument,
256-
PointerGetDatum(&de),
257-
ObjectIdGetDatum(key[0].sk_procedure));
258-
}
259-
else
260-
{
261-
test = FunctionCall3(&key[0].sk_func,
262-
PointerGetDatum(&de),
263-
key[0].sk_argument,
264-
ObjectIdGetDatum(key[0].sk_procedure));
265-
}
252+
test = FunctionCall3(&key[0].sk_func,
253+
PointerGetDatum(&de),
254+
key[0].sk_argument,
255+
Int32GetDatum(key[0].sk_strategy));
266256

267257
if (de.key != datum && !isAttByVal(giststate, key[0].sk_attno - 1))
268258
if (DatumGetPointer(de.key) != NULL)
269259
pfree(DatumGetPointer(de.key));
270260

271-
if (DatumGetBool(test) == !!(key[0].sk_flags & SK_NEGATE))
261+
if (!DatumGetBool(test))
272262
return false;
273263

274264
scanKeySize--;

src/backend/access/gist/gistscan.c

Lines changed: 5 additions & 9 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.47 2003/08/04 02:39:57 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/gist/gistscan.c,v 1.48 2003/11/09 21:30:35 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -106,17 +106,13 @@ gistrescan(PG_FUNCTION_ARGS)
106106
s->numberOfKeys * sizeof(ScanKeyData));
107107

108108
/*
109-
* Play games here with the scan key to use the Consistent
110-
* function for all comparisons: 1) the sk_procedure field will
111-
* now be used to hold the strategy number 2) the sk_func field
112-
* will point to the Consistent function
109+
* Modify the scan key so that the Consistent function is called
110+
* for all comparisons. The original operator is passed to the
111+
* Consistent function in the form of its strategy number, which
112+
* is available from the sk_strategy field.
113113
*/
114114
for (i = 0; i < s->numberOfKeys; i++)
115115
{
116-
s->keyData[i].sk_procedure =
117-
RelationGetGISTStrategy(s->indexRelation,
118-
s->keyData[i].sk_attno,
119-
s->keyData[i].sk_procedure);
120116
s->keyData[i].sk_func = p->giststate->consistentFn[s->keyData[i].sk_attno - 1];
121117
}
122118
}

src/backend/access/gist/giststrat.c

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy