@@ -117,6 +117,15 @@ join_pathlist_hook(PlannerInfo *root,
117117text * dist_func_name = cstring_to_text ("dist(spoint,spoint)" );
118118Oid dist_func ;
119119List * restrict_clauses = extra -> restrictlist ;
120+ Relids required_relids = NULL ;
121+
122+ if (outerrel -> reloptkind == RELOPT_BASEREL &&
123+ innerrel -> reloptkind == RELOPT_BASEREL )
124+ {
125+ required_relids = bms_add_member (required_relids ,outerrel -> relid );
126+ required_relids = bms_add_member (required_relids ,innerrel -> relid );
127+ }
128+ else return ;/* one of relations can't have index */
120129
121130dist_func = DatumGetObjectId (DirectFunctionCall1 (to_regprocedure ,
122131PointerGetDatum (dist_func_name )));
@@ -136,14 +145,9 @@ join_pathlist_hook(PlannerInfo *root,
136145{
137146RestrictInfo * restrInfo = (RestrictInfo * )lfirst (restr );
138147
139- if (outerrel -> reloptkind == RELOPT_BASEREL &&
140- innerrel -> reloptkind == RELOPT_BASEREL &&
141- bms_is_member (outerrel -> relid ,restrInfo -> clause_relids )&&
142- bms_is_member (innerrel -> relid ,restrInfo -> clause_relids ))
143- {
144- /* This is our case */
145- }
146- else continue ;
148+ /* Skip irrelevant JOIN case */
149+ if (!bms_equal (required_relids ,restrInfo -> required_relids ))
150+ continue ;
147151
148152if (IsA (restrInfo -> clause ,OpExpr ))
149153{
@@ -176,7 +180,6 @@ join_pathlist_hook(PlannerInfo *root,
176180required_outer ,
177181& restrict_clauses );
178182
179- /* DEBUG */
180183create_crossmatch_path (root ,joinrel ,outer_path ,inner_path ,
181184param_info ,restrict_clauses ,required_outer );
182185
@@ -187,6 +190,7 @@ join_pathlist_hook(PlannerInfo *root,
187190IsA (arg2 ,FuncExpr )&&
188191 ((FuncExpr * )arg2 )-> funcid == dist_func )
189192{
193+ /* TODO: merge duplicate code */
190194Path * outer_path = crossmatch_find_cheapest_path (root ,joinrel ,outerrel );
191195Path * inner_path = crossmatch_find_cheapest_path (root ,joinrel ,innerrel );
192196
@@ -200,14 +204,11 @@ join_pathlist_hook(PlannerInfo *root,
200204required_outer ,
201205& restrict_clauses );
202206
203- /* DEBUG */
204207create_crossmatch_path (root ,joinrel ,outer_path ,inner_path ,
205208param_info ,restrict_clauses ,required_outer );
206209}
207210}
208211}
209-
210- pprint (root -> parse -> rtable );
211212}
212213
213214static Plan *
@@ -241,7 +242,7 @@ create_crossmatch_plan(PlannerInfo *root,
241242cscan -> scan .plan .qual = NIL ;
242243cscan -> scan .scanrelid = 0 ;
243244
244- cscan -> custom_scan_tlist = tlist ;
245+ cscan -> custom_scan_tlist = tlist ;/* TODO: recheck target list */
245246
246247elog (LOG ,"tlist:" );
247248pprint (tlist );
@@ -268,6 +269,7 @@ crossmatch_create_scan_state(CustomScan *node)
268269return (Node * )scan_state ;
269270}
270271
272+ /* HACK: remove this */
271273static int i = 0 ;
272274
273275static void