Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C3A14B5DD0D for ; Mon, 11 Jul 2011 13:51:48 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 13913-07 for ; Mon, 11 Jul 2011 16:51:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id 37006B5DC68 for ; Mon, 11 Jul 2011 13:51:48 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p6BGplwg047959 for ; Mon, 11 Jul 2011 16:51:47 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p6BGpluQ047958; Mon, 11 Jul 2011 16:51:47 GMT (envelope-from www) Date: Mon, 11 Jul 2011 16:51:47 GMT Message-Id: <201107111651.p6BGpluQ047958@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #6112: heuristic for empty parent tables that are members of inheritance trees From: "Anish Kejariwal" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201107/88 X-Sequence-Number: 30700 The following bug has been logged online: Bug reference: 6112 Logged by: Anish Kejariwal Email address: anishkej@gmail.com PostgreSQL version: 9.0.3 Operating system: Linux Description: heuristic for empty parent tables that are members of inheritance trees Details: Hello, I'm filing this issue as a bug, and it seems like Tom Lane agrees that there is a bug, and said: " maybe we should reconsider the heuristic for tables that are members of inheritance trees --- particularly parents of inheritance trees." All information is in: http://archives.postgresql.org/pgsql-performance/2011-07/msg00063.php Scenario: -empty parent table -all data is in child/partitioned tables Bug: optimizer considers the parent table to be empty. Result: The execution plan is incorrect. My particularly query took 25 seconds with the wrong execution plan, but 0.3 seconds with the correct execution plan. Work around: Tom Lane suggested the following workaround to "defeat the empty-table heuristic: update pg_class set relpages = 1 where relname = 'icecream'; I'm using this work around for now, but I don't think this is acceptable. If someone were to accidentally run vacuum analyze on the parent table, then the relpages will be set back to zero, and the query will run slowly. Please let me know if you have any questions. Anish