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 8FE419DC898 for ; Wed, 14 Dec 2005 16:57:58 -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 90555-10 for ; Wed, 14 Dec 2005 16:57:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from linux.dunaweb.hu (linux.dunaweb.hu [62.77.196.1]) by postgresql.org (Postfix) with ESMTP id 0D54C9DC87E for ; Wed, 14 Dec 2005 16:57:55 -0400 (AST) Received: from localhost (linux.dunaweb.hu [127.0.0.1]) by linux.dunaweb.hu (Postfix) with ESMTP id 4569A8E0722 for ; Wed, 14 Dec 2005 21:57:53 +0100 (CET) Received: from linux.dunaweb.hu ([127.0.0.1]) by localhost (linux.dunaweb.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 05795-10 for ; Wed, 14 Dec 2005 21:57:51 +0100 (CET) Received: from szolnok.dunaweb.hu (unknown [192.168.3.154]) by linux.dunaweb.hu (Postfix) with ESMTP id E6F3B8E06F9 for ; Wed, 14 Dec 2005 21:57:51 +0100 (CET) Received: from [81.17.177.202] (unknown [81.17.177.202]) by szolnok.dunaweb.hu (Postfix) with ESMTP id 41C3F8913CC for ; Wed, 14 Dec 2005 21:57:56 +0100 (CET) Message-ID: <43A08EF5.4060306@dunaweb.hu> Date: Wed, 14 Dec 2005 22:30:29 +0100 From: Zoltan Boszormenyi User-Agent: Mozilla Thunderbird 1.0.7-1.1.fc3 (X11/20050929) X-Accept-Language: hu-hu, hu, en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Auto-tuning a VIEW? Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: amavisd-new at dunaweb.hu 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: 200512/332 X-Sequence-Number: 16153 Hi, we have a VIEW that is an UNION of 12 SELECTs, and every member of the UNION have a constant field to be able to distinguish between them. An often performed operation on this VIEW is to search for only one record that can be found by the value of the constant field and the serial of a table in one of the UNION members. Unfortunately, the search operation works in such a way so these two fields are concatenated and the results is searched for. Here is a shorter example, so it gets obvious what I tried to describe: create view v1 (code,num) as select 'AAA',id from table1 union select 'BBB',id from table2; The query is: select * from v1 where code||num = 'AAA2005000001'; My problem is that this is slow, even after creating expression indexes on the tables for e.g. ('AAA'||id). If I optimize the UNION manually, it becomes: select * from table1 where 'AAA'||id = 'AAA2005000001' union select * from table2 where 'BBB'||id = 'AAA2005000001'; and because of the expression indexes it's fast. Is there a GEQO setting that make the above optimization on VIEWs automatic? From the VIEW definition, the database already knows the connection between the fields of the view and the fields of the table(s) so the above optimization could be performed automatically. Best regards, Zoltán Böszörményi