Skip to content
Permalink
Browse files
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.
  • Loading branch information
jrgemignani committed Apr 22, 2022
1 parent ab70781 commit 58dccb68c96587f993b1ffeb02cf9e794d105451
Showing 7 changed files with 93 additions and 18 deletions.
@@ -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.
@@ -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) */
@@ -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)
{
@@ -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
@@ -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);

@@ -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
@@ -52,19 +52,18 @@ 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)

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

0 comments on commit 58dccb6

Please sign in to comment.