Re: order by and aggregate
От | Tom Lane |
---|---|
Тема | Re: order by and aggregate |
Дата | |
Msg-id | 14734.1041870875@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | order by and aggregate (Tomasz Myrta <jasiek@klaster.net>) |
Список | pgsql-sql |
Tomasz Myrta <jasiek@klaster.net> writes: > I found I can obey this using subselect: > select > maxsum(X.value) > from > (select value > from some_table > order by some_field) X > I can't create subselect, because I want to change this query into a > view. In my case postgresql doesn't use indexes on subselect inside a view. I don't understand what you think is wrong with this solution. It works fine for me: regression=# create view vv as regression-# select max(unique1) from (select unique1 from tenk1 regression(# order by unique2) x; CREATE VIEW regression=# explain select * from vv; QUERY PLAN ---------------------------------------------------------------------------------------------------Subquery Scan vv (cost=523.00..523.00rows=1 width=8) -> Aggregate (cost=523.00..523.00 rows=1 width=8) -> Subquery Scan x (cost=0.00..498.00rows=10000 width=8) -> Index Scan using tenk1_unique2 on tenk1 (cost=0.00..498.00 rows=10000width=8) (4 rows) regards, tom lane
В списке pgsql-sql по дате отправления: