Anonymous user
Hash join: Difference between revisions
Changed the whole SQL solution to illustrate better practices. Original solution was missing the key ingredient, the optimizer hint.
(Changed the whole SQL solution to illustrate better practices. Original solution was missing the key ingredient, the optimizer hint.) |
|||
Line 2,849:
=={{header|SQL}}==
{{works with|oracle}}
<lang sql>
create table
insert into
select 27, 'Jonah' from dual union all
select 18, 'Alan' from dual union all
select 28, 'Glory' from dual union all
select 18, 'Popeye' from dual union all
select 28, 'Alan' from dual
;
create table nemesises (name varchar2(30), nemesis varchar2(30));
select 'Jonah', 'Whales' from dual union all
select 'Jonah', 'Spiders' from dual union all
select 'Alan' , 'Ghosts' from dual union all
select 'Alan' , 'Zombies' from dual union all
select 'Glory', 'Buffy' from dual
;</lang>
Doing the join is trivial. Normally we would let the optimizer select the join method. However, to force a hash join, we can use an optimizer hint, USE_HASH.
<lang sql>select /*+ use_hash */ * from people join nemesises using(name);</lang>
{{out}}
<pre>
=={{header|Tcl}}==
|