Thread: five-key syscaches

five-key syscaches

From
Robert Haas
Date:
Per previous discussion, PFA a patch to change the maximum number of
keys for a syscache from 4 to 5.

http://archives.postgresql.org/pgsql-hackers/2010-02/msg01105.php

This is intended for application to 9.1, and is supporting
infrastructure for knngist.

...Robert

Attachment

Re: five-key syscaches

From
Joachim Wieland
Date:
On Mon, Mar 29, 2010 at 12:32 AM, Robert Haas <robertmhaas@gmail.com> wrote:
> Per previous discussion, PFA a patch to change the maximum number of
> keys for a syscache from 4 to 5.
>
> http://archives.postgresql.org/pgsql-hackers/2010-02/msg01105.php
>
> This is intended for application to 9.1, and is supporting
> infrastructure for knngist.

It looks like there should be a 5 rather than a 4 for nkeys of
SearchSysCacheList().

+#define SearchSysCacheList5(cacheId, key1, key2, key3, key4, key5) \
+    SearchSysCacheList(cacheId, 4, key1, key2, key3, key4, key5)


Joachim


Re: five-key syscaches

From
Robert Haas
Date:
On Mon, Mar 29, 2010 at 4:21 AM, Joachim Wieland <joe@mcknight.de> wrote:
> On Mon, Mar 29, 2010 at 12:32 AM, Robert Haas <robertmhaas@gmail.com> wrote:
>> Per previous discussion, PFA a patch to change the maximum number of
>> keys for a syscache from 4 to 5.
>>
>> http://archives.postgresql.org/pgsql-hackers/2010-02/msg01105.php
>>
>> This is intended for application to 9.1, and is supporting
>> infrastructure for knngist.
>
> It looks like there should be a 5 rather than a 4 for nkeys of
> SearchSysCacheList().
>
> +#define SearchSysCacheList5(cacheId, key1, key2, key3, key4, key5) \
> +       SearchSysCacheList(cacheId, 4, key1, key2, key3, key4, key5)

Good catch.  Will fix.

...Robert


Re: five-key syscaches

From
Yeb Havinga
Date:
Hello Robert,

As part of the current reviewfest, I reviewed your patch, and made some
changes on the way.

This was all ok:

*) while proofreading I did not find typos other than the one that
Joachim had already pointed out.
*) the addition of 5-key lookups to the existing ones seems a natural
extension, and the best way to solve finding the index that
can-order-by-op needed for the knngist. Solutions were debated in a
relatively long thread 'knngist patch support', where the first
reference of four columns being too less was in
http://archives.postgresql.org/pgsql-hackers/2010-02/msg01071.php
*) regression test ok
*) performance: comparing make check speeds with and without patch did
not reveal significant differences.

The changes:

*) since the API of the syscache functions is changed, one would expect
a lot of compile errors but none were found. The patch of
http://archives.postgresql.org/pgsql-committers/2010-02/msg00174.php
that introduced macro's around the base functions made that possible.
Two calls in contrib/tsearch2 were overlooked.
*) after changing the calls in contrib/tsearch2 and compiled and
installchecked ok
*) I also removed a few unneeded includes of syscache.h from some
contrib modules
*) In syscache.c the cachedesc structure has a key array that is
increased from 4 to CATCACHE_MAXKEYS. However, each element of the
cacheinfo[] array still has 4 attribute numbers listed, so the 5th
element is undefined. To not rely on compiler or platform and for code
uniformity I changed all syscaches to have 5 attribute numbers.
*) To test the new functions I added an extra syscache and performed a 5
key lookup. This gave the following error FATAL:  wrong number of hash
keys: 5 in CatalogCacheComputeHashValue. I changed that as well, but
somebody with intimate knowledge of hash algorithms should probably
decide which bit-shifting on the key values is appropriate. It currently
does the same as key 3: hashValue ^= oneHash << 16; hashValue ^= oneHash
 >> 16;

I tested a negative and positive search with SearchSysCacheExists5, that
were executed as expected. Regression test still ok.

Attach is a new patch with all things described above addressed.

regards,
Yeb Havinga


