mirror of
https://github.com/postgres/postgres.git
synced 2025-11-15 03:41:20 +03:00
Change pg_amop's index on (amopclaid,amopopr) to index (amopopr,amopclaid).
This makes no difference for existing uses, but allows SelectSortFunction() and pred_test_simple_clause() to use indexscans instead of seqscans to locate entries for a particular operator in pg_amop. Better yet, they can use the SearchSysCacheList() API to cache the search results.
This commit is contained in:
6
src/backend/utils/cache/lsyscache.c
vendored
6
src/backend/utils/cache/lsyscache.c
vendored
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.93 2003/05/09 18:08:48 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.94 2003/05/13 04:38:58 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Eventually, the index information should go through here, too.
|
||||
@@ -44,8 +44,8 @@ bool
|
||||
op_in_opclass(Oid opno, Oid opclass)
|
||||
{
|
||||
return SearchSysCacheExists(AMOPOPID,
|
||||
ObjectIdGetDatum(opclass),
|
||||
ObjectIdGetDatum(opno),
|
||||
ObjectIdGetDatum(opclass),
|
||||
0, 0);
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ op_requires_recheck(Oid opno, Oid opclass)
|
||||
bool result;
|
||||
|
||||
tp = SearchSysCache(AMOPOPID,
|
||||
ObjectIdGetDatum(opclass),
|
||||
ObjectIdGetDatum(opno),
|
||||
ObjectIdGetDatum(opclass),
|
||||
0, 0);
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "op_requires_recheck: op %u is not a member of opclass %u",
|
||||
|
||||
4
src/backend/utils/cache/syscache.c
vendored
4
src/backend/utils/cache/syscache.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.87 2002/09/04 20:31:30 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.88 2003/05/13 04:38:58 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* These routines allow the parser/planner/executor to perform
|
||||
@@ -128,8 +128,8 @@ static const struct cachedesc cacheinfo[] = {
|
||||
0,
|
||||
2,
|
||||
{
|
||||
Anum_pg_amop_amopclaid,
|
||||
Anum_pg_amop_amopopr,
|
||||
Anum_pg_amop_amopclaid,
|
||||
0,
|
||||
0
|
||||
}},
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplesort.c,v 1.32 2002/11/13 00:39:48 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplesort.c,v 1.33 2003/05/13 04:38:58 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -87,18 +87,18 @@
|
||||
|
||||
#include "access/heapam.h"
|
||||
#include "access/nbtree.h"
|
||||
#include "catalog/catname.h"
|
||||
#include "catalog/pg_amop.h"
|
||||
#include "catalog/pg_amproc.h"
|
||||
#include "catalog/pg_operator.h"
|
||||
#include "miscadmin.h"
|
||||
#include "utils/catcache.h"
|
||||
#include "utils/datum.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/logtape.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/tuplesort.h"
|
||||
|
||||
|
||||
/*
|
||||
* Possible states of a Tuplesort object. These denote the states that
|
||||
* persist between calls of Tuplesort routines.
|
||||
@@ -1708,32 +1708,30 @@ SelectSortFunction(Oid sortOperator,
|
||||
RegProcedure *sortFunction,
|
||||
SortFunctionKind *kind)
|
||||
{
|
||||
Relation relation;
|
||||
HeapScanDesc scan;
|
||||
ScanKeyData skey[1];
|
||||
CatCList *catlist;
|
||||
int i;
|
||||
HeapTuple tuple;
|
||||
Form_pg_operator optup;
|
||||
Oid opclass = InvalidOid;
|
||||
|
||||
/*
|
||||
* Scan pg_amop to see if the target operator is registered as the "<"
|
||||
* Search pg_amop to see if the target operator is registered as the "<"
|
||||
* or ">" operator of any btree opclass. It's possible that it might
|
||||
* be registered both ways (eg, if someone were to build a "reverse
|
||||
* sort" opclass for some reason); prefer the "<" case if so. If the
|
||||
* operator is registered the same way in multiple opclasses, assume
|
||||
* we can use the associated comparator function from any one.
|
||||
*/
|
||||
ScanKeyEntryInitialize(&skey[0], 0x0,
|
||||
Anum_pg_amop_amopopr,
|
||||
F_OIDEQ,
|
||||
ObjectIdGetDatum(sortOperator));
|
||||
catlist = SearchSysCacheList(AMOPOPID, 1,
|
||||
ObjectIdGetDatum(sortOperator),
|
||||
0, 0, 0);
|
||||
|
||||
relation = heap_openr(AccessMethodOperatorRelationName, AccessShareLock);
|
||||
scan = heap_beginscan(relation, SnapshotNow, 1, skey);
|
||||
|
||||
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
|
||||
for (i = 0; i < catlist->n_members; i++)
|
||||
{
|
||||
Form_pg_amop aform = (Form_pg_amop) GETSTRUCT(tuple);
|
||||
Form_pg_amop aform;
|
||||
|
||||
tuple = &catlist->members[i]->tuple;
|
||||
aform = (Form_pg_amop) GETSTRUCT(tuple);
|
||||
|
||||
if (!opclass_is_btree(aform->amopclaid))
|
||||
continue;
|
||||
@@ -1751,8 +1749,7 @@ SelectSortFunction(Oid sortOperator,
|
||||
}
|
||||
}
|
||||
|
||||
heap_endscan(scan);
|
||||
heap_close(relation, AccessShareLock);
|
||||
ReleaseSysCacheList(catlist);
|
||||
|
||||
if (OidIsValid(opclass))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user