function in index expression and unnecessary function calls in select - Mailing list pgsql-general

From Eugene Prokopiev
Subject function in index expression and unnecessary function calls in select
Date
Msg-id 4392BE54.7060202@stc.donpac.ru
Whole thread Raw
Responses Re: function in index expression and unnecessary function calls in select
List pgsql-general
Hi,

I have Linux, PostgreSQL 8.1, Python 2.3

pgsql code:

test=# create table t1(name varchar(10), value integer);
CREATE TABLE
test=# create or replace function f1(integer) returns integer as $$
test$# file = open('/tmp/f1.log', 'a')
test$# file.write('log\n')
test$# file.close
test$# return args[0]+1
test$# $$ language plpythonu immutable;
CREATE FUNCTION
test=# select name, f1(value) from t1;
  name | f1
------+----
  r1   |  2
  r2   |  3
(records: 2)

$ cat /tmp/f1.log
log
log

After creating index:

test=# create index i1 on t1 (f1(value));
CREATE INDEX

$ cat /tmp/f1.log
log
log
log
log

After select:

test=# select name, f1(value) from t1;
  name | f1
------+----
  r1   |  2
  r2   |  3
(records: 2)

$ cat /tmp/f1.log
log
log
log
log
log
log

Why f1 was called in last case? Why select can't use index values
instead of function call results? Is it bug? Can it be configured?

--
Thanks,
Eugene Prokopiev

pgsql-general by date:

Previous
From: "Qingqing Zhou"
Date:
Subject: Re: keeping track of inserts (periodical) into a table
Next
From: Anton Nikiforov
Date:
Subject: Re: int to inet conversion