Thread: avoid select expens_expr(col) like unneccessary calculations

avoid select expens_expr(col) like unneccessary calculations

From
Markus Bertheau
Date:
Hi,

when you have
select expensive_expression(column), * from table offset 20 limit 40

can you somehow save the cost for the first 20 calculations of
expensive_expression?

-- 
Markus Bertheau.
Berlin, Berlin.
Germany.


Re: avoid select expens_expr(col) like unneccessary calculations

From
Stephan Szabo
Date:
On 8 Jul 2003, Markus Bertheau wrote:

> when you have
> select expensive_expression(column), * from table offset 20 limit 40
>
> can you somehow save the cost for the first 20 calculations of
> expensive_expression?

Right now the only way I can think of that might work is to push the
offset/limit into a subselect on table and then do the
expensive_expression at the top level.



Re: avoid select expens_expr(col) like unneccessary calculations

From
"scott.marlowe"
Date:
On 8 Jul 2003, Markus Bertheau wrote:

> Hi,
> 
> when you have
> select expensive_expression(column), * from table offset 20 limit 40
> 
> can you somehow save the cost for the first 20 calculations of
> expensive_expression?

Might a functional or partial index work here?  



Re: avoid select expens_expr(col) like unneccessary calculations

From
Bruce Momjian
Date:
Stephan Szabo wrote:
> On 8 Jul 2003, Markus Bertheau wrote:
> 
> > when you have
> > select expensive_expression(column), * from table offset 20 limit 40
> >
> > can you somehow save the cost for the first 20 calculations of
> > expensive_expression?
> 
> Right now the only way I can think of that might work is to push the
> offset/limit into a subselect on table and then do the
> expensive_expression at the top level.

Well, you can do:
SELECT * FROM (SELECT * FROM pg_class) AS pg_class

so you could do:
SELECT func(relname), * FROM (SELECT * FROM pg_class OFFSET 20 LIMIT 40) AS pg_class

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073