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

Commit85801a4

Browse files
committed
Rearrange fmgr.c and relcache so that it's possible to keep FmgrInfo
lookup info in the relcache for index access method support functions.This makes a huge difference for dynamically loaded support functions,and should save a few cycles even for built-in ones. Also tweak dfmgr.cso that load_external_function is called only once, not twice, whendoing fmgr_info for a dynamically loaded function. All per performancegripe from Teodor Sigaev, 5-Oct-01.
1 parenta965750 commit85801a4

File tree

31 files changed

+423
-389
lines changed

31 files changed

+423
-389
lines changed

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

Lines changed: 29 additions & 1 deletion
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.19 2001/06/01 02:41:35 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/scankey.c,v 1.20 2001/10/06 23:21:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -69,3 +69,31 @@ ScanKeyEntryInitialize(ScanKey entry,
6969

7070
Assert(ScanKeyEntryIsLegal(entry));
7171
}
72+
73+
/*
74+
* ScanKeyEntryInitializeWithInfo
75+
*Initializes a scan key entry using an already-completed FmgrInfo
76+
*function lookup record.
77+
*
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.
80+
*/
81+
void
82+
ScanKeyEntryInitializeWithInfo(ScanKeyentry,
83+
bits16flags,
84+
AttrNumberattributeNumber,
85+
FmgrInfo*finfo,
86+
MemoryContextmcxt,
87+
Datumargument)
88+
{
89+
Assert(PointerIsValid(entry));
90+
Assert(RegProcedureIsValid(finfo->fn_oid));
91+
92+
entry->sk_flags=flags;
93+
entry->sk_attno=attributeNumber;
94+
entry->sk_procedure=finfo->fn_oid;
95+
entry->sk_argument=argument;
96+
fmgr_info_copy(&entry->sk_func,finfo,mcxt);
97+
98+
Assert(ScanKeyEntryIsLegal(entry));
99+
}

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

Lines changed: 22 additions & 22 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/gist.c,v 1.83 2001/08/22 18:24:26 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.84 2001/10/06 23:21:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1542,13 +1542,6 @@ gistbulkdelete(PG_FUNCTION_ARGS)
15421542
void
15431543
initGISTstate(GISTSTATE*giststate,Relationindex)
15441544
{
1545-
RegProcedureconsistent_proc,
1546-
union_proc,
1547-
compress_proc,
1548-
decompress_proc,
1549-
penalty_proc,
1550-
picksplit_proc,
1551-
equal_proc;
15521545
inti;
15531546

15541547
if (index->rd_att->natts>INDEX_MAX_KEYS)
@@ -1559,20 +1552,27 @@ initGISTstate(GISTSTATE *giststate, Relation index)
15591552

15601553
for (i=0;i<index->rd_att->natts;i++)
15611554
{
1562-
consistent_proc=index_getprocid(index,i+1,GIST_CONSISTENT_PROC);
1563-
union_proc=index_getprocid(index,i+1,GIST_UNION_PROC);
1564-
compress_proc=index_getprocid(index,i+1,GIST_COMPRESS_PROC);
1565-
decompress_proc=index_getprocid(index,i+1,GIST_DECOMPRESS_PROC);
1566-
penalty_proc=index_getprocid(index,i+1,GIST_PENALTY_PROC);
1567-
picksplit_proc=index_getprocid(index,i+1,GIST_PICKSPLIT_PROC);
1568-
equal_proc=index_getprocid(index,i+1,GIST_EQUAL_PROC);
1569-
fmgr_info(consistent_proc,&((giststate->consistentFn)[i]) );
1570-
fmgr_info(union_proc,&((giststate->unionFn)[i]) );
1571-
fmgr_info(compress_proc,&((giststate->compressFn)[i]) );
1572-
fmgr_info(decompress_proc,&((giststate->decompressFn)[i]) );
1573-
fmgr_info(penalty_proc,&((giststate->penaltyFn)[i]) );
1574-
fmgr_info(picksplit_proc,&((giststate->picksplitFn)[i]) );
1575-
fmgr_info(equal_proc,&((giststate->equalFn)[i]) );
1555+
fmgr_info_copy(&(giststate->consistentFn[i]),
1556+
index_getprocinfo(index,i+1,GIST_CONSISTENT_PROC),
1557+
CurrentMemoryContext);
1558+
fmgr_info_copy(&(giststate->unionFn[i]),
1559+
index_getprocinfo(index,i+1,GIST_UNION_PROC),
1560+
CurrentMemoryContext);
1561+
fmgr_info_copy(&(giststate->compressFn[i]),
1562+
index_getprocinfo(index,i+1,GIST_COMPRESS_PROC),
1563+
CurrentMemoryContext);
1564+
fmgr_info_copy(&(giststate->decompressFn[i]),
1565+
index_getprocinfo(index,i+1,GIST_DECOMPRESS_PROC),
1566+
CurrentMemoryContext);
1567+
fmgr_info_copy(&(giststate->penaltyFn[i]),
1568+
index_getprocinfo(index,i+1,GIST_PENALTY_PROC),
1569+
CurrentMemoryContext);
1570+
fmgr_info_copy(&(giststate->picksplitFn[i]),
1571+
index_getprocinfo(index,i+1,GIST_PICKSPLIT_PROC),
1572+
CurrentMemoryContext);
1573+
fmgr_info_copy(&(giststate->equalFn[i]),
1574+
index_getprocinfo(index,i+1,GIST_EQUAL_PROC),
1575+
CurrentMemoryContext);
15761576
}
15771577
}
15781578

