pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
using limit
4+ messages / 2 participants
[nested] [flat]

* using limit
@ 2010-12-16 19:18 Anibal David Acosta <aa@devshock.com>
  2010-12-16 19:23 ` Re: using limit Michael Holt <michael@aers.ca>
  0 siblings, 1 reply; 4+ messages in thread

From: Anibal David Acosta @ 2010-12-16 19:18 UTC (permalink / raw)
  To: pgsql-admin

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

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: using limit
  2010-12-16 19:18 using limit Anibal David Acosta <aa@devshock.com>
@ 2010-12-16 19:23 ` Michael Holt <michael@aers.ca>
  2010-12-16 19:33   ` Re: using limit Anibal David Acosta <aa@devshock.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Michael Holt @ 2010-12-16 19:23 UTC (permalink / raw)
  To: Anibal David Acosta <aa@devshock.com>; pgsql-admin

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

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: using limit
  2010-12-16 19:18 using limit Anibal David Acosta <aa@devshock.com>
  2010-12-16 19:23 ` Re: using limit Michael Holt <michael@aers.ca>
@ 2010-12-16 19:33   ` Anibal David Acosta <aa@devshock.com>
  2010-12-16 19:46     ` Re: using limit Michael Holt <michael@aers.ca>
  0 siblings, 1 reply; 4+ messages in thread

From: Anibal David Acosta @ 2010-12-16 19:33 UTC (permalink / raw)
  To: 'Michael Holt' <michael@aers.ca>; pgsql-admin

Is a table with 10 million of rows with a primary key but conditions used in
select are not part of PK.

 

My table is like this:

Column 1 - PK

Column 2 - Indexed

Column 3 - Indexed

 

Column 2 and Column 3 are Indexed in the same index but they are not mark as
unique or PK

 

The Query is like this:

Select column1 from myTable where Column2 between X and Y

 

I am expecting just one record

 

 

 

De: Michael Holt [mailto:michael@aers.ca] 
Enviado el: jueves, 16 de diciembre de 2010 04:23 p.m.
Para: Anibal David Acosta; pgsql-admin@postgresql.org
Asunto: RE: [ADMIN] using limit

 

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

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: using limit
  2010-12-16 19:18 using limit Anibal David Acosta <aa@devshock.com>
  2010-12-16 19:23 ` Re: using limit Michael Holt <michael@aers.ca>
  2010-12-16 19:33   ` Re: using limit Anibal David Acosta <aa@devshock.com>
@ 2010-12-16 19:46     ` Michael Holt <michael@aers.ca>
  0 siblings, 0 replies; 4+ messages in thread

From: Michael Holt @ 2010-12-16 19:46 UTC (permalink / raw)
  To: Anibal David Acosta <aa@devshock.com>; pgsql-admin

Yes, a limit should speed up your query from the sounds of things.



*From:* Anibal David Acosta [mailto:aa@devshock.com]
*Sent:* Thursday, December 16, 2010 11:34 AM
*To:* 'Michael Holt'; pgsql-admin@postgresql.org
*Subject:* RE: [ADMIN] using limit



Is a table with 10 million of rows with a primary key but conditions used in
select are not part of PK.



My table is like this:

Column 1 – PK

Column 2 – Indexed

Column 3 – Indexed



Column 2 and Column 3 are Indexed in the same index but they are not mark as
unique or PK



The Query is like this:

Select column1 from myTable where Column2 between X and Y



I am expecting just one record







*De:* Michael Holt [mailto:michael@aers.ca]
*Enviado el:* jueves, 16 de diciembre de 2010 04:23 p.m.
*Para:* Anibal David Acosta; pgsql-admin@postgresql.org
*Asunto:* RE: [ADMIN] using limit



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

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2010-12-16 19:46 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-12-16 19:18 using limit Anibal David Acosta <aa@devshock.com>
2010-12-16 19:23 ` Michael Holt <michael@aers.ca>
2010-12-16 19:33   ` Anibal David Acosta <aa@devshock.com>
2010-12-16 19:46     ` Michael Holt <michael@aers.ca>

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