Robert Haas wrote:
> On Mon, Mar 29, 2010 at 4:21 AM, Joachim Wieland <joe@mcknight.de> wrote:
>
>> On Mon, Mar 29, 2010 at 12:32 AM, Robert Haas <robertmhaas@gmail.com> wrote:
>>
>>> Per previous discussion, PFA a patch to change the maximum number of
>>> keys for a syscache from 4 to 5.
>>>
>>> http://archives.postgresql.org/pgsql-hackers/2010-02/msg01105.php
>>>
>>> This is intended for application to 9.1, and is supporting
>>> infrastructure for knngist.
>>>
>> It looks like there should be a 5 rather than a 4 for nkeys of
>> SearchSysCacheList().
>>
>> +#define SearchSysCacheList5(cacheId, key1, key2, key3, key4, key5) \
>> +       SearchSysCacheList(cacheId, 4, key1, key2, key3, key4, key5)
>>
>
> Good catch.  Will fix.
>
> ...Robert
>
>

diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 82b0730..e803652 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -63,7 +63,6 @@
 #include "utils/hsearch.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
-#include "utils/syscache.h"
 #include "utils/tqual.h"

 #include "dblink.h"
diff --git a/contrib/ltree/ltree_op.c b/contrib/ltree/ltree_op.c
index c76e6cc..906d38d 100644
--- a/contrib/ltree/ltree_op.c
+++ b/contrib/ltree/ltree_op.c
@@ -11,7 +11,6 @@
 #include "utils/builtins.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
-#include "utils/syscache.h"
 #include "ltree.h"

 PG_MODULE_MAGIC;
diff --git a/contrib/tsearch2/tsearch2.c b/contrib/tsearch2/tsearch2.c
index d421f77..224563a 100644
--- a/contrib/tsearch2/tsearch2.c
+++ b/contrib/tsearch2/tsearch2.c
@@ -172,9 +172,8 @@ tsa_set_curdict(PG_FUNCTION_ARGS)
 {
     Oid            dict_oid = PG_GETARG_OID(0);

-    if (!SearchSysCacheExists(TSDICTOID,
-                              ObjectIdGetDatum(dict_oid),
-                              0, 0, 0))
+    if (!SearchSysCacheExists1(TSDICTOID,
+                               ObjectIdGetDatum(dict_oid)))
         elog(ERROR, "cache lookup failed for text search dictionary %u",
              dict_oid);

@@ -211,9 +210,8 @@ tsa_set_curprs(PG_FUNCTION_ARGS)
 {
     Oid            parser_oid = PG_GETARG_OID(0);

-    if (!SearchSysCacheExists(TSPARSEROID,
-                              ObjectIdGetDatum(parser_oid),
-                              0, 0, 0))
+    if (!SearchSysCacheExists1(TSPARSEROID,
+                              ObjectIdGetDatum(parser_oid)))
         elog(ERROR, "cache lookup failed for text search parser %u",
              parser_oid);

diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 07d6d89..c1ef41b 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -183,6 +183,13 @@ CatalogCacheComputeHashValue(CatCache *cache, int nkeys, ScanKey cur_skey)

     switch (nkeys)
     {
+        case 5:
+            oneHash =
+                DatumGetUInt32(DirectFunctionCall1(cache->cc_hashfunc[4],
+                                                   cur_skey[4].sk_argument));
+            hashValue ^= oneHash << 16;
+            hashValue ^= oneHash >> 16;
+            /* FALLTHROUGH */
         case 4:
             oneHash =
                 DatumGetUInt32(DirectFunctionCall1(cache->cc_hashfunc[3],
@@ -1057,7 +1064,8 @@ SearchCatCache(CatCache *cache,
                Datum v1,
                Datum v2,
                Datum v3,
-               Datum v4)
+               Datum v4,
+               Datum v5)
 {
     ScanKeyData cur_skey[CATCACHE_MAXKEYS];
     uint32        hashValue;
@@ -1086,6 +1094,7 @@ SearchCatCache(CatCache *cache,
     cur_skey[1].sk_argument = v2;
     cur_skey[2].sk_argument = v3;
     cur_skey[3].sk_argument = v4;
+    cur_skey[4].sk_argument = v5;

     /*
      * find the hash bucket in which to look for the tuple
@@ -1298,7 +1307,8 @@ SearchCatCacheList(CatCache *cache,
                    Datum v1,
                    Datum v2,
                    Datum v3,
-                   Datum v4)
+                   Datum v4,
+                   Datum v5)
 {
     ScanKeyData cur_skey[CATCACHE_MAXKEYS];
     uint32        lHashValue;
@@ -1333,6 +1343,7 @@ SearchCatCacheList(CatCache *cache,
     cur_skey[1].sk_argument = v2;
     cur_skey[2].sk_argument = v3;
     cur_skey[3].sk_argument = v4;
+    cur_skey[4].sk_argument = v5;

     /*
      * compute a hash value of the given keys for faster search.  We don't
diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c
index 61b06ac..8dca335 100644
--- a/src/backend/utils/cache/syscache.c
+++ b/src/backend/utils/cache/syscache.c
@@ -95,7 +95,7 @@ struct cachedesc
     Oid            reloid;            /* OID of the relation being cached */
     Oid            indoid;            /* OID of index relation for this cache */
     int            nkeys;            /* # of keys needed for cache lookup */
-    int            key[4];            /* attribute numbers of key attrs */
+    int            key[CATCACHE_MAXKEYS];    /* attribute numbers of key attrs */
     int            nbuckets;        /* number of hash buckets for this cache */
 };

@@ -107,6 +107,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_aggregate_aggfnoid,
             0,
             0,
+            0,
             0
         },
         32
@@ -118,6 +119,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_am_amname,
             0,
             0,
+            0,
             0
         },
         4
@@ -129,6 +131,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         4
@@ -140,6 +143,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_amop_amopopr,
             Anum_pg_amop_amopfamily,
             0,
+            0,
             0
         },
         64
@@ -151,7 +155,8 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_amop_amopfamily,
             Anum_pg_amop_amoplefttype,
             Anum_pg_amop_amoprighttype,
-            Anum_pg_amop_amopstrategy
+            Anum_pg_amop_amopstrategy,
+            0
         },
         64
     },
