-- minus
select foo, bar, baz
from table1
minus
select foo, bar, baz
from table2
-- hash antijoin
select foo, bar, baz
from table1
where (foo, bar, baz) not in (
select/*+ hash_aj */ foo, bar, baz
from table2
)
The explain plan for the minus query looks reasonable, while the one for the hash antijoin looks awful and, indeed, performs badly.
However, I'm also querying against a view, which in turn is getting its data from a link, so that might be a major issue. The view itself seems to be reasonable.
Anyone out there have an opinion?
Is the hint being used? (Score:1)
As a side note, I've never had the opportunity to use a multi-column /(not )?in/ clause, I've wanted it for years and have never heard of it being a valid syntax until now.
I googled for hash_aj and found this [oracle.com] in which one of the replies suggests that the hint is not being used, and that there should be a 'and field is not null' clause in both the query and subquery (the example there is a single column 'not in' clause, so I assume there should be a 'not null' condition for each column?).
Re:Is the hint being used? (Score:1)
Re:Is the hint being used? (Score:2)
Besides, in my 10 column compare the performance increase was negligible - about 1 second faster, and that was with a PARALLEL(4) hint tossed in to boot.
But, it's good to know and YMMV. :)
Re:Is the hint being used? (Score:1)
Then I think you need to use the MINUS anyway (which is not portable -- doesn't work on my version of Informix, and SqlServer doesn't complain, but it doesn't do the right thing either). If there are any nulls in the sub-query table, then you shouldn't get any results at all unless you have 'is not null' for those columns in the subquery, and if you have nulls in the main query table, then those records shouldn't be showing up. It's that old "if it's null, then
Re:Is the hint being used? (Score:2)
I'll admit I had brushed this off, so now I'll go back and see how it compares. We don't have control over the remote databases we're pulling some data from so it may or may not be an option.
is it being used ? (Score:1)
I remember reading somewhere that the hint wasn't being used (I see runrig has found a link). minus is way cool, besides (who said tuning was a rational procedure, anyway ?)
Re:is it being used ? (Score:2)
Yeah, it does the job, although one potential drawback is that you can't PARALLEL a minus.
Re:is it being used ? (Score:1)
And that's why they have External SQL Rewriters [ddj.com]. (sorry, gotta buy the article if you don't have the hard copy - May 2002 DDJ). Automated brute force SQL rewriting to find the best SQL statement.
Re: (Score:1)
Hey, a link to the article [ddj.com] that works! (at the time of this post anyway).