X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 172C29DCC51 for ; Tue, 6 Dec 2005 12:19:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36573-09 for ; Tue, 6 Dec 2005 12:19:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.rilk.com (mail.rilk.com [193.19.217.130]) by postgresql.org (Postfix) with ESMTP id 8C7999DCBBC for ; Tue, 6 Dec 2005 12:19:56 -0400 (AST) Received: from [192.168.0.2] (cev75-1-81-57-249-136.fbx.proxad.net [81.57.249.136]) (authenticated bits=0) by mail.rilk.com (8.13.0/8.13.0) with ESMTP id jB6GJe4k003576 (version=TLSv1/SSLv3 cipher=EDH-DSS-DES-CBC3-SHA bits=168 verify=NO) for ; Tue, 6 Dec 2005 17:19:54 +0100 (CET) Mime-Version: 1.0 (Apple Message framework v746.2) In-Reply-To: <334D9941-B5B3-4D18-8312-F85D0FB054ED@rilk.com> References: <334D9941-B5B3-4D18-8312-F85D0FB054ED@rilk.com> Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: quoted-printable From: Pailloncy Jean-Gerard Subject: Re: 8.1 count(*) distinct: IndexScan/SeqScan Date: Tue, 6 Dec 2005 17:19:34 +0100 To: pgsql-performance@postgresql.org X-Mailer: Apple Mail (2.746.2) X-DCC-CTc-dcc2-Metrics: mail.rilk.com 1031; Body=1 Fuz1=1 Fuz2=1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200512/169 X-Sequence-Number: 15990 Hi, After few test, the difference is explained by the =20 effective_cache_size parameter. with effective_cache_size=3D1000 (default) the planner chooses the following plan postgres=3D# explain select count(*) from (select distinct on (val) * =20= from test) as foo; QUERY PLAN ------------------------------------------------------------------------=20= -------- Aggregate (cost=3D421893.64..421893.65 rows=3D1 width=3D0) -> Unique (cost=3D385193.48..395679.24 rows=3D2097152 width=3D8) -> Sort (cost=3D385193.48..390436.36 rows=3D2097152 width=3D8)= Sort Key: test.val -> Seq Scan on test (cost=3D0.00..31252.52 =20 rows=3D2097152 width=3D8) (5 rows) with effective_cache_size=3D15000 the planner chooses the following plan postgres=3D# explain select count(*) from (select distinct on (val) * =20= from test) as foo; QUERY PLAN ------------------------------------------------------------------------=20= ------------------ Aggregate (cost=3D101720.39..101720.40 rows=3D1 width=3D0) -> Unique (cost=3D0.00..75505.99 rows=3D2097152 width=3D8) -> Index Scan using testval on test (cost=3D0.00..70263.11 =20= rows=3D2097152 width=3D8) (3 rows) I test some other values for effective_cache_size. The switch from seq to index scan happens between 9900 and 10000 for =20 effective_cache_size. I have my sql server on a OpenBSD 3.8 box with 1 Gb of RAM with =20 nothing else running on it. I setup the cachepercent to 25. I expect to have 25% of 1 Gb of RAM =20 (256 Mb) as file cache. effective_cache_size=3D15000 means 15000 x 8K of OS cache =3D 120,000 Kb = =20 which is lower than my 256 MB of disk cache. I recall the result of my precedent test. #rows 2097152 IndexScan 1363396,581s SeqScan 98758,445s Ratio 13,805 So the planner when effective_cache_size=3D15000 chooses a plan that is =20= 13 times slower than the seqscan one. I did not understand where the problem comes from. Any help welcome. Cordialement, Jean-G=E9rard Pailloncy