@@ -162,7 +167,8 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_amproc_amprocfamily,
             Anum_pg_amproc_amproclefttype,
             Anum_pg_amproc_amprocrighttype,
-            Anum_pg_amproc_amprocnum
+            Anum_pg_amproc_amprocnum,
+            0
         },
         64
     },
@@ -173,6 +179,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_attribute_attrelid,
             Anum_pg_attribute_attname,
             0,
+            0,
             0
         },
         2048
@@ -184,6 +191,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_attribute_attrelid,
             Anum_pg_attribute_attnum,
             0,
+            0,
             0
         },
         2048
@@ -195,6 +203,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_auth_members_member,
             Anum_pg_auth_members_roleid,
             0,
+            0,
             0
         },
         128
@@ -206,6 +215,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_auth_members_roleid,
             Anum_pg_auth_members_member,
             0,
+            0,
             0
         },
         128
@@ -217,6 +227,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_authid_rolname,
             0,
             0,
+            0,
             0
         },
         128
@@ -228,6 +239,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         128
@@ -240,6 +252,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_cast_castsource,
             Anum_pg_cast_casttarget,
             0,
+            0,
             0
         },
         256
@@ -251,6 +264,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_opclass_opcmethod,
             Anum_pg_opclass_opcname,
             Anum_pg_opclass_opcnamespace,
+            0,
             0
         },
         64
@@ -262,6 +276,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         64
@@ -274,6 +289,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_conversion_conforencoding,
             Anum_pg_conversion_contoencoding,
             ObjectIdAttributeNumber,
+            0
         },
         128
     },
@@ -284,6 +300,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_conversion_conname,
             Anum_pg_conversion_connamespace,
             0,
+            0,
             0
         },
         128
@@ -295,6 +312,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         1024
@@ -306,6 +324,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         128
@@ -317,6 +336,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         4
@@ -328,6 +348,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_default_acl_defaclrole,
             Anum_pg_default_acl_defaclnamespace,
             Anum_pg_default_acl_defaclobjtype,
+            0,
             0
         },
         256
@@ -339,6 +360,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         256
@@ -350,6 +372,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_enum_enumtypid,
             Anum_pg_enum_enumlabel,
             0,
+            0,
             0
         },
         256
@@ -361,6 +384,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_foreign_data_wrapper_fdwname,
             0,
             0,
+            0,
             0
         },
         8
@@ -372,6 +396,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         8
@@ -383,6 +408,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_foreign_server_srvname,
             0,
             0,
+            0,
             0
         },
         32
