From dd490b63764823238e2804f6477074cebd0ad013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Wed, 9 Oct 2019 18:17:36 +0000 Subject: [PATCH] Cache whether an object is in pg_dist_object. Avoids redundant lookups for non-distributed objects --- src/backend/distributed/commands/call.c | 2 +- src/backend/distributed/planner/function_call_delegation.c | 2 +- src/backend/distributed/utils/metadata_cache.c | 5 +++-- src/include/distributed/metadata_cache.h | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backend/distributed/commands/call.c b/src/backend/distributed/commands/call.c index 431a6b72c..d8f241a45 100644 --- a/src/backend/distributed/commands/call.c +++ b/src/backend/distributed/commands/call.c @@ -54,7 +54,7 @@ CallDistributedProcedureRemotely(CallStmt *callStmt, DestReceiver *dest) Oid functionId = funcExpr->funcid; procedure = LookupDistObjectCacheEntry(ProcedureRelationId, functionId, 0); - if (procedure == NULL) + if (procedure == NULL || !procedure->isDistributed) { return false; } diff --git a/src/backend/distributed/planner/function_call_delegation.c b/src/backend/distributed/planner/function_call_delegation.c index 3587fd12a..fd5fcb6af 100644 --- a/src/backend/distributed/planner/function_call_delegation.c +++ b/src/backend/distributed/planner/function_call_delegation.c @@ -221,7 +221,7 @@ TryToDelegateFunctionCall(Query *query, bool *hasExternParam) funcExpr = (FuncExpr *) targetEntry->expr; procedure = LookupDistObjectCacheEntry(ProcedureRelationId, funcExpr->funcid, 0); - if (procedure == NULL) + if (procedure == NULL || !procedure->isDistributed) { /* not a distributed function call */ ereport(DEBUG4, (errmsg("function is not distributed"))); diff --git a/src/backend/distributed/utils/metadata_cache.c b/src/backend/distributed/utils/metadata_cache.c index e455575d3..7018fae56 100644 --- a/src/backend/distributed/utils/metadata_cache.c +++ b/src/backend/distributed/utils/metadata_cache.c @@ -991,6 +991,7 @@ LookupDistObjectCacheEntry(Oid classid, Oid objid, int32 objsubid) isNullArray); cacheEntry->isValid = true; + cacheEntry->isDistributed = true; cacheEntry->distributionArgIndex = DatumGetInt32(datumArray[Anum_pg_dist_object_distribution_argument_index - @@ -1000,8 +1001,8 @@ LookupDistObjectCacheEntry(Oid classid, Oid objid, int32 objsubid) } else { - /* return NULL, cacheEntry left invalid in hash table */ - cacheEntry = NULL; + cacheEntry->isValid = true; + cacheEntry->isDistributed = false; } systable_endscan(pgDistObjectScan); diff --git a/src/include/distributed/metadata_cache.h b/src/include/distributed/metadata_cache.h index 77280aebf..565824e8a 100644 --- a/src/include/distributed/metadata_cache.h +++ b/src/include/distributed/metadata_cache.h @@ -110,6 +110,7 @@ typedef struct DistObjectCacheEntry DistObjectCacheEntryKey key; bool isValid; + bool isDistributed; int distributionArgIndex; int colocationId;