Re: [GENERAL] how to avoid repeating expensive computation in select

2011-03-02 Thread Merlin Moncure
On Tue, Mar 1, 2011 at 2:51 AM, Orhan Kavrakoglu wrote: >> I would like to know if there is a way in PostgreSQL to avoid repeating an >> expensive computation in a SELECT where the result is needed both as a >> returned value and as an expression in the WHERE clause. > > I think I've seen it said

Re: [GENERAL] how to avoid repeating expensive computation in select

2011-03-01 Thread Orhan Kavrakoglu
On 2011-02-03 18:07, Bob Price wrote: I would like to know if there is a way in PostgreSQL to avoid repeating an expensive computation in a SELECT where the result is needed both as a returned value and as an expression in the WHERE clause. I think I've seen it said here that PG avoids redund

Re: [GENERAL] how to avoid repeating expensive computation in select

2011-02-04 Thread Bob Price
enable only a single computation of the data for any given row as long as the same args are used as parameters. But, is this safe, or have any pitfalls I would need to look out for? Thanks! Bob --- On Thu, 2/3/11, Tom Lane wrote: > From: Tom Lane > Subject: Re: [GENERAL] how to

Re: [GENERAL] how to avoid repeating expensive computation in select

2011-02-03 Thread Tom Lane
Nicklas =?ISO-8859-1?Q?Av=E9n?= writes: > I thought the "offset 0" trick was just a dirty hack, but coming from > you, Tom, I assume it is a robust way of doing it. Well, I can't deny it's a dirty hack ... but it's not something we'll break until we have a better solution. > I also tried some of

Re: [GENERAL] how to avoid repeating expensive computation in select

2011-02-03 Thread Tom Lane
Bob Price writes: > If I set the COST of expensivefunc high, and label it IMMUTABLE, will the > query executor note that the two invocations to expensivefunc have the same > inputs so it can only call it once and re-use the result the second time? No. There is a myth prevalent among certain wi

Re: [GENERAL] how to avoid repeating expensive computation in select

2011-02-03 Thread Nicklas Avén
That's interesting Tom. This is a discussion coming up sometimes at PostGIS lists since PostGIS often handles "expensive" calculations. Regina wrote a blog post about it: http://postgresonline.com/journal/archives/113-How-to-force-PostgreSQL-to-use-a-pre-calculated-value.html I thought the "off

Re: [GENERAL] how to avoid repeating expensive computation in select

2011-02-03 Thread Bob Price
ime use function that declared a variable with this 'constantdata...'::X value, and then pass this variable in both calls. Would this work? Thanks again! Bob --- On Thu, 2/3/11, Bill Moran wrote: > From: Bill Moran > Subject: Re: [GENERAL] how to avoid repeating expensive com

Re: [GENERAL] how to avoid repeating expensive computation in select

2011-02-03 Thread Pavel Stehule
Hello 2011/2/3 Tom Lane : > Bob Price writes: >> I would like to know if there is a way in PostgreSQL to avoid repeating an >> expensive computation in a SELECT where the result is needed both as a >> returned value and as an expression in the WHERE clause. > > Use a subselect.  You might need

Re: [GENERAL] how to avoid repeating expensive computation in select

2011-02-03 Thread Tom Lane
Bob Price writes: > I would like to know if there is a way in PostgreSQL to avoid repeating an > expensive computation in a SELECT where the result is needed both as a > returned value and as an expression in the WHERE clause. Use a subselect. You might need OFFSET 0 to prevent the planner fro

Re: [GENERAL] how to avoid repeating expensive computation in select

2011-02-03 Thread David Johnston
Is using a pl/pgsql function a viable option. Within or without the use of a function you can create a temporary table to hold the needed intermediate results. You can even use a permanent working table and write functions to perform the needed queries against it. Especially for expensive calcul

Re: [GENERAL] how to avoid repeating expensive computation in select

2011-02-03 Thread Bill Moran
In response to Bob Price : > I have been searching through the docs and mailing list and haven't found a > way to do this, so I thought I would ask the community. > > I would like to know if there is a way in PostgreSQL to avoid repeating an > expensive computation in a SELECT where the result