Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions age--1.6.0--y.y.y.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,23 @@
--* file. We need to keep the order of these changes.
--* REMOVE ALL LINES ABOVE, and this one, that start with --*

CREATE FUNCTION ag_catalog._ag_enforce_edge_uniqueness2(graphid, graphid)
RETURNS bool
LANGUAGE c
STABLE
PARALLEL SAFE
as 'MODULE_PATHNAME';

CREATE FUNCTION ag_catalog._ag_enforce_edge_uniqueness3(graphid, graphid, graphid)
RETURNS bool
LANGUAGE c
STABLE
PARALLEL SAFE
as 'MODULE_PATHNAME';

CREATE FUNCTION ag_catalog._ag_enforce_edge_uniqueness4(graphid, graphid, graphid, graphid)
RETURNS bool
LANGUAGE c
STABLE
PARALLEL SAFE
as 'MODULE_PATHNAME';
21 changes: 21 additions & 0 deletions sql/agtype_graphid.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ CALLED ON NULL INPUT
PARALLEL SAFE
AS 'MODULE_PATHNAME';

CREATE FUNCTION ag_catalog._ag_enforce_edge_uniqueness2(graphid, graphid)
RETURNS bool
LANGUAGE c
STABLE
PARALLEL SAFE
as 'MODULE_PATHNAME';

CREATE FUNCTION ag_catalog._ag_enforce_edge_uniqueness3(graphid, graphid, graphid)
RETURNS bool
LANGUAGE c
STABLE
PARALLEL SAFE
as 'MODULE_PATHNAME';

CREATE FUNCTION ag_catalog._ag_enforce_edge_uniqueness4(graphid, graphid, graphid, graphid)
RETURNS bool
LANGUAGE c
STABLE
PARALLEL SAFE
as 'MODULE_PATHNAME';

CREATE FUNCTION ag_catalog._ag_enforce_edge_uniqueness(VARIADIC "any")
RETURNS bool
LANGUAGE c
Expand Down
33 changes: 28 additions & 5 deletions src/backend/parser/cypher_clause.c
Original file line number Diff line number Diff line change
Expand Up @@ -3276,13 +3276,13 @@ static FuncCall *prevent_duplicate_edges(cypher_parsestate *cpstate,
{
List *edges = NIL;
ListCell *lc;
List *qualified_function_name;
String *ag_catalog, *edge_fn;
List *qualified_function_name = NULL;
String *ag_catalog;
String *edge_fn = NULL;
bool is_vle_edge = false;
int nentities = list_length(entities);

ag_catalog = makeString("ag_catalog");
edge_fn = makeString("_ag_enforce_edge_uniqueness");

qualified_function_name = list_make2(ag_catalog, edge_fn);

/* iterate through each entity, collecting the access node for each edge */
foreach (lc, entities)
Expand All @@ -3298,10 +3298,33 @@ static FuncCall *prevent_duplicate_edges(cypher_parsestate *cpstate,
}
else if (entity->type == ENT_VLE_EDGE)
{
is_vle_edge = true;
edges = lappend(edges, entity->expr);
}
}

if (!is_vle_edge && (nentities >= 5 && nentities <= 9))
{
if (nentities == 5)
{
edge_fn = makeString("_ag_enforce_edge_uniqueness2");
}
else if (nentities == 7)
{
edge_fn = makeString("_ag_enforce_edge_uniqueness3");
}
else
{
edge_fn = makeString("_ag_enforce_edge_uniqueness4");
}
}
else
{
edge_fn = makeString("_ag_enforce_edge_uniqueness");
}

qualified_function_name = list_make2(ag_catalog, edge_fn);

return makeFuncCall(qualified_function_name, edges, COERCE_SQL_SYNTAX, -1);
}

Expand Down
49 changes: 49 additions & 0 deletions src/backend/utils/adt/age_vle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,55 @@ Datum age_build_vle_match_edge(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(agtype_value_to_agtype(result.res));
}

PG_FUNCTION_INFO_V1(_ag_enforce_edge_uniqueness2);

Datum _ag_enforce_edge_uniqueness2(PG_FUNCTION_ARGS)
{
graphid gid1 = AG_GETARG_GRAPHID(0);
graphid gid2 = AG_GETARG_GRAPHID(1);

if (gid1 == gid2)
{
PG_RETURN_BOOL(false);
}

PG_RETURN_BOOL(true);
}

PG_FUNCTION_INFO_V1(_ag_enforce_edge_uniqueness3);

Datum _ag_enforce_edge_uniqueness3(PG_FUNCTION_ARGS)
{
graphid gid1 = AG_GETARG_GRAPHID(0);
graphid gid2 = AG_GETARG_GRAPHID(1);
graphid gid3 = AG_GETARG_GRAPHID(2);

if (gid1 == gid2 || gid1 == gid3 || gid2 == gid3)
{
PG_RETURN_BOOL(false);
}

PG_RETURN_BOOL(true);
}

PG_FUNCTION_INFO_V1(_ag_enforce_edge_uniqueness4);

Datum _ag_enforce_edge_uniqueness4(PG_FUNCTION_ARGS)
{
graphid gid1 = AG_GETARG_GRAPHID(0);
graphid gid2 = AG_GETARG_GRAPHID(1);
graphid gid3 = AG_GETARG_GRAPHID(2);
graphid gid4 = AG_GETARG_GRAPHID(3);

if (gid1 == gid2 || gid1 == gid3 || gid1 == gid4 ||
gid2 == gid3 || gid2 == gid4 || gid3 == gid4)
{
PG_RETURN_BOOL(false);
}

PG_RETURN_BOOL(true);
}

/*
* This function checks the edges in a MATCH clause to see if they are unique or
* not. Filters out all the paths where the edge uniques rules are not met.
Expand Down