@@ -394,6 +420,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         32
@@ -405,6 +432,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_index_indexrelid,
             0,
             0,
+            0,
             0
         },
         1024
@@ -416,6 +444,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_language_lanname,
             0,
             0,
+            0,
             0
         },
         4
@@ -427,6 +456,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         4
@@ -438,6 +468,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_namespace_nspname,
             0,
             0,
+            0,
             0
         },
         256
@@ -449,6 +480,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         256
@@ -460,7 +492,9 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_operator_oprname,
             Anum_pg_operator_oprleft,
             Anum_pg_operator_oprright,
-            Anum_pg_operator_oprnamespace
+            Anum_pg_operator_oprnamespace,
+            0
+
         },
         1024
     },
@@ -471,6 +505,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         1024
@@ -482,6 +517,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_opfamily_opfmethod,
             Anum_pg_opfamily_opfname,
             Anum_pg_opfamily_opfnamespace,
+            0,
             0
         },
         64
@@ -493,6 +529,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         64
@@ -504,6 +541,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_proc_proname,
             Anum_pg_proc_proargtypes,
             Anum_pg_proc_pronamespace,
+            0,
             0
         },
         2048
@@ -515,6 +553,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         2048
@@ -526,6 +565,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_class_relname,
             Anum_pg_class_relnamespace,
             0,
+            0,
             0
         },
         1024
@@ -537,6 +577,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         1024
@@ -548,6 +589,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_rewrite_ev_class,
             Anum_pg_rewrite_rulename,
             0,
+            0,
             0
         },
         1024
@@ -559,6 +601,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_statistic_starelid,
             Anum_pg_statistic_staattnum,
             Anum_pg_statistic_stainherit,
+            0,
             0
         },
         1024
@@ -571,6 +614,7 @@ static const struct cachedesc cacheinfo[] = {
             0,
             0,
             0,
+            0
         },
         16
     },
@@ -581,6 +625,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_ts_config_map_mapcfg,
             Anum_pg_ts_config_map_maptokentype,
             Anum_pg_ts_config_map_mapseqno,
+            0,
             0
         },
         4
@@ -592,6 +637,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_ts_config_cfgname,
             Anum_pg_ts_config_cfgnamespace,
             0,
+            0,
             0
         },
         16
@@ -603,6 +649,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         16
@@ -614,6 +661,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_ts_dict_dictname,
             Anum_pg_ts_dict_dictnamespace,
             0,
+            0,
             0
         },
         16
@@ -625,6 +673,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         16
@@ -636,6 +685,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_ts_parser_prsname,
             Anum_pg_ts_parser_prsnamespace,
             0,
+            0,
             0
         },
         4
@@ -647,6 +697,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         4
@@ -658,6 +709,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_ts_template_tmplname,
             Anum_pg_ts_template_tmplnamespace,
             0,
+            0,
             0
         },
         16
@@ -669,6 +721,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         16
@@ -680,6 +733,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_type_typname,
             Anum_pg_type_typnamespace,
             0,
+            0,
             0
         },
         1024
@@ -691,6 +745,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         1024
@@ -702,6 +757,7 @@ static const struct cachedesc cacheinfo[] = {
             ObjectIdAttributeNumber,
             0,
             0,
+            0,
             0
         },
         128
@@ -713,6 +769,7 @@ static const struct cachedesc cacheinfo[] = {
             Anum_pg_user_mapping_umuser,
             Anum_pg_user_mapping_umserver,
             0,
+            0,
             0
         },
         128
