Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X9wTn-0002bd-Hn for pgsql-performance@arkaria.postgresql.org; Wed, 23 Jul 2014 13:21:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X9wTn-0003jX-1n for pgsql-performance@arkaria.postgresql.org; Wed, 23 Jul 2014 13:21:11 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X9wTl-0003jQ-Rh for pgsql-performance@postgresql.org; Wed, 23 Jul 2014 13:21:10 +0000 Received: from mail-pa0-x22e.google.com ([2607:f8b0:400e:c03::22e]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1X9wTi-0001uR-Hk for pgsql-performance@postgresql.org; Wed, 23 Jul 2014 13:21:07 +0000 Received: by mail-pa0-f46.google.com with SMTP id lj1so1724968pab.19 for ; Wed, 23 Jul 2014 06:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:message-id:date:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=4sJbdBVpLQemMWBUjeQuxfUIz8YD+djpWzThOOVcwWo=; b=E5AZdDebUxLaJ1+lASZynwQ6sh9tPdKf9MisSr4STFfppbSm2QbgI/pmJ5NPqHdcjG SYAIO/hz+U3n25wFNBRSK3HhodLhcubz+TT1WSl5EeYHK7gkwZ7QpkbnVJGylVbgoSjj xBcoR/mBXQKMU9bE0jKpqehoYiZsYfb50q8fIQyoQh3CctMmM4ePRuYGkl+wB/cvFLDU bAMjw49huFcQKx4Ioi92ejS9zPv7acKYfAUYKXwV253u25Yr0NXSqY7+toQU4DmfmFzX qeeNCBuhfPeBXC8bu9RkrD4jmsPgVyRCasw3O7XZ5ypZ81dWZFPpPiD9qNfP/6SZGaJI dZeA== X-Received: by 10.68.220.170 with SMTP id px10mr1575279pbc.33.1406121664083; Wed, 23 Jul 2014 06:21:04 -0700 (PDT) Received: from [192.168.11.4] ([180.164.153.84]) by mx.google.com with ESMTPSA id ez1sm2389988pbd.91.2014.07.23.06.21.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jul 2014 06:21:03 -0700 (PDT) From: Rural Hunter X-Google-Original-From: Rural Hunter Message-ID: <53CFB6BC.4050606@gmail.com> Date: Wed, 23 Jul 2014 21:21:00 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Very slow planning performance on partition table Content-Type: text/plain; charset=gb18030; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Hi, I have a table partitioned with about 60 children tables. Now I found the planning time of simple query with partition key are very slow. # explain analyze select count(*) as cnt from article where pid=88 and hash_code='2ca3ff8b17b163f0212c2ba01b80a064'; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=16.55..16.56 rows=1 width=0) (actual time=0.259..0.259 rows=1 loops=1) -> Append (cost=0.00..16.55 rows=2 width=0) (actual time=0.248..0.250 rows=1 loops=1) -> Seq Scan on article (cost=0.00..0.00 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1) Filter: ((pid = 88) AND (hash_code = '2ca3ff8b17b163f0212c2ba01b80a064'::bpchar)) -> Index Scan using article_88_hash_idx on article_88 article (cost=0.00..16.55 rows=1 width=0) (actual time=0.246..0.248 rows=1 loops=1) Index Cond: (hash_code = '2ca3ff8b17b163f0212c2ba01b80a064'::bpchar) Filter: (pid = 88) Total runtime: 3.816 ms (8 rows) Time: 30999.986 ms You can see the timing output that the actual run time of the 'explain analyze' is 30 seconds while the select sql itself takes only 3 ms. My partition key is on article.pid and the constraint is simple like this: CONSTRAINT article_88_pid_check CHECK (pid = 88). What's wrong and how can I improve the planning performance? -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance