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 137B99DCD13 for ; Wed, 1 Mar 2006 12:04: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 16782-08 for ; Wed, 1 Mar 2006 12:04:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227]) by postgresql.org (Postfix) with ESMTP id C3E049DCD06 for ; Wed, 1 Mar 2006 12:04:56 -0400 (AST) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1FETol-0004ht-00; Wed, 01 Mar 2006 11:04:47 -0500 To: Tom Lane Cc: PFC , pgsql-performance@postgresql.org Subject: Re: Bad plan on a view References: <10652.1141226168@sss.pgh.pa.us> In-Reply-To: <10652.1141226168@sss.pgh.pa.us> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 01 Mar 2006 11:04:47 -0500 Message-ID: <87r75mup5s.fsf@stark.xeocode.com> Lines: 38 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.13 required=5 tests=[AWL=0.130] X-Spam-Score: 0.13 X-Spam-Level: X-Archive-Number: 200603/7 X-Sequence-Number: 17444 Tom Lane writes: > PFC writes: > > So, in order to speed up requests which need a full table scan, I wanted > > to put the text fields in another table, and use a view to make it look > > like nothing happened. Also, the small table used for searching is a lot > > more likely to fit in RAM than the big table with all the text which is > > only used for display. > > Aren't you going to a lot of work to reinvent something that TOAST > already does for you? (At least, in the cases where the text fields > are wide enough that it really matters.) I think this is a fairly common data modelling trick actually. And it's not a terribly large amount of work either. While TOAST has a similar goal I don't think it has enough AI to completely replace this manual process. It suffers in a number of use cases: 1) When you have a large number of moderate sized text fields instead of a single very large text field. This is probably the case here. 2) When you know exactly which fields you'll be searching on and which you won't be. Often many speed-sensitive queries don't need to access the extended information at all. Instead of making the decision on a per-record basis you can *always* move the data to the other table saving even more space even in cases where you're gaining very little per record. In total across the entire scan you still gain a lot being able to scan just the dense integer fields. Also, is the optimizer capable of coming up with merge join type plans for TOAST tables when necessary? -- greg