sql优化

1分页语句

SELECT *
  FROM (SELECT t1.*, ROWNUM AS rowno
          FROM (
               sql
          ) t1
         WHERE ROWNUM <= 10) rsl
 WHERE rsl.rowno > 0

2--强制走索引
/*+ index(表名 索引名)*/

3--嵌套循环
/*+leading(t2) use_nl(t2,t1)*/

4Oracle获取sql_id,child_number

select sql_id,child_number,sql_text,last_load_time from v$sql order by last_load_time desc;

或(推荐)

  select sql_id,child_number,sql_text,last_load_time from v$sql where UPPER(sql_text) like 
UPPER('%你的sql语句%') order by last_load_time desc;

select /* recentsql */ sql_id,child_number,hash_value,address,executions,
sql_text from v$sql
 where parsing_user_id=(select user_id from all_users where username='你的Oralce用户')
 and command_type in (2,3,6,7,189)
  and UPPER(sql_text) not like UPPER('%recentsql%');

注:可以通过一段注释来唯一标识sql语句

5获取a-time执行计划

步骤8为前提

select * from table(dbms_xplan.display_cursor('bykuuz4yz35yg','0','ALLSTATS LAST'));

6创建索引

create index index_name on table_name(列1,列2 ...) [global/local];

7删除索引

drop index 索引名

8搜集统计信息

alter system set statistics_level=all;或在查询sql语句中加/*+ gather_plan_statistics full(test)*/

9???

sql优化_第1张图片

你可能感兴趣的:(database)