Skip to content
Advertisement

can I use different hints in one clause of union in oracle

I have a merge query of below format –

now I have to do union in this query

My question is do I have to give parallel hint in second union clause also . Also use_hash hint which was running good earlier would not have impact on adding union clause in the query

Advertisement

Answer

The hints apply to each select independently. First, you need to understand how parallel execution works in terms of session level and/or hints applied.

In this you have three elements

  • The merge statement itself which will update some rows and will not run in parallel
  • The first data set recover with the first select will run in parallel
  • The second will run in parallel because of the hints applied to the first statement

I am assuming the tables are configured with noparallel and that you are not enabling parallel dml. I won’t even try to replicate the query, because I don’t know exactly what you want to do with it.

Test case

Now I am going to build a merge statement to update the table t2 using a source based on a union select. Forget in this case the meaning of the query, which has no sense at all, but the resulting execution plan

The most important parts of the execution plan below:

  • As the tables has no statistics, Oracle has used dynamic sampling.
  • The degree used in 4 due to the hing.
  • Parallel DML is not enabled at session level, therefore the update resulting of the merge runs in noparallel.
  • Oracle builds an VIEW dynamically to join the two datasets of the union, as a result of one of them is running in parallel, the CBO runs in parallel the second one even though it has no hints.
  • In a USE_HASH hint use always as driving table the smaller table. Normally the CBO will always do that, so I would recommend to carefully use the USE_HASH hint, because if the smaller table grows to a point that is even greater than the second one, your hint will produce a lot of performance degradation.

Hope it clarifies.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement