summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/geqo/geqo_pool.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-02-10 20:37:29 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2015-02-10 20:37:29 -0500
commit52579d507e624d3e24a062aba741b985b60c40b7 (patch)
tree2237d3fb8c6b5e3f63bb23ca41d126a3471ad76c /src/backend/optimizer/geqo/geqo_pool.c
parent0d36d9f2b9a2178bb19ffbe663e39818f51a0f82 (diff)
Fix GEQO to not assume its join order heuristic always works.
Back in commit 400e2c934457bef4bc3cc9a3e49b6289bd761bc0 I rewrote GEQO's gimme_tree function to improve its heuristic for modifying the given tour into a legal join order. In what can only be called a fit of hubris, I supposed that this new heuristic would *always* find a legal join order, and ripped out the old logic that allowed gimme_tree to sometimes fail. The folly of this is exposed by bug #12760, in which the "greedy" clumping behavior of merge_clump() can lead it into a dead end which could only be recovered from by un-clumping. We have no code for that and wouldn't know exactly what to do with it if we did. Rather than try to improve the heuristic rules still further, let's just recognize that it *is* a heuristic and probably must always have failure cases. So, put back the code removed in the previous commit to allow for failure (but comment it a bit better this time). It's possible that this code was actually fully correct at the time and has only been broken by the introduction of LATERAL. But having seen this example I no longer have much faith in that proposition, so back-patch to all supported branches.
Diffstat (limited to 'src/backend/optimizer/geqo/geqo_pool.c')
-rw-r--r--src/backend/optimizer/geqo/geqo_pool.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/backend/optimizer/geqo/geqo_pool.c b/src/backend/optimizer/geqo/geqo_pool.c
index d2bbdce8047..9c14fa9dc22 100644
--- a/src/backend/optimizer/geqo/geqo_pool.c
+++ b/src/backend/optimizer/geqo/geqo_pool.c
@@ -92,13 +92,37 @@ random_init_pool(PlannerInfo *root, Pool *pool)
{
Chromosome *chromo = (Chromosome *) pool->data;
int i;
+ int bad = 0;
- for (i = 0; i < pool->size; i++)
+ /*
+ * We immediately discard any invalid individuals (those that geqo_eval
+ * returns DBL_MAX for), thereby not wasting pool space on them.
+ *
+ * If we fail to make any valid individuals after 10000 tries, give up;
+ * this probably means something is broken, and we shouldn't just let
+ * ourselves get stuck in an infinite loop.
+ */
+ i = 0;
+ while (i < pool->size)
{
init_tour(root, chromo[i].string, pool->string_length);
pool->data[i].worth = geqo_eval(root, chromo[i].string,
pool->string_length);
+ if (pool->data[i].worth < DBL_MAX)
+ i++;
+ else
+ {
+ bad++;
+ if (i == 0 && bad >= 10000)
+ elog(ERROR, "geqo failed to make a valid plan");
+ }
}
+
+#ifdef GEQO_DEBUG
+ if (bad > 0)
+ elog(DEBUG1, "%d invalid tours found while selecting %d pool entries",
+ bad, pool->size);
+#endif
}
/*