From 5495257559bc1eaa0e87ea88247b16a7bc6f7853 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Thu, 22 Oct 2026 22:25:43 -0400 Subject: [PATCH] Pass NULL root when costing in find_simplified_clause(). It runs during eval_const_expressions, which get_relation_info and apply_child_basequals call before the rel is in simple_rel_array, so estimate_array_length could fail in find_base_rel. Discussion: https://postgr.es/m/2828180.1792700071@sss.pgh.pa.us --- src/backend/utils/adt/rangetypes.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/adt/rangetypes.c b/src/backend/utils/adt/rangetypes.c index 84d71761c1b..2a3e579b974 100644 --- a/src/backend/utils/adt/rangetypes.c +++ b/src/backend/utils/adt/rangetypes.c @@ -3073,11 +3073,12 @@ find_simplified_clause(PlannerInfo *root, Expr *rangeExpr, Expr *elemExpr) * We define "expensive" as "contains any subplan or more than 10 * operators". Note that the subplan search has to be done * explicitly, since cost_qual_eval() will barf on unplanned - * subselects. + * subselects. Pass a NULL root, since we can be called before + * the RelOptInfos of the referenced rels exist. */ if (contain_subplans((Node *) elemExpr)) return NULL; - cost_qual_eval_node(&eval_cost, (Node *) elemExpr, root); + cost_qual_eval_node(&eval_cost, (Node *) elemExpr, NULL); if (eval_cost.startup + eval_cost.per_tuple > 10 * cpu_operator_cost) return NULL; -- 2.37.1 (Apple Git-137.1)