Skip to content

Conversation

tarasom
Copy link
Contributor

@tarasom tarasom commented Sep 25, 2025

This PR resolves a bug in FunctionEvaluator.php related to how aggregate functions (specifically SUM()) are evaluated when the query returns an empty set. The issue stemmed from a previous change intended to handle scalar queries (e.g., SELECT 1+1) that inadvertently caused incorrect evaluation for table-based queries that return no rows.

Changes

  • Problem: The if ($expr instanceof FunctionExpression) condition was too permissive. It was triggered when a query (e.g., SELECT SUM(IF( id > 1, 0, 1 )) FROM video_game_characters WHERE id > 100;) returned an empty result set, causing the code to incorrectly proceed with function evaluation as if it were a scalar query. This led to a bug.
  • Solution: I introduced the $isQueryWithoutFromClause variable to precisely identify queries without a FROM clause. This check is based on whether the result object has columns. The evaluate method is now called only for these true scalar queries, ensuring that SUM() on an empty result from a table-based query correctly returns NULL.

Impact

This fix ensures that the system adheres to standard SQL behavior for aggregate functions on empty sets and resolves the associated bug without affecting the correct evaluation of true scalar queries.

@aaronm67 aaronm67 merged commit ba50273 into vimeo:master Sep 25, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants