473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

MQT Query Rewrite Puzzling

I created a MQT defined as:
select a.col1,a.col2,a.col3,b.col1.b.col2
from a , b
where a.id = b.id

Now, I execute this query which get rewritten to the MQT:
select a.col1,b.col1, c.val
from a, b, c
where a.id = b.id
and a.col2 = c.id

But when I execute the exact same query with a filter on c, it wouldnt
rewrite to MQT:
select a.col1,b.col1, c.val
from a, b, c
where a.id = b.id
and a.col2 = c.id and c.type = 'xyz' and c.bu = 'abc'

Nov 12 '05 #1
4 1856
But with only one filter on c, it rewrites. Isnt that strange? Any
input is highly appreciated.
select a.col1,b.col1, c.val
from a, b, c
where a.id = b.id
and a.col2 = c.id and c.type = 'xyz'

Nov 12 '05 #2
Look at explains of the statements. I'd suspect that the additional
predicate on table c makes a big difference in (row) selectivity of that
table. Indexes on a, b, and the MQT will impact the access path too.

Phil Sherman

ra*********@gmail.com wrote:
But with only one filter on c, it rewrites. Isnt that strange? Any
input is highly appreciated.
select a.col1,b.col1, c.val
from a, b, c
where a.id = b.id
and a.col2 = c.id and c.type = 'xyz'

Nov 12 '05 #3
Thanks for the response, Phil.
Is that right? If it finds that the explain plan cost or estimated rows
is better when hitting the base table than the MQT, it would hit base
table? I tried various combinations of various filters and I did find
that when filtered on certain columns than others, the plan changes
from MQT to base table.
But shouldn't MQT always be better than the base? Is there a way to
direct DB2 to use MQT irrespective of the plan cost difference between
base table and MQT.

Phil Sherman wrote:
Look at explains of the statements. I'd suspect that the additional
predicate on table c makes a big difference in (row) selectivity of that
table. Indexes on a, b, and the MQT will impact the access path too.

Phil Sherman

ra*********@gmail.com wrote:
But with only one filter on c, it rewrites. Isnt that strange? Any
input is highly appreciated.
select a.col1,b.col1, c.val
from a, b, c
where a.id = b.id
and a.col2 = c.id and c.type = 'xyz'


Nov 12 '05 #4
The optimizer's job is to find the most efficient (lowest cost) way to
retrieve the data. Assume no indexes in the MQT and indexes on
appropriate columns of tables a and b. If the selectivity on table c
yields only a few rows, then nested loop joins, using indexes are very
efficient. When selectivity on table c yields a larger number of rows,
then a scan/sort of the MQT becomes more efficient.

You don't state if you placed indexes on the MQT. Try adding one on the
a.col2 column and see if that encourages the optimizer to always use the
MQT. I'd also suspect that if you use "optimize for 1 rows" then the
optimizer will be biased to use the base tables a and b if there are no
indexes on the MQT.

Phil Sherman

ra*********@gmail.com wrote:
Thanks for the response, Phil.
Is that right? If it finds that the explain plan cost or estimated rows
is better when hitting the base table than the MQT, it would hit base
table? I tried various combinations of various filters and I did find
that when filtered on certain columns than others, the plan changes
from MQT to base table.
But shouldn't MQT always be better than the base? Is there a way to
direct DB2 to use MQT irrespective of the plan cost difference between
base table and MQT.

Phil Sherman wrote:
Look at explains of the statements. I'd suspect that the additional
predicate on table c makes a big difference in (row) selectivity of that
table. Indexes on a, b, and the MQT will impact the access path too.

Phil Sherman

ra*********@gmail.com wrote:
But with only one filter on c, it rewrites. Isnt that strange? Any
input is highly appreciated.
select a.col1,b.col1, c.val
from a, b, c
where a.id = b.id
and a.col2 = c.id and c.type = 'xyz'


Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: George Stout | last post by:
First off I do not know alot about writing queries to an Access Database from an ASP page. This is why I need help. I have an Events database for 6 colleges in our metro area. On the homepage I...
2
by: Tim Fountain | last post by:
We've recently enabled slow query logging on a server and it's proving interesting seeing which queries are bogging things down. This one is puzzling me a little: SELECT articleid, type,...
0
by: krystoffff | last post by:
Hi all For speed reasons, I would like to rewrite the following query without the subquery : SELECT * FROM table1 WHERE field1 NOT IN (SELECT field1 FROM table2 where field2=X); I thought...
9
by: majsen | last post by:
Hi, I have problem running this query. It will time out for me... My database are small just about 200 members. I have a site for swaping appartments (rental). my query should look for match in...
5
by: kjaggi | last post by:
-- tested schema below -- -- create tables -- create table tbl_test (serialnumber char(12)) go create table tbl_test2 (serialnumber char(12), exportedflag int) go --insert data --
3
by: JC Mugs | last post by:
Help needed for project-Access 2002(office xp) PROBLEM: Figuring out how to lookup a record and DDate field in Table1 - Take that DDate-field data from record looked up and assign it to Date...
1
by: j.mandala | last post by:
I created a simple link between two tables in a query. TableA has Social Security numbers stored as Long Integer Data. (I imported this table). The Join is between these two fields Table ...
3
by: Janross | last post by:
I'm having trouble with a query that's prohibitively slow. On my free-standing office computer it's fine (well, 2-4 seconds), but on the client's network, it takes at least 5 minutes to run. ...
2
by: StuckProgrammer | last post by:
Hi, I have 10 queries linked together via an incident number. There is a form where the user enters start and end dates to define which incident numbers are used within the queries. On running...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.