pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Yves Vindevogel <yves.vindevogel@implements.be>
To: pgsql-performance@postgresql.org
Subject: Re: View not using index
Date: Mon, 13 Jun 2005 09:35:47 +0200
Message-ID: <d0e84110335f1e6d7e4c9b0c0b2b2266@implements.be> (raw)
In-Reply-To: <ea465cec82454372ead9c8a92a795d71@implements.be>
References: <9e1745a6fe1ae29c6f1c824128871d36@implements.be>
	<200506131705.35852.mr-russ@pws.com.au>
	<ea465cec82454372ead9c8a92a795d71@implements.be>

Note the last query below (prev post)
There it does use the index


rvponp=# create type tpJobsPerDay as
rvponp-# ( documentname varchar(1000),
rvponp(# eventdate date,
rvponp(# eventtime time,
rvponp(# loginuser varchar(255),
rvponp(# pages varchar(20)
rvponp(# ) ;
CREATE TYPE
rvponp=# create function fnJobsPerDay (bigint, bigint) returns setof  
tpJobsPerDay as
rvponp-# '
rvponp'# select documentname, eventdate, eventtime, loginuser,  
fnFormatInt(pages) as pages
rvponp'# from tblPrintjobs order by descpages, documentname
rvponp'# offset $1 limit $2 ;
rvponp'# ' language 'sql' ;
CREATE FUNCTION

rvponp=# analyze ;
ANALYZE
rvponp=# explain select * from fnJobsperday (1, 10) ;
                               QUERY PLAN
-----------------------------------------------------------------------
  Function Scan on fnjobsperday  (cost=0.00..12.50 rows=1000 width=697)
(1 row)


With the function, it still is very slow.  I can't see anything in the  
explain here, but it seems to be using a table scan.

On 13 Jun 2005, at 09:18, Yves Vindevogel wrote:

> rvponp=# explain select * from vw_document_pagesperjob ;
>                                        QUERY PLAN
> ----------------------------------------------------------------------- 
> -----------------
>  Subquery Scan vw_document_pagesperjob  (cost=82796.59..90149.20  
> rows=588209 width=706)
>    ->  Sort  (cost=82796.59..84267.11 rows=588209 width=74)
>          Sort Key: tblprintjobs.descpages, tblprintjobs.documentname
>          ->  Seq Scan on tblprintjobs  (cost=0.00..26428.61  
> rows=588209 width=74)
> (4 rows)
>
> rvponp=# explain select * from vw_document_pagesperjob limit 10 ;
>                                           QUERY PLAN
> ----------------------------------------------------------------------- 
> -----------------------
>  Limit  (cost=82796.59..82796.72 rows=10 width=706)
>    ->  Subquery Scan vw_document_pagesperjob  (cost=82796.59..90149.20  
> rows=588209 width=706)
>          ->  Sort  (cost=82796.59..84267.11 rows=588209 width=74)
>                Sort Key: tblprintjobs.descpages,  
> tblprintjobs.documentname
>                ->  Seq Scan on tblprintjobs  (cost=0.00..26428.61  
> rows=588209 width=74)
> (5 rows)
>
> rvponp=# explain select documentname, eventdate, eventtime, loginuser,  
> pages from tblPrintjobs order
> by descpages, documentname ;
>                                  QUERY PLAN
> ----------------------------------------------------------------------- 
> -----
>  Sort  (cost=81326.07..82796.59 rows=588209 width=74)
>    Sort Key: descpages, documentname
>    ->  Seq Scan on tblprintjobs  (cost=0.00..24958.09 rows=588209  
> width=74)
> (3 rows)
>
> rvponp=# explain select documentname, eventdate, eventtime, loginuser,  
> pages from tblPrintjobs order
> by descpages, documentname limit 10 ;
>                                                  QUERY PLAN
> ----------------------------------------------------------------------- 
> --------------------------------------
>  Limit  (cost=0.00..33.14 rows=10 width=74)
>    ->  Index Scan using ixprintjobspagesperjob on tblprintjobs   
> (cost=0.00..1949116.68 rows=588209 width=74)
> (2 rows)
>
>
> create or replace view vw_document_pagesperjob as
> 	select documentname, eventdate, eventtime, loginuser,
> 		fnFormatInt(pages) as pages
> 	from tblPrintjobs
> 	order by descpages, documentname ;
>
>
>
>
>
>
> On 13 Jun 2005, at 09:05, Russell Smith wrote:
>
>> On Mon, 13 Jun 2005 04:54 pm, Yves Vindevogel wrote:
>>> Still, when I use explain, pg says it will first sort my tables  
>>> instead
>>> of using my index
>>> How is that possible ?
>>
>> Can we see the output of the explain analyze?
>> The definition of the view?
>>
>> Regards
>>
>> Russell Smith
>>
>>
> Met vriendelijke groeten,
> Bien à vous,
> Kind regards,
>
> Yves Vindevogel
> Implements
>
> <Pasted Graphic 2.tiff>
>
> 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.
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faq
>
Met vriendelijke groeten,
Bien à vous,
Kind regards,

Yves Vindevogel
Implements


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.

Attachments:

Pasted Graphic 2.tiff (image/tiff, 5.6K) download view image

view thread (6+ messages)  latest in thread

Message-ID: <d0e84110335f1e6d7e4c9b0c0b2b2266@implements.be>
Permalink:  ../d0e84110335f1e6d7e4c9b0c0b2b2266@implements.be/
Also on:    postgresql.org/message-id/d0e84110335f1e6d7e4c9b0c0b2b2266@implements.be

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: yves.vindevogel@implements.be
  Subject: Re: View not using index
  In-Reply-To: <d0e84110335f1e6d7e4c9b0c0b2b2266@implements.be>
  References: <9e1745a6fe1ae29c6f1c824128871d36@implements.be> <200506131705.35852.mr-russ@pws.com.au> <ea465cec82454372ead9c8a92a795d71@implements.be> <d0e84110335f1e6d7e4c9b0c0b2b2266@implements.be>

* 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