8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.126 2009/09/19 17:48:09 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.127 2009/12/25 17:11:32 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -228,6 +228,11 @@ join_is_removable(PlannerInfo *root,
228
228
* We can't remove the join if any inner-rel attributes are used above
229
229
* the join.
230
230
*
231
+ * Note that this test only detects use of inner-rel attributes in
232
+ * higher join conditions and the target list. There might be such
233
+ * attributes in pushed-down conditions at this join, too. We check
234
+ * that case below.
235
+ *
231
236
* As a micro-optimization, it seems better to start with max_attr and
232
237
* count down rather than starting with min_attr and counting up, on the
233
238
* theory that the system attributes are somewhat less likely to be wanted
@@ -253,13 +258,16 @@ join_is_removable(PlannerInfo *root,
253
258
RestrictInfo * restrictinfo = (RestrictInfo * ) lfirst (l );
254
259
255
260
/*
256
- * We are always considering an outer join here, so ignore pushed-down
257
- * clauses. Also ignore anything that doesn't have a mergejoinable
258
- * operator.
261
+ * If we find a pushed-down clause, it must have come from above the
262
+ * outer join and it must contain references to the inner rel. (If
263
+ * it had only outer-rel variables, it'd have been pushed down into
264
+ * the outer rel.) Therefore, we can conclude that join removal
265
+ * is unsafe without any examination of the clause contents.
259
266
*/
260
267
if (restrictinfo -> is_pushed_down )
261
- continue ;
268
+ return false ;
262
269
270
+ /* Ignore if it's not a mergejoinable clause */
263
271
if (!restrictinfo -> can_join ||
264
272
restrictinfo -> mergeopfamilies == NIL )
265
273
continue ; /* not mergejoinable */
0 commit comments