v$sql,v$sqlarea,v$sqltext,v$open_cursor
4张表区别:
v$sql:跟v$sqlarea的明细表,v$sqlarea是v$sql 通过对hash_value,sql_id 这两个值group by 得来的,v$sqlarea 进行了group by,v$sql没有进行group by。
v$sql:lists statistics on shared SQL area without the GROUP BY clause and contains one row for each child of the original SQL text entered. Statistics displayed in V$SQL are normally updated at the end of query execution. However, for long running queries, they are updated every 5 seconds. This makes it easy to see the impact of long running SQL statements while they are still in progress.
v$sqltext:This view contains the text of SQL statements belonging to shared SQL cursors in the SGA. 一条sql分多行,需要piece进行整合。
v$sqlarea;V$SQLAREA是v$sql的汇总表,进行了group by hash_value,sql_id的汇总。 lists statistics on shared SQL area and contains one row per SQL string. It provides statistics on SQL statements that are in memory, parsed, and ready for execution.,一条sql一行。
v$open_cursor:ists cursors that each user session currently has opened and parsed.
这4张表中,ADDRESS,HASH_VALUE,SQL_ID 标示的意思都一样,而且字段名一样,若对应相同的sql语句,他们的这3个值都是相同的
sql语句可以被一个cursor下的多个child cursor打开多次,但用的都是同一个hash_value,每打开一次就会在v$sql下多一条记录,但v$sqlarea是对hash_value,和sql_id 进行group by 后,在其他列上进行汇总后的值,所以v$sqlarea对每一个hash_value 只有一条记录,但可对应。
两个实用的sql:
--根据操作系统top进程的PID找到相应的session和正在执行的sql,关联的时候一般用hash_value关联,虽然address也是可以关联到的(address都是逻辑的概念),关联sql 语句的时候,sql_id,address()
select b.spid,a.sid,a.username,s.hash_value,s.sql_text
from v$session a , v$process b, v$sqlarea s
where a.PADDR = b.ADDR and a.sql_hash_value = s.hash_value and b.spid=&PID;
--有时是没有显示的,说明是系统运行的sql(此时sql_address为00,sql_hash_value为0,SQL_ID为null),若是用户运行的sql是有显示的
--根据操作系统top进程的PID找到相应的session和该session执行过的sql
select b.spid,a.sid,a.username,c.hash_value,c.SQL_ID,c.sql_text
from v$session a,v$process b,v$open_cursor c
where a.sid=c.sid
and b.ADDR=a.PADDR
and b.spid=&PID;
==end==