Summary of this chapter
------------------------------------------------------
Tuning technology and when to use it
------------------------------------------------------
It is absolutely necessary to ask yourself the following three questions:
~ Is this SQL statement known and determined to be constant?
~ What measures will be taken to affect one SQL statement or all SQL statements for a single session (or even the entire system)?
~ Is it possible to change this SQL statement?
7.1 Changing the access structure
The response time of an SQL statement often depends not only on how the data is stored, but also on how the data is accessed.
When you question the current SQL statement, the first thing you need to do is check the current access structure, get the information from the data dictionary, and answer the following questions:
~ What is the structure type of the table involved in the statement? Heap table, index organization table, or external table? and is the table stored in the cluster?
~ is the materialized view containing the required data available?
~ What indexes exist in tables, clusters, and materialized views? What fields are these indexes based on, and what are the order of those fields?
~ How are all these data segments (tables, indexes, and other logical storage structures) partitioned?
When you want to change the access structure, the most important thing is to carefully consider the possible side effects.
7.2 Modifying SQL statements
SQL can often submit an exact same request in different ways. Example:
/*The following 4 queries, the returned result sets are the same, but their execution plans are different. SQL can return the same result set in a variety of ways what's the best way to do that? It's a developer's consideration.*/SELECTDeptno fromDeptWHEREDeptno not inch(SELECTDeptno fromEMP);SELECTDeptno fromDeptWHERE not EXISTS(SELECT 1 fromEmpWHEREEmp.deptno=Dept.deptno)SELECTDeptno fromDeptminusSELECTDeptno fromEMPSELECTDept.deptno fromDept, EMPWHEREDept.deptno=Emp.deptno (+) andEmp.deptno is NULL
7-1
7.3 Hints
Specify the hint, and your goal is to reduce the data for the execution plan that the query optimizer will evaluate.
~ Prompt must follow the delete, insert, merge, update keyword.
~ The first character after the comment delimiter must be a plus sign (+)
Categories of hints: many, specific references to Oracle's SQL Reference, 11g can be queried later through the V$sql_hint view
Valid fields for prompt: Prompts only work on a single query block. For example:
--two query blocks specify a hint withEmps as(SELECT /*+ Full (EMP)*/DeptnoCount(*) asCNT fromEMPGROUP bydeptno)SELECT /*+ Full (dept)*/Dept.dname, emps.cnt fromDept, EmpsWHEREDept.deptno=Emps.deptno
7-2
Wait, personal feeling hint in the test when the use of more, the real development, feel not how to use the hint, so this part did not complete, when needed to add it.
In addition, the hint is only for the query optimizer to make a reference, the query optimizer may not necessarily use hints.
7.4 Changing the execution environment
To modify a lot of parameters, personally feel that the default is OK, and then confirm it
7.5 SQL Overview
Graphics sector something, but it feels like a charge or something, now skip
To summarize, what I can use now is to change the access structure, modify the SQL statements, and use hints to test them.