PDF Translator 1693652510100
PDF Translator 1693652510100
If the working ability of the database is to be greatly improved, the hardware facilities of the server must be upgraded. According to IT industry statistics
like
According to statistics, 70% of the improvement of database capacity depends on the quality of server hardware. In the remaining 30% that can be manually t
Inside is the space for database managers to show their skills.
In terms of improving system optimization by hardware and management personnel, many people think that the skills of management personnel are more imp
As much as 90% of the proportion of system optimization. For this discussion, we can draw an analogy: if the hardware is a house, the application
The system is like furniture and decoration. If the house has been given, the manager's job is just how to adjust the position of the furniture
The location makes the house look more pleasing to the eye and more comfortable. Hardware facilities, for application software, if the facilities are too good, it is a
resources, but it is better than a house too small, too much furniture, difficult to arrange the dilemma. Many times, data administrators and system administrators
There is no way for the staff to have decisive rights to the configuration of the hardware. What they can do is to implement the
optimized to the maximum.
The industry has also conducted a survey on the division of this space that can be improved artificially, and the results are shown in Figure 25-1.
As can be seen from Figure 25-1, among the parts that can be adjusted manually, 60% of the problems occur in the SQL part; 20% of the problems occur in the
The problem occurs in the design part of the database. Both parts are done by the developer. as a real database administrator
DBA, the tuning and adjustment of the database can only achieve a maximum of 18% of the human-adjustable share, accounting for 5.4% of the entire system adju
That's all. System administrators accounted for an even smaller share, just 2% of human system adjustments, accounting for 0.6% of the overall system.
Therefore, the joke in the industry is that the optimal state required by the system is achieved in this way:
Index (Index), as the name suggests, is the fastest path to find the required data. In SQL tuning, the use of indexes,
Is a convenient way to avoid a full table scan of the table being queried when performing a query operation. When updating the data or
Or delete operation, the use of indexes can also improve performance.
Another function of the index is to enforce the control of data integrity. As we all know, in two cases, the system will automatically
The columns of the table are indexed:
(1) When the column of the table is designated as the primary key.
(2) When the column of the table has a unique constraint.
When a foreign key exists in a table, it is usually recommended to use an index for this column. When inserting data into a table
When checking whether the inserted data is duplicated with the existing data, it is the index check of the columns of PK and UK. When FK
When there is an index on the column, if you insert or update data to its parent table, it is not the child table that is locked, but the FK column of the child table
face index. However, Oracle has gradually changed some operating methods since version 9i.
Listed below are some frequently asked questions about index management for your reference.
For applications using the Oracle Cost Based Optimizer (CBO), for databases in daily use, it is recommended
The entire database is analyzed every day. Of course, this is based on the fact that the database is not very large. Generally, the analysis can take 30 to 60 minutes
Finished around. If it is a large database, it is enough to analyze only the tables with large data changes every day, and for static tables that do not change
The table does not need to be analyzed every day.
In Oracle version 7.x, Oracle provides two methods of table analysis: ANALYZE DBMS_UTILITY
Oracle, starting with its version 8.1.5, recommends using the DBMS_STATS package. It is worth noting that many DBAs reflect
It is said that the DBMS_STATS package has many bugs. My environment currently still uses ANALYZE and DBMS_UTILITY.
If the analysis work of the database is run regularly every day, when a performance problem occurs, can it be ignored?
Is there a problem with statistics?
In fact, it is still necessary to check the time when the table and index were last analyzed. If a table happens to be done that day
drop/import, the unanalyzed data of that table exists in the system table. If it happens that this table is a large query
Correlation table needed, which is likely to be bad. If you are not sure whether someone has moved the database, check the table score
The time for analysis is mostly beneficial and harmless.
2. number of indexes
Many programmers believe that all columns in where clauses should be indexed. This kind of thinking is wrong. Overbuilt
Indexing, and too few indexes will greatly affect the performance of the database.
Why does too much indexing affect performance?
When insert/update/delete operations are performed on the data in the table, the data in the index will also be updated accordingly. if not one
For a read-only table, an index needs a balance point to improve performance or reduce performance for query and update data. and
This balance is difficult to grasp. Remember the information I read many years ago, Oracle recommends that the columns of the index should not exceed the numb
40% of the number of columns. Another question derived from this topic is when to build an index and what kind of index to build
Improving the performance of the database is the most beneficial, which is a rather complicated issue.
If the entire table really needs to be indexed, consider whether IOT (Indexed Organized Table) is possible. IoT
Applicable to lookup data, search by PK to force data to be sorted according to PK to provide better clustering factor,
Reduce the cost of range scan. Therefore, IOT also has many restrictions. For example, the data in the table should preferably be static. It is recommended that the
Don't wait too long.
354 Oracle Database Performance Optimization
There are many kinds of indexes, and not all databases support all kinds of indexes. Commonly used are the following. B-Tree: The most commonly used inde
All books on data structures and algorithms. FBI (Function Based Index): When the function is used in the where statement, the B-tree index cannot be used.
The way to change is to use the FBI index. Updating the FBI is relatively expensive for a table that is updated frequently
Affection. Also, Rule Based Optimizer does not support FBI indexes. Bitmap: Bitmap index is not supported by all databases, and Oracle database is only supporte
Support for Bitmap indexing. Bitmap indexes are suitable for tables that are read statically, and the columns on which the indexes reside are low cardinality. data w
The environment is the best environment for the Bitmap index to function.
Many times, the correct column of the table has the correct index, but some queries use the index on the column, and
Without being used, queries are unacceptably slow. Oracle explains that there are many situations that lead to Oracle's optimization
The Optimizer cannot use the index. At this time, you need to modify the SQL to force the SQL statement to use the index. now only
We only know that in the following situations, the index is not used, and the affected tables must be retrieved from the full table (full table
scan).
Here we use the table scott.emp to do the experiment, in addition to the primary key above the original empno, in comm, mgr,
Indexes are also created on the three columns of the job:
SQL> select table_name, index_name, column_name from user_ind_columns where table_name='EMP';
SQL> DESC EMP Name Null? Type -------------------------------------------- - ------- ---------------------------- EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(
SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- -- -------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20
Chapter 25 Introduction to Index (Index) for Oracle Database Optimization 81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-
14 rows selected.
---------- ---------- --------- ---------- --------- -- -------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-
7 rows selected.
Execution Plan
-------------------------------------------------- -------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=8 Bytes=296 ) 1 0 TABLE ACCESS (FULL) OF 'E
Statistics
-------------------------------------------------- -------- 1 recursive calls 0 db block gets 8 consistent gets 0 physical reads 0 redo size 1043 bytes se
356 Oracle Database Performance Optimization 0 sorts (memory) 0 sorts (disk) 7 rows processed
(2) Null value. Normally, Null values do not exist in the index. If is null or is not appears in the where statement
When null, the index cannot be used (comm._tst is not used).
SQL> select * from emp where comm is not null; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- -- -------- ---------- ---------- 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7
Execution Plan
-------------------------------------------------- -------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=4 Bytes=148 ) 1 0 TABLE ACCESS (FULL) OF 'E
Statistics
-------------------------------------------------- -------- 0 recursive calls 0 db block gets 8 consistent gets 0 physical reads 0 redo size 902 bytes sen
(3) When there is a not function in the where statement, such as not in, not exist, column <> value, column1
In the case of > value or column2 < value, the index cannot be used.
SQL> select * from emp where comm <> 1000; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- -- -------- ---------- ---------- 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7
Execution Plan
Chapter 25 Introduction to Oracle Database Optimization Index (Index) 357
-------------------------------------------------- -------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=3 Bytes=111 ) 1 0 TABLE ACCESS (FULL) OF 'E
Statistics
-------------------------------------------------- -------- 1 recursive calls 0 db block gets 8 consistent gets 6 physical reads 0 redo size 902 bytes sen
(4) When the single-row function is used, such as nvl, to_char, lower, etc., the index cannot be used.
SQL> select ename, nvl(comm, 0) from emp;
ENAME NVL(COMM,0)
---------- -----------
SMITH 0
ALLEN 300
WARD 500
JONES 0
MARTIN 1400
BLAKE 0
CLARK 0
SCOTT 0
KING 0
TURNER 0
Adams 0
JAMES 0
FORD 0
MILLER 0
14 rows selected.
Execution Plan
-------------------------------------------------- -------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=14 Bytes=11 2) 1 0 TABLE ACCESS (FULL) OF '
(5) When using the wildcard symbol % or _ as the first character of the query string, for example, in the statement "where name
like ' %xxxx ' ", the index cannot be used (for this case, many databases now support the so-called "full-text
Retrieve Index", can solve this problem well). However, if the first word of the query string is determined, such as "where name
like ' a% ' ", you can use the index.
SQL> select ename, job from emp where job like '%C%';
ENAME JOB
---------- ---------
SMITH CLERK
Adams Clerk
JAMES CLERK
MILLER CLERK
Execution Plan
-------------------------------------------------- -------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=1 Bytes=14) 1 0 TABLE ACCESS (FULL) OF 'EMP
Statistics
-------------------------------------------------- -------- 1 recursive calls 0 db block gets 8 consistent gets 0 physical reads 0 redo size 497 bytes sen
SQL> select ename, job from emp where job like 'C%';
ENAME JOB
---------- ---------
SMITH CLERK
Adams Clerk
JAMES CLERK
MILLER CLERK
Execution Plan
-------------------------------------------------- -------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=3 Bytes=42) 1 0 TABLE ACCESS (BY INDEX ROWI
Statistics
-------------------------------------------------- -------- 1 recursive calls 0 db block gets 4 consistent gets 1 physical reads 0 redo size 497 bytes sen
5. index rebuild
The so-called index rebuilding generally refers to rebuilding the B-Tree index. For tables that are frequently updated, when inserting data,
Attached to the back of the index block (block) above the corresponding PCTFREE List, if the data contained in this block reaches the PTCFREE
According to the regulations, the block where the index data is located will be split into two. To a certain extent, the B-Tree index may be deepened by one level (sp
move down to next level). When a table deletes a lot of data, the space occupied by these data in the index cannot
was released for reuse.
For what kind of situation, the table must be rebuilt. Long ago, Oracle once suggested that in the following two situations,
Index needs to be rebuilt: When the index has more than 4 levels. The deleted data in the index exceeds 20% of the total index data (because this data is analyzed f
In many cases, the results of table and index analysis force the CBO to use these results for SQL optimization.
calculation).
SQL> analyze index abcd validate structure;
SQL> select (del_lf_rows_len/lf_rows_len)*100 as index_usage From index_stats Where index_name = 'ABCD';
In recent materials, Oracle no longer gives the criteria for rebuilding the index, and it seems that it depends on the wishes of the DBA to decide whether to rebu
index.
360 Oracle Database Performance Optimization
For the database I manage, I use the simplest method to judge whether the index needs to be rebuilt. The databases I manage,
Indexes are concentrated in 2 to 3 table spaces (tablespace). I use the tablespace management tool Tablespace Map in EM
Analyze the table space, and if there is a red flag in the index, I will rebuild the index. So far this method is very economical
Save time and effort.
Next, there are several issues that need to be paid attention to in actual operation.
1. How to find out that the table has too few indexes
This problem seems to be very simple. If full table scan is displayed on the explain plan, and the relevant columns have no indexes,
And you need to create an index, so please create one.
If it is an infrequently used query, or a one-time query, if it takes half an hour to build an index, the query can be
The running time is shortened by 2 hours, or 3 hours, or more, you can consider creating a temporary index first, and after running
Delete it later.
2. How to find out that the table has too many indexes
This problem is much more troublesome, and it is usually necessary to check the tables one by one to find the problem. For a number with only three or four ta
According to the database, it may not be difficult to check the tables one by one. For a database with two or three hundred tables, it can be done by filtering it caref
For a database in an ERP environment, it is almost an impossible task. The new version of the PeopleSoft Financial database,
The number of tables is as high as more than 7000, and the number of indexes has reached 5000. Too many indexes are a common problem. but for this
The package software provided by this manufacturer, the DBA can hardly make any changes.
Therefore, it is found that the performance problems caused by too many indexes on the table are usually only for applications developed by the company, or w
When the user cannot bear the performance problem, it is possible to find the root of the problem, and the solution must also be developed
After the approval of the personnel, jointly determine the improvement method. Generally speaking, the DBA is unable to understand the details of many applicatio
Objects created by others must never be easily deleted, even if the DBA is sure that the Object is useless.
The way to find that there are too many indexes in a table is to list all the indexes in a table. Find out if there are duplicate indexes created,
If there is an index with the same function, then delete it.
Starting from the 9i version of the Oracle database, the function of monitoring whether the index is used has been added, so that the database administrator c
Easily find indexes that are never used, or rarely used. This function is the following SQL command:
Alter index <index_name> monitoring usage;
Alter index <index_name> nomonitoring usage;
Pay attention to the bug of Index Monitoring, which cannot monitor the index of Sys. Oracle announced the revision after version 9.2.0.5
Corrected this problem. In addition, the index that is not used is displayed. If it is a Unique Index, it may not be able to Drop. Some are for
Needed by Unique Constraint.
Oracle recommends using it only when you need to monitor index usage. While monitoring does not cause any major performance issues,
However, every time index monitoring is used, the relevant part of the index in the explain plan must be run repeatedly, instead of
Reuse the already generated explain plan.
3. rebuild index
Since Oracle supports the rebuild online function, generally smaller indexes can be rebuilt at any time
Online is no longer a problem. The main aspect is how to judge whether the index needs to be rebuilt (discussed earlier).
For relatively large indexes, it is recommended to do it during non-busy hours. rebuild takes slightly longer to run than rebuild online
Be quick.
(Thanks to Mr. You Lixin, the super moderator of itpub.net easyfree, for providing the EZSQL tool)
EZSQL This small tool is the predecessor of Quest's famous management tool TOAD. In Quest Corporation to EZSQL's
The inventor John Dorlon bought out EZSQL and invited him to join Quest to continue developing TOAD. Before EZSQL was
Free download to use. EZSQL is a very small tool with a total size of only 1.57 MB, but it is small and full of internal organs.
Complete. Among them, the GUI interface for monitoring index usage status is simple and easy to use, as shown in Figure 25-3.
When writing this article, I searched the Internet and found that there are two versions available for download on oradb.net
Download, the address is as follows. http://www.oradb.net/book/Ezsql2.3.15.6677.rar http://www.oradb.net/book/19818ezsqlexe.zip
DB Expert for Oracle also has strong functions in adjusting and monitoring indexes. But this tool requires payment
of. In addition, LECCO has been acquired and merged by Quest. I don't know the current upgrade status of this software, and
The cost of the purchase.
The index monitoring function of DB Export for Oracle is shown in Figure 25-4.
The index tuning function of DB Export for Oracle is shown in Figure 25-5.
prompt
ACCEPT spoolfile CHAR prompt 'Output-file : ';
ACCEPT schema CHAR prompt 'Schema name (% allowed) : ';
prompt
prompt
prompt Rebuild the index when:
prompt - deleted entries represent 20% or more of the current entries
prompt - the index depth is more then 4 levels.
prompt Possible candidate for bitmap index :
prompt - when distinctiveness is more than 99%
prompt
spool &spoolfile
364 Oracle database performance optimization cursor c_indx is select owner, table_name, index_name from dba_indexes where owner like upper('&schema') and owne
begin dbms_output.enable (1000000); dbms_output.put_line ('Owner Index Name % Deleted Entries Blevel Distinctiveness'); dbms_output.put_line ('------- ---
--
-- Index is considered as candidate for rebuild when:
-- - when deleted entries represent 20% or more of the current entries
-- - when the index depth is more then 4 levels.(height starts counting from 1 so > 5)
-- Index is (possible) candidate for a bitmap index when:
-- - distinctiveness is more than 99%
-- if ( height > 5 ) OR ( (del_lf_rows/lf_rows) > 0.2 ) then dbms_output.put_line (rpad(r_indx.owner,16,' ') || rpad(r_indx.index_name,40,' ') || lpad (ro
spool off
set verify on
--************************************************ ***************************
--Copyright 2004 by Rampant TechPress Inc.
-- Free for non-commercial use!
-- To license, e-mail [email protected]
break on c1 ship 2
select
to_char(sn.begin_interval_time, 'yy-mm-dd hh24') c1,
p. search_columns c2,
count(*) c3
from
dba_hist_snapshot sn,
dba_hist_sql_plan p,
dba_hist_sqlstat st
where
st.sql_id = p.sql_id
and
sn.snap_id = st.snap_id
and
p.object_name = '&idxname'
group by
begin_interval_time, search_columns;