X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 301829FA4D8 for ; Mon, 5 Jun 2006 23:43:16 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 35883-02 for ; Mon, 5 Jun 2006 23:43:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id A7DCF9F9316 for ; Mon, 5 Jun 2006 23:43:07 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k562h2KI009626; Mon, 5 Jun 2006 22:43:02 -0400 (EDT) To: Dan Libby cc: pgsql-performance@postgresql.org Subject: Re: Problem: query becomes slow when calling a fast user defined function. In-reply-to: <200606051804.00381.dan@libby.com> References: <200606051804.00381.dan@libby.com> Comments: In-reply-to Dan Libby message dated "Mon, 05 Jun 2006 18:03:59 -0600" Date: Mon, 05 Jun 2006 22:43:02 -0400 Message-ID: <9625.1149561782@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/49 X-Sequence-Number: 19406 Dan Libby writes: > Or failing that, I'd at least like to understand why the planner > is deciding not to use the category_lang index when the result > set is coming from a function instead of a "regular" table. The planner defaults to assuming that set-returning functions return 1000 rows (as you can see in the EXPLAIN output). A plan that would win for a single returned row would lose badly at 1000 rows ... and vice versa. See the archives for various debates about how to get a better estimate; it's not an easy problem. regards, tom lane