<html><head></head><body class="ApplePlainTextBody" dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Ooops, forgot to mail the list.<br><br>W<br><br><blockquote type="cite">Begin forwarded message:<br><br>From: wrb <wrb(at)autistici(dot)org><br>Subject: Re: [BUGS] BUG #13863: Select from views gives wrong results<br>Date: 14. ledna 2016 10:49:27 SEČ<br>To: Haribabu Kommi <kommi(dot)haribabu(at)gmail(dot)com><br><br>Followup: <br><br>This query should show better what's wrong with the optimizer:<br><br><br>select a, count(*) from test group by cube (a);<br>a | count <br>---+-------<br>1 | 1<br>2 | 1<br> | 2<br>(3 rows)<br><br>select * from (select a, count(*) from test group by cube (a)) t where a is null;<br>a | count <br>---+-------<br> | 0<br><br>explain select * from (select a, count(*) from test group by cube (a)) t where a is null;<br> QUERY PLAN <br>------------------------------------------------------------------<br>GroupAggregate (cost=32.79..32.89 rows=2 width=4)<br> Group Key: test.a<br> Group Key: ()<br> Filter: (test.a IS NULL)<br> -> Sort (cost=32.79..32.82 rows=11 width=4)<br> Sort Key: test.a<br> -> Seq Scan on test (cost=0.00..32.60 rows=11 width=4)<br> Filter: (a IS NULL)<br><br><br>The predicate "a is null" in the outer select should refer to results of inner select and should therefore return (null, 2) instead of no rows, right?<br><br>W<br></blockquote><br></body></html>