@@ -44,7 +44,8 @@ static void set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti,
4444static cypher_clause_kind get_cypher_clause_kind (RangeTblEntry * rte );
4545static void handle_cypher_create_clause (PlannerInfo * root , RelOptInfo * rel ,
4646 Index rti , RangeTblEntry * rte );
47-
47+ static void handle_cypher_merge_clause (PlannerInfo * root , RelOptInfo * rel ,
48+ Index rti , RangeTblEntry * rte );
4849void set_rel_pathlist_init (void )
4950{
5051 prev_set_rel_pathlist_hook = set_rel_pathlist_hook ;
@@ -59,6 +60,7 @@ void set_rel_pathlist_fini(void)
5960static void set_rel_pathlist (PlannerInfo * root , RelOptInfo * rel , Index rti ,
6061 RangeTblEntry * rte )
6162{
63+
6264 if (prev_set_rel_pathlist_hook )
6365 prev_set_rel_pathlist_hook (root , rel , rti , rte );
6466
@@ -67,6 +69,9 @@ static void set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti,
6769 case CYPHER_CLAUSE_CREATE :
6870 handle_cypher_create_clause (root , rel , rti , rte );
6971 break ;
72+ case CYPHER_CLAUSE_MERGE :
73+ handle_cypher_merge_clause (root , rel , rti , rte );
74+ break ;
7075 case CYPHER_CLAUSE_NONE :
7176 break ;
7277 default :
@@ -103,6 +108,8 @@ static cypher_clause_kind get_cypher_clause_kind(RangeTblEntry *rte)
103108
104109 if (is_oid_ag_func (fe -> funcid , CREATE_CLAUSE_FUNCTION_NAME ))
105110 return CYPHER_CLAUSE_CREATE ;
111+ else if (is_oid_ag_func (fe -> funcid , MERGE_CLAUSE_FUNCTION_NAME ))
112+ return CYPHER_CLAUSE_MERGE ;
106113 else
107114 return CYPHER_CLAUSE_NONE ;
108115}
@@ -130,3 +137,27 @@ static void handle_cypher_create_clause(PlannerInfo *root, RelOptInfo *rel,
130137 // Add the new path to the rel.
131138 add_path (rel , (Path * )cp );
132139}
140+
141+ // replace all possible paths with our CustomPath
142+ static void handle_cypher_merge_clause (PlannerInfo * root , RelOptInfo * rel ,
143+ Index rti , RangeTblEntry * rte )
144+ {
145+ TargetEntry * te ;
146+ FuncExpr * fe ;
147+ List * custom_private ;
148+ CustomPath * cp ;
149+
150+ // Add the pattern to the CustomPath
151+ te = (TargetEntry * )llast (rte -> subquery -> targetList );
152+ fe = (FuncExpr * )te -> expr ;
153+ // pass the const that holds the data structure to the path.
154+ custom_private = fe -> args ;
155+
156+ cp = create_cypher_merge_path (root , rel , custom_private );
157+
158+ // Discard any pre-existing paths
159+ rel -> pathlist = NIL ;
160+ rel -> partial_pathlist = NIL ;
161+
162+ add_path (rel , (Path * )cp );
163+ }
0 commit comments