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_li st>". 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 2 5135
"Eugene" <eu****@profitl ogic.com> wrote in message
news:95******** *************** ***@posting.goo gle.com... 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_li st>". 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?
You didn't state which version of DB2 you are using or what platform you are
running.
Assuming you are talking about DB2 V8.1 on Windows/Unix/Linux, the answer
can be found in the SQL Reference, Part 2: ftp://ftp.software.ibm.com/ps/produc...r/db2s2e80.pdf.
If you look at the article about CREATE FUNCTION (SQL Scalar, Table or Row),
you'll see that your UDF may contain a "dynamic-compound-statement". If you
follow the link for that at the end of the article to page 123 of the
manual, you'll see that the only version of the SET statement supported by
UDFs is "SET variable statement". "SET CURRENT QUERY OPTIMIZATION" is
different from "SET variable". This is consistent with the error message you
are getting, which appears to be detecting the fact that your SET statement
doesn't match the syntax of the "SET variable" statement.
I'm not sure what to suggest as an alternative.
Rhino
Eugene wrote: 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_li st>". 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?
First, because as Rhino stated, the SET CURRENT QUERY OPTIMIZATION is not
supported inside the body of a UDF.
To understand that, it helps to know how UDFs are processed by DB2 LUW. If
you have a SQL statement that calls the UDF, the UDF is compiled into the
statement as is. Essentially, the UDF body is pasted into the SQL
statement and then the DB2 optimizer kicks in and optimizes the complete
SQL statement, including the body of the UDF.
Note that the same happens for triggers. They are compiled into the
statement and then the complete statement is optimized.
--
Knut Stolze
Information Integration
IBM Germany / University of Jena This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ensnare |
last post by:
This query is running REAL slow ... like 1.2 secs ... any ideas on how
I could optimize it? Perhaps my indexes are incorrect?
$this->query = "SELECT m.username as username,
e.title as title,
e.exhibition_id as
exhibition_id,
LEFT(e.text,50) as
text,
e.random_key,
|
by: AC Slater |
last post by:
Whats the simplest way to change a single stored procedures query
optimization level?
In UDB8 that is.
/F
|
by: Sean C. |
last post by:
Helpful folks,
I have recently migrated our test server, which runs Win NT 4, from
V7.2 FP11 to V8.1.3. Just about everything works wondefully, except I
am having major problems getting the previously defined federated
servers/nicknames to work. But I will start a different thread about
that problem. I thought I'd ask about the less critical problem first.
It deals with the Control Center and the following error:
SQL0713N The...
|
by: WantedToBeDBA |
last post by:
Hi all,
db2 => create table emp(empno int not null primary key, \
db2 (cont.) => sex char(1) not null constraint s_check check \
db2 (cont.) => (sex in ('m','f')) \
db2 (cont.) => not enforced \
db2 (cont.) => enable query optimization)
DB20000I The SQL command completed successfully.
db2 => insert into emp values(1,'m')
|
by: 73blazer |
last post by:
We are migrating a customer from Version 7.1 FP3, to Version 8.2 (8.1 FP8).
For the most part, things are faster, but there is one query that is
much much slower, and it is a query that is used all the time.
select ATTR1,ATTR2,ATTR3,ATTR4 from physical.part_list
where S_PART_NUMBER like '%KJS%'
The widlcard before and after seems to be hosing it, but for this
particular piece of the application, this type of query is neccessary.
| |
by: UnixSlaxer |
last post by:
Hello,
Running a query for the first time on DB2 takes a fixed amount of time.
But when query is executed for the second time, the amount of time is
usually less since the query is (most probably) cached already.
I would like to clear out the DB2-UDB 8.2 query cache (I want the
previous execution time again).
Any advice would be appreciated.
|
by: Bernard Dhooghe |
last post by:
To retrieve data from a query where multiple rows can be returned, a
cursor can be used.
Different programming interface exist for cursors: embedded SQL, CLI,
SQL PL, SQLJ, JDBC.
I we look at the CLI interface, as a statement is first prepared in CLI
before a cursor is associated with it, the cursor attributes are not
known at prepare time. Does it mean that the query path for retrieving
rows is not dependent of the cursor attributes...
|
by: ADezii |
last post by:
One frequently asked question at TheScripts is "Should I use a Stored Query or an SQL Statement in those situations that require a Query (RecordSets, RecordSources, Append, Delete, Update Operations, etc.)?" The response, in virtually all but a few circumstances, is that you should use a Stored Query in place of the parallel SQL Statement. The brief explanation that follows will explain the reasoning behind this:
When you store a Query as a...
|
by: Don Li |
last post by:
Hi,
Env: MS SQL Server 2000
DB Info (sorry no DDL nor sample data):
tblA has 147249 rows -- clustered index on pk (one key of
datatype(int)) and
has two clumns, both are being used in joins;
intersecTbl4AB has 207016 rows -- clustered index on two fks and
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |