If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to disable cross-join in DB2?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-20-09, 05:31
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
How to disable cross-join in DB2?

Hi,
using DB2 v9.5.2 on Linux I often get SQL from performance hell that is not using where conditional sample (programmer just forgets to put joins):
Code:
SELECT t1.col1, t2.col2
FROM table1 t1, table2 t2
but correct is:
Code:
SELECT t1.col1, t2.col2
FROM table1, table2 t2
WHERE t1.pk=t2.pk
Is there any way I could prevent executing this kind of SQLs. So to tell DB2 if "select...from..." is used without where conditional then return error and don't execute SQL.

But just in case if someone needs this kind of functionality I would like that "cross join" kind of syntax is allowed (if someone writes this kind of syntax then he/she is aware of what is he/she doing):
So sintax:
Code:
SELECT t1.col1, t2.col2
FROM table1 t1 CROSS JOIN table2 t2
should be allowed, but
Code:
SELECT t1.col1, t2.col2
FROM table1 t1, table2 t2
should not be allowed.

Regards

Last edited by grofaty; 07-20-09 at 06:40.
Reply With Quote
  #2 (permalink)  
Old 07-20-09, 06:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
maybe educate your programmers instead?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-20-09, 06:40
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Yes, you are funny... Programmers know how to write SQLs, but sometimes someone of them just forgets to write it.
Reply With Quote
  #4 (permalink)  
Old 07-20-09, 08:29
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
There is nothing that I know of that you can do to prevent certain kinds of queries. If educating your programmers does not work, get new programmers. Either that, or all SQL that they create must go through a code review before it can be used.

Andy
Reply With Quote
  #5 (permalink)  
Old 07-20-09, 11:01
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Quote:
Originally Posted by grofaty
Yes, you are funny... Programmers know how to write SQLs, but sometimes someone of them just forgets to write it.
Sounds like they forget this things way too many times. Which leads one to question is it forgetfulness or ...


If those are big tables that end up reading millions of records you can set up a monitor to check on it and then force those connections off. Down side to this is you might kill a "good" thread. It might not be appropriate in some cases.

Best to do what others already said.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #6 (permalink)  
Old 07-20-09, 11:31
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
You can't "disable cross-joins", however, you could use the workload management feature, which is integrated in DB2 9.5, to track and react (e.g. stop or throttle) heavy-hitting queries. Check the manual.
Reply With Quote
  #7 (permalink)  
Old 07-20-09, 14:19
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Disabling cross-joins won't do you much good anyway. There are a lot of other constructs that could lead to bad query performance. So you should review all the SQL statements - that's why there are shops that don't allow dynamic SQL and only run applications with carefully reviewed and tuned static SQL.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On