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
avoid repeating expensive computation in select > To: "Bob Price" > Cc: "Bill Moran" , pgsql-general@postgresql.org > Date: Thursday, February 3, 2011, 5:33 PM > Bob Price > writes: > > If I set the COST of expensivefunc high, and label it > IMMUTABLE, will the

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

[GENERAL] how to avoid repeating expensive computation in select

2011-02-03 Thread 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 is needed both as a returned value an

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
-general-ow...@postgresql.org] On Behalf Of Bob Price Sent: Thursday, February 03, 2011 12:18 PM To: pgsql-general@postgresql.org Subject: [GENERAL] how to avoid repeating expensive computation in select I have been searching through the docs and mailing list and haven't found a way to do this,

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

[GENERAL] how to avoid repeating expensive computation in select

2011-02-03 Thread 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 is needed both as a returned value an