Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id D5A4A2E3381 for ; Thu, 6 Dec 2007 11:42:27 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 55978-01-4 for ; Thu, 6 Dec 2007 11:42:15 -0400 (AST) Received: from vms046pub.verizon.net (vms046pub.verizon.net [206.46.252.46]) by postgresql.org (Postfix) with ESMTP id 2D8502E32A8 for ; Thu, 6 Dec 2007 11:42:20 -0400 (AST) Received: from osgiliath.mathom.us ([71.178.10.55]) by vms046.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JSM00D44WYJOW1E@vms046.mailsrvcs.net> for pgsql-performance@postgresql.org; Thu, 06 Dec 2007 09:42:19 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by osgiliath.mathom.us (Postfix) with ESMTP id EAB461F814 for ; Thu, 06 Dec 2007 10:42:15 -0500 (EST) Received: from osgiliath.mathom.us ([127.0.0.1]) by localhost (osgiliath.home.mathom.us [127.0.0.1]) (amavisd-new, port 10024) with LMTP id JwmSUMDvmuCP for ; Thu, 06 Dec 2007 10:42:14 -0500 (EST) Received: by osgiliath.mathom.us (Postfix, from userid 1000) id AF9CF1F80D; Thu, 06 Dec 2007 10:42:14 -0500 (EST) Date: Thu, 06 Dec 2007 10:42:14 -0500 From: Michael Stone Subject: Re: TB-sized databases In-reply-to: <1196933896.4255.340.camel@ebony.site> To: pgsql-performance@postgresql.org Mail-followup-to: pgsql-performance@postgresql.org Message-id: <20071206154212.GP5294@mathom.us> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-disposition: inline X-Virus-Scanned: Debian amavisd-new at mathom.us X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C 84 52 84 C5 EE DF 7C 88 References: <4544e0330711260904g45d893a8ub1731e245aa8fc84@mail.gmail.com> <13851.1196351131@sss.pgh.pa.us> <1196352866.4246.1304.camel@ebony.site> <200712051507.22745.xzilla@users.sourceforge.net> <1196933896.4255.340.camel@ebony.site> User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/80 X-Sequence-Number: 27896 On Thu, Dec 06, 2007 at 09:38:16AM +0000, Simon Riggs wrote: >The issue is that if somebody issues a "large query" then it will be a >problem whichever plan the query takes. Forcing index scans can make a >plan more expensive than a seq scan in many cases. OTOH, the planner can really screw up queries on really large databases. IIRC, the planner can use things like unique constraints to get some idea, e.g., of how many rows will result from a join. Unfortunately, the planner can't apply those techniques to certain constructs common in really large db's (e.g., partitioned tables--how do you do a unique constraint on a partitioned table?) I've got some queries that the planner thinks will return on the order of 10^30 rows for that sort of reason. In practice, the query may return 10^3 rows, and the difference between the seq scan and the index scan is the difference between a query that takes a few seconds and a query that I will never run to completion. I know the goal would be to make the planner understand those queries better, but for now the answer seems to be to craft the queries very carefully and run explain first, making sure you see index scans in the right places. Mike Stone