Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Pragma UDF works?

Recently, I have read about UDF Pragma optimization method in Oracle Database 12.

I'm very interested in how exactly it works. I've only found very short description in the Oracle documentation.

As I understand, every Pragma in PL/SQL is some kind of compiler directive (I could be wrong here) similar to C++ Pragma Directives.

Maybe someone can explain to me in more details (or provide links :) ) how the internal mechanism of UDF Pragma works?

like image 805
Oiale Avatar asked Jan 14 '19 21:01

Oiale


People also ask

What is Pragma UDF?

The UDF pragma tells the compiler that the PL/SQL unit is a user defined function that is used primarily in SQL statements, which might improve its performance.

What is Pragma in Oracle with example?

A pragma is a compiler directive that allows you to provide additional information to the compiler. This information can change compilation details that are not otherwise under your control. For example, the pack pragma affects the layout of data within a structure. Compiler pragmas are also called directives.

What is Oracle UDF?

The return value of the user-defined function is used to replace the original values. The user-defined function is a PL/SQL function that can be invoked in a SELECT statement. Inputs. Package Name: The name of the database package. Function Name: The name of the database function.


1 Answers

The internals are not made available to us, but essentially the pragma is an instruction to the compiler to focus on reducing the cost of the PL/SQL => SQL context switch overhead. If I had to hypothesise I would say that it takes advantage of a different 12c feature which allow PL/SQL directly within a CTE (common table expression), e.g.:

WITH 
  function myfunction(x int) return int as
  begin
    ...
    return ...
  end;
select myfunction(col) from my_table

PL/SQL functions coded like the above exist solely for the duration of the SQL execution and also execute with improved performance characteristics over that of standalone functions. So I suspect the UDF pragma allows invocation of a standalone function via the same code path as the inline example above.

(But all just hypothesis on my part)

like image 139
Connor McDonald Avatar answered Oct 23 '22 23:10

Connor McDonald