X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 795C65E4710 for ; Tue, 31 Aug 2004 16:21:48 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28723-06 for ; Tue, 31 Aug 2004 19:21:42 +0000 (GMT) Received: from server.gpdnet.co.uk (gpdnet.plus.com [212.56.100.243]) by svr1.postgresql.org (Postfix) with ESMTP id 195625E46F3 for ; Tue, 31 Aug 2004 16:21:40 -0300 (ADT) Received: from gary (unknown [192.168.1.2]) by server.gpdnet.co.uk (Postfix) with ESMTP id D308EFBEA6 for ; Tue, 31 Aug 2004 20:21:46 +0100 (BST) From: "Gary Doades" To: pgsql-performance@postgresql.org Date: Tue, 31 Aug 2004 20:21:49 +0100 MIME-Version: 1.0 Subject: Re: Optimizing a request Message-ID: <4134DDDD.428.4AF67CC@localhost> In-reply-to: <4b09a0c0408311159fa91802@mail.gmail.com> X-mailer: Pegasus Mail for Windows (v4.12a) Content-type: Multipart/Alternative; boundary="Alt-Boundary-12526.78604236" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.9 tagged_above=0.0 required=5.0 tests=HTML_50_60, HTML_FONTCOLOR_RED, HTML_FONTCOLOR_UNSAFE, HTML_MESSAGE, HTML_TITLE_EMPTY X-Spam-Level: X-Archive-Number: 200408/479 X-Sequence-Number: 8115 --Alt-Boundary-12526.78604236 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body On 31 Aug 2004 at 20:59, Jean-Max Reymond wrote: > hi, > > I want to optimize the following request and avoid the seq scan on the > table article (10000000 rows). > > explain SELECT art_id, art_titre, art_texte, rub_titre > FROM article inner join rubrique on article.rub_id = rubrique.rub_id > where rub_parent = 8; > > Hash Join (cost=8.27..265637.59 rows=25 width=130) > Hash Cond: ("outer".rub_id = "inner".rub_id) > -> Seq Scan on article (cost=0.00..215629.00 rows=10000000 width=108) > -> Hash (cost=8.26..8.26 rows=3 width=22) > -> Index Scan using rubrique_parent on rubrique > (cost=0.00..8.26 rows=3 width=22) > Index Cond: (rub_parent = 8) > > > thanks for your answers, > > -- Have you run ANALYZE on this database after creating the indexes or loading the data? What percentage of rows in the "article" table are likely to match the keys selected from the "rubrique" table? If it is likely to fetch a high proportion of the rows from article then it may be best that a seq scan is performed. What are your non-default postgresql.conf settings? It may be better to increase the default_statistics_target (to say 100 to 200) before running ANALYZE and then re-run the query. Cheers, Gary. --Alt-Boundary-12526.78604236 Content-type: text/html; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body
On 31 Aug 2004 at 20:59, Jean-Max Reymond wrote:

> hi,
>
> I want to optimize the following request and avoid the seq scan on the
> table article (10000000 rows).
>
> explain SELECT art_id, art_titre, art_texte, rub_titre
> FROM article inner join rubrique on article.rub_id = rubrique.rub_id
> where rub_parent = 8;
>
> Hash Join  (cost=8.27..265637.59 rows=25 width=130)
>   Hash Cond: ("outer".rub_id = "inner".rub_id)
>   ->  Seq Scan on article  (cost=0.00..215629.00 rows=10000000 width=108)
>   ->  Hash  (cost=8.26..8.26 rows=3 width=22)
>         ->  Index Scan using rubrique_parent on rubrique
> (cost=0.00..8.26 rows=3 width=22)
>               Index Cond: (rub_parent = 8)
>
>
> thanks for your answers,
>
> --

Have you run ANALYZE on this database after creating the indexes or loading the data?

What percentage of rows in the "article" table are likely to match the keys selected from the "rubrique" table?

If it is likely to fetch a high proportion of the rows from article then it may be best that a seq scan is performed.

What are your non-default postgresql.conf settings? It may be better to increase the default_statistics_target (to say 100 to 200) before running ANALYZE and then re-run the query.

Cheers,
Gary.
--Alt-Boundary-12526.78604236--