Re: assert in nested SQL procedure call in current HEAD

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: Joe Conway <mail(at)joeconway(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: assert in nested SQL procedure call in current HEAD
Date: 2018-06-12 13:37:24
Message-ID: 7e2abcce-aa65-67fb-0d4f-78ded0e56dfe@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 6/10/18 15:06, Dmitry Dolgov wrote:
>> I added it to the open items list since nobody else seems to have taken
>> notice; from Tom's linked message it seems this should be Peter E's bag?
> I've taken a look at this - indeed, the situation looks similar to what
> described in the linked message, namely after a transaction rollback and
> creation of a new one no active snapshot was pushed. But in this particular
> case the timeframe without an active snapshot is actually limited and includes
> only some initialization and planning activity (after that a new one is
> pushed). The commentary says that "Planner must have a snapshot in case it
> calls user-defined functions." - I tried to simulate this in order to see what
> would happen, but got no errors. Is there a chance that it's an outdated
> Assert?

The problem with these nested procedure calls is that if the nested call
does a commit, you would get the dreaded "snapshot %p still active"
warning. So PL/pgSQL in combination with SPI is going out of its way to
make sure that there is no active snapshot when we call out to
ProcessUtility() for the nested CALL. However, if whatever the nested
CALL executes requires an active snapshot to be set, then there is this
problem. Apparently, the LANGUAGE SQL procedure requires a snapshot to
be set previously. This is not a problem, for example, if you replace
the example procedure with LANGUAGE plpgsql, which does its own snapshot
management. So perhaps a fix here is to teach the LANGUAGE SQL handler
to set a snapshot if there isn't one already. That would make the
different language handlers behave consistently. (The alternative is to
get rid of the warning in snapmgr.c.)

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2018-06-12 13:49:09 Re: cursors with prepared statements
Previous Message Ashutosh Bapat 2018-06-12 13:34:14 Re: why partition pruning doesn't work?