I am trying to set query optimization class in a simple SQL UDF like
this:
CREATE FUNCTION udftest ( in_item_id INT )
SPECIFIC udftest
MODIFIES SQL DATA
RETURNS TABLE( location_id INT, period_id INT )
BEGIN ATOMIC
SET CURRENT QUERY OPTIMIZATION 1;
RETURN
SELECT location_id, period_id FROM activities WHERE item_id =
in_item_id;
END
@
where 'activities' is a very complex view built on multiple objects
and I found that the optimization class changed from the default 5 to
1 improves performance considerably.
But the compilation fails with the error:
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "CURRENT QUERY OPTIMIZATION 1" was found
following "EGIN ATOMIC SET". Expected tokens may include:
"<set_clause_list>". LINE NUMBER=6. SQLSTATE=42601
It works fine without the SET CURRENT QUERY OPTIMIZATION 1 statement
though.
From the DB2 SQL reference it seems like SET special registers is
allowed in SQL routines as long as MODIFIES SQL DATA is specified.
Any idea why it does not compile?
Thanks,
-Eugene