Re: [HACKERS] indexes and floats - Mailing list pgsql-hackers

From Brook Milligan
Subject Re: [HACKERS] indexes and floats
Date
Msg-id 199808061842.MAA02106@trillium.nmsu.edu
Whole thread Raw
In response to Re: [HACKERS] indexes and floats  (Bruce Momjian <maillist@candle.pha.pa.us>)
Responses Re: [HACKERS] indexes and floats  (dg@informix.com (David Gould))
List pgsql-hackers
   > Sorry, but maybe it would be better to add new attribute
   > to pg_proc (and change CREATE FUNCTION syntax) to let
   > parser know does result of function call on constants depend
   > on execution time or not. This would be much better just
   > execute function in parser and replace function with
   > constant.
   > Currently, only random(), now() and SPI-functions should be
   > replaced by PARAM_EXEC, all others could be evaluated by parser.

   I see.  We have pg_proc.proiscachable.  This looks like a good
   candidate, and is not used for anything currently.  Maybe rename it to
   something clearer.

Wouldn't the concept of VOLATILE be relevant here (ala the same
keyword in C and C++)?  In those languages the keyword influences the
nature of optimizations that can be done, which seems to be the
problems involved here.  We could have a function bool
pg_proc.is_volatile() to determine whether or not the result of the
function call can be determined from its arguments.  If so and the
arguments are constants, the function could be evaluated once in the
parser; otherwise, it would need to be evaluated for each tuple.

The current situation, I presume, corresponds with all functions being
VOLATILE and hence evaluated many times.  We could 1) add new syntax
for declaring user-defined functions to optionally include VOLATILE
(and/or NONVOLATILE; default being VOLATILE in the absense of a
keyword to maintain compatibility and to be safe), 2) have the
is_volatile() function return appropriate values for all "standard"
functions defined in the system, and 3) include handling of the
distinction in the parser.

Cheers,
Brook

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] indexes and floats
Next
From: "Dr. Michael Meskes"
Date:
Subject: Re: [HACKERS] Declare Cursor question again