Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-02-02 Thread Sean Davis
M To: [EMAIL PROTECTED]; Greg Stark Cc: Richard Huxton; pgsql-sql@postgresql.org; pgsql-performance@postgresql.org Subject: Re: [PERFORM] [SQL] OFFSET impact on Performance??? The problems still stays open. The thing is that I have about 20 - 30 clients that are using that SQL query where the offse

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-02-01 Thread PFC
As I read the docs, a temp table doesn't solve our problem, as it does not persist between sessions. With a web page there is no guarentee that you will receive the same connection between requests, so a temp table doesn't solve the problem. It looks like you either have to create a real table (

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread Kevin Brown
PFC wrote: > > Supposing your searches display results which are rows coming from one > specific table, you could create a cache table : > > search_id serial primary key > index_n position of this result in the global result set > result_id id of the resulting row. > > Then, maki

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread Greg Stark
"Merlin Moncure" <[EMAIL PROTECTED]> writes: > what about > CREATE AGGREGATE array_accum ( > sfunc = array_append, > basetype = anyelement, > stype = anyarray, > initcond = '{}' > ); huh, that is faster. It's only 14x slower than the C implementation. For completeness, here are

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread PFC
What you want is called UNNEST. It didn't get done in time for 8.0. But if what you have is an array of integers the int_array_enum() function I quoted in the other post is basically that. Yes, I used it, thanks. That's what I wanted. The query plans are good. You don't really need the int_

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread Merlin Moncure
Greg Stark wrote: > test=> create or replace function array_push (anyarray, anyelement) > returns anyarray as 'select $1 || $2' language sql immutable strict; > CREATE FUNCTION > test=> create aggregate array_aggregate (basetype=anyelement, > sfunc=array_push, stype=anyarray, initcond = '{}'); >

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread Greg Stark
PFC <[EMAIL PROTECTED]> writes: > intset(x) seems to be like array[x] ? > Actually what I want is the opposite. What you want is called UNNEST. It didn't get done in time for 8.0. But if what you have is an array of integers the int_array_enum() function I quoted in the other post i

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread PFC
However, it seems that integer && integer[] does not exist : Try intset(id) && int[]. intset is an undocumented function :) I'm going to add intset() to README. SELECT * FROM table WHERE id && int[] Mm. intset(x) seems to be like array[x] ? Actually what I want is the opposite. I have a btree

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread Merlin Moncure
> Actually, you can if you assume you can "temporarily materialize" that > view. > > Then, you use a join on my_query to pull the bits you want: > > select [big table.details] from [big table], > [select * from my_query order by [something] offset 280 limit 20] > where [join criteria between

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread Oleg Bartunov
On Thu, 27 Jan 2005, PFC wrote: for example, http://www.sai.msu.su/~megera/postgres/gist/code/7.3/README.intarray see OPERATIONS and EXAMPLE USAGE: Thanks, I already know this documentation and have used intarray before (I find it absolutely fabulous in the right application, it has a great p

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread PFC
for example, http://www.sai.msu.su/~megera/postgres/gist/code/7.3/README.intarray see OPERATIONS and EXAMPLE USAGE: Thanks, I already know this documentation and have used intarray before (I find it absolutely fabulous in the right application, it has a great potential for getting out of t

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread Greg Stark
Oleg Bartunov writes: > On Thu, 27 Jan 2005, PFC wrote: > > > > > > > beware that SELECT * FROM table WHERE id =ANY( array ) won't use an > > > > index, > > > contrib/intarray provides index access to such queries. > > > > Can you provide an example of such a query ? I've looked at the operato

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread Oleg Bartunov
On Thu, 27 Jan 2005, PFC wrote: The best part is that you can skip the LIMIT/OFFSET entirely if you put page numbers in your cache table while inserting into it, via a temporary sequence or something. Retrieving the results will then be very fast, but beware that SELECT * FROM table WHERE id =

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread PFC
The best part is that you can skip the LIMIT/OFFSET entirely if you put page numbers in your cache table while inserting into it, via a temporary sequence or something. Retrieving the results will then be very fast, but beware that SELECT * FROM table WHERE id =ANY( array ) won't use an i

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread Oleg Bartunov
On Thu, 27 Jan 2005, PFC wrote: Thats a really good idea, just store a list of the sorted ids in the temp table - small amount of data for insert... I like it! Alex Turner NetEconomist The best part is that you can skip the LIMIT/OFFSET entirely if you put page numbers in your cache table while

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-27 Thread PFC
Thats a really good idea, just store a list of the sorted ids in the temp table - small amount of data for insert... I like it! Alex Turner NetEconomist The best part is that you can skip the LIMIT/OFFSET entirely if you put page numbers in your cache table while inserting into it, via a tempor

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-26 Thread Christopher Browne
In an attempt to throw the authorities off his trail, [EMAIL PROTECTED] ("Merlin Moncure") transmitted: > Alex wrote: >> How do you create a temporary view that has only a small subset of the >> data from the DB init? (Links to docs are fine - I can read ;). My >> query isn't all that complex, a

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-26 Thread Alex Turner
Thats a really good idea, just store a list of the sorted ids in the temp table - small amount of data for insert... I like it! Alex Turner NetEconomist On Wed, 26 Jan 2005 22:24:34 +0100, PFC <[EMAIL PROTECTED]> wrote: > > The problem with this approach is TTFB (Time to first Byte). The > > in

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-26 Thread PFC
The problem with this approach is TTFB (Time to first Byte). The initial query is very slow, but additional requests are fast. In most situations we do not want the user to have to wait a disproportionate amount of time for the initial query. If this is the first time using the system this will

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-26 Thread Greg Stark
Alex Turner <[EMAIL PROTECTED]> writes: > The problem with this approach is TTFB (Time to first Byte). The > initial query is very slow, but additional requests are fast. In most > situations we do not want the user to have to wait a disproportionate > amount of time for the initial query. If

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-26 Thread Merlin Moncure
> The problem with this approach is TTFB (Time to first Byte). The > initial query is very slow, but additional requests are fast. In most > situations we do not want the user to have to wait a disproportionate > amount of time for the initial query. If this is the first time using > the system

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-26 Thread Alex Turner
The problem with this approach is TTFB (Time to first Byte). The initial query is very slow, but additional requests are fast. In most situations we do not want the user to have to wait a disproportionate amount of time for the initial query. If this is the first time using the system this will

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-26 Thread PFC
Supposing your searches display results which are rows coming from one specific table, you could create a cache table : search_id serial primary key index_n position of this result in the global result set result_id id of the resulting row. Then, making a search with 50k results woul

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-26 Thread Richard Huxton
Alex Turner wrote: As I read the docs, a temp table doesn't solve our problem, as it does not persist between sessions. With a web page there is no guarentee that you will receive the same connection between requests, so a temp table doesn't solve the problem. It looks like you either have to cre

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-26 Thread Alex Turner
; > To: <[EMAIL PROTECTED]> > Cc: "Richard Huxton" ; "Andrei Bintintan" > <[EMAIL PROTECTED]>; ; > > Sent: Tuesday, January 25, 2005 8:28 PM > Subject: Re: [PERFORM] [SQL] OFFSET impact on Performance??? > > > > > > Alex Turner

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-26 Thread Leeuw van der, Tim
of Andrei Bintintan Sent: Wed 1/26/2005 11:11 AM To: [EMAIL PROTECTED]; Greg Stark Cc: Richard Huxton; pgsql-sql@postgresql.org; pgsql-performance@postgresql.org Subject: Re: [PERFORM] [SQL] OFFSET impact on Performance??? The problems still stays open. The thing is that I have about 20 - 30

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-26 Thread Andrei Bintintan
gards, Andy. - Original Message - From: "Greg Stark" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: "Richard Huxton" ; "Andrei Bintintan" <[EMAIL PROTECTED]>; ; Sent: Tuesday, January 25, 2005 8:28 PM Subject: Re: [PERFORM] [SQL] OFFSET imp

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-25 Thread Greg Stark
Alex Turner <[EMAIL PROTECTED]> writes: > I am also very interesting in this very question.. Is there any way to > declare a persistant cursor that remains open between pg sessions? > This would be better than a temp table because you would not have to > do the initial select and insert into a f

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-24 Thread Merlin Moncure
Alex wrote: > How do you create a temporary view that has only a small subset of the > data from the DB init? (Links to docs are fine - I can read ;). My > query isn't all that complex, and my number of records might be from > 10 to 2k depending on how I implement it. Well, you can't. My point

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-21 Thread Greg Stark
> > Now I read all the posts and I have some answers. > > > > Yes, I have a web aplication. I HAVE to know exactly how many pages I have > > and I have to allow the user to jump to a specific page(this is where I > > used limit and offset). We have this feature and I cannot take it out. I'm afra

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-21 Thread Merlin Moncure
> Now I read all the posts and I have some answers. > > Yes, I have a web aplication. > I HAVE to know exactly how many pages I have and I have to allow the user > to > jump to a specific page(this is where I used limit and offset). We have > this > feature and I cannot take it out. If your worki

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-21 Thread Andrei Bintintan
DIGGING for solutions. Andy. - Original Message - From: "Ragnar Hafstað" <[EMAIL PROTECTED]> To: Cc: "Andrei Bintintan" <[EMAIL PROTECTED]>; Sent: Thursday, January 20, 2005 9:23 PM Subject: Re: [PERFORM] [SQL] OFFSET impact on Performance??? On Thu, 2005-01-

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Alex Turner
How do you create a temporary view that has only a small subset of the data from the DB init? (Links to docs are fine - I can read ;). My query isn't all that complex, and my number of records might be from 10 to 2k depending on how I implement it. Alex Turner NetEconomist On Thu, 20 Jan 2005

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Merlin Moncure
> this will only work unchanged if the index is unique. imagine , for > example if you have more than 50 rows with the same value of col. > > one way to fix this is to use ORDER BY col,oid nope! oid is 1. deprecated 2. not guaranteed to be unique even inside a (large) table. Use a sequence inst

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Ragnar Hafstað
On Thu, 2005-01-20 at 19:12 +, Ragnar Hafstað wrote: > On Thu, 2005-01-20 at 11:59 -0500, Greg Stark wrote: > > > The best way to do pages for is not to use offset or cursors but to use an > > index. This only works if you can enumerate all the sort orders the > > application might be using an

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Ragnar =?ISO-8859-1?Q?Hafsta=F0?=
On Thu, 2005-01-20 at 11:59 -0500, Greg Stark wrote: > The best way to do pages for is not to use offset or cursors but to use an > index. This only works if you can enumerate all the sort orders the > application might be using and can have an index on each of them. > > To do this the query woul

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Spiegelberg, Greg
AM To: Andrei Bintintan Cc: pgsql-sql@postgresql.org; pgsql-performance@postgresql.org Subject: Re: [PERFORM] [SQL] OFFSET impact on Performance??? Andrei Bintintan wrote: >> If you're using this to provide "pages" of results, could you use a >> cursor? > > What

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Richard Huxton
Greg Stark wrote: "Andrei Bintintan" <[EMAIL PROTECTED]> writes: If you're using this to provide "pages" of results, could you use a cursor? What do you mean by that? Cursor? Yes I'm using this to provide "pages", but If I jump to the last pages it goes very slow. The best way to do pages for is

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Richard Huxton
Ron Mayer wrote: Richard Huxton wrote: If you've got a web-application then you'll probably want to insert the results into a cache table for later use. If I have quite a bit of activity like this (people selecting 1 out of a few million rows and paging through them in a web browser), would i

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Merlin Moncure
> I am also very interesting in this very question.. Is there any way to > declare a persistant cursor that remains open between pg sessions? > This would be better than a temp table because you would not have to > do the initial select and insert into a fresh table and incur those IO > costs, whic

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Greg Stark
"Andrei Bintintan" <[EMAIL PROTECTED]> writes: > > If you're using this to provide "pages" of results, could you use a cursor? > What do you mean by that? Cursor? > > Yes I'm using this to provide "pages", but If I jump to the last pages it goes > very slow. The best way to do pages for is not t

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Richard Huxton
Alex Turner wrote: I am also very interesting in this very question.. Is there any way to declare a persistant cursor that remains open between pg sessions? Not sure how this would work. What do you do with multiple connections? Only one can access the cursor, so which should it be? This would b

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Ron Mayer
Richard Huxton wrote: If you've got a web-application then you'll probably want to insert the results into a cache table for later use. If I have quite a bit of activity like this (people selecting 1 out of a few million rows and paging through them in a web browser), would it be good to have

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Alex Turner
I am also very interesting in this very question.. Is there any way to declare a persistant cursor that remains open between pg sessions? This would be better than a temp table because you would not have to do the initial select and insert into a fresh table and incur those IO costs, which are oft

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Richard Huxton
Andrei Bintintan wrote: If you're using this to provide "pages" of results, could you use a cursor? What do you mean by that? Cursor? Yes I'm using this to provide "pages", but If I jump to the last pages it goes very slow. DECLARE mycursor CURSOR FOR SELECT * FROM ... FETCH FORWARD 10 IN mycurso

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Andrei Bintintan
If you're using this to provide "pages" of results, could you use a cursor? What do you mean by that? Cursor? Yes I'm using this to provide "pages", but If I jump to the last pages it goes very slow. Andy. - Original Message - From: "Richard Huxton" To: "Andrei Bintintan" <[EMAIL PROTE

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-20 Thread Richard Huxton
Andrei Bintintan wrote: Hi to all, I have the following 2 examples. Now, regarding on the offset if it is small(10) or big(>5) what is the impact on the performance of the query?? I noticed that if I return more data's(columns) or if I make more joins then the query runs even slower if the OFFS