Proposed fix for bug #14826 (the invalid empty array business)

Started by Tom Laneover 8 years ago1 messageshackers
Jump to latest
#1Tom Lane
tgl@sss.pgh.pa.us

I poked around among the callers of construct_[md_]array() and found at
least two more besides ts_lexize() that could build zero-element arrays;
one of very ancient standing is in the pg_prepared_statements view.

So I think we've got a clear hazard here that justifies changing the
behavior of the low-level array functions, rather than expecting every
call site to be on its guard about empty arrays. Accordingly, I propose
the attached patch which makes construct_md_array responsible for getting
this right.

In principle we could now remove code from the places that do take care to
call construct_empty_array instead. But I found only one place where it
really seemed worth removing anything, in ExecEvalArrayExpr.

I'm a little bit scared about back-patching this, as it seems at least
possible that some external code could be broken by the change in what
construct_[md_]array could hand back. Given that some of these bugs
have been in place for ~ten years and nobody noticed till now, seems
like it might be good enough to fix them in HEAD only.

Comments?

regards, tom lane

Attachments:

handle-empty-arrays-correctly-always.patchtext/x-diff; charset=us-ascii; name=handle-empty-arrays-correctly-always.patchDownload+6-12