Re: Limit clause not using index - Mailing list pgsql-performance

From Yves Vindevogel
Subject Re: Limit clause not using index
Date
Msg-id 7e514564b9a159480857de53cc1764fd@implements.be
Whole thread Raw
In response to Re: Limit clause not using index  (John A Meinel <john@arbash-meinel.com>)
Responses Re: Limit clause not using index
List pgsql-performance
rvponp=# explain analyze select * from tblPrintjobs order by
loginuser, desceventdate, desceventtime ;

                                                           QUERY PLAN
        


--------------------------------------------------------------------------------------------------------------------------------

 Sort  (cost=345699.06..347256.49 rows=622972 width=203) (actual
time=259438.952..268885.586 rows=622972 loops=1)

   Sort Key: loginuser, desceventdate, desceventtime

   ->  Seq Scan on tblprintjobs  (cost=0.00..25596.72 rows=622972
width=203) (actual time=21.155..8713.810 rows=622972 loops=1)

 Total runtime: 271583.422 ms

(4 rows)


On 21 Jun 2005, at 16:42, John A Meinel wrote:


<excerpt>Yves Vindevogel wrote:


<excerpt>Hi,


I have a very simple query on a big table. When I issue a "limit"
and/or "offset" clause, the query is not using the index.

Can anyone explain me this ?

</excerpt>

You didn't give enough information. What does you index look like that
you are expecting it to use?

Generally, you want to have matching columns. So you would want

CREATE INDEX blah ON tblprintjobs(loginuser, desceventdate,
desceventtime);


Next, you should post EXPLAIN ANALYZE instead of regular explain, so
we can have an idea if the planner is actually making correct
estimations.


John

=:->


<excerpt>

rvponp=# explain select * from tblprintjobs order by loginuser,
desceventdate, desceventtime offset 25 limit 25 ;

QUERY PLAN

-----------------------------------------------------------------------------------

Limit (cost=349860.62..349860.68 rows=25 width=206)

-> Sort (cost=349860.56..351416.15 rows=622236 width=206)

Sort Key: loginuser, desceventdate, desceventtime

-> Seq Scan on tblprintjobs (cost=0.00..25589.36 rows=622236 width=206)

(4 rows)


rvponp=# explain select * from tblprintjobs order by loginuser,
desceventdate, desceventtime ;

QUERY PLAN

-----------------------------------------------------------------------------

Sort (cost=349860.56..351416.15 rows=622236 width=206)

Sort Key: loginuser, desceventdate, desceventtime

-> Seq Scan on tblprintjobs (cost=0.00..25589.36 rows=622236 width=206)

(3 rows)


Met vriendelijke groeten,

Bien à vous,

Kind regards,


*Yves Vindevogel*

*Implements*

</excerpt>




</excerpt>Met vriendelijke groeten,

Bien à vous,

Kind regards,


<bold>Yves Vindevogel</bold>

<bold>Implements</bold>

<smaller>

</smaller>rvponp=# explain analyze select * from tblPrintjobs order by loginuser,
desceventdate, desceventtime ;
                                                            QUERY PLAN
------------------------------------------------------------------------
--------------------------------------------------------
  Sort  (cost=345699.06..347256.49 rows=622972 width=203) (actual
time=259438.952..268885.586 rows=622972 loops=1)
    Sort Key: loginuser, desceventdate, desceventtime
    ->  Seq Scan on tblprintjobs  (cost=0.00..25596.72 rows=622972
width=203) (actual time=21.155..8713.810 rows=622972 loops=1)
  Total runtime: 271583.422 ms
(4 rows)

On 21 Jun 2005, at 16:42, John A Meinel wrote:

> Yves Vindevogel wrote:
>
>> Hi,
>>
>> I have a very simple query on a big table. When I issue a "limit"
>> and/or "offset" clause, the query is not using the index.
>> Can anyone explain me this ?
>
> You didn't give enough information. What does you index look like that
> you are expecting it to use?
> Generally, you want to have matching columns. So you would want
> CREATE INDEX blah ON tblprintjobs(loginuser, desceventdate,
> desceventtime);
>
> Next, you should post EXPLAIN ANALYZE instead of regular explain, so
> we can have an idea if the planner is actually making correct
> estimations.
>
> John
> =:->
>
>>
>> rvponp=# explain select * from tblprintjobs order by loginuser,
>> desceventdate, desceventtime offset 25 limit 25 ;
>> QUERY PLAN
>> ----------------------------------------------------------------------
>> -------------
>> Limit (cost=349860.62..349860.68 rows=25 width=206)
>> -> Sort (cost=349860.56..351416.15 rows=622236 width=206)
>> Sort Key: loginuser, desceventdate, desceventtime
>> -> Seq Scan on tblprintjobs (cost=0.00..25589.36 rows=622236
>> width=206)
>> (4 rows)
>>
>> rvponp=# explain select * from tblprintjobs order by loginuser,
>> desceventdate, desceventtime ;
>> QUERY PLAN
>> ----------------------------------------------------------------------
>> -------
>> Sort (cost=349860.56..351416.15 rows=622236 width=206)
>> Sort Key: loginuser, desceventdate, desceventtime
>> -> Seq Scan on tblprintjobs (cost=0.00..25589.36 rows=622236
>> width=206)
>> (3 rows)
>>
>> Met vriendelijke groeten,
>> Bien à vous,
>> Kind regards,
>>
>> *Yves Vindevogel*
>> *Implements*
>
>
>
>
Met vriendelijke groeten,
Bien à vous,
Kind regards,

Yves Vindevogel
Implements

<smaller>


Mail: yves.vindevogel@implements.be  - Mobile: +32 (478) 80 82 91


Kempische Steenweg 206 - 3500 Hasselt - Tel-Fax: +32 (11) 43 55 76


Web: http://www.implements.be

<italic><x-tad-smaller>

First they ignore you.  Then they laugh at you.  Then they fight you.
Then you win.

Mahatma Ghandi.</x-tad-smaller></italic></smaller>



Mail: yves.vindevogel@implements.be  - Mobile: +32 (478) 80 82 91

Kempische Steenweg 206 - 3500 Hasselt - Tel-Fax: +32 (11) 43 55 76

Web: http://www.implements.be

First they ignore you.  Then they laugh at you.  Then they fight you.
Then you win.
Mahatma Ghandi.

Attachment

pgsql-performance by date:

Previous
From: Jone C
Date:
Subject: Re: slow growing table
Next
From: Yves Vindevogel
Date:
Subject: Re: Limit clause not using index