X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 11BA9D86FB for ; Fri, 4 Nov 2005 11:55:58 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45971-10 for ; Fri, 4 Nov 2005 15:55:53 +0000 (GMT) X-Greylist: delayed 04:17:25.078739 by SQLgrey- Received: from mx.mall.cz (mx.mall.cz [62.168.45.106]) by svr1.postgresql.org (Postfix) with ESMTP id 3B513D7115 for ; Fri, 4 Nov 2005 11:55:55 -0400 (AST) Received: from localhost (asterix [127.0.0.1]) by mx.mall.cz (Postfix) with ESMTP id 7C2D913FC03; Fri, 4 Nov 2005 16:55:58 +0100 (CET) Received: from mx.mall.cz ([127.0.0.1]) by localhost (asterix [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id 18148-02; Fri, 4 Nov 2005 16:55:57 +0100 (CET) Message-ID: <436B848F.5030402@mall.cz> Date: Fri, 04 Nov 2005 16:55:59 +0100 From: Michal Taborsky User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: cs, en-us, en MIME-Version: 1.0 To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: Searching union views not using indices References: <436B4836.7030300@mall.cz> <13815.1131118294@sss.pgh.pa.us> In-Reply-To: <13815.1131118294@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at mall.cz X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/81 X-Sequence-Number: 15338 Tom Lane napsal(a): > Michal Taborsky writes: > >>We are facing a performance problem with views consisting of several >>unioned tables. The simplified schema is as follows: > > > Perhaps you should show us the real schema, because I cannot duplicate > your complaint on the toy case you show. > As noted by others, you probably want to be using UNION ALL not UNION, > but that's not the crux of the issue. OK. Mystery (sort of) solved. After you told me it works for you I had to assume the problem was somewhere else. And, indeed, it was, though it's not too obvious. The two attributes are actually not of tybe bigint, but of type "crm_object_id", which is created as follows: CREATE DOMAIN "public"."crm_object_id" AS bigint NULL; Everything started working perfectly after I modified the view like this: CREATE VIEW commonview AS SELECT foo_object_id::bigint as object_id, link_id::bigint, 'It is in foo' as loc FROM foo UNION SELECT bar_object_id::bigint as object_id, link_id::bigint, 'It is in bar' as loc FROM bar Not even modifying the select as this did not help: explain SELECT object_id FROM commonview WHERE link_id=1234567::crm_object_id; Is this a bug or feature? -- Michal Táborský CTO, Internet Mall, a.s. Internet Mall - obchody, které si oblíbíte