A database engine and optimizer framework includes a decoder to identify
and process SQL queries or statements that reference a UDF before they
are executed. Once such a statement is detected, the decoder determines
if the UDF is capable of being merged into an SQL statement and, if so,
performs such a merge. In some embodiments, the decoder may not use a
pre-cached version of the UDF but, instead, may include a component that
locates and retrieves the latest version of the UDF for use when
performing the merge. Also, for UDFs that cannot easily be merged into an
SQL statement, the decoder may not merge the UDF into an SQL statement
but may allow the optimizer and execution engine to retrieve and execute
the UDF in the usual manner.