pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: pgsql-hackers@lists.postgresql.org
Subject: Incorrect assertion in ExecBuildAggTrans ?
Date: Mon, 21 Dec 2020 12:02:16 +0000
Message-ID: <87mty7peb3.fsf@news-spur.riddles.org.uk> (raw)

ExecBuildAggTrans has this sequence:

                if (pertrans->deserialfn.fn_strict)
                    scratch.opcode = EEOP_AGG_STRICT_DESERIALIZE;
                else
                    scratch.opcode = EEOP_AGG_DESERIALIZE;

                scratch.d.agg_deserialize.fcinfo_data = ds_fcinfo;
                scratch.d.agg_deserialize.jumpnull = -1;    /* adjust later */
                scratch.resvalue = &trans_fcinfo->args[argno + 1].value;
                scratch.resnull = &trans_fcinfo->args[argno + 1].isnull;

                ExprEvalPushStep(state, &scratch);
                adjust_bailout = lappend_int(adjust_bailout,
                                             state->steps_len - 1);

but later on, where adjust_bailout is processed, we see this (note that
EEOP_AGG_DESERIALIZE is not checked for):

            if (as->opcode == EEOP_JUMP_IF_NOT_TRUE)
            {
                Assert(as->d.jump.jumpdone == -1);
                as->d.jump.jumpdone = state->steps_len;
            }
            else if (as->opcode == EEOP_AGG_STRICT_INPUT_CHECK_ARGS ||
                     as->opcode == EEOP_AGG_STRICT_INPUT_CHECK_NULLS)
            {
                Assert(as->d.agg_strict_input_check.jumpnull == -1);
                as->d.agg_strict_input_check.jumpnull = state->steps_len;
            }
            else if (as->opcode == EEOP_AGG_STRICT_DESERIALIZE)
            {
                Assert(as->d.agg_deserialize.jumpnull == -1);
                as->d.agg_deserialize.jumpnull = state->steps_len;
            }
            else
                Assert(false);

Seems clear to me that the assertion is wrong, and that even though a
non-strict DESERIALIZE opcode might not need jumpnull filled in, the
code added it to adjust_bailout anyway, so we crash out here on an
asserts build. This may have been overlooked because all the builtin
deserialize functions appear to be strict, but postgis has at least one
non-strict one and can hit this.

This could be fixed either by fixing the assert, or by not adding
non-strict deserialize opcodes to adjust_bailout; anyone have any
preferences?

-- 
Andrew (irc:RhodiumToad)





Message-ID: <87mty7peb3.fsf@news-spur.riddles.org.uk>
Permalink:  ../87mty7peb3.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/87mty7peb3.fsf@news-spur.riddles.org.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: andrew@tao11.riddles.org.uk
  Subject: Re: Incorrect assertion in ExecBuildAggTrans ?
  In-Reply-To: <87mty7peb3.fsf@news-spur.riddles.org.uk>
  References: <87mty7peb3.fsf@news-spur.riddles.org.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox