You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by jg...@apache.org on 2022/04/22 00:26:57 UTC

[incubator-age] branch master updated: Cache AGTYPE and GRAPHID Oids

This is an automated email from the ASF dual-hosted git repository.

jgemignani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-age.git


The following commit(s) were added to refs/heads/master by this push:
     new 58dccb6  Cache AGTYPE and GRAPHID Oids
58dccb6 is described below

commit 58dccb68c96587f993b1ffeb02cf9e794d105451
Author: John Gemignani <jr...@gmail.com>
AuthorDate: Wed Apr 20 17:36:08 2022 -0700

    Cache AGTYPE and GRAPHID Oids
    
    Set up caching mechanism for AGTYPE and GRAPHID Oids.
    
    Previously these were set up as #define statements that used syscache
    lookups, as these are all dynamically allocated.
    
    They are now set up to use global variables to hold the values, after
    the first lookup, to enable faster lookups.
    
    No regression tests were affected.
---
 src/backend/catalog/ag_catalog.c |  4 ++++
 src/backend/utils/adt/age_vle.c  |  1 -
 src/backend/utils/adt/agtype.c   | 36 ++++++++++++++++++++++++++++++++++++
 src/backend/utils/adt/graphid.c  | 36 ++++++++++++++++++++++++++++++++++++
 src/include/catalog/ag_catalog.h |  3 +++
 src/include/utils/agtype.h       | 18 ++++++++----------
 src/include/utils/graphid.h      | 13 ++++++-------
 7 files changed, 93 insertions(+), 18 deletions(-)

diff --git a/src/backend/catalog/ag_catalog.c b/src/backend/catalog/ag_catalog.c
index 7798dd6..e74be5a 100644
--- a/src/backend/catalog/ag_catalog.c
+++ b/src/backend/catalog/ag_catalog.c
@@ -114,6 +114,10 @@ static void drop_age_extension(DropStmt *stmt)
      * extension.
      */
     RemoveObjects(stmt);
+
+    /* reset global variables for OIDs */
+    clear_global_Oids_AGTYPE();
+    clear_global_Oids_GRAPHID();
 }
 
 // Check to see if the Utility Command is to drop the AGE Extension.
