Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> DROP TABLE IF EXISTS foo;
> CREATE TABLE foo(a int, b int);
> INSERT INTO foo SELECT (random()*10000)::int, (random()*10)::int from generate_series(1,100000);
> ANALYZE foo;
> CREATE INDEX ON foo(a,b);
> CREATE INDEX ON foo(b,a);
> EXPLAIN SELECT max(a), b
> FROM foo, generate_series(0,30) g(v)
> WHERE a = (SELECT max(a) FROM foo WHERE b = v)
> GROUP BY b;
Fixed, thanks.
regards, tom lane