Hi,
This is a real hopeful one!
What we are trying to do:
1. We MUST present a mappable database object for our application
objects i.e a Table or a View
Some of the views are very complex, which raises another couple of
reqs.
1. The view complexity may need to be reduced. Using Table Functions,
could allow for
a.predicating parameters to obtain best performance
b.and the use of SQL/PL to help reduce complexity with the
inclusion of some procedural logic.
But, the heart of the problem is this,
How do we use Table functions within a view and still manage to pass
parameters in ?
One idea I have been looking at, is to create a 'parameter table'
which is populated with call parameters by the application, which the
view then performs a correlated join with
i.e
Calling App: (JABSTFP = table function parameter table for view)
insert into JABSTFP.ADD VALUES (1,1),(1,2),(1,3);
Select * from JABSTFV.ADD;
View definition (JABSTFV):
SELECT b.RESULT
FROM JABSTFP.ADD a, TABLE(JABSTF.ADD(a.v1,a.v2)) b
This works in the simple case but raises questions of
1. Multiple concurrent queries, how do we uniquely identify the
correct rows in the parameter table ?
2. How do we automatically delete the rows from the parameter table
after the select ? - (we can't do it within the Table function, as
MODIFIES SQL DATA is not valid when
referenced
inside a view).
If anybody has any input on any of this at all, then feel free.
Thanks.
Paul. 11 13317
Paul,
Can you define "mappable" object?
Or in other words:
Why can't you expose a table-function? Is it for updatability?
One rtaher wild thought would be to expose the "parameters" in in the
signature of the view (as columns!) and of course in the RETURNS clause
of the table function
You would then use a WHERE clause to pin the values.
After that it's up to the optimizer to tunnel through the mess
(predicate push down right into the RETURN statement, transitive
closure, etc....)
You may want to try this in FP4. Taught the horse a few more tricks there)
No guarantees... Depends on just how complex the table functions are.
Keep me posted :-)
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Serge, One rtaher wild thought would be to expose the "parameters" in in the signature of the view (as columns!) and of course in the RETURNS clause of the table function You would then use a WHERE clause to pin the values. After that it's up to the optimizer to tunnel through the mess (predicate push down right into the RETURN statement, transitive closure, etc....) You may want to try this in FP4. Taught the horse a few more tricks there)
not easy to understand. A working example would be helpful
*gulp*I was affraid of that....
CREATE TABLE T1(c1 INT, c2 INT);
CREATE FUNCTION foo() RETURNS TABLE(a INT, b INT)
RETURN SELECT * FROM T1;
CREATE VIEW v AS SELECT * FROM TABLE(foo()) AS F;
SELECT * FROM v WHERE a = 5;
DB2 will unravel all this and turn it into:
SELECT * FROM T1 WHERE c1 = 5;
This of course is a trivial example.
The point is that the table function is, at the end of the day just a
correlated subquery.
Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Serge Rielau <sr*****@ca.eye-be-em.com> wrote in message news:<c0**********@hanover.torolab.ibm.com>... Paul,
Can you define "mappable" object? Or in other words: Why can't you expose a table-function? Is it for updatability?
By 'mappable' I mean ..
We use a ObjectRelational mapping layer called TopLink(owned by Oracle
now).
This requires that we have physical Tables or Views to map the objects
too,
I don't believe we can map directly to a table function. Hence, we
need a way to wrap Table functions in views.
Serge,
Thanks a lot for this input.
The one area I'm still not sure of with this approach, is when
the table function gets more complex (which ours do & will).
i.e One of the main reasons for going this route would be to
pass parameters in to use those parameters throughout the function
to optimise ALL the queries within it. Would the predicate push-down
be as effective at achieving this throughout the function whereever the
parameter/predicate appeared, and not just in the final select ?
Thanks.
Paul.
Serge Rielau <sr*****@ca.eye-be-em.com> wrote in message news:<c1**********@hanover.torolab.ibm.com>... *gulp*I was affraid of that....
CREATE TABLE T1(c1 INT, c2 INT); CREATE FUNCTION foo() RETURNS TABLE(a INT, b INT) RETURN SELECT * FROM T1;
CREATE VIEW v AS SELECT * FROM TABLE(foo()) AS F;
SELECT * FROM v WHERE a = 5;
DB2 will unravel all this and turn it into: SELECT * FROM T1 WHERE c1 = 5;
This of course is a trivial example. The point is that the table function is, at the end of the day just a correlated subquery.
Cheers Serge
Paul,
Ok let's refine this:
CREATE V AS SELECT p1, p2, c1, c2)
FROM (SELECT p1, p2 FROM SYSIBM.SYSDUMMY1) AS P,
TABLE(foo(P.p1, P.p2)) AS F(c1l, c2);
SELECT c1, c2 FROM V WHERE p1 = 5 and p2 = 6;
I think the optimizer has enough power to substitute p1 and p2 with 5
and 6 everywhere in the table function body.
Now I have never tried this and if it doesn't do it in all cases, too bad.
Note that the example above is, of course, not updatable anymore.
An instead of trigger may be advised here.
Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
I see, fat chance to convince Oracle to support DB2 Table functions, eh?
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Serge,
I have now a had chance to look/a try at this.
I don't think the FROM (select p1,p2 FROM SYSIBM.SYSDUMMMY1) you
suggest can be made to work.
Since...
1. p1,p2 are not a valid columns for SYSIBM.SYSDUMMY.
- I have also tried (VALUES(p1,p2)) as P(p1,p2) but again the
compiler
complains that p1 not valid where it used.
Presumably, you cannot reference p1 on itself in this way?
Many Thanks
Paul.
Serge Rielau <sr*****@ca.eye-be-em.com> wrote in message news:<c1**********@hanover.torolab.ibm.com>... Paul,
Ok let's refine this:
CREATE V AS SELECT p1, p2, c1, c2) FROM (SELECT p1, p2 FROM SYSIBM.SYSDUMMY1) AS P, TABLE(foo(P.p1, P.p2)) AS F(c1l, c2);
SELECT c1, c2 FROM V WHERE p1 = 5 and p2 = 6;
I think the optimizer has enough power to substitute p1 and p2 with 5 and 6 everywhere in the table function body.
Hmm, which version are you on? I dimply recall some name resolution
issues which ought to be fixed now.
Simply use:
from TABLE(......) as x
That will make suer DB2 can access all columns/variabels outside the
subquery.
Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Serge,
I am running on V8.1 Fp4.
The following is the small test script I'm using. This works, but
note I have hard coded values in the view, (which I actually want to replace
with the "select p1,p2 from sysibm.sysdummy1" subquery - see later).
CREATE FUNCTION ADD(p_v1 INT, p_v2 INT )
RETURNS TABLE (RESULT INT)
F1: BEGIN ATOMIC
RETURN VALUES(p_v1 + p_v2);
END/
CREATE VIEW ADD_VIEW
(p1,
p2,
c1
)
AS SELECT p1,p2,c1
FROM
TABLE (VALUES(1,2),(2,3)) AS P(p1,p2),
TABLE (ADD(P.p1, P.p2)) AS F(c1)
/
The following version of the view can't be created
CREATE VIEW ADD_VIEW
(p1,
p2,
c1
)
AS SELECT p1,p2,c1
FROM
TABLE (select p1,p2 from sysibm.sysdummy1) AS P(p1,p2),
TABLE (ADD(P.p1, P.p2)) AS F(c1)
/
SQL0206N "P1" is not valid in the context where it is used. SQLSTATE=42703
I'm a little worried because this looks fundamentally strange to be referencing
p1 in both the main select and in the table subquery ?
Thanks again
Paul.
Serge Rielau <sr*****@ca.eye-be-em.com> wrote in message news:<c1**********@hanover.torolab.ibm.com>... Hmm, which version are you on? I dimply recall some name resolution issues which ought to be fixed now. Simply use: from TABLE(......) as x That will make suer DB2 can access all columns/variabels outside the subquery.
Cheers Serge
OK, looking at this again, I was out for lunch with that example.
We seem to have a bit of a chicken-egg problem here.
If we start of with p1 and p2 being constants (just to have something to
start with), then the theorem prover will compare what you pass in with
the constnts chosen in the view definition and you end up with an empty
table because they are not the same.
I confess I don't see an out right now :-(
Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lauren Quantrell |
last post by:
I did this thing with host_name(). I'm hoping someone can tell me if
I'm gonna get into trouble with this scheme before it's too late...
I have...
|
by: PaulR |
last post by:
Hi,
We have several inter-related SQL Table Functions, which all optimise
fine on their own and most of the time together. However, increasingly...
|
by: Michelle Keys |
last post by:
I am trying to call a print function to print a string from a database
using javascript.
Which is RC_DATA of Varchar2(2500).
This is a javascript...
|
by: ratnakarp |
last post by:
Hi,
I have a search text box. The user enters the value in the text box and
click on enter button. In code behind on button click i'm writing the...
|
by: Serge Rielau |
last post by:
Hi all,
Following Ian's passionate postings on problems with ALTOBJ and the
alter table wizard in the control center I'll try to explain how to...
|
by: Beowulf |
last post by:
I was just messing around with some ad hoc views and table returning
UDFs today so I could look at and print out data from a small table
and...
|
by: lesperancer |
last post by:
it looks like this will save many versions of a relationship window,
but based on the fact that the same tables are displayed in the
relationship...
|
by: Sibongile Khanyile |
last post by:
If anyone can help... I have a function that takes one parameter and
bring back quite a lot of records. but with a conventional function the
field...
|
by: swethak |
last post by:
hi,
i have a code to disply the calendar and add events to that. It works fine.But my requirement is to i have to disply a weekly and daily...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
| |