On Sat, Nov 19, 2016 at 8:59 AM, Pavel Stehule <pavel.steh...@gmail.com> wrote:

> > > >> SELECT MIN(a) m FROM >> (SELECT a FROM t WHERE a=2) AS v(a) >> >> The subquery is going to return an intermediate result of: >> >> V:A >> --- >> 2 >> >> And the minimum of that is 2, which is the wrong answer. >> > > yes, you have true, > > In above case wondering if we could do this Min(a) = 2 is the condition, generate condition *"a <= 2"* and push it down as scan key. Since pushed down condition is lossy one for us ( it gives values < 2), finally do a recheck of *"Min(a) = 2"*. For Max(a) = 2 we can have *"a >=2"*, If both are given we can combine them appropriately. -- Thanks and Regards Mithun C Y EnterpriseDB: http://www.enterprisedb.com