‎src/backend/access/hash/hashutil.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashutil.c,v 1.26 2001/02/2221:48:49 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashutil.c,v 1.27 2001/10/06 23:21:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515

1616
#include"postgres.h"
1717

18+
#include"access/genam.h"
1819
#include"access/hash.h"
1920
#include"access/iqual.h"
2021

@@ -27,8 +28,8 @@ _hash_mkscankey(Relation rel, IndexTuple itup, HashMetaPage metap)
2728
intnatts;
2829
AttrNumberi;
2930
Datumarg;
30-
RegProcedureproc;
31-
boolnull;
31+
FmgrInfo*procinfo;
32+
boolisnull;
3233

3334
natts=rel->rd_rel->relnatts;
3435
itupdesc=RelationGetDescr(rel);
@@ -37,10 +38,14 @@ _hash_mkscankey(Relation rel, IndexTuple itup, HashMetaPage metap)
3738

3839
for (i=0;i<natts;i++)
3940
{
40-
arg=index_getattr(itup,i+1,itupdesc,&null);
41-
proc=metap->hashm_procid;
42-
ScanKeyEntryInitialize(&skey[i],
43-
0x0, (AttrNumber) (i+1),proc,arg);
41+
arg=index_getattr(itup,i+1,itupdesc,&isnull);
42+
procinfo=index_getprocinfo(rel,i+1,HASHPROC);
43+
ScanKeyEntryInitializeWithInfo(&skey[i],
44+
0x0,
45+
(AttrNumber) (i+1),
46+
procinfo,
47+
CurrentMemoryContext,
48+
arg);
4449
}
4550

4651
returnskey;
@@ -89,10 +94,13 @@ _hash_formitem(IndexTuple itup)
8994
Bucket
9095
_hash_call(Relationrel,HashMetaPagemetap,Datumkey)
9196
{
97+
FmgrInfo*procinfo;
9298
uint32n;
9399
Bucketbucket;
94100

95-
n=DatumGetUInt32(OidFunctionCall1(metap->hashm_procid,key));
101+
/* XXX assumes index has only one attribute */
102+
procinfo=index_getprocinfo(rel,1,HASHPROC);
103+
n=DatumGetUInt32(FunctionCall1(procinfo,key));
96104
bucket=n&metap->hashm_highmask;
97105
if (bucket>metap->hashm_maxbucket)
98106
bucket=bucket&metap->hashm_lowmask;

‎src/backend/access/index/indexam.c

Lines changed: 48 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/index/indexam.c,v 1.52 2001/07/15 22:48:15 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.53 2001/10/06 23:21:43 tgl Exp $
1212
*
1313
* INTERFACE ROUTINES
1414
*index_open- open an index relation by relationId
@@ -428,12 +428,58 @@ index_getprocid(Relation irel,
428428
{
429429
RegProcedure*loc;
430430
intnproc;
431+
intprocindex;
431432

432433
nproc=irel->rd_am->amsupport;
433434

435+
Assert(procnum>0&&procnum <= (uint16)nproc);
436+
437+
procindex= (nproc* (attnum-1))+ (procnum-1);
438+
434439
loc=irel->rd_support;
435440

436441
Assert(loc!=NULL);
437442

438-
returnloc[(nproc* (attnum-1))+ (procnum-1)];
443+
returnloc[procindex];
444+
}
445+
446+
/* ----------------
447+
*index_getprocinfo
448+
*
449+
*This routine allows index AMs to keep fmgr lookup info for
450+
*support procs in the relcache.
451+
* ----------------
452+
*/
453+
structFmgrInfo*
454+
index_getprocinfo(Relationirel,
455+
AttrNumberattnum,
456+
uint16procnum)
457+
{
458+
FmgrInfo*locinfo;
459+
intnproc;
460+
intprocindex;
461+
462+
nproc=irel->rd_am->amsupport;
463+
464+
Assert(procnum>0&&procnum <= (uint16)nproc);
465+
466+
procindex= (nproc* (attnum-1))+ (procnum-1);
467+
468+
locinfo=irel->rd_supportinfo;
469+
470+
Assert(locinfo!=NULL);
471+
472+
locinfo+=procindex;
473+
474+
/* Initialize the lookup info if first time through */
475+
if (locinfo->fn_oid==InvalidOid)
476+
{
477+
RegProcedure*loc=irel->rd_support;
478+
479+
Assert(loc!=NULL);
480+
481+
fmgr_info_cxt(loc[procindex],locinfo,irel->rd_indexcxt);
482+
}
483+
484+
returnlocinfo;
439485
}

‎src/backend/access/index/istrat.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/index/Attic/istrat.c,v 1.52 2001/08/21 16:36:00 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/index/Attic/istrat.c,v 1.53 2001/10/06 23:21:43 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -486,12 +486,9 @@ FillScanKeyEntry(Oid operatorObjectId, ScanKey entry)
486486
operatorObjectId);
487487

488488
/*
489-
* Formerly we initialized entry->sk_func here, but that's a waste of
490-
* time because ScanKey entries in strategy maps are never actually
491-
* used to invoke the operator. Furthermore, to do that we'd have to
492-
* worry about setting the proper memory context (the map is probably
493-
* not allocated in the current memory context!)
489+
* Mark entry->sk_func invalid, until and unless someone sets it up.
494490
*/
491+
entry->sk_func.fn_oid=InvalidOid;
495492
}
496493

