Evaluate arguments of COALESCE and NULLIF only once.

From: Kris Jurka <books(at)ejurka(dot)com>
To: <pgsql-patches(at)postgresql(dot)org>
Subject: Evaluate arguments of COALESCE and NULLIF only once.
Date: 2003-02-12 02:43:06
Message-ID: Pine.LNX.4.33.0302112136090.21758-200000@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches


Currently the parser transforms COALESCE and NULLIF statements to an
equivalent CASE statement. The downside to this is that arguments must be
evaluated for both the WHEN and THEN sections of the CASE statement.
This is a problem if the arguments are expensive or volatile functions.
Consider evaluating

SELECT COALESCE(ten_millionth_digit_of_pi(),1);

OR

SELECT COALESCE(randomlynull(), 1);

The first statement will take twice as long. The second statement will
sometimes return NULL because the first evaluation returns a non null
value, but the second evaluation returns null.

The following patch makes COALESCE and NULLIF first class expressions with
all the associated machinery.

Kris Jurka

Attachment Content-Type Size
one_eval.patch text/plain 39.2 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Matthew T. O'Connor 2003-02-12 02:48:23 pg_avd
Previous Message Zhenbang Wei 2003-02-11 15:25:30 [PATCH]pg_resetxlog-zh_TW.po