if (outer_relids == NULL)
return 1.0;
- result = 1.0;
+ result = 0.0;
outer_relid = -1;
while ((outer_relid = bms_next_member(outer_relids, outer_relid)) >= 0)
{
outer_rel->rows);
/* Remember smallest row count estimate among the outer rels */
- if (result == 1.0 || result > rowcount)
+ if (result == 0.0 || result > rowcount)
result = rowcount;
}
- return result;
+ /* Return 1.0 if we found no valid relations (shouldn't happen) */
+ return (result > 0.0) ? result : 1.0;
}
/*
explain (costs off)
select a.unique1, b.unique1, c.unique1, coalesce(b.twothousand, a.twothousand)
from tenk1 a left join tenk1 b on b.thousand = a.unique1 left join tenk1 c on c.unique2 = coalesce(b.twothousand, a.twothousand)
- where a.unique2 = 5530 and coalesce(b.twothousand, a.twothousand) = 44;
+ where a.unique2 < 10 and coalesce(b.twothousand, a.twothousand) = 44;
QUERY PLAN
---------------------------------------------------------------------------------------------
Nested Loop Left Join
-> Nested Loop Left Join
Filter: (COALESCE(b.twothousand, a.twothousand) = 44)
-> Index Scan using tenk1_unique2 on tenk1 a
- Index Cond: (unique2 = 5530)
+ Index Cond: (unique2 < 10)
-> Bitmap Heap Scan on tenk1 b
Recheck Cond: (thousand = a.unique1)
-> Bitmap Index Scan on tenk1_thous_tenthous
select a.unique1, b.unique1, c.unique1, coalesce(b.twothousand, a.twothousand)
from tenk1 a left join tenk1 b on b.thousand = a.unique1 left join tenk1 c on c.unique2 = coalesce(b.twothousand, a.twothousand)
- where a.unique2 = 5530 and coalesce(b.twothousand, a.twothousand) = 44;
+ where a.unique2 < 10 and coalesce(b.twothousand, a.twothousand) = 44;
unique1 | unique1 | unique1 | coalesce
---------+---------+---------+----------
(0 rows)
explain (costs off)
select a.unique1, b.unique1, c.unique1, coalesce(b.twothousand, a.twothousand)
from tenk1 a left join tenk1 b on b.thousand = a.unique1 left join tenk1 c on c.unique2 = coalesce(b.twothousand, a.twothousand)
- where a.unique2 = 5530 and coalesce(b.twothousand, a.twothousand) = 44;
+ where a.unique2 < 10 and coalesce(b.twothousand, a.twothousand) = 44;
select a.unique1, b.unique1, c.unique1, coalesce(b.twothousand, a.twothousand)
from tenk1 a left join tenk1 b on b.thousand = a.unique1 left join tenk1 c on c.unique2 = coalesce(b.twothousand, a.twothousand)
- where a.unique2 = 5530 and coalesce(b.twothousand, a.twothousand) = 44;
+ where a.unique2 < 10 and coalesce(b.twothousand, a.twothousand) = 44;
--
-- check handling of join aliases when flattening multiple levels of subquery