SET STATISTICS IO, TIME ON SET SHOWPLAN ON -- Report all Products with Current State of 3 -- Subquery SELECT p.ProductId, p.Description, ps.DateTime FROM Product p, ProductStatus ps WHERE p.ProductId = ps.ProductId -- Join AND StatusCode = 3 -- Request AND DateTime = ( -- Current Status on the left ... SELECT MAX( DateTime ) -- Current Status row for outer Product FROM ProductStatus subquery WHERE subquery.ProductId = ps.ProductId ) ---------------- -- Query Plan -- ---------------- QUERY PLAN FOR STATEMENT 3 (at line 7). STEP 1 The type of query is SELECT. 6 operator(s) under root |ROOT:EMIT Operator (VA = 6) | | |NESTED LOOP JOIN Operator (VA = 5) (Join Type: Inner Join) | | | | |SQFILTER Operator (VA = 3) has 2 children. | | | | | | |SCAN Operator (VA = 0) | | | | FROM TABLE | | | | Product | | | | p | | | | Table Scan. | | | | Forward Scan. | | | | Positioning at start of table. | | | | Using I/O Size 8 Kbytes for data pages. | | | | With LRU Buffer Replacement Strategy for data pages. | | | | | | Run subquery 1 (at nesting level 1). | | | | | | QUERY PLAN FOR SUBQUERY 1 (at nesting level 1 and at line 16). | | | | | | Correlated Subquery. | | | Subquery under an EXPRESSION predicate. | | | | | | |SCALAR AGGREGATE Operator (VA = 2) | | | | Evaluate Ungrouped MAXIMUM AGGREGATE. | | | | | | | | |SCAN Operator (VA = 1) | | | | | FROM TABLE | | | | | ProductStatus | | | | | subquery | | | | | Using Clustered Index. | | | | | Index : UC_Prod_Dtm | | | | | Forward Scan. | | | | | Positioning by key. | | | | | Keys are: | | | | | ProductId ASC | | | | | Using I/O Size 2 Kbytes for data pages. | | | | | With LRU Buffer Replacement Strategy for data pages. | | | | | | END OF QUERY PLAN FOR SUBQUERY 1. | | | | |SCAN Operator (VA = 4) | | | FROM TABLE | | | ProductStatus | | | ps | | | Using Clustered Index. | | | Index : UC_Prod_Dtm | | | Forward Scan. | | | Positioning by key. | | | Keys are: | | | ProductId ASC | | | DateTime ASC | | | Using I/O Size 2 Kbytes for data pages. | | | With LRU Buffer Replacement Strategy for data pages. --------------------- -- Execution Stats -- --------------------- Parse and Compile Time 0. Adaptive Server cpu time: 0 ms. Total writes for this command: 0 Execution Time 0. Adaptive Server cpu time: 0 ms. Adaptive Server elapsed time: 0 ms. Total writes for this command: 0 Execution Time 0. Adaptive Server cpu time: 0 ms. Adaptive Server elapsed time: 0 ms. Table: Product (p) scan count 1, logical reads: (regular=2000 apf=0 total=2000), physical reads: (regular=0 apf=0 total=0), apf IOs used=0 Table: ProductStatus (subquery) scan count 20000, logical reads: (regular=97287 apf=0 total=97287), physical reads: (regular=0 apf=0 total=0), apf IOs used=0 Table: ProductStatus (ps) scan count 20000, logical reads: (regular=80000 apf=0 total=80000), physical reads: (regular=0 apf=0 total=0), apf IOs used=0 Total writes for this command: 0 Execution Time 17. Adaptive Server cpu time: 1700 ms. Adaptive Server elapsed time: 1843 ms. Total writes for this command: 0 Execution Time 0. Adaptive Server cpu time: 0 ms. Adaptive Server elapsed time: 0 ms.