(13 rows)
COMMIT;
+-- Test the case where the subquery containing a semijoin is removed from
+-- the query entirely; this test is just to make sure that advice generation
+-- does not fail.
+EXPLAIN (COSTS OFF, PLAN_ADVICE)
+SELECT * FROM
+ (SELECT * FROM sj_narrow WHERE id IN (SELECT val1 FROM sj_wide)
+ LIMIT 1) x,
+ LATERAL (SELECT 1 WHERE false) y;
+ QUERY PLAN
+--------------------------
+ Result
+ Replaces: Scan on x
+ One-Time Filter: false
+ Generated Plan Advice:
+ NO_GATHER(x)
+(5 rows)
+
/*
* Compute the range table offset for each pgpa_planner_info for which it
* is possible to meaningfully do so.
+ *
+ * For pgpa_planner_info objects for which no RT offset can be computed,
+ * clear sj_unique_rels, which is meaningless in such cases.
*/
static void
pgpa_compute_rt_offsets(pgpa_planner_state *pps, PlannedStmt *pstmt)
* there's no fixed rtoffset that we can apply to the RTIs
* used during planning to locate the corresponding relations.
*/
- if (rtinfo->dummy)
+ if (!rtinfo->dummy)
{
- /*
- * It will not be possible to make any effective use of
- * the sj_unique_rels list in this case, and it also won't
- * be important to do so. So just throw the list away to
- * avoid confusing pgpa_plan_walker.
- */
- proot->sj_unique_rels = NIL;
- break;
+ Assert(!proot->has_rtoffset);
+ proot->has_rtoffset = true;
+ proot->rtoffset = rtinfo->rtoffset;
}
- Assert(!proot->has_rtoffset);
- proot->has_rtoffset = true;
- proot->rtoffset = rtinfo->rtoffset;
break;
}
}
+
+ /*
+ * If we didn't end up setting has_rtoffset, then it will not be
+ * possible to make any effective use of sj_unique_rels, and it also
+ * won't be important to do so. So just throw the list away to avoid
+ * confusing pgpa_plan_walker.
+ */
+ if (!proot->has_rtoffset)
+ proot->sj_unique_rels = NIL;
}
}
EXPLAIN (COSTS OFF, PLAN_ADVICE)
SELECT * FROM generate_series(1,1000) g, sj_narrow s WHERE g = s.val1;
COMMIT;
+
+-- Test the case where the subquery containing a semijoin is removed from
+-- the query entirely; this test is just to make sure that advice generation
+-- does not fail.
+EXPLAIN (COSTS OFF, PLAN_ADVICE)
+SELECT * FROM
+ (SELECT * FROM sj_narrow WHERE id IN (SELECT val1 FROM sj_wide)
+ LIMIT 1) x,
+ LATERAL (SELECT 1 WHERE false) y;