Oracle Database optimization-Analyze existing SQL

Source: Internet
Author: User
Tags what sql

In the database SQL optimization, the first is to optimize the existing database SQL, mainly including the following:

1. What SQL is the database executing?

2, has been executed SQL is?

3. What is the most time-consuming first few SQL?

4. What is the most IO-consuming SQL?

5. What is the plan for a SQL execution? Does the optimization strategy on a SQL function?

The following will be stated separately for the above cases.

One, query the SQL that is being executed.

Select A.username, A.sid,b.sql_text, B.sql_fulltext
From V$session A, V$sqlarea b
where a.sql_address = b.address and B.parsing_schema_name= ' GTSPM ' #PARSING_SCHEMA_NAME a user name

Second, the query has been executed SQL

Select B.sql_text,b.first_load_time,b.sql_fulltext
From V$sqlarea b WHERE b.parsing_schema_name= ' GTSPM ' ORDER by first_load_time Desc

Third, the query performance of the worst first n sql

SELECT * FROM (select Parsing_user_id,executions,sorts,
Command_type,disk_reads,sql_text from V$sqlarea WHERE parsing_schema_name= ' GTSPM '
ORDER by Disk_reads DESC) where rownum<10;

Four, the most IO-consuming SQL

SELECT SE.SID,SE.SERIAL#,PR. Spid,se.username,se.status,
Se.terminal,se.program,se. Module,se.sql_address,st.event,st.
P1text,si.physical_reads,
Si.block_changes from V$session Se,v$session_wait St,
V$sess_io si,v$process PR WHERE St.sid=se.sid and St.
Sid=si.sid and SE. Paddr=pr. ADDR and Se.sid>6 and St.
Wait_time=0 and st.event not like '%sql% ' ORDER by Physical_reads DESC

Five, query the execution plan of SQL.

See if the index is valid, whether full table scan is performed, and whether the index is used properly.

Oracle Database optimization-Analyze existing SQL

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.