Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Predicate Pushdown on Views with OLAP

 
   Database Help (Home) -> DB2 RSS
Next:  Query for Cross Reference Table  
Author Message
Michel Esber

External


Since: May 14, 2007
Posts: 22



(Msg. 1) Posted: Mon Feb 16, 2009 8:25 am
Post subject: Predicate Pushdown on Views with OLAP
Archived from groups: comp>databases>ibm-db2 (more info?)

Hello,

DB2 LUW V9.5 FP3.

Whenever I include rownumber on the outer select of a view, my access
plan is very slow and has a lot of tablescans.

# select machine_id, sw_id, homologation_status, type from
VIEW_WITH_OLAP_INSIDE where MACHINE_ID=?

If I remove the OLAP function from the view body, I get excellent
speeds:

# select machine_id, sw_id, homologation_status, type, rownumber ()
over (partition by machine_id, sw_id order by type) as rn from
VIEW_WITHOUT_OLAP where id = '?'

The *only* difference between both statements is where my OLAP
function is placed. The first one is used inside the view, the second
one is used in a view without any OLAP.

Also, the first access plan has a much higher cost than the second
one. Are there any known limitations on using Views and OLAP ?

Thanks,

Michel

 >> Stay informed about: Predicate Pushdown on Views with OLAP 
Back to top
Login to vote
ChrisC

External


Since: May 11, 2007
Posts: 11



(Msg. 2) Posted: Mon Feb 16, 2009 9:40 am
Post subject: Re: Predicate Pushdown on Views with OLAP [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

That makes sense when you are talking about the columns in the ORDER
BY clause of row_number(). However, Michel was talking about the
columns in the PARTITION BY clause, which I would think would be safe
to push down:


On Feb 16, 9:13 am, Serge Rielau wrote:
> Michel Esber wrote:
>
> > # select machine_id, sw_id, homologation_status, type from
> > VIEW_WITH_OLAP_INSIDE where MACHINE_ID=?
and
> > # select machine_id, sw_id, homologation_status, type, rownumber ()
> > over  (partition by machine_id, sw_id order by type) as rn  from
> > VIEW_WITHOUT_OLAP where id = '?'

Sure, the column names are a bit garbled, but I suspect he wanted to
reference MACHINE_ID is both places. And if he didn't, I'd like to
know what DB2 is supposed to do in that case.

Thanks,
Chris

 >> Stay informed about: Predicate Pushdown on Views with OLAP 
Back to top
Login to vote
Serge Rielau6

External


Since: Oct 04, 2004
Posts: 441



(Msg. 3) Posted: Mon Feb 16, 2009 12:13 pm
Post subject: Re: Predicate Pushdown on Views with OLAP [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Michel Esber wrote:
> Hello,
>
> DB2 LUW V9.5 FP3.
>
> Whenever I include rownumber on the outer select of a view, my access
> plan is very slow and has a lot of tablescans.
>
> # select machine_id, sw_id, homologation_status, type from
> VIEW_WITH_OLAP_INSIDE where MACHINE_ID=?
>
> If I remove the OLAP function from the view body, I get excellent
> speeds:
>
> # select machine_id, sw_id, homologation_status, type, rownumber ()
> over (partition by machine_id, sw_id order by type) as rn from
> VIEW_WITHOUT_OLAP where id = '?'
>
> The *only* difference between both statements is where my OLAP
> function is placed. The first one is used inside the view, the second
> one is used in a view without any OLAP.
>
> Also, the first access plan has a much higher cost than the second
> one. Are there any known limitations on using Views and OLAP ?
Michel,

This is all about semantics.
Now, your examples are a bit cobbled together (= '?' ??) so let's look
at a scenario:

CREATE TABLE T(c1);
INSERT INTO T VALUES 10, 20, 30, 40;

SELECT ROW_NUMBER() OVER(ORDER BY c1) AS rn, c1 FROM T WHERE c1 = 30;
=> (1, 30)
The where clause executes before teh select list. All is well.

WITH V AS (SELECT ROW_NUMBER() OVER(ORDER BY c1) AS rn, c1 FROM T)
SELECT rn, c1 FROM V WHERE c1 = 30
=> (3, 30) -- <--- Three!
You get what you ask for here. You asked for an resultset "V" with all
rows ordered. Then of that resultset you asked to get the one with c1 = 30.
If DB2 pushed the predicate down then the answer would change. The
optimizer must never change the result. That's a cardinal rule of RDBMS.

Now if you do:
WITH V AS (SELECT ROW_NUMBER() OVER(ORDER BY c1) AS rn, c1 FROM T)
SELECT c1 FROM V WHERE c1 = 30
=> (30)
In this case the rn column has not been used and DB2 can toss it out.
With the rn column gone the predicate can be pushed down.
(and I hope that is what you see, otherwise there is indeed a problem).

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
 >> Stay informed about: Predicate Pushdown on Views with OLAP 
Back to top
Login to vote
Serge Rielau6

External


Since: Oct 04, 2004
Posts: 441



(Msg. 4) Posted: Mon Feb 16, 2009 1:55 pm
Post subject: Re: Predicate Pushdown on Views with OLAP [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

ChrisC wrote:
> That makes sense when you are talking about the columns in the ORDER
> BY clause of row_number(). However, Michel was talking about the
> columns in the PARTITION BY clause, which I would think would be safe
> to push down:
True enough, yes predicates on GROUP BY/PARTITION BY can/could be pushed
down.
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
 >> Stay informed about: Predicate Pushdown on Views with OLAP 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Problem with IN predicate - I have a query in Oracle like this: Select 1 from dual where (1,1) IN ( (1,1), (2,1) ) and want to convert it to DB2. I tried this query: Select 1 from sysibm.sysdummy1 where (1,1) IN ( (1,1), (2,1) ) I replaced "," with SPACE and ";&quot...

Pattern Matching using LIKE predicate on a DB2 column usin.. - I have a column in db2 with an index. When I search using LIKE predicate, sometimes it gives results very slow (about 3 to 5 mins). But after the initial hit, subsequent searches using different expressions return very fast (2 secs). It is almost as-if....

Estimating performance on an OLAP database (virtualization.. - Hi all, We're trying to test DB2's performance for an OLAP data warehouse. We went with a column-store based approach after loading using a row- store approach generated over 2 million rows for just a single month's worth of data. We're using Alphablo...

User-defined aggregate functions and OLAP windowing - Friends: In v8 or v9 LUW, if I were to write (in Java or C) my own user-defined aggregate function, would I be able to use it in an OLAP windowing clause as I could use, e.g., COUNT or SUM? Example: SELECT JEFFS_UDAF() OVER(PARTITION BY SOME_COL)....

Views & performance - Hi, simple question I have 2 hugge tables Table A and Table B. I define a view over these 2 tables (select,..joint,...) My question is: Does the DB2 runs the query every time that I access the View? or only the first time that I create the view. Is th...
   Database Help (Home) -> DB2 All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]