Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1chHAl-0002co-Ae for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Feb 2017 14:48:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1chHAk-0001Hm-SI for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Feb 2017 14:48:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1chHAj-0001H8-Cm for pgsql-hackers@postgresql.org; Fri, 24 Feb 2017 14:48:37 +0000 Received: from mail-qt0-x22e.google.com ([2607:f8b0:400d:c0d::22e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1chHAf-0006UB-Mj for pgsql-hackers@postgresql.org; Fri, 24 Feb 2017 14:48:36 +0000 Received: by mail-qt0-x22e.google.com with SMTP id r45so18153497qte.3 for ; Fri, 24 Feb 2017 06:48:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=BF/wNNIhCM1e0DXr3FDJBV4dnSkVI9ETAX8yR/kkrlk=; b=J1UK9LY3yNNjQLekuxC/6LtZOhAVDCyhlKjUNGaZnrq3FbaCJrRpdRA0cpwAbNqhSb uA52lt2SF0+TFeS5rB7nilJMqncgXuyIwGXl1seOsi/Uhh1NizPNajI9K0gihKP4WnLq YQoA6fPy/5iiLZNZrgCG1AAEsin12pEPG0X2vi/5gMYf4ZIklpMeO8/H8x8jh6kpE8ew EKzU83+HQRTCJcBLz0KzYrgwU6sZ8RRJXNL0zRdnLmG6mhQMyaE4oNB5V+/etloK8ckv l4kL8kxvLQoUnQR0bym9YVPRCshynhxjKjR/e0qYIe7aM0/htReDmoCARX38Sk8X0615 mAaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=BF/wNNIhCM1e0DXr3FDJBV4dnSkVI9ETAX8yR/kkrlk=; b=RLU891XeFq3AqEELE+7B4GODOnQoGXdX/ddjOj6q7r/lpToP9Cxrt7QHCVdJv4AwnI WsZlLkZov913pKt4ACt2Ih+tM3UAxAU4o/RLaMLBk/ZjFQsYhs21aBb0ZAQX+ZLeRmA+ SyPn4wHMEEnsd7Sr9kN7CXw+7+LV2UNm46wCji64Wmhsn0w5ms+RQ1oZB3AjjxtmZqN3 gfXvkEUN5WtlkXW6QRJTRMuvE/klDYSButMfJqoBzwA1grRF6p7uLzOCUdv1GMDswzwH sm4qt0hw2h2L5SgcdR+muvK08VHN5DXI87JGKHmzt0nua4KnM4a4+Jqy6wGg6oymQpNz XzLg== X-Gm-Message-State: AMke39nZVVp3RQGbr9/dbSQJO1g6YbTb1PLBMkNqxaB79DP649IcB5mF1q21mJdXbKOSUf1e0i9w8em7sSG4aTPcXatFYleZTSp04IHEw7sAzi4VdOVo+WwhQtgQ8y6FWSFq+QSZbr1Ww4yb1bg6mWFHrZ6G8eGkQnIOsJgItUsT72FXE0QaSa7t3eUWl4Dp/E+vXuiur3HHUCM= X-Received: by 10.200.38.117 with SMTP id v50mr2808545qtv.230.1487947711526; Fri, 24 Feb 2017 06:48:31 -0800 (PST) Received: from [192.168.10.146] ([98.122.164.227]) by smtp.gmail.com with ESMTPSA id r33sm4615036qta.19.2017.02.24.06.48.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Feb 2017 06:48:31 -0800 (PST) From: Andrew Dunstan X-Google-Original-From: Andrew Dunstan Subject: Re: btree_gin and btree_gist for enums To: Tom Lane References: <56EA8A71.8060107@dunslane.net> <56EACB8C.1040406@dunslane.net> <03f7d748-0f89-e8e1-094d-f04e1026b93d@dunslane.net> <27220.1478360811@sss.pgh.pa.us> <31412.1478366009@sss.pgh.pa.us> <60fb708c-8b3c-1337-934e-c1bfe2afc539@dunslane.net> <8258.1487886101@sss.pgh.pa.us> Cc: PostgreSQL-development Message-ID: <4376a7bf-ab8c-e640-9021-94b148f9d733@2ndQuadrant.com> Date: Fri, 24 Feb 2017 09:48:30 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <8258.1487886101@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 02/23/2017 04:41 PM, Tom Lane wrote: > Andrew Dunstan writes: >> I'm not entirely sure how I should replace those DirectFunctionCall2 calls. > Basically what we want is for the called function to be able to use the > fcinfo->flinfo->fn_extra and fcinfo->flinfo->fn_mcxt fields of the > FmgrInfo struct that GIN has set up for the btree_gin support function. > > The fast but somewhat scary way to do it would just be to pass through > the flinfo pointer as-is. Imagine that fmgr.c grows a set of functions > like > > Datum > DontKnowWhatToCallThisFunctionCall2(PGFunction func, > FmgrInfo *flinfo, Oid collation, > Datum arg1, Datum arg2) > { > FunctionCallInfoData fcinfo; > Datum result; > > InitFunctionCallInfoData(fcinfo, flinfo, 2, collation, NULL, NULL); > > fcinfo.arg[0] = arg1; > fcinfo.arg[1] = arg2; > fcinfo.argnull[0] = false; > fcinfo.argnull[1] = false; > > result = (*func) (&fcinfo); > > /* Check for null result, since caller is clearly not expecting one */ > if (fcinfo.isnull) > elog(ERROR, "function %p returned NULL", (void *) func); > > return result; > } > > and then you'd just pass through the fcinfo->flinfo you got. > > The reason this is kind of scary is that it's just blithely assuming > that the function won't look at the *other* fields of the FmgrInfo. > If it did, it would likely get very confused, since those fields > would be describing the GIN support function, not the function we're > calling. > > We could alternatively have this trampoline function set up a fresh, local > FmgrInfo struct that it zeroes except for copying fn_extra and fn_mcxt > from the caller's struct, and then it copies fn_extra back again on the > way out. That's a few more cycles but it would be safer, I think; if the > function tried to look at the other fields such as fn_oid it would see > obviously bogus data. > > Do we want one or both of these? I'm prepared to code up a patch to fmgr.[ch] to provide them. I don't know what to call it either. In my test I used CallerContextFunctionCall2 - not sure if that's quite right, but should be close. The technique is somewhat similar to what we do in plperl.c where we fake up a function call for handling DO blocks. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers