Re: jsonb subscript operator returns null when key is fetched from table - Mailing list pgsql-bugs

From Tom Lane
Subject Re: jsonb subscript operator returns null when key is fetched from table
Date
Msg-id 2035559.1670872161@sss.pgh.pa.us
Whole thread Raw
In response to Re: jsonb subscript operator returns null when key is fetched from table  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-bugs
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> Someone more experienced than I will need to actually do the debugging work
> though; hoping this reply will be seen by one of them.

Meh.  Somebody was cavalier about detoasting the subscript:

            jbvp = getKeyJsonValueFromContainer(container,
                                                VARDATA(path[i]),
                                                VARSIZE(path[i]) - VARHDRSZ,
                                                NULL);

Neither VARDATA nor VARSIZE are valid to apply to an arbitrary datum.
Apparently, nobody has ever tested this with a subscript value fetched
straight from disk :-(.  The given example accidentally works with
a NOT MATERIALIZED CTE because the whole thing gets stepwise folded
to constants.  Likewise, the expression with || accidentally works
because concatenation always yields a non-toasted result.

            regards, tom lane



pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: jsonb subscript operator returns null when key is fetched from table
Next
From: David Rowley
Date:
Subject: Re: BUG #17710: Slow queries (100% CPU) after auto-vacuum