@@ -803,13 +860,14 @@ SearchSysCache(int cacheId,
                Datum key1,
                Datum key2,
                Datum key3,
-               Datum key4)
+               Datum key4,
+               Datum key5)
 {
     if (cacheId < 0 || cacheId >= SysCacheSize ||
         !PointerIsValid(SysCache[cacheId]))
         elog(ERROR, "invalid cache id: %d", cacheId);

-    return SearchCatCache(SysCache[cacheId], key1, key2, key3, key4);
+    return SearchCatCache(SysCache[cacheId], key1, key2, key3, key4, key5);
 }

 /*
@@ -835,12 +893,13 @@ SearchSysCacheCopy(int cacheId,
                    Datum key1,
                    Datum key2,
                    Datum key3,
-                   Datum key4)
+                   Datum key4,
+                   Datum key5)
 {
     HeapTuple    tuple,
                 newtuple;

-    tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
+    tuple = SearchSysCache(cacheId, key1, key2, key3, key4, key5);
     if (!HeapTupleIsValid(tuple))
         return tuple;
     newtuple = heap_copytuple(tuple);
@@ -859,11 +918,12 @@ SearchSysCacheExists(int cacheId,
                      Datum key1,
                      Datum key2,
                      Datum key3,
-                     Datum key4)
+                     Datum key4,
+                     Datum key5)
 {
     HeapTuple    tuple;

-    tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
+    tuple = SearchSysCache(cacheId, key1, key2, key3, key4, key5);
     if (!HeapTupleIsValid(tuple))
         return false;
     ReleaseSysCache(tuple);
@@ -882,12 +942,13 @@ GetSysCacheOid(int cacheId,
                Datum key1,
                Datum key2,
                Datum key3,
-               Datum key4)
+               Datum key4,
+               Datum key5)
 {
     HeapTuple    tuple;
     Oid            result;

-    tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
+    tuple = SearchSysCache(cacheId, key1, key2, key3, key4, key5);
     if (!HeapTupleIsValid(tuple))
         return InvalidOid;
     result = HeapTupleGetOid(tuple);
@@ -1008,12 +1069,12 @@ SysCacheGetAttr(int cacheId, HeapTuple tup,
  */
 struct catclist *
 SearchSysCacheList(int cacheId, int nkeys,
-                   Datum key1, Datum key2, Datum key3, Datum key4)
+                   Datum key1, Datum key2, Datum key3, Datum key4, Datum key5)
 {
     if (cacheId < 0 || cacheId >= SysCacheSize ||
         !PointerIsValid(SysCache[cacheId]))
         elog(ERROR, "invalid cache id: %d", cacheId);

     return SearchCatCacheList(SysCache[cacheId], nkeys,
-                              key1, key2, key3, key4);
+                              key1, key2, key3, key4, key5);
 }
diff --git a/src/include/utils/catcache.h b/src/include/utils/catcache.h
index 0db116d..64e683e 100644
--- a/src/include/utils/catcache.h
+++ b/src/include/utils/catcache.h
@@ -32,7 +32,7 @@
  *        struct catcacheheader:    information for managing all the caches.
  */

-#define CATCACHE_MAXKEYS        4
+#define CATCACHE_MAXKEYS        5

 typedef struct catcache
 {
@@ -171,12 +171,14 @@ extern void InitCatCachePhase2(CatCache *cache, bool touch_index);

 extern HeapTuple SearchCatCache(CatCache *cache,
                Datum v1, Datum v2,
-               Datum v3, Datum v4);
+               Datum v3, Datum v4,
+               Datum v5);
 extern void ReleaseCatCache(HeapTuple tuple);

 extern CatCList *SearchCatCacheList(CatCache *cache, int nkeys,
                    Datum v1, Datum v2,
-                   Datum v3, Datum v4);
+                   Datum v3, Datum v4,
+                   Datum v5);
 extern void ReleaseCatCacheList(CatCList *list);

 extern void ResetCatalogCaches(void);
diff --git a/src/include/utils/syscache.h b/src/include/utils/syscache.h
index 2f19e5c..fc9bb08 100644
--- a/src/include/utils/syscache.h
+++ b/src/include/utils/syscache.h
@@ -91,16 +91,17 @@ extern void InitCatalogCache(void);
 extern void InitCatalogCachePhase2(void);

 extern HeapTuple SearchSysCache(int cacheId,
-               Datum key1, Datum key2, Datum key3, Datum key4);
+               Datum key1, Datum key2, Datum key3, Datum key4, Datum key5);
 extern void ReleaseSysCache(HeapTuple tuple);

 /* convenience routines */
 extern HeapTuple SearchSysCacheCopy(int cacheId,
-                   Datum key1, Datum key2, Datum key3, Datum key4);
+                   Datum key1, Datum key2, Datum key3, Datum key4, Datum key5);
 extern bool SearchSysCacheExists(int cacheId,
-                     Datum key1, Datum key2, Datum key3, Datum key4);
+                     Datum key1, Datum key2, Datum key3,
+                     Datum key4, Datum key5);
 extern Oid GetSysCacheOid(int cacheId,
-               Datum key1, Datum key2, Datum key3, Datum key4);
+               Datum key1, Datum key2, Datum key3, Datum key4, Datum key5);

 extern HeapTuple SearchSysCacheAttName(Oid relid, const char *attname);
 extern HeapTuple SearchSysCacheCopyAttName(Oid relid, const char *attname);
