Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

%_HINT

Former Member
0 Likes
2,688

Hi,

is there a way to specify in Open-SQL hint to optimizer dynamically? I had in mind something like dynamic where clause.....

thx

1 ACCEPTED SOLUTION
Read only

former_member207438
Participant
0 Likes
2,199

You can build your hint and put it into a variable. If the variable is initial the hint is not passed to the database engine.

For example:


data:
  lv_hint type c length 30.

  lv_hint = 'index("&TABLE&")'. " Oracle hint

  SELECT *
  INTO TABLE lt_mara
  up to 10 rows
  FROM mara
  %_hints oracle lv_hint.

Read SAP note 129385 about hints for your database type.

14 REPLIES 14
Read only

Former Member
0 Likes
2,199

Well, if you just leave out the hint, it will optimize dynamically.

Rob

Read only

Former Member
0 Likes
2,199

what should be the purpose of dynamic hint ?????

Hints are for exceptions, only if the optimizer has problems, and these problems should be very specific.

Dynamic where-clause is dynamic where-clause, read documentation

Read only

former_member207438
Participant
0 Likes
2,200

You can build your hint and put it into a variable. If the variable is initial the hint is not passed to the database engine.

For example:


data:
  lv_hint type c length 30.

  lv_hint = 'index("&TABLE&")'. " Oracle hint

  SELECT *
  INTO TABLE lt_mara
  up to 10 rows
  FROM mara
  %_hints oracle lv_hint.

Read SAP note 129385 about hints for your database type.

Read only

0 Likes
2,199

maybe I should be more specific. I'm working on some add on Croatia(Foreign Trade), and I'm selecting all kind of data from BSID, BSAD, BISK , BSAK well not always with key/index fields and therefore I figured out that in some cases optimizer uses default index, which is not the best. Local, on our development server, I tried in this case %_HINT ORACLE "FIRST_ROW" and performance is better, but what if some customer doesnt have Oracle? In this case I thought to replace specific DB hint with some string, and this string should be customer specific(set up through customizing).

Read only

0 Likes
2,199

Hi Mario,

you can extend Edwards example:


data:
  lv_hint type c length 30.
 

select hint into lv_hint
from cust_hint_table
...
 
  SELECT *
  INTO TABLE lt_mara
  up to 10 rows
  FROM mara
  %_hints oracle lv_hint
  %_hints db2 lv_hint
  %_hints db4 lv_hint
  %_hints db6 lv_hint
... .

Kind regards,

Hermann

Read only

0 Likes
2,199

ok, that is not to bad, but also not to elegant. is it possible also to generic specify for which DB id hint?

Read only

0 Likes
2,199

Hi Mario,

>

> ok, that is not to bad, but also not to elegant.

true.

>

> is it possible also to generic specify for which DB id hint?

like this?

 
data:
  lv_hint type c length 30.
 
 
select hint into lv_hint
from cust_hint_table
*where dbsys = sy-dbsys*
AND ...
...
 
  SELECT *
  INTO TABLE lt_mara
  up to 10 rows
  FROM mara
  %_hints oracle lv_hint
  %_hints db2 lv_hint
  %_hints db4 lv_hint
  %_hints db6 lv_hint
... .

ADBC is completely native and dynamic (SQL in strings like JDBC)...

but i don't think that this is appropriate. I would stick with the OPEN SQL Hints.

Kind regards,

Hermann

Read only

0 Likes
2,199

I thought on something like this, instead of

%_hints oracle lv_hint

%_hints db2 lv_hint

%_hints db4 lv_hint

%_hints db6 lv_hint

to use only one:

%_hints lv_hint

and system knows that is Oracle DB or DB2....

Read only

0 Likes
2,199

Hi Mario,

I'm afraid, that is not possible. You have to specify the hint for each database.

Even a DBI Hint uses the DB specific part infront because even the DBI hints

that don't go to the database can be database specific.

Back to your topic:

Dynamic hints from customizing ... We had a once a customer who build

a whole frame work (on one DB platform) wich dynamic hints from a customizing

table. With that he was able to quickly react on problem queries for example in case

of bugs without code changes (if the dynamic hint solution was implemented).

So the hints were "switchable" which actually was a nice thing.

I've never seen it over database borders. And in general i would say it is for

sure no common practise.

But if you consider that more and more DB manufacturers offer solutions to

obtain a "execution plan stability" without changing the code ... your thoughts

are just going in the same direction ... on the ABAP side.

However i don't know if it would work over database borders because the

possibilites with hints between the databases are VERY diverse. And there

is still lots and lots of undocumented stuff. So i don't know if it will turn out

to be sucessfull. For the customer i mentioned, within one database it turned

out to be sucessfull in terms of reacting quickly on problems without code or

configuration changes.

Kind regards,

Hermann

Read only

0 Likes
2,199

ok, I will simply use code like Hermann Gahm said, with my own customizing in Z*table or z-program

thx all

br

mario

Read only

Former Member
0 Likes
2,199

I must say I find this discussion useless, please explain, how you would fill the dynamic hint variable.

In theory it can be possible, and practise if is probably very rare.

I would to see the logic which fills lv_hint.

Maybe somebody can propose the self-optizing SELECT statement. If performance is low it will generate a hint. if still low it tries another. Please provide decision logic

Read only

0 Likes
2,199

No Siegfried, self optimizing SELECT is not what I meant(Ich glaube, dass Sie nicht ein Zyniker tief in Seiner Seele sind). As this AddOn could be deployed to many different SAP systems with different DBs, I want to write only once per select %_HINT lv_hint. In lv_hint then would be db-string and optimizer hint. How could be this done, is pure programming logic which is not relevant.

Read only

0 Likes
2,199

Mario - if you look for hints in SAP standard programs, I think you'll see that SAP uses sy-dbsys to determine the database and therefore the format of the hint to construct.

Rob

Read only

Former Member
0 Likes
2,199

> self optimizing SELECT is

no, in fact it is not even impossible, that you trigger a hint, if the ST04 figures out, that a statement is slow. not done but not impossible.

dynamic hint, still I would not recommend it.

There is no 1:1 relation between the hints of the different databases, usually there is an index hint, but this is not always the first choice.

And even the index hint needs table name, and index name. Better write it by hand.

I would assume that most of your dynamic hints will simply not work, but the have one or the other bug and are simply ignored.

Overall, you should use hints carefully and only in exceptions, your idea is against this rule.

Siegfried