Paul White points out a couple odd scenarios with the ANY
aggregate in SQL Server:
The execution plan erroneously computes separate
ANY
aggregates for thec2
andc3
columns, ignoring nulls. Each aggregate independently returns the first non-null value it encounters, giving a result where the values forc2
andc3
come from different source rows. This is not what the original SQL query specification requested.The same wrong result can be produced with or without the clustered index by adding an
OPTION (HASH GROUP)
hint to produce a plan with an Eager Hash Aggregate instead of a Stream Aggregate.
Click through for the scenarios. Paul has also reported the second scenario as a bug.