@@ -111,7 +112,7 @@ extern Datum SysCacheGetAttr(int cacheId, HeapTuple tup,

 /* list-search interface.  Users of this must import catcache.h too */
 extern struct catclist *SearchSysCacheList(int cacheId, int nkeys,
-                   Datum key1, Datum key2, Datum key3, Datum key4);
+                   Datum key1, Datum key2, Datum key3, Datum key4, Datum key5);

 /*
  * The use of the macros below rather than direct calls to the corresponding
@@ -119,49 +120,59 @@ extern struct catclist *SearchSysCacheList(int cacheId, int nkeys,
  * maximum number of keys.
  */
 #define SearchSysCache1(cacheId, key1) \
-    SearchSysCache(cacheId, key1, 0, 0, 0)
+    SearchSysCache(cacheId, key1, 0, 0, 0, 0)
 #define SearchSysCache2(cacheId, key1, key2) \
-    SearchSysCache(cacheId, key1, key2, 0, 0)
+    SearchSysCache(cacheId, key1, key2, 0, 0, 0)
 #define SearchSysCache3(cacheId, key1, key2, key3) \
-    SearchSysCache(cacheId, key1, key2, key3, 0)
+    SearchSysCache(cacheId, key1, key2, key3, 0, 0)
 #define SearchSysCache4(cacheId, key1, key2, key3, key4) \
-    SearchSysCache(cacheId, key1, key2, key3, key4)
+    SearchSysCache(cacheId, key1, key2, key3, key4, 0)
+#define SearchSysCache5(cacheId, key1, key2, key3, key4, key5) \
+    SearchSysCache(cacheId, key1, key2, key3, key4, key5)

 #define SearchSysCacheCopy1(cacheId, key1) \
-    SearchSysCacheCopy(cacheId, key1, 0, 0, 0)
+    SearchSysCacheCopy(cacheId, key1, 0, 0, 0, 0)
 #define SearchSysCacheCopy2(cacheId, key1, key2) \
-    SearchSysCacheCopy(cacheId, key1, key2, 0, 0)
+    SearchSysCacheCopy(cacheId, key1, key2, 0, 0, 0)
 #define SearchSysCacheCopy3(cacheId, key1, key2, key3) \
-    SearchSysCacheCopy(cacheId, key1, key2, key3, 0)
+    SearchSysCacheCopy(cacheId, key1, key2, key3, 0, 0)
 #define SearchSysCacheCopy4(cacheId, key1, key2, key3, key4) \
-    SearchSysCacheCopy(cacheId, key1, key2, key3, key4)
+    SearchSysCacheCopy(cacheId, key1, key2, key3, key4, 0)
+#define SearchSysCacheCopy5(cacheId, key1, key2, key3, key4, key5) \
+    SearchSysCacheCopy(cacheId, key1, key2, key3, key4, key5)

 #define SearchSysCacheExists1(cacheId, key1) \
-    SearchSysCacheExists(cacheId, key1, 0, 0, 0)
+    SearchSysCacheExists(cacheId, key1, 0, 0, 0, 0)
 #define SearchSysCacheExists2(cacheId, key1, key2) \
-    SearchSysCacheExists(cacheId, key1, key2, 0, 0)
+    SearchSysCacheExists(cacheId, key1, key2, 0, 0, 0)
 #define SearchSysCacheExists3(cacheId, key1, key2, key3) \
-    SearchSysCacheExists(cacheId, key1, key2, key3, 0)
+    SearchSysCacheExists(cacheId, key1, key2, key3, 0, 0)
 #define SearchSysCacheExists4(cacheId, key1, key2, key3, key4) \
-    SearchSysCacheExists(cacheId, key1, key2, key3, key4)
+    SearchSysCacheExists(cacheId, key1, key2, key3, key4, 0)
+#define SearchSysCacheExists5(cacheId, key1, key2, key3, key4, key5) \
+    SearchSysCacheExists(cacheId, key1, key2, key3, key4, key5)

 #define GetSysCacheOid1(cacheId, key1) \
