Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 00BBB159076 for ; Mon, 5 Mar 2012 11:11:26 -0400 (AST) Received: from mx01.clickware.de ([78.35.13.85]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1S4ZZH-00031v-UO for pgsql-performance@postgresql.org; Mon, 05 Mar 2012 15:11:25 +0000 Received: (qmail 31726 invoked by uid 1010); 5 Mar 2012 15:11:01 -0000 Received: from localhost (marc@localhost) by mx01 (envelope-from , uid 1002) with qmail-scanner-2.06st (sophie: //. spamassassin: 3.2.3. Clear:RC:0(127.0.0.1):SA:0(-4.2/5.0):. Processed in 0.157673 secs); 05 Mar 2012 15:11:01 -0000 X-Spam-Status: No, hits=-4.2 required=5.0 Received: from localhost (HELO ?192.168.1.220?) (marc@127.0.0.1) by mx01.clickware.de with SMTP; 5 Mar 2012 15:11:01 -0000 Message-ID: <4F54D785.6090200@clickware.de> Date: Mon, 05 Mar 2012 16:11:01 +0100 From: Marc Schablewski User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Partitioning / Strange optimizer behaviour X-Enigmail-Version: 1.3.5 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201203/54 X-Sequence-Number: 46504 We have an optimizer problem regarding partitioned tables on 8.4.11. We started partitioning a large table containing approx. 1 billion records. So far, there is only the master table, called edifactmsgpart (which is empty) and 1 partition, called edifactmsgpart_pact. There is a bigint column called emg_id with a btree-index on it. \d edifactmsgpart_pact ... ... "emp_emg_ept_i_pact" btree (emg_id, ept_id) ... gdw=> select relname, reltuples from pg_class where relname in( 'edifactmsgpart', 'edifactmsgpart_pact' ); relname | reltuples ---------------------+------------- edifactmsgpart_pact | 1.03102e+09 edifactmsgpart | 0 a select on the big partition yields a decent plan and performs as expected, lasting only a fraction of a second. gdw=> explain select min( emg_id ) from edifactmsgpart_pact; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------ Result (cost=2.05..2.06 rows=1 width=0) InitPlan 1 (returns $0) -> Limit (cost=0.00..2.05 rows=1 width=8) -> Index Scan using emp_emg_ept_i_pact on edifactmsgpart_pact (cost=0.00..2109171123.79 rows=1031020672 width=8) Filter: (emg_id IS NOT NULL) gdw=> select min( emg_id ) from edifactmsgpart_pact; min ----------- 500008178 =>>> very fast. a select on the partitioned table, however, yields a... shall we call it "sub-optimal" plan: gdw=> explain select min( emg_id ) from edifactmsgpart; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Aggregate (cost=23521692.03..23521692.04 rows=1 width=8) -> Append (cost=0.00..20944139.42 rows=1031021042 width=8) -> Seq Scan on edifactmsgpart (cost=0.00..13.70 rows=370 width=8) -> Seq Scan on edifactmsgpart_pact edifactmsgpart (cost=0.00..20944125.72 rows=1031020672 width=8) I would expect this to run half an hour or so, completely overloading the server... Any Ideas? Kind regards Marc