Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 753F5476142 for ; Thu, 12 Sep 2002 11:53:35 -0400 (EDT) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id 13C1C476067 for ; Thu, 12 Sep 2002 11:53:35 -0400 (EDT) Received: by news.hub.org (Postfix, from userid 8) id 865FA38257E; Thu, 12 Sep 2002 11:53:33 -0400 (EDT) From: "Gaetano Mendola" X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Performance inside and outside view ( WAS Re: Select the max on a field ) Date: Thu, 12 Sep 2002 17:53:38 +0200 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 36 Message-ID: References: <7350.1031842223@sss.pgh.pa.us> X-Complaints-To: news@hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 To: pgsql-sql@postgresql.org X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/106 X-Sequence-Number: 9383 "Tom Lane" wrote in message news:7350.1031842223@sss.pgh.pa.us... > "Gaetano Mendola" writes: > > Yes that's right it's help me, > > but here the optimizer have some problems: > > What's the datatype of id_user, and why are you quoting the compared > constant in some cases but not others? I don't think the difference > has anything to do with the view here ... id_user is an INTEGER type. Well what about this two selects: a) SELECT DISTINCT ON (id_user) * FROM user_logs WHERE id_user = 5430 ORDER BY id_user, id_user_log DESC; b) CREATE VIEW last_user_logs AS SELECT DISTINCT ON (id_user) * FROM user_logs ORDER BY id_user, id_user_log DESC; SELECT * FROM last_user_logs WHERE id_user = 5430 I think that in the second case the filter is not pushed inside the view. Ciao Gaetano