You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by es...@apache.org on 2017/02/03 09:00:40 UTC
[38/50] [abbrv] incubator-hawq git commit: HAWQ-1286. Reduce
unnecessary calls of namespace check when run \d
HAWQ-1286. Reduce unnecessary calls of namespace check when run \d
Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/5da0476a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/5da0476a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/5da0476a
Branch: refs/heads/2.1.0.0-incubating
Commit: 5da0476a168a754a1c3d55096d6bbb31ecdd78ab
Parents: 517e6d2
Author: interma <in...@outlook.com>
Authored: Fri Jan 20 14:46:16 2017 +0800
Committer: interma <in...@outlook.com>
Committed: Fri Jan 20 14:46:16 2017 +0800
----------------------------------------------------------------------
src/backend/catalog/namespace.c | 23 +++++++++++++++++++++++
src/backend/tcop/postgres.c | 4 ++++
src/include/catalog/namespace.h | 6 +++++-
3 files changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/5da0476a/src/backend/catalog/namespace.c
----------------------------------------------------------------------
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index 7049d32..a780625 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -48,9 +48,11 @@
#include "utils/memutils.h"
#include "utils/syscache.h"
#include "utils/guc.h"
+#include "utils/hsearch.h"
#include "cdb/cdbvars.h"
#include "tcop/utility.h"
+
/*
* The namespace search path is a possibly-empty list of namespace OIDs.
* In addition to the explicit list, several implicitly-searched namespaces
@@ -113,6 +115,8 @@
* namespaceUser is the userid the path has been computed for.
*/
+extern const char *debug_query_string;
+
static List *namespaceSearchPath = NIL;
static Oid namespaceUser = InvalidOid;
@@ -129,6 +133,9 @@ static bool tempCreationPending = false;
/* The above five values are valid only if namespaceSearchPathValid */
static bool namespaceSearchPathValid = true;
+/* store the query sign on the last call of recomputeNamespacePath(), and used the sign to judge cache invalidation */
+static uint32 last_query_sign = 0;
+
/*
* myTempNamespace is InvalidOid until and unless a TEMP namespace is set up
* in a particular backend session (this happens when a CREATE TEMP TABLE
@@ -178,6 +185,11 @@ Datum pg_my_temp_schema(PG_FUNCTION_ARGS);
Datum pg_is_other_temp_schema(PG_FUNCTION_ARGS);
Datum pg_objname_to_oid(PG_FUNCTION_ARGS);
+void
+reset_query_sign()
+{
+ last_query_sign = 0;
+}
/*
* GetCatalogId
@@ -1935,9 +1947,20 @@ recomputeNamespacePath(void)
if (namespaceSearchPathValid && namespaceUser == roleid)
{
if (!enable_ranger)
+ {
return;
+ }
else
+ {
+ uint32 current_query_sign = 0;
+ if (debug_query_string != NULL)
+ current_query_sign = string_hash(debug_query_string, strlen(debug_query_string));
+
+ if (current_query_sign == last_query_sign)
+ return;
+ last_query_sign = current_query_sign;
elog(DEBUG3, "recompute search_path[%s] when enable_ranger", namespace_search_path);
+ }
}
/* Need a modifiable copy of namespace_search_path string */
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/5da0476a/src/backend/tcop/postgres.c
----------------------------------------------------------------------
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index fc71eda..74c5dd6 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -115,6 +115,7 @@
#include "cdb/cdbinmemheapam.h"
#include "utils/rangerrest.h"
+#include "catalog/namespace.h"
#include "resourcemanager/dynrm.h"
#include "resourcemanager/envswitch.h"
@@ -591,6 +592,9 @@ ReadCommand(StringInfo inBuf)
result = SocketBackend(inBuf);
else
result = InteractiveBackend(inBuf);
+
+ /* reset last_query_sign to 0 when running a new sql */
+ reset_query_sign();
return result;
}
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/5da0476a/src/include/catalog/namespace.h
----------------------------------------------------------------------
diff --git a/src/include/catalog/namespace.h b/src/include/catalog/namespace.h
index 34b3f1a..b8fce41 100644
--- a/src/include/catalog/namespace.h
+++ b/src/include/catalog/namespace.h
@@ -90,9 +90,13 @@ extern void AtEOXact_Namespace(bool isCommit);
extern void AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid,
SubTransactionId parentSubid);
+extern List *fetch_search_path(bool includeImplicit);
+
+extern void reset_query_sign();
+
/* stuff for search_path GUC variable */
extern char *namespace_search_path;
-extern List *fetch_search_path(bool includeImplicit);
+
#endif /* NAMESPACE_H */