Re: SPI/backend equivalent of extended-query Describe(statement)?

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Chapman Flack <chap(at)anastigmatix(dot)net>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: SPI/backend equivalent of extended-query Describe(statement)?
Date: 2018-05-26 19:22:43
Message-ID: 87zi0mz305.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>>>> "Chapman" == Chapman Flack <chap(at)anastigmatix(dot)net> writes:

>> Really our hook mechanism only supports adding hooks, not removing
>> them.

Chapman> I suppose the pllua_spi_prepare_checkparam_hook could be
Chapman> linked in once and for all, and turned on and off just where
Chapman> the code now hooks and unhooks it, and just forward to the
Chapman> next hook when it's off.

Yeah, or have it detect whether the ParseState it's being called for is
ours by some other means.

>> I'm not following why that's such a problem? The whole point of
>> SPI_prepare_params and friends is that the actual number and types
>> of the parameters is hidden behind the parse hooks and ParamListInfo
>> --- and, indeed, could change from one execution to the next.

So while looking at the hook issue, I found another can of worms.

What a protocol-level Parse does is to call parse-analysis via
parse_analyze_varparams, which calls parse_variable_parameters _without_
making it a parser setup hook (either there or in CompleteCachedPlan).

This has the effect of casting the parameter types in stone on the first
parse, as the client expects; a subsequent revalidate of the statement
will use pg_analyze_and_rewrite, which takes a fixed parameter list.

However if you call parse_variable_parameters from a hook passed to
SPI_prepare_params, then you're asking for it to be called again on
revalidations, which means that the parameters might change (even if
just changing types, I think you'd need a more complex set of hooks than
parse_variable_parameters uses to change the number of parameters too).

So what I'm thinking now is that the way to go, if one wants to imitate
the client-side protocol behavior closely, would be to have a setup hook
that calls parse_variable_parameters the first time, and then
parse_fixed_parameters on subsequent calls for revalidation.

--
Andrew (irc:RhodiumToad)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chapman Flack 2018-05-26 20:33:31 Re: SPI/backend equivalent of extended-query Describe(statement)?
Previous Message Tom Lane 2018-05-26 16:54:45 Re: Adding a new table to the system catalog