Dynamic Oracle 11g sampling

Source: Internet
Author: User

Recently, I encountered a performance problem caused by dynamic sampling, which is a bit difficult for me to understand. by reading the document and doing experiments, I will summarize it as follows:
Let's take a look at the Online Document's explanation of dynamic adoption.
Oracle 10GR2 documentation:
This dynamic sampling feature is controlled by the OPTIMIZER_DYNAMIC_SAMPLING parameter.
For dynamic sampling to automatically gather the necessary statistics, this parameter shocould be set to a value of 2 or higher.
The default value is 2. See "Dynamic Sampling Levels" for information about the sampling levels that can be set.

Oracle 11GR2 documentation:
When the Optimizer Uses Dynamic Sampling
During compilation, the optimizer decides whether to use dynamic sampling based on a number of factors,
Including whether the statements use parallel processing or serial processing.
For parallel statements, the optimizer automatically decides whether to use dynamic sampling and which level to use.
The demo-depends on the size of the tables and the complexity of the predicates. The optimizer expects parallel statements to be
Resource-intensive, so the additional overhead at compile time is worth it to ensure the best plan. The database ignores the OPTIMIZER_DYNAMIC_SAMPLING setting
Unless set to a nondefault value, in which case the value is honored.
For serially processed SQL statements, the dynamic sampling level depends on the value of the OPTIMIZER_DYNAMIC_SAMPLING parameter and
Is not triggered automatically by the optimizer. Serial statements are typically short-running, so that any overhead at compile time
Cocould have a huge impact on their performance.
Note: we have noticed that 11.2.0 is unavailable. * If the statement is executed in parallel, whether to use dynamic sampling and level is determined by the table size and the complexity of table join in SQL, that is, CBO determines the sampling level value.
CBO ignores the default value of OPTIMIZER_DYNAMIC_SAMPLING. For Oracle's various features, if there are automatic functions, more or less unstable, there will always be problems. Of course, the level of the serial execution statement that is still dynamically sampled will still be determined by OPTIMIZER_DYNAMIC_SAMPLING. In fact, level 2 is sufficient in most cases.

Let's take a look at the dynamic usage in 11.2.0.3.

  1. SQL>Create table leo (id number,
  2. 2 leo_date date,
  3. 3 value varchar2 (20 ),
  4. 4 name varchar2 (30) tablespace users;
  5. Table created.
  6. <SPAN Style="FONT-FAMILY: 'comic Sans Ms '">Generate million data with a random number and insert it into the table.</SPAN>
  7. SQL>Insert into leo
  8. 2 select rownum id, sysdate-dbms_random.value (1,500) leo_create,
  9. 3 dbms_random.string ('1', 15) value,
  10. 4 dbms_random.string ('1', 20) name
  11. 5 from dual
  12. 6 * connect by level<= 1e6;
  13. 1000000 rows created.
  14. SQL>Commit;
  15. Commit complete

Note: Do not collect statistics

  1. SQL>Show parameter optimizer
  2. NAME TYPE VALUE
  3. -------------------------------------------------------------
  4. Optimizer_dynamic_sampling integer 2
  5. Optimizer_features_enable string 11.2.0.3
  6. SQL>Explain plan for select * from leo;
  7. Explained.
  8. SQL>@ Explain
  9. PLAN_TABLE_OUTPUT
  10. ----------------------------------------------------------------------------
  11. Plan hash value: 1174476904
  12. --------------------------------------------------------------------------
  13. | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
  14. --------------------------------------------------------------------------
  15. | 0 | select statement | 897K | 43M | 2105 (2) | 00:00:26 |
  16. | 1 | table access full | LEO | 897K | 43M | 2105 (2) | 00:00:26 |
  17. --------------------------------------------------------------------------
  18. Note
  19. -----
  20. -Dynamic sampling used for this statement (Level=2)
  21. 12 rows selected.
  22. SQL>Explain plan for select/* + parallel */* from leo;
  23. Explained.
  24. SQL>@ Explain
  25. PLAN_TABLE_OUTPUT
  26. Bytes -----------------------------------------------------------------------------------------------------------------
  27. Plan hash value: 3240177498
  28. Bytes -------------------------------------------------------------------------------------------------------------
  29. | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time | TQ | IN-OUT | PQ Distrib |
  30. Bytes --------------------------------------------------------------------------------------------------------------
  31. | 0 | select statement | 897K | 43M | 1166 (2) | 00:00:14 |
  32. | 1 | px coordinator |
  33. | 2 | px send qc (RANDOM) |: TQ10000 | 897K | 43M | 1166 (2) | 00:00:14 | Q1, 00 | P->S | QC (RAND) |
  34. | 3 | px block iterator | 897K | 43M | 1166 (2) | 00:00:14 | Q1, 00 | PCWC |
  35. | 4 | table access full | LEO | 897K | 43M | 1166 (2) | 00:00:14 | Q1, 00 | PCWP |
  36. Bytes --------------------------------------------------------------------------------------------------------------
  37. Note
  38. -----
  39. -Dynamic sampling used for this statement (Level=6)
  40. --Automatic DOP: skipped because of IO calibrate statistics are missing
  41. 16 rows selected.
  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.