diff --git a/src/backend/utils/adt/age_vle.c b/src/backend/utils/adt/age_vle.c
index 5d316cc..20f2cae 100644
--- a/src/backend/utils/adt/age_vle.c
+++ b/src/backend/utils/adt/age_vle.c
@@ -54,7 +54,6 @@ typedef struct edge_state_entry
  */
 typedef enum
 {                                  /* Given a path (u)-[e]-(v)                */
-
     VLE_FUNCTION_PATHS_FROM,       /* Paths from a (u) without a provided (v) */
     VLE_FUNCTION_PATHS_TO,         /* Paths to a (v) without a provided (u)   */
     VLE_FUNCTION_PATHS_BETWEEN,    /* Paths between a (u) and a provided (v)  */
diff --git a/src/backend/utils/adt/agtype.c b/src/backend/utils/adt/agtype.c
index 240ad72..b3277d6 100644
--- a/src/backend/utils/adt/agtype.c
+++ b/src/backend/utils/adt/agtype.c
@@ -167,6 +167,42 @@ static int extract_variadic_args_min(FunctionCallInfo fcinfo,
                                      int min_num_args);
 agtype_value *agtype_composite_to_agtype_value_binary(agtype *a);
 
+/* global storage of  OID for agtype and _agtype */
+static Oid g_AGTYPEOID = InvalidOid;
+static Oid g_AGTYPEARRAYOID = InvalidOid;
+
+/* helper function to quickly set, if necessary, and retrieve AGTYPEOID */
+Oid get_AGTYPEOID(void)
+{
+    if (g_AGTYPEOID == InvalidOid)
+    {
+        g_AGTYPEOID = GetSysCacheOid2(TYPENAMENSP, CStringGetDatum("agtype"),
+                                      ObjectIdGetDatum(ag_catalog_namespace_id()));
+    }
+
+    return g_AGTYPEOID;
+}
+
+/* helper function to quickly set, if necessary, and retrieve AGTYPEARRAYOID */
+Oid get_AGTYPEARRAYOID(void)
+{
+    if (g_AGTYPEARRAYOID == InvalidOid)
+    {
+        g_AGTYPEARRAYOID = GetSysCacheOid2(TYPENAMENSP,
+                                           CStringGetDatum("_agtype"),
+                                           ObjectIdGetDatum(ag_catalog_namespace_id()));
+    }
+
+    return g_AGTYPEARRAYOID;
+}
+
+/* helper function to clear the AGTYPEOIDs after a drop extension */
+void clear_global_Oids_AGTYPE(void)
+{
+    g_AGTYPEOID = InvalidOid;
+    g_AGTYPEARRAYOID = InvalidOid;
+}
+
 /* fast helper function to test for AGTV_NULL in an agtype */
 bool is_agtype_null(agtype *agt_arg)
 {
diff --git a/src/backend/utils/adt/graphid.c b/src/backend/utils/adt/graphid.c
index 131e6c3..bd65b95 100644
--- a/src/backend/utils/adt/graphid.c
+++ b/src/backend/utils/adt/graphid.c
@@ -27,6 +27,42 @@
 
 static int graphid_btree_fast_cmp(Datum x, Datum y, SortSupport ssup);
 
+/* global storage of  OID for graphid and _graphid */
+static Oid g_GRAPHIDOID = InvalidOid;
+static Oid g_GRAPHIDARRAYOID = InvalidOid;
+
+/* helper function to quickly set, if necessary, and retrieve GRAPHIDOID */
+Oid get_GRAPHIDOID(void)
+{
+    if (g_GRAPHIDOID == InvalidOid)
+    {
+        g_GRAPHIDOID = GetSysCacheOid2(TYPENAMENSP, CStringGetDatum("graphid"),
+                                       ObjectIdGetDatum(ag_catalog_namespace_id()));
+    }
+
+    return g_GRAPHIDOID;
+}
+
+/* helper function to quickly set, if necessary, and retrieve GRAPHIDARRAYOID */
+Oid get_GRAPHIDARRAYOID(void)
+{
+    if (g_GRAPHIDARRAYOID == InvalidOid)
+    {
+        g_GRAPHIDARRAYOID = GetSysCacheOid2(TYPENAMENSP,
+                                            CStringGetDatum("_graphid"),
+                                            ObjectIdGetDatum(ag_catalog_namespace_id()));
+    }
+
+    return g_GRAPHIDARRAYOID;
+}
+
+/* helper function to clear the GRAPHOIDs after a drop extension */
+void clear_global_Oids_GRAPHID(void)
+{
+    g_GRAPHIDOID = InvalidOid;
+    g_GRAPHIDARRAYOID = InvalidOid;
+}
+
 PG_FUNCTION_INFO_V1(graphid_in);
 
 // graphid type input function
diff --git a/src/include/catalog/ag_catalog.h b/src/include/catalog/ag_catalog.h
index 1c371f6..3b8a36b 100644
--- a/src/include/catalog/ag_catalog.h
+++ b/src/include/catalog/ag_catalog.h
@@ -22,6 +22,9 @@
 
 #include "postgres.h"
 
+#include "utils/agtype.h"
+#include "utils/graphid.h"
+
 void object_access_hook_init(void);
 void object_access_hook_fini(void);
 
diff --git a/src/include/utils/agtype.h b/src/include/utils/agtype.h
index bcc1106..e5019d5 100644
--- a/src/include/utils/agtype.h
+++ b/src/include/utils/agtype.h
@@ -544,14 +544,12 @@ agtype_value *string_to_agtype_value(char *s);
 agtype_value *integer_to_agtype_value(int64 int_value);
 void add_agtype(Datum val, bool is_null, agtype_in_state *result, Oid val_type,
                 bool key_scalar);
-// OID of agtype and _agtype
-#define AGTYPEOID \
-    (GetSysCacheOid2(TYPENAMENSP, CStringGetDatum("agtype"), \
-                     ObjectIdGetDatum(ag_catalog_namespace_id())))
-#define AGTYPEARRAYOID \
-    (GetSysCacheOid2(TYPENAMENSP, CStringGetDatum("_agtype"), \
-                     ObjectIdGetDatum(ag_catalog_namespace_id())))
-#define GRAPHIDOID \
-    (GetSysCacheOid2(TYPENAMENSP, CStringGetDatum("graphid"), \
-                     ObjectIdGetDatum(ag_catalog_namespace_id())))
+
+/* Oid accessors for AGTYPE */
+Oid get_AGTYPEOID(void);
+Oid get_AGTYPEARRAYOID(void);
+void clear_global_Oids_AGTYPE(void);
+#define AGTYPEOID get_AGTYPEOID()
+#define AGTYPEARRAYOID get_AGTYPEARRAYOID()
+
 #endif
diff --git a/src/include/utils/graphid.h b/src/include/utils/graphid.h
index 6327ce5..1039777 100644
--- a/src/include/utils/graphid.h
+++ b/src/include/utils/graphid.h
@@ -52,13 +52,9 @@ typedef int64 graphid;
 #define AG_GETARG_GRAPHID(a) DATUM_GET_GRAPHID(PG_GETARG_DATUM(a))
 #define AG_RETURN_GRAPHID(x) return GRAPHID_GET_DATUM(x)
 
-// OID of graphid and _graphid
-#define GRAPHIDOID \
-    (GetSysCacheOid2(TYPENAMENSP, CStringGetDatum("graphid"), \
-                     ObjectIdGetDatum(ag_catalog_namespace_id())))
-#define GRAPHIDARRAYOID \
-    (GetSysCacheOid2(TYPENAMENSP, CStringGetDatum("_graphid"), \
-                     ObjectIdGetDatum(ag_catalog_namespace_id())))
+/* Oid accessors for GRAPHID */
+#define GRAPHIDOID get_GRAPHIDOID()
+#define GRAPHIDARRAYOID get_GRAPHIDARRAYOID()
 
 #define GET_LABEL_ID(id) \
        (((uint64)id) >> ENTRY_ID_BITS)
@@ -66,5 +62,8 @@ typedef int64 graphid;
 graphid make_graphid(const int32 label_id, const int64 entry_id);
 int32 get_graphid_label_id(const graphid gid);
 int64 get_graphid_entry_id(const graphid gid);
+Oid get_GRAPHIDOID(void);
+Oid get_GRAPHIDARRAYOID(void);
+void clear_global_Oids_GRAPHID(void);
 
 #endif