create table test_c(id number,name char(100),address char(100),create_date date); create table test_p(id number,name char(100)); declare v_m number; begin for i in 1..10000000 loop select round(dbms_random.value() * 44444444444) + 1 into v_m from dual t; insert into test_c values (i, 'My _name'||dbms_random.value(),'My _name'||dbms_random.value(),sysdate); end loop; commit; end; declare v_m number; begin for i in 1..10000000 loop select round(dbms_random.value() * 44444444444) + 1 into v_m from dual t; insert into test_p values (i, 'My _name'||dbms_random.value()); commit; end loop; end; SQL> create index i1_test_c on test_c(id); SQL> create index i1_test_p on test_p(id);
The following query may pick adaptive plan.But this depend on your environment.
SQL> variable var1 number; SQL> variable var2 number; SQL> exec :var1:=1; PL/SQL procedure successfully completed. SQL> exec :var2:=1000; PL/SQL procedure successfully completed. SQL> set autotrace traceonly; SQL> select /*+ gather_plan_statistics */ a.name,a.address,b.id from test_c a,test_p b where a.id=b.id and b.id between :var1 and :var2 order by a.name;
1000 rows selected.
SQL> SET LINESIZE 200 PAGESIZE 100 SELECT * FROM TABLE(DBMS_XPLAN.display_cursor(format => 'allstats last adaptive'));
exec :var2:=1000; SQL>set autotrace traceonly; SQL> select /*+ gather_plan_statistics */ a.name,a.address,b.id from test_c a,test_p b where a.id=b.id and b.id between :var1 and :var2 order by a.name; 1000 rows selected.
SQL> set linesize 200 pagesize 100; SQL> SELECT * FROM table(dbms_xplan.display_cursor('fwhp6ukwmb1fj', 0, 'iostats last'));
exec :var2:=1000; Elapsed: 00:02:02.74 SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(format => 'ADVANCED')); PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- SQL_ID fwhp6ukwmb1fj, child number 2 ------------------------------------- select /*+ gather_plan_statistics */ a.name,a.address,b.id from test_c a,test_p b where a.id=b.id and b.id between :var1 and :var2 order by a.name Plan hash value: 3508152348
Query Block Name / Object Alias (identified by operation id):
————————————————————-
1 – SEL$1
4 – SEL$1 / B@SEL$1
5 – SEL$1 / A@SEL$1
6 – SEL$1 / A@SEL$1
Outline Data
————-
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE(‘12.1.0.2’)
DB_VERSION(‘12.1.0.2’)
ALL_ROWS
OUTLINE_LEAF(@”SEL$1″)
INDEX_RS_ASC(@”SEL$1″ “A”@”SEL$1” (“TEST_C”.”ID”))
BATCH_TABLE_ACCESS_BY_ROWID(@”SEL$1″ “A”@”SEL$1″)
INDEX(@”SEL$1” “B”@”SEL$1” (“TEST_P”.”ID”))
LEADING(@”SEL$1″ “A”@”SEL$1” “B”@”SEL$1″)
USE_HASH(@”SEL$1” “B”@”SEL$1″)
SWAP_JOIN_INPUTS(@”SEL$1” “B”@”SEL$1”)
END_OUTLINE_DATA
*/
Peeked Binds (identified by position):
————————————–
1 – :VAR1 (NUMBER): 1
2 – :VAR2 (NUMBER): 1000
Predicate Information (identified by operation id):
—————————————————
2 – filter(:VAR2>=:VAR1)
3 – access(“A”.”ID”=”B”.”ID”)
4 – access(“B”.”ID”>=:VAR1 AND “B”.”ID”<=:VAR2)
6 – access(“A”.”ID”>=:VAR1 AND “A”.”ID”<=:VAR2)
Column Projection Information (identified by operation id):
———————————————————–
1 – (#keys=1) “A”.”NAME”[CHARACTER,100], “B”.”ID”[NUMBER,22],
“A”.”ADDRESS”[CHARACTER,100]
2 – “B”.”ID”[NUMBER,22], “A”.”ADDRESS”[CHARACTER,100], “A”.”NAME”[CHARACTER,100]
3 – (#keys=1) “B”.”ID”[NUMBER,22], “A”.”ADDRESS”[CHARACTER,100],
“A”.”NAME”[CHARACTER,100]
4 – “B”.”ID”[NUMBER,22]
5 – “A”.”ID”[NUMBER,22], “A”.”NAME”[CHARACTER,100], “A”.”ADDRESS”[CHARACTER,100]
6 – “A”.ROWID[ROWID,10], “A”.”ID”[NUMBER,22]
73 rows selected.
select sql_text,sql_id,executions,users_executing,invalidations,disk_reads,buffer_gets,optimizer_cost,cpu_time,elapsed_time,rows_processed,is_bind_sensitive from v$sql where sql_id='fwhp6ukwmb1fj'
SELECT DBMS_SQLTUNE.report_sql_monitor(sql_id => ‘fwhp6ukwmb1fj’, type => ‘HTML’, report_level => ‘ALL’) AS report FROM dual;
SQL> select * from table(dbms_xplan.display_awr('fwhp6ukwmb1fj'));
sqlplus / as sysdba SQL> @?/rdbms/admin/awrsqrpt.sql Type Specified: html Enter value for num_days: 1 Enter value for begin_snap: 11949 Begin Snapshot Id specified: 11949 Enter value for end_snap: 11957 End Snapshot Id specified: 11957 Specify the SQL Id ~~~~~~~~~~~~~~~~~~ Enter value for sql_id:Enter SQL_ID to check