Here's the output to the second query
The Lop tree:
( project
( scalar
( scan CB
)
)
)
OptBlock1
The Lop tree:
( scan CB
)
Generic Tables: ( Gtt1( CB ) Gti2( IDX1 ) )
Generic Columns: ( Gc0(CB ,Rid) Gc1(CB ,MID) Gc2(CB ,ValuationDate)) Virtual Generic Columns: ( )
Predicates: ( { CB.MID } = 0 tc:{1} )
Transitive Closures: ( Tc0 = { Gc0(CB ,Rid)} Tc1 = { Gc1(CB ,MID)} Tc2 = { Gc2(CB ,ValuationDate)} )
OptBlock0
The Lop tree:
( pseudoscan
)
Generic Tables: ( Gta0 )
Generic Columns: ( Gc3(Gta0 ,_virtualagg) Gc4(,_virtualconstresult) Gc5(Gta0 ,_virtualagg) Gc6(,_virtualconstresult)) Virtual Generic Columns: ( )
Predicates: ( )
Transitive Closures: ( Tc3 = { Gc3(Gta0 ,_virtualagg) Gc6(,_virtualconstresult) Gc5(Gta0 ,_virtualagg) Gc4(,_virtualconstresult)} )
OptCriteria:
distinct_sorted
distinct_sorting
distinct_hashing
group_sorted
group_hashing
nl_join
append_union_all
merge_union_all
merge_union_distinct
hash_union_distinct
opportunistic_distinct_view
order_sorting
store_index
replicated_partition
index_union
streaming_sort
nary_nl_join
alternative_greedy_search
conserve_tempdb_space: keep estimated tempdb below resource granularity
search_engine_timeout_factor
cr559034: avoid preferring non-covering over covered index scans
allow_wide_top_sort: allow max row size to be exceeded for top sorts
cr562947: OPTLEVEL EXCEPTION SEE CR - allow cursor table scans
data_page_prefetch_costing: clustered row bias added
mru_buffer_costing: wash size buffer limit for MRU
cr546125: implicitly updatable cursor non-unique index scan
cr545771: improves multi-table outer-join and semi-join costing
cr545653: avoid inner table buffer estimate starvation
cr545585: covered iscan CPU costing too expensive
cr545379: disallow reformatting on user forced index scan
cr545180: avoid reformat with no sargs if useful index exists
cr545059: reduce usage of buffer manager optimization sorts
cr544485: mark subquery join predicates with distinct view as sargs
cr556728: facilitates merge joins between small tables
cr534175: compute GROUP BY worktables in nested subqueries only once when possible
cr531199: increases the number of useful nested loop join plans considered
cr500736: supports nocase sortorder columns in mergejoin and hashjoin keys
cr487450: improves DISTINCT costing of multi-table outer joins and/or semi-joins
cr467566: allow abstract plans and statement cache to work together
avoid_bmo_sorts: avoid sorts used only for buffer manager optimization
cr497066: infer the nullability of isnull() by looking at its parameters
cr421607: support NULL=NULL merge and hash join keys
distinct_exists_transform: transform distinct to semi-join
cr552795: eliminate duplicate rows during reformatting when they're not needed
outer_join_costing: outer join row counts and histogramming
join_duplicate_estimates: avoid overestimates of dups in joins
imdb_costing: 0 PIO costing for scans for in-memory database
auto_temptable_stats: auto generation of statistics for #temptables
use_mixed_dt_sarg_under_specialor: allow special OR in case of mixed datatype sargs in IN/OR list
timeout_cart_product: timeout queries involving cartesian product and more than 5 tables.
in_list_general_or: optimize in lists under general ors
cr611385: enable ScanValues costing
cr574923: extend search space hidden by greedy algorithm
cr614461: enable in-order rid scan estimates
cr611637: avoid duplicate NULL selectivity
cr619965: dense frequency for 'Jan 1 1900 12:00:00:000AM'
cr439123: 0.0 range density for low cardinality tables
cr619756: DISTINCT, EXISTS, and GROUP BY row estimation
cr624835: correlated equi-join constant costing
cr628311: subquery decorrelated store index costing
cr628845: ORDER BY consumes parallel bmo sorts
cr636592: do not skip good opportunistic distinct plans
cr631416: semi-join row estimate adjustment
cr639977: eager virtual column sarg evaluation
allow_large_index_row: allow large index row in basic optimization
basic_optimization_partitions: allow partitioned tables in basic optimization
cr606288: disable parallelism in 12.5 optimizer
cr647051: correct NULL selectivity estimates
cr644777: allow multiple IN lists in large-IN-List transformation
cr649006: reduce CPU cost for table scan partition elimination
cr646024: add in sort operator's child costs for fastfirstrow recosting
cr649470: subquery conserve_tempdb_space
cr649590: optimize always false queries
allow_minmax: allow local session to consider MINMAX optimization
cr646220: enable better store index key generation with correlated predicate
cr663304: forced index will restrict one row rule
cr575761: allow general OR scans under dirty reads
cr675179: composite special OR costing
cr673625: avoid_bmo_sorts performance INSERT/SELECT INTO with ORDER BY
cr674607: fixes parallel thread use count calculations
cr685239: enable XCHG op and basic parallel cost based costing updates
cr669847: transform non-functional update producer lop to semi-join
cr683626: forceplan shouldn't fail with subquery under outer join
cr685996: enhanced subquery and outerjoin rules for busy/right-nested plan
limit_row_constructor: limit index starting position optimization
cr731808: remove zeros from LIKE lower bound sarg
cr702725: optimize the INSERT...SELECT...ORDER BY plan selection
cr713638: LIKE optimization - upper bound mis-estimation
cr739820: accurate parallel create index cluster ratios
cr738692: copy multi node subquery cost
cr737628: intelligent index scan null support
cr741742: small table unique index density
cr744975: nested loop bmo sort ordering extension
cr752225: compatibility mode can handle greater than 32 GROUP BY columns
remove_orphaned_subplans: remove subplans not part of a best plan
equals_scan_superset: choose index with a superset of equality keys
avoid_zero_weight_histograms: avoid applying 0 weight to all histogram cells
cr759142: avoid 0 weight range cells followed by small weight frequency cells
Optimizer Level: ase_current
Optimization Goal: allrows_oltp
Optimization Learning mode enabled.
Optimization Timeout limit: 10% (Default)
Server Level Optimization Timeout has been set.
Optimization query tuning time limit enabled.
The compiler will use the current best plan when 10%(Optimization Timeout limit) of average execution time is exceeded.
Optimization query tuning mem limit enabled.
The compiler will use the current best plan when 10%(Max Resource Granularity) of procedure cache is exceeded.
******************************************************************************
BEGIN: Search Space Traversal for OptBlock1
******************************************************************************
** Costing set up for Min/Max optimization **
Scan plans selected for this optblock:
Beginning selection of qualifying indexes for table 'CB',
Estimating selectivity of index 'CB.IDX1', indid 2
MID = 0
Estimated selectivity for MID,
selectivity = 0.001940126,
scan selectivity 0.001940126, filter selectivity 0.001940126
Cost adjusted for Min/Max optimization, Adjustment ratio 6.28987e-06
158985.8 rows, 383.3457 pages
Adjustment ratio 6.28987e-06 applied gives 1 rows, 1 pages
Index covers query.
Data Row Cluster Ratio 0.9370485
Index Page Cluster Ratio 0.9126954
Data Page Cluster Ratio 0.5194609
using index prefetch (size 128K I/O)
Large IO selected: The number of leaf pages qualified is > MIN_PREFETCH pages
Adjustment using index prefetch (size 128K I/O)
in index cache 'default data cache' (cacheid 0) with LRU replacement
Estimating selectivity for table 'CB'
Table scan cost is 8.19461e+07 rows, 516435 pages,
The table (Datarows) has 8.19461e+07 rows, 516435 pages,
Data Page Cluster Ratio 0.9999900
MID = 0
Estimated selectivity for MID,
selectivity = 0.001940126,
Search argument selectivity is 0.001940126.
using table prefetch (size 128K I/O)
Large IO selected: The number of leaf pages qualified is > MIN_PREFETCH pages
in data cache 'default data cache' (cacheid 0) with MRU replacement
MRU selected: More than 1/2 of the pool is swept out by the scan
OptBlock1 Eqc{1} -> Pops added:
( PopTabScan CB ) cost:1.089176e+07 T(L520046,P65010.3,C8.226407e+07) O(L520046,P65010.3,C8.226407e+07) tempdb:0 order: none
( PopIndScan IDX1 CB ) cost:81.29999 T(L3,P3,C2.999999) O(L3,P3,C2.999999) tempdb:0 order: {2}
The best plan found in OptBlock1 :
( PopTabScan cost:1.089176e+07 T(L520046,P65010.3,C8.226407e+07) O(L520046,P65010.3,C8.226407e+07) tempdb:0 props: [{}] Gtt1( CB ) ) cost:1.089176e+07 T(L520046,P65010.3,C8.226407e+07) O(L520046,P65010.3,C8.226407e+07) tempdb:0 order: none
( PopIndScan cost:81.29999 T(L3,P3,C2.999999) O(L3,P3,C2.999999) tempdb:0 props: [{2}] Gti2( IDX1 ) Gtt1( CB ) ) cost:81.29999 T(L3,P3,C2.999999) O(L3,P3,C2.999999) tempdb:0 order: {2}
******************************************************************************
DONE: Search Space Traversal for OptBlock1
******************************************************************************
******************************************************************************
BEGIN: Search Space Traversal for OptBlock0
******************************************************************************
Scan plans selected for this optblock:
OptBlock0 Eqc{0} -> Pops added:
( PopScalar ( PopIndScan IDX1 CB ) ) cost:81.39999 T(L3,P3,C3.999999) O(L0,P0,C1) tempdb:0 order: none
The best plan found in OptBlock0 :
( PopScalar cost:81.39999 T(L3,P3,C3.999999) O(L0,P0,C1) tempdb:0 props: [{}] ( PopIndScan cost:81.29999 T(L3,P3,C2.999999) O(L3,P3,C2.999999) tempdb:0 props: [{2}] Gti2( IDX1 ) Gtt1( CB ) ) cost:81.29999 T(L3,P3,C2.999999) O(L3,P3,C2.999999) tempdb:0 order: {2}
) cost:81.39999 T(L3,P3,C3.999999) O(L0,P0,C1) tempdb:0 order: none
******************************************************************************
DONE: Search Space Traversal for OptBlock0
******************************************************************************
The Abstract Plan (AP) of the final query execution plan:
( scalar_agg ( i_scan IDX1 CB ) ) ( prop CB ( parallel 1 ) ( prefetch 16 ) ( lru ) )
To experiment with the optimizer behavior, this AP can be modified and then passed to the optimizer using the PLAN clause: SELECT/INSERT/DELETE/UPDATE ... PLAN '( ... )'.
The best global plan (Pop tree) :
FINAL PLAN ( total cost = 81.39999 ):
lio=3 pio=3 cpu=3.999999 tempdb=0
( PopEmit
proj: {{ Gta0._virtualagg _virtualconstresult Gta0._virtualagg _virtualconstresult } }
pred: [Tc{} Pe{}]
subs: {}
cost: 81.39999
I/O estimate : [
rowcount=1
averagewidth=15
pages=1
prefetchpages=1
lio=0 pio=0 cpu=0
total lio=3 total pio=3 total cpu=3.999999
tempdb=0
]
Cache Strategy: [
prefetch=YES
iosize=131072 Bytes
bufreplace=LRU
]
order: none
( PopScalar
proj: {{ Gta0._virtualagg _virtualconstresult Gta0._virtualagg _virtualconstresult } }
pred: [Tc{} Pe{}]
subs: {Gta0._virtualagg }
cost: 81.39999
I/O estimate : [
rowcount=1
averagewidth=15
pages=1
prefetchpages=1
lio=0 pio=0 cpu=1
total lio=3 total pio=3 total cpu=3.999999
tempdb=0
]
Cache Strategy: [
prefetch=YES
iosize=131072 Bytes
bufreplace=LRU
]
order: none
( PopIndScan index: Gti2( IDX1 )
table: Gtt1( CB )
proj: {{ CB.ValuationDate } }
pred: [Tc{} Pe{{ CB.MID } = 0}]
subs: {CB.MID ,CB.ValuationDate }
cost: 81.29999
I/O estimate : [
rowcount=1
averagewidth=10
pages=1
prefetchpages=1
lio=3 pio=3 cpu=2.999999
scanlio=3 scanpio=3 scancpu=2.999999
tempdb=0
]
Cache Strategy: [
prefetch=NO
iosize=16384 Bytes
bufreplace=LRU
]
order: {2}
)
)
)
QUERY PLAN FOR STATEMENT 1 (at line 1).
STEP 1
The type of query is DECLARE.
Total estimated I/O cost for statement 1 (at line 1): 0.
QUERY PLAN FOR STATEMENT 2 (at line 2).
Optimized using Serial Mode
QUERY PLAN FOR STATEMENT 3 (at line 4).
Optimized using Serial Mode
STEP 1
The type of query is SELECT.
2 operator(s) under root
|ROOT:EMIT Operator (VA = 2)
|
| |SCALAR AGGREGATE Operator (VA = 1)
| | Evaluate Ungrouped MAXIMUM AGGREGATE.
| | Scanning only up to the first qualifying row.
| |
| | |SCAN Operator (VA = 0)
| | | FROM TABLE
| | | CB
| | | Index : IDX1
| | | Backward scan.
| | | Positioning by key.
| | | Index contains all needed columns. Base table will not be read.
| | | Keys are:
| | | MID ASC
| | | Using I/O Size 16 Kbytes for index leaf pages.
| | | With LRU Buffer Replacement Strategy for index leaf pages.
Total estimated I/O cost for statement 3 (at line 4): 81.
Parse and Compile Time 0.
Adaptive Server cpu time: 0 ms.
Statement: 2 Compile time resource usage: (est worker processes=0 proccache=0), Execution time resource usage: (worker processes=0 auxsdesc=0 plansize=2 proccache=3 proccache hwm=3 tempdb hwm=0)
==================== Lava Operator Tree ====================
Emit
(VA = 1)
r:1 er:300
l:0 el:100
p:0 ep:100
cpu: 0
/
Scalar
(0)
(VA = 0)
r:1 er:-1
l:0 el:-1
p:0 ep:-1
============================================================
Total actual I/O cost for this command: 0.
Total writes for this command: 0
Execution Time 0.
Adaptive Server cpu time: 0 ms. Adaptive Server elapsed time: 0 ms.
Statement: 3 Compile time resource usage: (est worker processes=0 proccache=110), Execution time resource usage: (worker processes=0 auxsdesc=0 plansize=6 proccache=9 proccache hwm=9 tempdb hwm=0)
==================== Lava Operator Tree ====================
Emit
(VA = 2)
r:1 er:1
cpu: 0
/
ScalarAgg
Max
(VA = 1)
r:1 er:1
cpu: 0
/
IndexScan
IDX1
(VA = 0)
r:1 er:1
l:3 el:3
p:3 ep:3
============================================================
Table: CB scan count 1, logical reads: (regular=3 apf=0 total=3), physical reads: (regular=3 apf=0 total=3), apf IOs used=0
Total actual I/O cost for this command: 81.
Total writes for this command: 0
Execution Time 0.
Adaptive Server cpu time: 0 ms. Adaptive Server elapsed time: 25 ms.
(1 row affected)