497494

‎src/backend/access/nbtree/nbtsearch.c

Lines changed: 10 additions & 5 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/nbtree/nbtsearch.c,v 1.67 2001/07/15 22:48:16 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.68 2001/10/06 23:21:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -435,7 +435,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
435435
BlockNumberblkno;
436436
StrategyNumberstrat;
437437
RetrieveIndexResultres;
438-
RegProcedureproc;
439438
int32result;
440439
BTScanOpaqueso;
441440
boolcontinuescan;
@@ -532,6 +531,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
532531
scankeys= (ScanKey)palloc(keysCount*sizeof(ScanKeyData));
533532
for (i=0;i<keysCount;i++)
534533
{
534+
FmgrInfo*procinfo;
535+
535536
j=nKeyIs[i];
536537

537538
/*
@@ -545,9 +546,13 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
545546
elog(ERROR,"_bt_first: btree doesn't support is(not)null, yet");
546547
return ((RetrieveIndexResult)NULL);
547548
}
548-
proc=index_getprocid(rel,i+1,BTORDER_PROC);
549-
ScanKeyEntryInitialize(scankeys+i,so->keyData[j].sk_flags,
550-
i+1,proc,so->keyData[j].sk_argument);
549+
procinfo=index_getprocinfo(rel,i+1,BTORDER_PROC);
550+
ScanKeyEntryInitializeWithInfo(scankeys+i,
551+
so->keyData[j].sk_flags,
552+
i+1,
553+
procinfo,
554+
CurrentMemoryContext,
555+
so->keyData[j].sk_argument);
551556
}
552557
if (nKeyIs)
553558
pfree(nKeyIs);

‎src/backend/access/nbtree/nbtutils.c

Lines changed: 17 additions & 15 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/nbtutils.c,v 1.45 2001/05/17 14:59:31 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.46 2001/10/06 23:21:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -36,7 +36,7 @@ _bt_mkscankey(Relation rel, IndexTuple itup)
3636
TupleDescitupdesc;
3737
intnatts;
3838
inti;
39-
RegProcedureproc;
39+
FmgrInfo*procinfo;
4040
Datumarg;
4141
boolnull;
4242
bits16flag;
@@ -48,14 +48,15 @@ _bt_mkscankey(Relation rel, IndexTuple itup)
4848

4949
for (i=0;i<natts;i++)
5050
{
51-
proc=index_getprocid(rel,i+1,BTORDER_PROC);
51+
procinfo=index_getprocinfo(rel,i+1,BTORDER_PROC);
5252
arg=index_getattr(itup,i+1,itupdesc,&null);
5353
flag=null ?SK_ISNULL :0x0;
54-
ScanKeyEntryInitialize(&skey[i],
55-
flag,
56-
(AttrNumber) (i+1),
57-
proc,
58-
arg);
54+
ScanKeyEntryInitializeWithInfo(&skey[i],
55+
flag,
56+
(AttrNumber) (i+1),
57+
procinfo,
58+
CurrentMemoryContext,
59+
arg);
5960
}
6061

6162
returnskey;
@@ -76,20 +77,21 @@ _bt_mkscankey_nodata(Relation rel)
7677
ScanKeyskey;
7778
intnatts;
7879
inti;
79-
RegProcedureproc;
80+
FmgrInfo*procinfo;
8081

8182
natts=RelationGetNumberOfAttributes(rel);
8283

8384
skey= (ScanKey)palloc(natts*sizeof(ScanKeyData));
8485

8586
for (i=0;i<natts;i++)
8687
{
87-
proc=index_getprocid(rel,i+1,BTORDER_PROC);
88-
ScanKeyEntryInitialize(&skey[i],
89-
SK_ISNULL,
90-
(AttrNumber) (i+1),
91-
proc,
92-
(Datum)NULL);
88+
procinfo=index_getprocinfo(rel,i+1,BTORDER_PROC);
89+
ScanKeyEntryInitializeWithInfo(&skey[i],
90+
SK_ISNULL,
91+
(AttrNumber) (i+1),
92+
procinfo,
93+
CurrentMemoryContext,
94+
(Datum)0);
9395
}
9496

9597
returnskey;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp