Index scan vs indexonly scan method

From: Enrico Pirozzi <sscotty71(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Index scan vs indexonly scan method
Date: 2014-10-22 15:18:03
Message-ID: 5447CAAB.7040407@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I was working on this simple query

select field1 from table A
where A.field2 <= some_value
order by 1 desc limit some_value

and I saw that:

1) the planner on this query uses an index only scan method:

select field1 from table A
where A.field2 <= '2014-08-13 10:20:59.99648+02'
order by 1 desc limit 100

2) the planner on this query uses a classic index scan method:

select field1 from table A
where A.field2 <= '2014-08-13 10:20:59.99648+02'
order by 1 desc limit 1

the only difference between the two queries is the limit clause,
for the first query the limit is 100 and for the second the limit is 1

it seems a little bit strange...someone can help me to understand why?

My develop PostgreSQL version is a 9.4 beta

regards,
Enrico

--
That's one small step for man; one giant leap for mankind

Enrico Pirozzi
Tel. +39 0861 1855771 - Mob.+39 328 4164437 - Fax +39 0861 1850310
http://www.pgtraining.com <http://www.pgtraining.com-> -
info(at)pgtraining(dot)com
www.enricopirozzi.info - info(at)enricopirozzi(dot)info
PEC: enrico(dot)pirozzi(at)pec(dot)it
Skype sscotty71 - Gtalk sscotty71(at)gmail(dot)com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2014-10-22 15:37:47 Re: Index scan vs indexonly scan method
Previous Message Igor Neyman 2014-10-22 14:54:11 Re: To increase RAM or not