*** ./src/backend/utils/cache/catcache.c.orig 2009-07-06 22:06:52.000000000 +0900 --- ./src/backend/utils/cache/catcache.c 2009-07-06 13:51:48.000000000 +0900 *************** *** 1124,1140 **** /* * initialize the search key information */ ! memcpy(cur_skey, cache->cc_skey, sizeof(cur_skey)); ! cur_skey[0].sk_argument = v1; ! cur_skey[1].sk_argument = v2; ! cur_skey[2].sk_argument = v3; ! cur_skey[3].sk_argument = v4; /* * find the hash bucket in which to look for the tuple */ ! hashValue = CatalogCacheComputeHashValue(cache, cache->cc_nkeys, cur_skey); hashIndex = HASH_INDEX(hashValue, cache->cc_nbuckets); /* --- 1124,1141 ---- /* * initialize the search key information + * use cache->cc_skey directly in looking for hash table */ ! cache->cc_skey[0].sk_argument = v1; ! cache->cc_skey[1].sk_argument = v2; ! cache->cc_skey[2].sk_argument = v3; ! cache->cc_skey[3].sk_argument = v4; /* * find the hash bucket in which to look for the tuple */ ! hashValue = CatalogCacheComputeHashValue(cache, cache->cc_nkeys, ! cache->cc_skey); hashIndex = HASH_INDEX(hashValue, cache->cc_nbuckets); /* *************** *** 1160,1166 **** HeapKeyTest(&ct->tuple, cache->cc_tupdesc, cache->cc_nkeys, ! cur_skey, res); if (!res) continue; --- 1161,1167 ---- HeapKeyTest(&ct->tuple, cache->cc_tupdesc, cache->cc_nkeys, ! cache->cc_skey, res); if (!res) continue; *************** *** 1222,1227 **** --- 1223,1234 ---- */ relation = heap_open(cache->cc_reloid, AccessShareLock); + /* + * We need copy ScanKey data, because systable_beginscan changes + * the ScanKey data. + */ + memcpy(cur_skey, cache->cc_skey, sizeof(cur_skey)); + scandesc = systable_beginscan(relation, cache->cc_indexoid, IndexScanOK(cache, cur_skey), *************** *** 1371,1389 **** /* * initialize the search key information */ ! memcpy(cur_skey, cache->cc_skey, sizeof(cur_skey)); ! cur_skey[0].sk_argument = v1; ! cur_skey[1].sk_argument = v2; ! cur_skey[2].sk_argument = v3; ! cur_skey[3].sk_argument = v4; /* * compute a hash value of the given keys for faster search. We don't * presently divide the CatCList items into buckets, but this still lets * us skip non-matching items quickly most of the time. */ ! lHashValue = CatalogCacheComputeHashValue(cache, nkeys, cur_skey); /* * scan the items until we find a match or exhaust our list --- 1378,1396 ---- /* * initialize the search key information + * use cache->cc_skey directly in looking for hash table */ ! cache->cc_skey[0].sk_argument = v1; ! cache->cc_skey[1].sk_argument = v2; ! cache->cc_skey[2].sk_argument = v3; ! cache->cc_skey[3].sk_argument = v4; /* * compute a hash value of the given keys for faster search. We don't * presently divide the CatCList items into buckets, but this still lets * us skip non-matching items quickly most of the time. */ ! lHashValue = CatalogCacheComputeHashValue(cache, nkeys, cache->cc_skey); /* * scan the items until we find a match or exhaust our list *************** *** 1410,1416 **** HeapKeyTest(&cl->tuple, cache->cc_tupdesc, nkeys, ! cur_skey, res); if (!res) continue; --- 1417,1423 ---- HeapKeyTest(&cl->tuple, cache->cc_tupdesc, nkeys, ! cache->cc_skey, res); if (!res) continue; *************** *** 1460,1465 **** --- 1467,1478 ---- relation = heap_open(cache->cc_reloid, AccessShareLock); + /* + * We need copy ScanKey data, because systable_beginscan changes + * the ScanKey data. + */ + memcpy(cur_skey, cache->cc_skey, sizeof(cur_skey)); + scandesc = systable_beginscan(relation, cache->cc_indexoid, true,