From 647d5315ad0976d6eca6df8c433cb4237c8898b0 Mon Sep 17 00:00:00 2001 From: Maxime Schoemans Date: Tue, 16 Sep 2025 18:19:58 +0200 Subject: [PATCH v1] Check that index can return in get_actual_variable_range() Follow-up to 9ef1851685b and ee1ae8b99f9. The min and/or max variables are retrieved from the index using the index-only-scan machinery, so first check that we can use it by looking at index->canreturn. --- src/backend/utils/adt/selfuncs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index a96b1b9c0bc..216c034825e 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -6514,6 +6514,13 @@ get_actual_variable_range(PlannerInfo *root, VariableStatData *vardata, if (index->hypothetical) continue; + /* + * get_actual_variable_endpoint uses the index-only-scan machinery, + * so ignore indexes that can't use it on their first column. + */ + if (!index->canreturn[0]) + continue; + /* * The first index column must match the desired variable, sortop, and * collation --- but we can use a descending-order index. -- 2.39.5 (Apple Git-154)