]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix estimate_array_length error with set-operation array coercions
authorRichard Guo <rguo@postgresql.org>
Sat, 11 Apr 2026 07:38:47 +0000 (16:38 +0900)
committerRichard Guo <rguo@postgresql.org>
Sat, 11 Apr 2026 07:41:58 +0000 (16:41 +0900)
commit93ed18720105ebacfd2a2bdeb55bf33feaf2ec80
tree41d60c132684b8bcfd19d37fe3cc60336ed5371a
parentc05c3baf169f353914ed34fcabd057be1d25f9b4
Fix estimate_array_length error with set-operation array coercions

When a nested set operation's output type doesn't match the parent's
expected type, recurse_set_operations builds a projection target list
using generate_setop_tlist with varno 0.  If the required type
coercion involves an ArrayCoerceExpr, estimate_array_length could be
called on such a Var, and would pass it to examine_variable, which
errors in find_base_rel because varno 0 has no valid relation entry.

Fix by skipping the statistics lookup for Vars with varno 0.

Bug introduced by commit 9391f7152.  Back-patch to v17, where
estimate_array_length was taught to use statistics.

Reported-by: Justin Pryzby <pryzby@telsasoft.com>
Author: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/adjW8rfPDkplC7lF@pryzbyj2023
Backpatch-through: 17
src/backend/utils/adt/selfuncs.c
src/test/regress/expected/union.out
src/test/regress/sql/union.sql