关于oracle:Oracle-固定执行计划之SqlPatch二

11次阅读

共计 1647 个字符,预计需要花费 5 分钟才能阅读完成。

明天在 19c 上又做了一次 SqlPatch,发现上次写的在 11gR2 的办法总是报错,于是又看了 19c 的 Online Documents。更新了一下 SqlPatch 的做成办法。

  1. 做成 TEST 用户和 Table,Index。
 SQL> grant connect,resource,unlimited tablespace to test3 identified by test3;

 権限付与が胜利しました。SQL> grant administer sql management object to test3;

 権限付与が胜利しました。SQL> conn test3/test3@localhost:1521/pdb
 接続されました。SQL> create table tab2(c1 number, c2 number, c3 varchar2(10));

 表が作成されました。SQL> declare
   a number;
 begin
   a := 1;
   for i in 1 .. 50 loop
 for j in 1 .. 100 loop
   insert into tab2 values(a,j,'a');
   commit;
   a := a+1;
 end loop;
   end loop;
 end;
 /

 PL/SQL プロシージャが失常に完了しました。SQL> create index ind2_2 on tab2(c2);

 索引が作成されました。

2. 做成 SQLPATCH。

SQL> var cnt varchar2(200);
SQL> exec :cnt := DBMS_SQLDIAG.CREATE_SQL_PATCH (sql\_text => TO_CLOB('select \* from tab2 where c2=1'),hint_text => TO_CLOB('INDEX_RS_ASC(@"SEL$1""TAB2"@"SEL$1" ("TAB2"."C2"))'));

PL/SQL プロシージャが失常に完了しました。
  1. 验证 SQLPATCH。
SQL> set autot traceonly exp
SQL> set lin 120 pages 999
SQL> select * from tab2 where c2=1;

実行計画
----------------------------------------------------------
Plan hash value: 616764305

----------------------------------------------------------------------------------------------
| Id  | Operation   | Name   | Rows  | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT||50 |  1650 |11   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| TAB2   |50 |  1650 |11   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN  | IND2_2 |50 |   | 1   (0)| 00:00:01 |
----------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("C2"=1)

Note
-----
- dynamic statistics used: dynamic sampling (level=2)
- SQL patch "SYS_SQLPTCH_0178349b7d430005" used for this statement
正文完
 0