Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id C581F64FD37 for ; Mon, 10 Nov 2008 14:21:32 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 44113-09 for ; Mon, 10 Nov 2008 14:21:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.147]) by mail.postgresql.org (Postfix) with ESMTP id 0AE9F64FD1A for ; Mon, 10 Nov 2008 14:21:32 -0400 (AST) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by ptb-relay03.plus.net with esmtp (Exim) id 1KzbOC-0004g8-1e; Mon, 10 Nov 2008 18:21:28 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id CCAB527406A; Mon, 10 Nov 2008 18:21:27 +0000 (GMT) Message-ID: <49187BA7.8020403@archonet.com> Date: Mon, 10 Nov 2008 18:21:27 +0000 From: Richard Huxton User-Agent: Thunderbird 2.0.0.17 (X11/20080914) MIME-Version: 1.0 To: "Jim 'Decibel!' Nasby" CC: Tom Lane , postgresql performance list Subject: Re: Oddity with view References: <3CF0CFC1-FDBA-4A61-ACAA-6AF556C4C6F4@cashnetusa.com> <3128.1226322412@sss.pgh.pa.us> <7B598355-07C0-450A-9914-B5979F48A5B3@cashnetusa.com> In-Reply-To: <7B598355-07C0-450A-9914-B5979F48A5B3@cashnetusa.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Plusnet-Relay: 387f1ed7937f7c8ce8da21e563b15848 X-Archive-Number: 200811/66 X-Sequence-Number: 31797 Jim 'Decibel!' Nasby wrote: > On Nov 10, 2008, at 7:06 AM, Tom Lane wrote: >> "Jim 'Decibel!' Nasby" writes: >>> loan_tasks effectively does SELECT * FROM loan_tasks_committed UNION >>> ALL SELECT * FROM loan_tasks_pending;. >> >> You seem to have neglected to mention a join or two. > > > Yeah, though I did show them at the end of the message... > > SELECT true AS "committed", loan_tasks_committed.id, ..., > loan_tasks_committed.task_amount > FROM loan_tasks_committed > UNION ALL > SELECT false AS "committed", ltp.id, ..., NULL::"unknown" AS task_amount > FROM loan_tasks_pending ltp > JOIN loan_task_codes ltc ON ltp.loan_task_code_id = ltc.id; > > Thing is, there's no data to be had on that side. All of the time is > going into the seqscan of loan_tasks_committed. But here's what's really > disturbing... > -> Seq Scan on loan_tasks_committed (cost=0.00..929345.35 > rows=26112135 width=0) (actual time=0.012..5116.776 rows=26115689 loops=1) > -> Seq Scan on loan_tasks_committed > (cost=0.00..929345.35 rows=26112135 width=162) (actual > time=0.014..22531.902 rows=26115689 loops=1) It's the width - the view is fetching all the rows. Is the "true as committed" bit confusing it? -- Richard Huxton Archonet Ltd