Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change update execution plan in Oracle?
    primarykey
    data
    text
    <p>I have a large table foo_large and a relatively small (a few hundred thousand rows) table foo_small. The large table has a primary-key column "id"; the small one also has "id" column that is a foreign key to foo_large. I want to update foo_small so that for every row its col_y has a value equal to col_x in the corresponding row of foo_large. The most straightforward way seems to be like this:</p> <pre><code>update foo_small sm set col_y = ( select col_x from foo_large where id = sm.id); </code></pre> <p>This is, however, very inefficient. For each row of foo_small, the corresponding row of foo_large is accessed by the index on its primary key. Though foo_small is small compared to foo_large, it still leads to several hundred thousand of index scans on that table. A better solution would be to hash foo_small in memory and perform a (possibly parallelized) full scan on foo_large once, updating the matching rows of foo_small encountered. I can do that in the following way:</p> <pre><code>update ( select /*+ ordered use_hash(lg) parallel(lg 2) */ sm.*, lg.col_x from foo_small sm, foo_large lg where sm.id = lg.id ) set col_y = col_x; </code></pre> <p>This query finishes within a minute. Unfortunately, it has another disadvantage: It requires that the user launching this query has a privilege to update not only foo_small, but also foo_large even though the latter table is not actually updated. Is there a solution to force the latter execution plan without updating a join? I know I could write a piece of procedural PL/SQL code with bulk fetch/update and probably keep most of the performance gain, but I suppose there must be a way to do it in a single query.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload