MySQL Forums
Forum List  »  General

Sargable Custom Functions in Queries
Posted by: David Allen
Date: December 02, 2021 05:01PM

Is there any way to enforce a custom function to be Sargable with a query? I've run multiple tests, and even with a simple function that returns a static number, it seems to take 2x as long as hardcoding the number of putting it in a Variable.

For example, doing a query that has a qualifier like:

WHERE table.column = 4

Is of course the fastest with indexing.

WHERE table.column = variable (which =4)

Is the same speed.

BUT WHERE table.column = DETERMINISTIC FUNCTION RESULT (4)

Takes 2x+ longer.

This seems ridiculous to me as functions are a critical part of complex SQL queries.

Is there any way to have MySQL treat a function call as a sargable application against a query?

Options: ReplyQuote


Subject
Written By
Posted
Sargable Custom Functions in Queries
December 02, 2021 05:01PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.