From: Michael Holt <michael@aers.ca>
To: Anibal David Acosta <aa@devshock.com>
To: pgsql-admin@postgresql.org
Subject: Re: using limit
Date: Thu, 16 Dec 2010 11:23:25 -0800
Message-ID: <f3f619af829b15d8b901614cef0074ac@mail.gmail.com> (raw)
In-Reply-To: <001f01cb9d56$13d69790$3b83c6b0$@devshock.com>
References: <001f01cb9d56$13d69790$3b83c6b0$@devshock.com>
This really depends on the type of query you’re talking about. If there’s
only one row in the table you’re querying then no, I don’t think it’ll
change anything. If you’re querying a single row using a primary key it
shouldn’t change anything. If you’re doing an aggregate query, say a sum of
a bunch of rows, it also won’t improve performance.
If you’re doing a query on a table with multiple rows and not filtering by a
primary key or other unique index then yes, it will improve the query.
*From:* pgsql-admin-owner@postgresql.org [mailto:
pgsql-admin-owner@postgresql.org] *On Behalf Of *Anibal David Acosta
*Sent:* Thursday, December 16, 2010 11:19 AM
*To:* pgsql-admin@postgresql.org
*Subject:* [ADMIN] using limit
Hi
I really like to do efficient SQL queries so, my question is if I am
expecting no more than one row from a select, using the LIMIT 1 could
improve the performance?
If I use my logic, the LIMIT 1 instruction tell to postgres that stop
searching when found 1 record, but maybe it is unnecessary
Thanks
Anibal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: michael@aers.ca, aa@devshock.com
Subject: Re: using limit
In-Reply-To: <f3f619af829b15d8b901614cef0074ac@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox