-
Notifications
You must be signed in to change notification settings - Fork 849
/
Copy pathexample.lst
759 lines (637 loc) · 25.5 KB
/
example.lst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
SQL>
SQL> alter system flush shared_pool;
System altered.
SQL>
SQL> @user
SQL> connect / as sysdba
Connected.
SQL>
SQL> create user spmtest identified by spmtest;
create user spmtest identified by spmtest
*
ERROR at line 1:
ORA-01920: user name 'SPMTEST' conflicts with another user or role name
SQL> grant dba to spmtest;
Grant succeeded.
SQL>
SQL> connect spmtest/spmtest
Connected.
SQL>
SQL> PROMPT
SQL> PROMPT **** It is easy to drop SQL plan baselines for a specific schema...
**** It is easy to drop SQL plan baselines for a specific schema...
SQL> PROMPT
SQL> @util/dropu SPMTEST
SQL> REM
SQL> REM Drop SQL plan baselines for a specified user
SQL> REM
SQL>
SQL> DECLARE
2 l_plans_dropped PLS_INTEGER;
3 BEGIN
4 FOR REC IN (SELECT DISTINCT SQL_HANDLE FROM DBA_SQL_PLAN_BASELINES WHERE parsing_schema_name = '&1')
5 LOOP
6 L_PLANS_DROPPED := DBMS_SPM.DROP_SQL_PLAN_BASELINE (
7 sql_handle => rec.sql_handle,
8 PLAN_NAME => NULL);
9 END LOOP;
10
11 END;
12 /
old 4: FOR REC IN (SELECT DISTINCT SQL_HANDLE FROM DBA_SQL_PLAN_BASELINES WHERE parsing_schema_name = '&1')
new 4: FOR REC IN (SELECT DISTINCT SQL_HANDLE FROM DBA_SQL_PLAN_BASELINES WHERE parsing_schema_name = 'SPMTEST')
PL/SQL procedure successfully completed.
SQL> @table
SQL> DROP TABLE tab1 purge;
Table dropped.
SQL>
SQL> CREATE TABLE tab1 (id, txt)
2 AS SELECT level, CAST (to_char(level) AS varchar2(10)) FROM dual
3 CONNECT BY level <= 10000
4 /
Table created.
SQL>
SQL> CREATE UNIQUE INDEX tabi ON tab1(id);
Index created.
SQL>
SQL> EXEC dbms_stats.gather_table_stats(USER, 'tab1');
PL/SQL procedure successfully completed.
SQL>
SQL> @q1
SQL> select /* MYSPMTEST */ count(*) from tab1 where id = 100;
COUNT(*)
----------
1
SQL>
SQL> PROMPT **** Capture our query
**** Capture our query
SQL>
SQL> @load
SQL> DECLARE
2 my_plans pls_integer;
3 BEGIN
4 my_plans := DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE(
5 attribute_name => 'SQL_TEXT'
6 ,attribute_value => '%MYSPMTEST%');
7 END;
8 /
PL/SQL procedure successfully completed.
SQL>
SQL> PROMPT **** Display the SQL Plan Baselines
**** Display the SQL Plan Baselines
SQL>
SQL> @util/listu SPMTEST
SQL> REM
SQL> REM List SQL plan baselines for a specified user
SQL> REM
SQL>
SQL> set linesize 200
SQL> set trims on
SQL> set tab off
SQL> column last_executed format a30
SQL> column sql_text format a40
SQL> column sql_handle format a40
SQL> column plan_name format a35
SQL> column signature format 999999999999999999999
SQL>
SQL> select signature,plan_name,sql_handle,sql_text, accepted, enabled
2 from dba_sql_plan_baselines
3 where parsing_schema_name = '&1'
4 /
old 3: where parsing_schema_name = '&1'
new 3: where parsing_schema_name = 'SPMTEST'
SIGNATURE PLAN_NAME SQL_HANDLE SQL_TEXT ACC ENA
---------------------- ----------------------------------- ---------------------------------------- ---------------------------------------- --- ---
10438310272222376619 SQL_PLAN_91r2mwdbk0cpbf7f677e5 SQL_90dc53e3572032ab select /* MYSPMTEST */ count(*) from tab YES YES
1 where id = 100
SQL>
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> PROMPT **** Display the plan for our SQL plan baseline
**** Display the plan for our SQL plan baseline
SQL>
SQL> var handle varchar2(50)
SQL> begin
2 select sql_handle into :handle from dba_sql_plan_baselines where parsing_schema_name = 'SPMTEST';
3 end;
4 /
PL/SQL procedure successfully completed.
SQL>
SQL> SELECT *
2 FROM TABLE(DBMS_XPLAN.DISPLAY_SQL_PLAN_BASELINE(:handle,NULL)) t;
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------
SQL handle: SQL_90dc53e3572032ab
SQL text: select /* MYSPMTEST */ count(*) from tab1 where id = 100
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Plan name: SQL_PLAN_91r2mwdbk0cpbf7f677e5 Plan id: 4160124901
Enabled: YES Fixed: NO Accepted: YES Origin: MANUAL-LOAD
Plan rows: From dictionary
--------------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 4160124901
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 1 | SORT AGGREGATE | | 1 | 4 | 0 (0)| |
|* 2 | INDEX UNIQUE SCAN| TABI | 1 | 4 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=100)
26 rows selected.
SQL>
SQL> PROMPT **** Note that the index is used in the exeution plan
**** Note that the index is used in the exeution plan
SQL> PROMPT
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> PROMPT **** Execute the query again and confirm that it is using the SQL plan baseline
**** Execute the query again and confirm that it is using the SQL plan baseline
SQL>
SQL> @q1
SQL> select /* MYSPMTEST */ count(*) from tab1 where id = 100;
COUNT(*)
----------
1
SQL> @util/plan
SQL> set linesize 200
SQL> set tab off
SQL> set pagesize 1000
SQL> column plan_table_output format a180
SQL>
SQL> SELECT *
2 FROM table(DBMS_XPLAN.DISPLAY_CURSOR(FORMAT=>'LAST'));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID 00axwq5w1q7x3, child number 0
-------------------------------------
select /* MYSPMTEST */ count(*) from tab1 where id = 100
Plan hash value: 4160124901
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 1 | SORT AGGREGATE | | 1 | 4 | | |
|* 2 | INDEX UNIQUE SCAN| TABI | 1 | 4 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=100)
Note
-----
- SQL plan baseline SQL_PLAN_91r2mwdbk0cpbf7f677e5 used for this statement
23 rows selected.
SQL>
SQL> PROMPT **** Note (above) that the SQL plan baseline is being used
**** Note (above) that the SQL plan baseline is being used
SQL> PROMPT
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> PROMPT **** We do not expect to see non-matching SQL execution plans...
**** We do not expect to see non-matching SQL execution plans...
SQL>
SQL> @util/nomatchu SPMTEST
SQL> REM
SQL> REM List SQL statements in the cursor cache that are not
SQL> REM matching a SQL plan baseline but a SQL plan baseline exists.
SQL> REM
SQL> REM You may want to investigate these cases because it implies
SQL> REM that there may have been a change preventing the plan in the
SQL> REM SQL plan baseline from being used.
SQL> REM
SQL> REM This query allows you to specify a particular schema.
SQL> REM
SQL>
SQL> set linesize 200
SQL> set trims on
SQL> set tab off
SQL> column sql_text format a50
SQL> column parsing_schema_name format a30
SQL> column exact_matching_signature format 99999999999999999999
SQL>
SQL> SELECT sql_text,
2 cpu_time,
3 buffer_gets,
4 executions,
5 parsing_schema_name,
6 sql_id,
7 exact_matching_signature
8 FROM v$sql v
9 WHERE executions>0
10 AND sql_plan_baseline IS NULL
11 AND EXISTS (SELECT 1
12 FROM dba_sql_plan_baselines
13 WHERE signature = v.exact_matching_signature
14 AND accepted = 'YES'
15 AND enabled = 'YES'
16 AND parsing_schema_name = '&1')
17 ORDER BY cpu_time;
old 16: AND parsing_schema_name = '&1')
new 16: AND parsing_schema_name = 'SPMTEST')
no rows selected
SQL>
SQL> PROMPT **** Query above returns no rows because all out queries
**** Query above returns no rows because all out queries
SQL> PROMPT **** with SQL plan baselines are using them
**** with SQL plan baselines are using them
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> PROMPT **** Drop the index
**** Drop the index
SQL>
SQL> DROP INDEX tabi;
Index dropped.
SQL>
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> PROMPT **** Execute the query again and confirm that it is NOT using the baselines
**** Execute the query again and confirm that it is NOT using the baselines
SQL> PROMPT because the plan cannot be used - the index has gone
because the plan cannot be used - the index has gone
SQL>
SQL> @q1
SQL> select /* MYSPMTEST */ count(*) from tab1 where id = 100;
COUNT(*)
----------
1
SQL> @q1
SQL> select /* MYSPMTEST */ count(*) from tab1 where id = 100;
COUNT(*)
----------
1
SQL> @util/plan
SQL> set linesize 200
SQL> set tab off
SQL> set pagesize 1000
SQL> column plan_table_output format a180
SQL>
SQL> SELECT *
2 FROM table(DBMS_XPLAN.DISPLAY_CURSOR(FORMAT=>'LAST'));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID 00axwq5w1q7x3, child number 0
-------------------------------------
select /* MYSPMTEST */ count(*) from tab1 where id = 100
Plan hash value: 3961288195
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 7 (100)| |
| 1 | SORT AGGREGATE | | 1 | 4 | | |
|* 2 | TABLE ACCESS FULL| TAB1 | 1 | 4 | 7 (29)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("ID"=100)
19 rows selected.
SQL>
SQL> PROMPT **** Note (above) that the SQL plan baseline is NOT being used
**** Note (above) that the SQL plan baseline is NOT being used
SQL> PROMPT **** because the index has gone.
**** because the index has gone.
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> var planname varchar2(100)
SQL> begin
2 select plan_name into :planname from dba_sql_plan_baselines where parsing_schema_name = 'SPMTEST' and accepted = 'YES';
3 end;
4 /
PL/SQL procedure successfully completed.
SQL>
SQL> column hint format a100
SQL> SELECT extractValue(value(h),'.') AS hint
2 FROM sys.sqlobj$plan od,
3 TABLE(xmlsequence(
4 extract(xmltype(od.other_xml),'/*/outline_data/hint'))) h
5 WHERE od.other_xml is not null
6 AND (signature,category,obj_type,plan_id) = (select signature,
7 category,
8 obj_type,
9 plan_id
10 from sys.sqlobj$ so
11 where so.name = :planname);
HINT
----------------------------------------------------------------------------------------------------
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('12.1.0.2')
DB_VERSION('12.1.0.2')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
INDEX(@"SEL$1" "TAB1"@"SEL$1" ("TAB1"."ID"))
6 rows selected.
SQL>
SQL> PROMPT **** Above - the SQL plan baseline outline hints include an INDEX hint for the index we dropped.
**** Above - the SQL plan baseline outline hints include an INDEX hint for the index we dropped.
SQL> PROMPT **** The query is no longer able to obey this hint.
**** The query is no longer able to obey this hint.
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> PROMPT **** We now expect to find our problem query...
**** We now expect to find our problem query...
SQL> @util/nomatchu SPMTEST
SQL> REM
SQL> REM List SQL statements in the cursor cache that are not
SQL> REM matching a SQL plan baseline but a SQL plan baseline exists.
SQL> REM
SQL> REM You may want to investigate these cases because it implies
SQL> REM that there may have been a change preventing the plan in the
SQL> REM SQL plan baseline from being used.
SQL> REM
SQL> REM This query allows you to specify a particular schema.
SQL> REM
SQL>
SQL> set linesize 200
SQL> set trims on
SQL> set tab off
SQL> column sql_text format a50
SQL> column parsing_schema_name format a30
SQL> column exact_matching_signature format 99999999999999999999
SQL>
SQL> SELECT sql_text,
2 cpu_time,
3 buffer_gets,
4 executions,
5 parsing_schema_name,
6 sql_id,
7 exact_matching_signature
8 FROM v$sql v
9 WHERE executions>0
10 AND sql_plan_baseline IS NULL
11 AND EXISTS (SELECT 1
12 FROM dba_sql_plan_baselines
13 WHERE signature = v.exact_matching_signature
14 AND accepted = 'YES'
15 AND enabled = 'YES'
16 AND parsing_schema_name = '&1')
17 ORDER BY cpu_time;
old 16: AND parsing_schema_name = '&1')
new 16: AND parsing_schema_name = 'SPMTEST')
SQL_TEXT CPU_TIME BUFFER_GETS EXECUTIONS PARSING_SCHEMA_NAME SQL_ID EXACT_MATCHING_SIGNATURE
-------------------------------------------------- ---------- ----------- ---------- ------------------------------ ------------- ------------------------
select /* MYSPMTEST */ count(*) from tab1 where id 4000 23 1 SPMTEST 00axwq5w1q7x3 10438310272222376619
= 100
SQL>
SQL> PROMPT **** Above, we can see that a SQL statement with a SQL plan baseline
**** Above, we can see that a SQL statement with a SQL plan baseline
SQL> PROMPT **** is not using the SQL plan baseline. In this case, it's because
**** is not using the SQL plan baseline. In this case, it's because
SQL> PROMPT **** we dropped the index so the accepted SQL plan baseline cannot be used.
**** we dropped the index so the accepted SQL plan baseline cannot be used.
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> PROMPT **** We have captured a new plan in SQL plan history...
**** We have captured a new plan in SQL plan history...
SQL> @util/listu SPMTEST
SQL> REM
SQL> REM List SQL plan baselines for a specified user
SQL> REM
SQL>
SQL> set linesize 200
SQL> set trims on
SQL> set tab off
SQL> column last_executed format a30
SQL> column sql_text format a40
SQL> column sql_handle format a40
SQL> column plan_name format a35
SQL> column signature format 999999999999999999999
SQL>
SQL> select signature,plan_name,sql_handle,sql_text, accepted, enabled
2 from dba_sql_plan_baselines
3 where parsing_schema_name = '&1'
4 /
old 3: where parsing_schema_name = '&1'
new 3: where parsing_schema_name = 'SPMTEST'
SIGNATURE PLAN_NAME SQL_HANDLE SQL_TEXT ACC ENA
---------------------- ----------------------------------- ---------------------------------------- ---------------------------------------- --- ---
10438310272222376619 SQL_PLAN_91r2mwdbk0cpbec1c7603 SQL_90dc53e3572032ab select /* MYSPMTEST */ count(*) from tab NO YES
1 where id = 100
10438310272222376619 SQL_PLAN_91r2mwdbk0cpbf7f677e5 SQL_90dc53e3572032ab select /* MYSPMTEST */ count(*) from tab YES YES
1 where id = 100
SQL> PROMPT **** Above, there are now two SQL plan history entries for our query. The new plan has not been accepted yet.
**** Above, there are now two SQL plan history entries for our query. The new plan has not been accepted yet.
SQL> PROMPT **** We can choose to evolve it if we wish and then the query will be under the control of SPM.
**** We can choose to evolve it if we wish and then the query will be under the control of SPM.
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> PROMPT **** The query will show up as a candidate for evolution
**** The query will show up as a candidate for evolution
SQL> @util/evou SPMTEST
SQL> REM
SQL> REM Query SQL plan history for evolve candidates
SQL> REM for a specified user
SQL> REM
SQL>
SQL> SELECT sql_text,
2 signature,
3 sql_handle,
4 plan_name
5 FROM dba_sql_plan_baselines
6 WHERE enabled = 'YES'
7 AND accepted = 'NO'
8 AND parsing_schema_name = '&1';
old 8: AND parsing_schema_name = '&1'
new 8: AND parsing_schema_name = 'SPMTEST'
SQL_TEXT SIGNATURE SQL_HANDLE PLAN_NAME
---------------------------------------- ---------------------- ---------------------------------------- -----------------------------------
select /* MYSPMTEST */ count(*) from tab 10438310272222376619 SQL_90dc53e3572032ab SQL_PLAN_91r2mwdbk0cpbec1c7603
1 where id = 100
SQL> PROMPT **** Above, we have identified a SQL plan history entry that is a candidate for evolving.
**** Above, we have identified a SQL plan history entry that is a candidate for evolving.
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> PROMPT **** Evolve our SQL plan history entry...
**** Evolve our SQL plan history entry...
SQL> DECLARE
2 ret CLOB;
3 BEGIN
4 ret := DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE(sql_handle=>:handle, verify=>'NO');
5 END;
6 /
PL/SQL procedure successfully completed.
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> @util/evou SPMTEST
SQL> REM
SQL> REM Query SQL plan history for evolve candidates
SQL> REM for a specified user
SQL> REM
SQL>
SQL> SELECT sql_text,
2 signature,
3 sql_handle,
4 plan_name
5 FROM dba_sql_plan_baselines
6 WHERE enabled = 'YES'
7 AND accepted = 'NO'
8 AND parsing_schema_name = '&1';
old 8: AND parsing_schema_name = '&1'
new 8: AND parsing_schema_name = 'SPMTEST'
no rows selected
SQL> PROMPT **** Above, there are no longer candidates for evolving.
**** Above, there are no longer candidates for evolving.
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> @util/listu SPMTEST
SQL> REM
SQL> REM List SQL plan baselines for a specified user
SQL> REM
SQL>
SQL> set linesize 200
SQL> set trims on
SQL> set tab off
SQL> column last_executed format a30
SQL> column sql_text format a40
SQL> column sql_handle format a40
SQL> column plan_name format a35
SQL> column signature format 999999999999999999999
SQL>
SQL> select signature,plan_name,sql_handle,sql_text, accepted, enabled
2 from dba_sql_plan_baselines
3 where parsing_schema_name = '&1'
4 /
old 3: where parsing_schema_name = '&1'
new 3: where parsing_schema_name = 'SPMTEST'
SIGNATURE PLAN_NAME SQL_HANDLE SQL_TEXT ACC ENA
---------------------- ----------------------------------- ---------------------------------------- ---------------------------------------- --- ---
10438310272222376619 SQL_PLAN_91r2mwdbk0cpbec1c7603 SQL_90dc53e3572032ab select /* MYSPMTEST */ count(*) from tab YES YES
1 where id = 100
10438310272222376619 SQL_PLAN_91r2mwdbk0cpbf7f677e5 SQL_90dc53e3572032ab select /* MYSPMTEST */ count(*) from tab YES YES
1 where id = 100
SQL> PROMPT **** Above, all out SQL plan baselines are accepted
**** Above, all out SQL plan baselines are accepted
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> @q1
SQL> select /* MYSPMTEST */ count(*) from tab1 where id = 100;
COUNT(*)
----------
1
SQL> @q1
SQL> select /* MYSPMTEST */ count(*) from tab1 where id = 100;
COUNT(*)
----------
1
SQL> @q1
SQL> select /* MYSPMTEST */ count(*) from tab1 where id = 100;
COUNT(*)
----------
1
SQL> @util/plan
SQL> set linesize 200
SQL> set tab off
SQL> set pagesize 1000
SQL> column plan_table_output format a180
SQL>
SQL> SELECT *
2 FROM table(DBMS_XPLAN.DISPLAY_CURSOR(FORMAT=>'LAST'));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID 00axwq5w1q7x3, child number 0
-------------------------------------
select /* MYSPMTEST */ count(*) from tab1 where id = 100
Plan hash value: 3961288195
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 7 (100)| |
| 1 | SORT AGGREGATE | | 1 | 4 | | |
|* 2 | TABLE ACCESS FULL| TAB1 | 1 | 4 | 7 (29)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("ID"=100)
Note
-----
- SQL plan baseline SQL_PLAN_91r2mwdbk0cpbec1c7603 used for this statement
23 rows selected.
SQL>
SQL> PROMPT **** Above, our query is using a SQL plan baseline again.
**** Above, our query is using a SQL plan baseline again.
SQL> PROMPT **** It's a full table scan this time because there is no index.
**** It's a full table scan this time because there is no index.
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> @util/nomatchu SPMTEST
SQL> REM
SQL> REM List SQL statements in the cursor cache that are not
SQL> REM matching a SQL plan baseline but a SQL plan baseline exists.
SQL> REM
SQL> REM You may want to investigate these cases because it implies
SQL> REM that there may have been a change preventing the plan in the
SQL> REM SQL plan baseline from being used.
SQL> REM
SQL> REM This query allows you to specify a particular schema.
SQL> REM
SQL>
SQL> set linesize 200
SQL> set trims on
SQL> set tab off
SQL> column sql_text format a50
SQL> column parsing_schema_name format a30
SQL> column exact_matching_signature format 99999999999999999999
SQL>
SQL> SELECT sql_text,
2 cpu_time,
3 buffer_gets,
4 executions,
5 parsing_schema_name,
6 sql_id,
7 exact_matching_signature
8 FROM v$sql v
9 WHERE executions>0
10 AND sql_plan_baseline IS NULL
11 AND EXISTS (SELECT 1
12 FROM dba_sql_plan_baselines
13 WHERE signature = v.exact_matching_signature
14 AND accepted = 'YES'
15 AND enabled = 'YES'
16 AND parsing_schema_name = '&1')
17 ORDER BY cpu_time;
old 16: AND parsing_schema_name = '&1')
new 16: AND parsing_schema_name = 'SPMTEST')
no rows selected
SQL>
SQL> PROMPT **** Now all the queries with SQL plan baselines are matching
**** Now all the queries with SQL plan baselines are matching
SQL> PROMPT **** successfully, so the above query returns no rows.
**** successfully, so the above query returns no rows.
SQL> PROMPT **** Press <CR> to continue...
**** Press <CR> to continue...
SQL> PAUSE
SQL>
SQL> spool off