Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-performance by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group