diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index f701954..d9f4776 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -1473,6 +1473,15 @@ query_is_distinct_for(Query *query, List *colnos, List *opids) Assert(list_length(colnos) == list_length(opids)); /* + * The presence of set returning functions in the query's target list can + * cause multiple rows per group to exist, so we'll need to play it safe + * here and report that the query is not distinct when set returning + * functions exist. + */ + if (expression_returns_set((Node *) query->targetList)) + return false; + + /* * DISTINCT (including DISTINCT ON) guarantees uniqueness if all the * columns in the DISTINCT clause appear in colnos and operator semantics * match.