diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 65ae682e298..c82bacd7c15 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -6554,6 +6554,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.