X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 2CA0DD1C4BF; Sun, 3 Aug 2003 23:55:23 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 67008-02; Sun, 3 Aug 2003 20:54:11 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id C3918D1C9DE; Sun, 3 Aug 2003 20:55:11 -0300 (ADT) 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 h73NrvSa004314; Sun, 3 Aug 2003 19:53:57 -0400 (EDT) To: Joe Conway , Hans Spaans , pgsql-admin@postgresql.org, pgsql-hackers@postgresql.org Subject: Re: concat_ws In-reply-to: <2270.1059952382@sss.pgh.pa.us> References: <20030803131931.GD4326@sch01r01.nexit.nl> <26941.1059926135@sss.pgh.pa.us> <3F2D4B3B.3050405@joeconway.com> <2270.1059952382@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sun, 03 Aug 2003 19:13:02 -0400" Date: Sun, 03 Aug 2003 19:53:57 -0400 Message-ID: <4313.1059954837@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/51 X-Sequence-Number: 9774 I said: > There is some code in the function inliner to abandon inlining if an > input expression is "too expensive", but its notion of "too expensive" > is currently just "contains subselects". I'm going to see if it helps > to reject inlining when the input grows "too large", for some value of > "too large". Okay, after further study, I see that the real problem here is that when expanding nested concat_ws calls, the expansions of the lower-level calls would get substituted in more than one place in the outer functions. Specifically, since $2 occurs twice in the bottom-level function, you'd end up with an expanded tree of O(2^n) nodes for n levels of function call. I added code to inline_function to stop inlining if a parameter expression to be substituted multiple times has cost greater than 10*cpu_operator_cost (which roughly means that it contains more than 10 operators or functions). This seems to cut off the problem nicely, at least for this example. The factor of 10 is a bit of a magic number but it seems reasonable. regards, tom lane