Optimization of MAX function with limited parameter RRS feed

  • Question

  • I have the following query

    SELECT MAX(someF.number)
    FROM someTable AS someT
    	SELECT someFunction(someT.column1, someT.column2) AS number
    ) AS someF

    I know that the function 'someFunction' returns number 0-9. So, after MAX has found first 9 (if there is 9 value in 'someTable' table), the query running can be finished with result 9. But SQL Server does not know that 'someFunction' returns number 0-9 and hence processes all records from someTable.
    How can I tune the query to achieve desired result?
    Tuesday, August 27, 2019 11:59 AM