X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 50478475E9D for ; Thu, 24 Apr 2003 11:57:02 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 79FB0474E42 for ; Thu, 24 Apr 2003 11:57:01 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h3OFuuU6014132; Thu, 24 Apr 2003 11:56:56 -0400 (EDT) To: Frederic Jolliton Cc: pgsql-performance@postgresql.org Subject: Re: Important speed difference between a query and a In-reply-to: <86el3rsxqu.fsf@mau.localdomain> References: <8665p56qx8.fsf@mau.localdomain> <86el3rsxqu.fsf@mau.localdomain> Comments: In-reply-to Frederic Jolliton message dated "Thu, 24 Apr 2003 17:47:53 +0200" Date: Thu, 24 Apr 2003 11:56:56 -0400 Message-ID: <14131.1051199816@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-32.5 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/197 X-Sequence-Number: 1703 Frederic Jolliton writes: >> To "emulate" a parametred view, I created a function as follow: >> >> CREATE FUNCTION get_info (integer) RETURNS SETOF type_get_info >> AS '...' <- here the query show below, where 'LIMIT $1' is used instead of 'LIMIT 10' >> LANGUAGE sql; > So, the query in the function is not using index but the exact same > query alone does ! But it's not the same query, is it? With "LIMIT $1" the planner can't know what the limit value is exactly, so it has to generate a plan that won't be too unreasonable for either a small or a large limit. regards, tom lane