473,396 Members | 1,891 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.

Optimizer questions

aj
DB2 LUW v8.2 FP 14 RHAS 2.1

Sorry if these are newbie questions. Optimizer stuff is black magic
to me. For both of these, assume stats are current and an even
distribution of data.
-------------------------
Lets say I have a table FOO1 that has, among other columns, a column
named A. There is a non-unique index on A that has medium selectivity.
Lets also say I have a table FOO2 that has, among other columns, a
column named B. There is a non-unique index on B that has medium
selectivity.

Now I create a view thusly:

create view c (col1,col2,col3,etc..) as
select A,another col,another col,another col,...
from FOO1
union
select B,another col,another col,another col,...
from FOO2

If I then query this view like:
select * from c where col1 = 'SOME VALUE'

Is the DB2 optimizer smart enough to query FOO1 using the index,
then query FOO2 using the index, then "glue" the results together?
Or does it have to select /all/ rows in FOO1 and FOO2, create a
temp table of sorts, then do a table scan (or build an index itself)?
---------
Another one: Lets say I have a table FOO1 that has, among other
columns, a column named A and a column B. There is a medium selectivity
non-unique index on A and a /separate/ non-unique medium selectivity
index on B.

If I then query FOO1 like:
select * from foo1 where a = 'SOME VALUE' and b = 'ANOTHER VALUE'

Is the DB2 optimizer smart enough to query FOO1 using the A index,
then separately query FOO1 using the B index, then do an "intersection"
of the results? Or must I have a /single/ non-unique composite index
based on A and B together?

TIA

aj
Apr 10 '07 #1
3 2354
On 10 Apr, 16:45, aj <ron...@mcdonalds.comwrote:
DB2 LUW v8.2 FP 14 RHAS 2.1

Sorry if these are newbie questions. Optimizer stuff is black magic
to me. For both of these, assume stats are current and an even
distribution of data.
-------------------------
Lets say I have a table FOO1 that has, among other columns, a column
named A. There is a non-unique index on A that has medium selectivity.
Lets also say I have a table FOO2 that has, among other columns, a
column named B. There is a non-unique index on B that has medium
selectivity.

Now I create a view thusly:

create view c (col1,col2,col3,etc..) as
select A,another col,another col,another col,...
from FOO1
union
select B,another col,another col,another col,...
from FOO2

If I then query this view like:
select * from c where col1 = 'SOME VALUE'

Is the DB2 optimizer smart enough to query FOO1 using the index,
then query FOO2 using the index, then "glue" the results together?
Or does it have to select /all/ rows in FOO1 and FOO2, create a
temp table of sorts, then do a table scan (or build an index itself)?
---------
Another one: Lets say I have a table FOO1 that has, among other
columns, a column named A and a column B. There is a medium selectivity
non-unique index on A and a /separate/ non-unique medium selectivity
index on B.

If I then query FOO1 like:
select * from foo1 where a = 'SOME VALUE' and b = 'ANOTHER VALUE'

Is the DB2 optimizer smart enough to query FOO1 using the A index,
then separately query FOO1 using the B index, then do an "intersection"
of the results? Or must I have a /single/ non-unique composite index
based on A and B together?

TIA

aj
Why don't you just try it?

Apr 10 '07 #2
aj
Well, yes, I suppose I could just try it.

However, I'm assuming (and perhaps I'm wrong) that these sort
of things are dependent upon things like data distribution,
index selectivity, index type, and maybe even other things.

Depending on the test data/scenario, I could get different
results, no? The optimizer could make a shortcut choice I'm
not even aware of. Maybe it will conclude that, for a small
enough table, a table scan is faster...

I was simply looking for a knowledgeable person to say yes
or no, the optimizer is/is not able to do that...

ja*******@hotmail.com wrote:
On 10 Apr, 16:45, aj <ron...@mcdonalds.comwrote:
>DB2 LUW v8.2 FP 14 RHAS 2.1

Sorry if these are newbie questions. Optimizer stuff is black magic
to me. For both of these, assume stats are current and an even
distribution of data.
-------------------------
Lets say I have a table FOO1 that has, among other columns, a column
named A. There is a non-unique index on A that has medium selectivity.
Lets also say I have a table FOO2 that has, among other columns, a
column named B. There is a non-unique index on B that has medium
selectivity.

Now I create a view thusly:

create view c (col1,col2,col3,etc..) as
select A,another col,another col,another col,...
from FOO1
union
select B,another col,another col,another col,...
from FOO2

If I then query this view like:
select * from c where col1 = 'SOME VALUE'

Is the DB2 optimizer smart enough to query FOO1 using the index,
then query FOO2 using the index, then "glue" the results together?
Or does it have to select /all/ rows in FOO1 and FOO2, create a
temp table of sorts, then do a table scan (or build an index itself)?
---------
Another one: Lets say I have a table FOO1 that has, among other
columns, a column named A and a column B. There is a medium selectivity
non-unique index on A and a /separate/ non-unique medium selectivity
index on B.

