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 398F4D97D6 for ; Fri, 4 Nov 2005 10:45:17 -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 00574-08 for ; Fri, 4 Nov 2005 14:45:10 +0000 (GMT) X-Greylist: delayed 03:06:39.978367 by SQLgrey- Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25]) by svr1.postgresql.org (Postfix) with ESMTP id 100B9D9437 for ; Fri, 4 Nov 2005 10:45:11 -0400 (AST) Received: from mx.mall.cz (mx.mall.cz [62.168.45.106]) by svr2.postgresql.org (Postfix) with ESMTP id CC5D3F0F89 for ; Fri, 4 Nov 2005 11:38:34 +0000 (GMT) Received: from localhost (asterix [127.0.0.1]) by mx.mall.cz (Postfix) with ESMTP id 0B5B113FC02 for ; Fri, 4 Nov 2005 12:38:30 +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 06153-02 for ; Fri, 4 Nov 2005 12:38:29 +0100 (CET) Message-ID: <436B4836.7030300@mall.cz> Date: Fri, 04 Nov 2005 12:38:30 +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: pgsql-performance@postgresql.org Subject: Searching union views not using indices 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/70 X-Sequence-Number: 15327 Hello everyone. We are facing a performance problem with views consisting of several unioned tables. The simplified schema is as follows: CREATE TABLE foo ( foo_object_id bigint, link_id bigint, somedata text, PRIMARY KEY (foo_object_id) ); CREATE TABLE bar ( bar_object_id bigint, link_id bigint, otherdata real, PRIMARY KEY (bar_object_id) ); There are actually five of such tables, all having two common attributes *_object_id and link_id. All tables have indices on link_id, which is very selective, close to unique. The *_object_id is unique within this scope across all tables, but that's not important. Then we have a view: CREATE VIEW commonview AS SELECT foo_object_id as object_id, link_id, 'It is in foo' as loc FROM foo UNION SELECT bar_object_id as object_id, link_id, 'It is in bar' as loc FROM bar We commonly do this: SELECT object_id FROM commonview WHERE link_id=1234567 The result is sequential scan on all tables, append, sort and then filter scan on this whole thing. Which of course is slow as hell. We use version 8.0.2. And now the question: Is there a way to force the planner to push the condition lower, so it will use the index? Or do you use some tricks in this scenario? Thanks for your suggestions. Bye. -- Michal Táborský CTO, Internet Mall, a.s. Internet Mall - obchody, které si oblíbíte