• Unlock the power of using Oracle Optimizer Hints to tune SQL statements

    From tracyto41@gmail.com@21:1/5 to All on Thu Feb 15 01:03:23 2018
    Common SQL tuning methods
    SQL tuning is the process to improve a SQL statement’s performance up to the user’s expectation. There are at least three methods which are commonly used by developers or DBAs, These methods are creating new indexes, rewriting the SQL syntax and
    applying Oracle Optimizer Hints to the SQL statements. Each method has its pros and cons and suitable for different stages of application cycle. Let’s discuss these three methods in the following.

    Create new indexes for SQL statement
    Creating new indexes for SQL statements are a very common method to improve SQL performance, it is especially important during database development. As new indexes to a SQL statement are not only affecting current SQL, it is also affecting other SQL
    statements running on the same database. So, it should be used very carefully in in production database. Normally, users are required to make impact analysis to other relevant SQL statements for the newly-created indexes.

    Rewrite SQL statement
    There are a lot of people teaching SQL rewrite skills over the internet. Most of those rewrite rules are inherited from Oracle rule-based SQL optimizer or older version of cost-based SQL optimizer. For example, some people may think that the following
    SQL may have different performances:

    Select * from A where A.unique_key in (select B.unique_key from B);
    Select * from A where exists (select ‘x’ from B where A.unique_key=B.unique_key);

    Actually, if you put these two SQLs into Oracle database, you may probably get the same query plan from Oracle; it is because Oracle SQL optimizer will rewrite these two SQLs into one standard form internally to enable better query plans generation. A
    stronger internal rewrite ability was developed by Oracle SQL optimizer in last two decades. So, some obvious problems such as “KEY IS NOT NULL” or “NVL(KEY,’ABC’) =’ABC’ ” were not able to use indexes are solved by Oracle already. Of
    course, there are still some limitations in Oracle SQL optimizer for complex SQL transformation, so experience users may still be able to tune a SQL statement through SQL rewrite to influence Oracle SQL optimizer to generate a better query plan. But this
    approach is getting more difficult to apply by DBAs since the relationship between SQL syntax and final query plan generation is getting weaker, this is because Oracle cost-based optimizer (CBO) is getting smarter and the syntax of the SQL text is no
    longer a dominating factor to the cost calculation and plans generation.
    SQL rewrite is still useful both in development and production database, since it is an isolated change to a database and no other SQLs’ performance will be affected, and it is safer than building new indexes. But it requires SQL code changes in
    program sources, so unit test or integration test may still be necessary. In contrast, using hints to tune a SQL is relatively safer, since it is not easy to change the semantics of the SQL accidentally.

    Apply hints to SQL statement
    ......for details, please visit here: https://tosska.com/unlock-power-using-oracle-optimizer-hints-tune-sql-statements/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From "Michel Cadot" @21:1/5 to All on Sun Feb 18 15:28:47 2018
    <tracyto41@gmail.com> a crit dans le message de news: 203ad84c-7b27-4860-a858-fd33cf9d9b7a@googlegroups.com...

    In contrast, using hints to tune a SQL is relatively safer,



    This is wrong and Jonathan Lewis definitively demonstrated it more than a decade ago, demonstration which is still valid in the
    current versions and for all the futures ones.

    You should take advantage to read Oracle documentation which states: https://docs.oracle.com/database/121/SQLRF/sql_elements006.htm#SQLRF00219 https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E

    <quote>
    Hints should be used sparingly, and only after you have collected statistics on the relevant tables and evaluated the optimizer plan
    without hints using the EXPLAIN PLAN statement. Changing database conditions as well as query performance enhancements in subsequent
    releases can have significant impact on how hints in your code affect performance.
    </quote>

    And you still did not answer to the pertinent remarks made by Nuno, Mladen and Ed in one of your previous threads about your
    "product".
    Go away ignorant spammer!

    Regards
    Michel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From tracyto41@gmail.com@21:1/5 to Michel Cadot on Wed Mar 14 19:29:10 2018
    On Sunday, February 18, 2018 at 10:28:52 PM UTC+8, Michel Cadot wrote:
    <tracyto41@gmail.com> a écrit dans le message de news: 203ad84c-7b27-4860-a858-fd33cf9d9b7a@googlegroups.com...

    In contrast, using hints to tune a SQL is relatively safer,



    This is wrong and Jonathan Lewis definitively demonstrated it more than a decade ago, demonstration which is still valid in the
    current versions and for all the futures ones.

    You should take advantage to read Oracle documentation which states: https://docs.oracle.com/database/121/SQLRF/sql_elements006.htm#SQLRF00219 https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E

    <quote>
    Hints should be used sparingly, and only after you have collected statistics on the relevant tables and evaluated the optimizer plan
    without hints using the EXPLAIN PLAN statement. Changing database conditions as well as query performance enhancements in subsequent
    releases can have significant impact on how hints in your code affect performance.
    </quote>

    And you still did not answer to the pertinent remarks made by Nuno, Mladen and Ed in one of your previous threads about your
    "product".
    Go away ignorant spammer!

    Regards
    Michel

    If collect statistics works, you should do it first. We are talking SQL tuning to make a SQL run faster. Only hints application can be used in SQL Patches or SQL Plan baselines, it is very important in source free SQL tuning.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)