If I then query FOO1 like:
select * from foo1 where a = 'SOME VALUE' and b = 'ANOTHER VALUE'

Is the DB2 optimizer smart enough to query FOO1 using the A index,
then separately query FOO1 using the B index, then do an "intersection"
of the results? Or must I have a /single/ non-unique composite index
based on A and B together?

TIA

aj

Why don't you just try it?
Apr 10 '07 #3
You're correct about how the optimizer figures out how to "best" access
the data. It's relatively easy to setup a test data base for running
explains. Use db2look to dump the architecture of the production
database and include all of the statistics. Use this to create the test
database and, if you have a an appropriate amount of memory available to
the test database, you should be able to run explains on the test one
and get results that will very closely match production. Note that you
don't need to have any data in the test database to do this.

Phil Sherman
aj wrote:
Well, yes, I suppose I could just try it.

However, I'm assuming (and perhaps I'm wrong) that these sort
of things are dependent upon things like data distribution,
index selectivity, index type, and maybe even other things.

Depending on the test data/scenario, I could get different
results, no? The optimizer could make a shortcut choice I'm
not even aware of. Maybe it will conclude that, for a small
enough table, a table scan is faster...

I was simply looking for a knowledgeable person to say yes
or no, the optimizer is/is not able to do that...

ja*******@hotmail.com wrote:
>On 10 Apr, 16:45, aj <ron...@mcdonalds.comwrote:
>>DB2 LUW v8.2 FP 14 RHAS 2.1

Sorry if these are newbie questions. Optimizer stuff is black magic
to me. For both of these, assume stats are current and an even
distribution of data.
-------------------------
Lets say I have a table FOO1 that has, among other columns, a column
named A. There is a non-unique index on A that has medium selectivity.
Lets also say I have a table FOO2 that has, among other columns, a
column named B. There is a non-unique index on B that has medium
selectivity.

Now I create a view thusly:

create view c (col1,col2,col3,etc..) as
select A,another col,another col,another col,...
from FOO1
union
select B,another col,another col,another col,...
from FOO2

If I then query this view like:
select * from c where col1 = 'SOME VALUE'

Is the DB2 optimizer smart enough to query FOO1 using the index,
then query FOO2 using the index, then "glue" the results together?
Or does it have to select /all/ rows in FOO1 and FOO2, create a
temp table of sorts, then do a table scan (or build an index itself)?
---------
Another one: Lets say I have a table FOO1 that has, among other
columns, a column named A and a column B. There is a medium selectivity
non-unique index on A and a /separate/ non-unique medium selectivity
index on B.

If I then query FOO1 like:
select * from foo1 where a = 'SOME VALUE' and b = 'ANOTHER VALUE'

Is the DB2 optimizer smart enough to query FOO1 using the A index,
then separately query FOO1 using the B index, then do an "intersection"
of the results? Or must I have a /single/ non-unique composite index
based on A and B together?

TIA

aj

Why don't you just try it?
Apr 11 '07 #4

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

Similar topics

1
by: Nick Mudge | last post by:
Hi, Does anybody know the performance difference between having your PHP code cached and just running your code with the zend optimizer? Is there much difference? Nick
9
by: hemal | last post by:
I came across a very strange situation at work. There is an order of magnitude difference in execution time for the following two queries (10 v/s ~130 msec): select count(*) from table_name...
3
by: Philip Yale | last post by:
I'm very puzzled by the choice of NC index being made by the optimizer in this example. I don't actually think it should use an NC index at all. I have: Table: CustomerStatus_T Single data...
3
by: Peter Arrenbrecht | last post by:
Hi all We ran into a very annoying optimizer problem recently. We had added a new key and self-join relation to a large production table. That key will be filled very rarely and having just...
9
by: Andrea | last post by:
Hi, I've read the former postings but was not able to solve my problem: I have a Summary Table (or MQT as you like it) and the query optimizer does not seem to use the summary table. I run...
5
by: Venkatesh Subbaramu | last post by:
Hi Expert DBAs, I am facing an issue with a query, can anyone help me through? I have a Query: UPDATE VMUS.MSG_MSTR a SET MSG_STA_ID =5 WHERE a.PROC_ID =2 AND a.file_type_id =1 AND MSG_STA_ID...
0
by: Larry Bertolini | last post by:
While trying to help a developer troubleshoot a performance problem, I have discovered something that strikes me as odd. When I run a particular query, using a non-privileged login that has...
5
by: Kevin | last post by:
Using a base table, a MQT table was created. With optimization - when querying the base table with calcuation that are already completed in the MQT - I would assume the optimizer would use the MQT...
2
by: boa sema | last post by:
Way back when, and at least in version 7 IIRC, the query optimizer gave up when the where clause in a statement contained more than 4 search conditions. Does anyone know if such a limitation...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
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,...

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.