-    GetSysCacheOid(cacheId, key1, 0, 0, 0)
+    GetSysCacheOid(cacheId, key1, 0, 0, 0, 0)
 #define GetSysCacheOid2(cacheId, key1, key2) \
-    GetSysCacheOid(cacheId, key1, key2, 0, 0)
+    GetSysCacheOid(cacheId, key1, key2, 0, 0, 0)
 #define GetSysCacheOid3(cacheId, key1, key2, key3) \
-    GetSysCacheOid(cacheId, key1, key2, key3, 0)
+    GetSysCacheOid(cacheId, key1, key2, key3, 0, 0)
 #define GetSysCacheOid4(cacheId, key1, key2, key3, key4) \
-    GetSysCacheOid(cacheId, key1, key2, key3, key4)
+    GetSysCacheOid(cacheId, key1, key2, key3, key4, 0)
+#define GetSysCacheOid5(cacheId, key1, key2, key3, key4, key5) \
+    GetSysCacheOid(cacheId, key1, key2, key3, key4, key5)

 #define SearchSysCacheList1(cacheId, key1) \
-    SearchSysCacheList(cacheId, 1, key1, 0, 0, 0)
+    SearchSysCacheList(cacheId, 1, key1, 0, 0, 0, 0)
 #define SearchSysCacheList2(cacheId, key1, key2) \
-    SearchSysCacheList(cacheId, 2, key1, key2, 0, 0)
+    SearchSysCacheList(cacheId, 2, key1, key2, 0, 0, 0)
 #define SearchSysCacheList3(cacheId, key1, key2, key3) \
-    SearchSysCacheList(cacheId, 3, key1, key2, key3, 0)
+    SearchSysCacheList(cacheId, 3, key1, key2, key3, 0, 0)
 #define SearchSysCacheList4(cacheId, key1, key2, key3, key4) \
-    SearchSysCacheList(cacheId, 4, key1, key2, key3, key4)
+    SearchSysCacheList(cacheId, 4, key1, key2, key3, key4, 0)
+#define SearchSysCacheList5(cacheId, key1, key2, key3, key4, key5) \
+    SearchSysCacheList(cacheId, 5, key1, key2, key3, key4, key5)

 #define ReleaseSysCacheList(x)    ReleaseCatCacheList(x)


Re: five-key syscaches

From
Robert Haas
Date:
On Wed, Jul 14, 2010 at 7:27 AM, Yeb Havinga <yebhavinga@gmail.com> wrote:
> Attach is a new patch with all things described above addressed.

Thanks!

I think we should probably hold off applying this until some of the
other KNNGIST work is ready, or we have some other concrete need for
5-key syscaches.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


Re: five-key syscaches

From
Yeb Havinga
Date:
Robert Haas wrote:
> On Wed, Jul 14, 2010 at 7:27 AM, Yeb Havinga <yebhavinga@gmail.com> wrote:
>   
>> Attach is a new patch with all things described above addressed.
>>     
>
> Thanks!
>
> I think we should probably hold off applying this until some of the
> other KNNGIST work is ready, or we have some other concrete need for
> 5-key syscaches.
>   
Any thoughts about the << 16 and >> 16 bit shifting on the 5th hash key 
computation? I blithely copied it from the 3rd key.

--
Yeb


Re: five-key syscaches

From
Robert Haas
Date:
On Wed, Jul 14, 2010 at 10:56 AM, Yeb Havinga <yebhavinga@gmail.com> wrote:
> Robert Haas wrote:
>> On Wed, Jul 14, 2010 at 7:27 AM, Yeb Havinga <yebhavinga@gmail.com> wrote:
>>> Attach is a new patch with all things described above addressed.
>> Thanks!
>>
>> I think we should probably hold off applying this until some of the
>> other KNNGIST work is ready, or we have some other concrete need for
>> 5-key syscaches.
>
> Any thoughts about the << 16 and >> 16 bit shifting on the 5th hash key
> computation? I blithely copied it from the 3rd key.

Hmm, I thought I had the bit in my version, but I see that I don't.
Must have gotten lost from an earlier incarnation.  It's probably bad
to duplicate the bit-shifting pattern of an existing key.  We might
want to shift by something that's not a multiple of 8, like 12/20.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company