473,805 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Left Outer Join Using Views


Hi there,

we have a problem using the left outer join-operation on a db2
database, v7, running on z/os.

Defined are two tables, table1 and table2. Both tables have a primary
key of field1, field2 and field3. There two tables exist in two
different schemas. Also, there are two view, view1 and view2. View1
joins the table1 on both of the schemas, also view2 for the table2 on
both schemas.

If running a sql-statement on each table (it does not matter on which
schema), there is an index access into the table. Running the following
sql-statement on the views, only view1 will use the index access for
its tables, view2 uses a full table scan:

select a.*
from schema.view1 a
right outer join schema.view2 b
on b.field1= a.field1
and b.field2 = a.field2
and b.field3 = a.field3
where b.field1 = ?
and b.field2 = ?
and b.field3 = ?
with ur;

Does anyone know what happens on the database? Why is there not an
index access on both views, althought both view use tables where the
where-statement has an index access to?

Thanx for your answers.

Ralf

Nov 12 '05 #1
3 6046
Hi.
we have a problem using the left outer join-operation on a db2
database, v7, running on z/os.


From my experience v7 (udb for LUW, not z/OS) doesn't like outer views.
I had such schema:
table t1(c1, c2, ...),
table t2(c1, c2, ...),
view v2 (select * from t2 where <fairly_simple_ condition>).

select ...
from t1
left join t2 on ...
where t1.pk = ...
produced index scans,

select ...
from t1
left join v2 on <join_clause>
where "t1.pk = <pk_expr>"
produced full scan of one of tables (I don't remember which),

finally, I had to do this:

select t1.c1, ..., v2.c1, ...
from t1
join v2 on <join_expr>
where "t1.pk = <pk_expr>"
union all
select t1.c1, ..., cast(NULL as ...), ...
from t1
where "t1.pk = <pk_expr>"
and not exists (select 1
from v2
where <join_expr>)

Sincerely,
Mark.
Nov 12 '05 #2
pz
rj**@gmx.de wrote:

If running a sql-statement on each table (it does not matter on which
schema), there is an index access into the table. Running the following
sql-statement on the views, only view1 will use the index access for
its tables, view2 uses a full table scan:

select a.*
from schema.view1 a
right outer join schema.view2 b
on b.field1= a.field1
and b.field2 = a.field2
and b.field3 = a.field3
where b.field1 = ?
and b.field2 = ?
and b.field3 = ?
with ur;


There was an article some time ago on the IBM Developerworks site regarding joins in DB2.
Apparently, if you specify conditions in the WHERE clause they will be applied after the join,
whereas if you put them in the ON clause they will be processed before the join. Try rewriting your
query as follows:

select a.*
from schema.view1 a
right outer join schema.view2 b
on b.field1= a.field1
and b.field2 = a.field2
and b.field3 = a.field3
and b.field1 = ?
and b.field2 = ?
and b.field3 = ?

and see if it makes any difference.
Nov 12 '05 #3
Hi.
There was an article some time ago on the IBM Developerworks site regarding joins in DB2. Apparently, if you specify conditions in the WHERE clause they will be applied after the join, whereas if you put them in the ON clause they will be processed before the join. Try rewriting your query as follows:

select a.*
from schema.view1 a
right outer join schema.view2 b
on b.field1= a.field1
and b.field2 = a.field2
and b.field3 = a.field3
and b.field1 = ?
and b.field2 = ?
and b.field3 = ?

and see if it makes any difference.


I tried this on my scheme (see posting above) and result is quite strange:
Table scanned by index became to be full scanned and vice versa.

Sincerely,
Mark.
Nov 12 '05 #4

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

Similar topics

1
6930
by: Justin Hennessy | last post by:
Hi all, I am working with a computer hardware asset database and I am trying to get information out of it for each PC in my organisation. Here is the basic table structure: Table1 -> Table2 -> Table3 -> Table4 -> Table5
3
10057
by: Dam | last post by:
Using SqlServer : Query 1 : SELECT def.lID as IdDefinition, TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour FROM serveur.Data_tblDEFINITIONTABLEDECODES def, serveur.Data_tblTABLEDECODEAUNEVALEUR TDC_AUneValeur where def.TYPEDETABLEDECODES = 4
1
4225
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins" slows the system down considerably. I've tried creating a temp db, but I can't figure out how to execute two select commands. (It throws the exception "The column prefix 'tempdb' does not match with a table name or alias name used in the query.")
7
31570
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins" slows the system down considerably. I've tried creating a temp db, but I can't figure out how to execute two select commands. (It throws the exception "The column prefix 'tempdb' does not match with a table name or alias name used in the query.")
6
9035
by: Thomas Beutin | last post by:
Hi, i've a speed problem withe the following statement: SELECT DISTINCT pz.l1_id, pz.l2_id, pz.l3_id, pz.l4_id FROM ot_adresse AS a, ot_produkt AS p LEFT OUTER JOIN ot_kat_prod AS pz ON ( p.p_id = pz.p_id ) WHERE p.a_id = a.id AND a.id = '105391105424941' AND a.m_id = '37'; This is terrible slow compared to the inner join: SELECT DISTINCT pz.l1_id, pz.l2_id, pz.l3_id, pz.l4_id
3
23103
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but he doesn't know how to do that, or even if he can, and i don't have to time to learn DB2 from scratch right now. The following SQL Query is a trimmed sample of the full View (i.e. Logical) definition - and i would create it on an SQL based...
14
5726
by: mike | last post by:
I'm using postgresl 7.3.2 and have a query that executes very slowly. There are 2 tables: Item and LogEvent. ItemID (an int4) is the primary key of Item, and is also a field in LogEvent. Some ItemIDs in LogEvent do not correspond to ItemIDs in Item, and periodically we need to purge the non-matching ItemIDs from LogEvent. The query is: delete from LogEvent where EventType != 'i' and ItemID in
4
2720
by: polycom | last post by:
Assistance needed to optimize this query SELECT SD.content_id AS Id, SD.title AS Title, CT.name AS Contenttype, PV.content_id AS SponsorId, PV.display_name AS Sponsor, CONCAT_WS("", NT.title, " - ", N.pubdate, " ") AS ListGroup,
1
3284
by: nico3334 | last post by:
I have a query that currently pulls data from a main table and a second table using LEFT OUTER JOIN. I know how to do make another LEFT OUTER JOIN with the main table, but I want to add another LEFT OUTER JOIN to the second table. So I want the third table to be joined through the second table, not the main table. Here is my original code that joins the main table and the second table SELECT t1.supply, t2.inventory, FROM MAIN_TABLE...
0
9718
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, 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...
0
10614
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10369
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
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...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.