Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 80D012E0038 for ; Fri, 23 Nov 2007 12:29:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 61827-08 for ; Fri, 23 Nov 2007 12:29:01 -0400 (AST) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.237]) by postgresql.org (Postfix) with ESMTP id A07B42E0040 for ; Fri, 23 Nov 2007 12:29:10 -0400 (AST) Received: by wr-out-0506.google.com with SMTP id 58so1852498wri for ; Fri, 23 Nov 2007 08:29:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=MGhPPs/E/FmSLniWfjJf0999Huul7w9ZhTNblkQJ888=; b=Y8k12GKCzIIaoY8K+jfqj6iYiPX2ktNKDKkGpOAzxbNRUhNUW1d1TKrVcRLjAIxFmv4vEzU/uoRDXXpD4dZSld6auoSWl1emhLpdbERnhpdkiX+iSsYhcXQmpIcjutVsjcBhgEMgfKRHF4yvDFAwIkS209pl6ttJJDdNW9r4jOo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=javcUsUjfSM9QLEgYnXkro1awMgUBGPlKWbVIIqBUQSV6V8d4v4Hu/naUcpGp4Qvmx47v1A8K9e6wflqdBaEcOXsh0fbnfDD4qNlT4Bjag5M+OG3w1Xr/Qcw/p7wugtxUqelT9a6juieGELIGNNlLw6uAROOPQMc6Lx+r3WAsPk= Received: by 10.143.16.9 with SMTP id t9mr2664845wfi.1195835347134; Fri, 23 Nov 2007 08:29:07 -0800 (PST) Received: by 10.142.232.20 with HTTP; Fri, 23 Nov 2007 08:29:07 -0800 (PST) Message-ID: Date: Fri, 23 Nov 2007 10:29:07 -0600 From: "Jeff Larsen" To: "Dean Rasheed" Subject: Re: Performance problem with UNION ALL view and domains Cc: pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/280 X-Sequence-Number: 27695 On Nov 23, 2007 7:29 AM, Dean Rasheed wrote: > I am having a performance problem trying to query a view which is a > UNION ALL of 2 tables. I have narrowed the problem down to my use of > DOMAINS in the underlying table. So in the test-case below, when the > column "a" is of domain type foo_text, the query runs slowly using > the following plan: I don't know much about DOMAINS, but I did learn somethings about views, unions and where conditions when I posted a similar performance question. The best answer was, of course, from Tom Lane here: http://archives.postgresql.org/pgsql-performance/2007-11/msg00041.php In my case, the data types in each segment of the union were not originally identical, preventing the planner from efficiently pushing the qualifications down to the individual segments prior to the union. In your case the use of a DOMAIN type may be one of those 'special cases' forcing the planner to perform the union first, then apply the conditions. Jeff