Written by

Question CJ H · Feb 19, 2018

%NOMERGE for query optimization

I don't quite understand the %NOMERGE mentioned in the documentation.

http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=RSQL_from#RSQL_from_nomerge

Is there any specific example provided to illustrate the idea?

Thanks.

Comments

Brendan Bannon · Feb 21, 2018

Hello

I am trying to get a good example, but for now I will just try to give you a general description. As the Docs say this hint is used in a subquery. At compile time the optimizer has 2 options for dealing with a subquery:
1) Treat it as a black box, executing the subquery independently from the other query and then applying the results to the outer query
2) rewrite the query incorporating the subquery into the outer query as a JOIN and combining conditions from the subquery to the WHERE clause of the outer query.

If you look at the show plan of a query you can see which option the optimizer is taking. If you see a section of the plan with a heading of SubQuery then you know it is option 1.

If the query does not have a Subquery section we are in option 2.

You can see that with the following query:

select home_state, avg(age) from sample.employee e
where home_state = ANY (select MAX(v.address_state) from sample.vendor v where balance > 0)
group by home_state

will be rewritten

while:

select home_state, avg(age) from sample.employee e
where home_state = ANY (select MAX(v.address_state) from %NOMERGE sample.vendor v where balance > 0)
group by home_state

will keep the subquery.

0
CJ H  Feb 21, 2018 to Brendan Bannon

Thanks, I think sth really confused is the difference between "%NOFLATTEN" and "%NOMERGE".

0
Brendan Bannon  Feb 21, 2018 to CJ H

Yes I would like a better understanding of the difference as well.

Sadly I just try both and see if either change the query.

brendan

0