Using LIMIT 1 in plpgsql PERFORM statements

From: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Using LIMIT 1 in plpgsql PERFORM statements
Date: 2005-10-22 05:05:21
Message-ID: 1129957521l.27845l.2l@mofo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hi,

I'm wondering if the plpgsql code:

PERFORM 1 FROM foo;
IF FOUND THEN ...

is any slower than:

PERFORM 1 FROM foo LIMIT 1;
IF FOUND THEN ...

Seems like it _could_ be smart enough to know that

1) It's selecting from a real table and not a function

2) GET DIAGNOSTICS is not used

and therefore it does not have to do more than set
FOUND, and need find only one row/plan the query
to find only one row. I'm particularly interested
in the query plan optimization aspect.

Would it be considered poor practice to rely on
such an optimization?

Thanks.

Karl <kop(at)meme(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Alvaro Herrera 2005-10-22 13:25:12 Re: Sequential scan on FK join
Previous Message Neil Conway 2005-10-21 21:44:47 Re: What gets cached?