Re: [PERFORM] Window functions and index usage

2011-10-04 Thread Robert Klemme
On Tue, Oct 4, 2011 at 4:06 PM, Anssi Kääriäinen wrote: > On 10/04/2011 04:27 PM, Robert Klemme wrote: >> >> On Tue, Oct 4, 2011 at 11:39 AM, Anssi Kääriäinen >>  wrote: >>> >>> I have the following setup: >>> >>> create table test(id integer, seq integer); >>> insert into test select generate_se

Re: [PERFORM] Window functions and index usage

2011-10-04 Thread Anssi Kääriäinen
On 10/04/2011 05:52 PM, Robert Klemme wrote: But then why do require using the second index column in the first place? If the data set is small then the query is likely fast if the selection via id can use any index. I mean the fetched dataset is not large, I didn't mean the dataset in total is

Re: [PERFORM] Window functions and index usage

2011-10-04 Thread Anssi Kääriäinen
On 10/04/2011 05:36 PM, Tom Lane wrote: The cost estimates I get are 806 for bitmap scan and sort, 2097 for seqscan and sort, 4890 for indexscan without sort. It *can* use the index for that query ... it just doesn't think it's a good idea. It's probably right, too. At least, the actual runtim

Re: [PERFORM] Window functions and index usage

2011-10-04 Thread Tom Lane
=?ISO-8859-1?Q?Anssi_K=E4=E4ri=E4inen?= writes: > I have the following setup: > create table test(id integer, seq integer); > insert into test select generate_series(0, 100), generate_series(0, 1000); > create unique index test_idx on test(id, seq); > analyze test; > Now I try to fetch the latest

Re: [PERFORM] Window functions and index usage

2011-10-04 Thread Anssi Kääriäinen
On 10/04/2011 04:27 PM, Robert Klemme wrote: On Tue, Oct 4, 2011 at 11:39 AM, Anssi Kääriäinen wrote: I have the following setup: create table test(id integer, seq integer); insert into test select generate_series(0, 100), generate_series(0, 1000); create unique index test_idx on test(id, seq

Re: [PERFORM] Window functions and index usage

2011-10-04 Thread Robert Klemme
On Tue, Oct 4, 2011 at 11:39 AM, Anssi Kääriäinen wrote: > I have the following setup: > > create table test(id integer, seq integer); > insert into test select generate_series(0, 100), generate_series(0, 1000); > create unique index test_idx on test(id, seq); > analyze test; > > Now I try to fetc

[PERFORM] Window functions and index usage

2011-10-04 Thread Anssi Kääriäinen
I have the following setup: create table test(id integer, seq integer); insert into test select generate_series(0, 100), generate_series(0, 1000); create unique index test_idx on test(id, seq); analyze test; Now I try to fetch the latest 5 values per id, ordered by seq from the table: select