Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Is there a replacement for HASH_AJ hint?

James SuJan 2 2025

hi experts,

I have a SQL looking like this:

select * from t
where  (t.col1,t.col2, ...)
        in     (select col1,col2, ...
                  from view1
               )  
  and not exists (
      select /*+ hash_aj */ null
        from view2
       where col1=t.col1 and col2=t.col2 and ....
      )

The optimizer generates a sql plan with nested loop anti join for the "not exists" part. It's suboptimal because there's a full scan on a global temp table in view2.

I tried rewriting it to:

  and (t.col1,t.col2, ...) not in (
      select /*+ hash_aj */ col1,col2, ...
        from view2
       where col1 is not null and col2 is not null and ...
      )

But it stills uses nested loop anti. In the hints report the hash_aj hint is marked as U(Unused).

hash_aj hint is deprecated in 10g. Is there a replacement to enforce a hash anti join?

If I populate the temp table with a lot of data and run dbms_stats.gather_table_stats it does come up with a hash anti join. I look at the outline and I see some USE_HASH, SWAP_JOIN_INPUTS hints. I would like to know if there's an easier way to hint it.

Thank you!

This post has been answered by Jonathan Lewis on Jan 6 2025
Jump to Answer
Comments
Post Details
Added on Jan 2 2025
11 comments
168 views