You are on page 1of 7

Exadata - SMART SCAN testing

-------------------------------------------Samrt scan works with cell offloading which relate to offloaded the sql processing from the database layer to the
cell (storage) layer.
Smart scan is the access mechanism to offload data from storage layer. For example passing only required data
blocks after applying predicate filters at the cell layer instead of sending every possible blocks from cell server
to database server.
Flash current buffer cache
====================
alter system flush buffer_cache;
Create a table for testing
=======================
create table sales_SM_SC as
select
mod(rownum,5) as channel_id,
mod(rownum,1000) as cust_id ,
5000 as amount_sold,
to_date
('01.' || lpad(to_char(mod(rownum,12)+1),2,'0') || '.2007' ,'dd.mm.yyyy')
as time_id
from dual connect by level<=2e4;
Check the table size
=================
SQL> select bytes/1024/1024 as SizeMB from user_segments where segment_name='SALES_SM_SC';
SIZEMB
---------.5625
SQL> alter table sales nologging;
Table altered.
Insert data
============
insert /*+ append */ into sales_SM_SC select
channel_id, cust_id,amount_sold, time_id
from sales;
12399984 rows created.
/
12399984 rows created.
SQL> commit;
Commit complete.
SQL> select bytes/1024/1024 as SizeMB from user_segments where segment_name='SALES_SM_SC';
SIZEMB
---------656
Gather Statistics
==============
SQL> exec dbms_stats.gather_table_stats('SH','SALES_SM_SC')
SQL>

--------------------------------SQL> set timing on select /* NO_SMART_SCAN */ count(*) from SALES_SM_SC where channel_id=1. SQL> alter session set cell_offload_processing=true.05 Note: Without cell_offload_processing query took 15:68 seconds where with cell_offload_processing it took 00:05 seconds.19 SQL> / COUNT(*) ---------4000 Elapsed: 00:00:15. Session altered. .PL/SQL procedure successfully completed. SQL> COUNT(*) ---------4000 Elapsed: 00:00:16. Session altered. SQL> set timing on SQL> select /* WITH_SMART_SCAN */ count(*) from SALES_SM_SC where channel_id=1. Check the Query Processing speed without Smart Scan: --------------------------------------------------------------------SQL> alter session set cell_offload_processing=false. --------------------------------------------------------------------------------------------------------------------------------------NOTE : Inside the SQL statement optimizer hint to disables Smart Scan for the query select /*+ OPT_PARAM('cell_offload_processing' 'false') */ count(*) from SALES_SM_SC where channel_id=1 -----------------------------------------------------------------------------------------------------.68 WIth Smart Scan: ---------------------SQL> set timing off.75 SQL> / COUNT(*) ---------4000 Elapsed: 00:00:00. COUNT(*) ---------4000 Elapsed: 00:00:23.

name. PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------SQL_ID 9fmuwnmmrvapv.188957214 cell physical IO bytes sent directly to DB node to balanceCPU u 0 cell physical IO bytes saved during optimized file creation 0 cell physical IO bytes saved during optimized RMAN file restore 0 cell physical IO bytes eligible for predicate offload 53.0625 10 rows selected.Query to check Predicate offload and smart scan ---------------------------------------------------------------SQL> select a.---------physical read total bytes 53.18MB data. 6 'cell IO uncompressed bytes') 7 or a. NAME MB ---------------------------------------------------------------. v$mystat b 3 where a. child number 0 ------------------------------------select /* NO_SMART_SCAN */ count(*) from SALES_SM_SC where channel_id=1 Plan hash value: 1381054164 -----------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time -----------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | 1 | SORT AGGREGATE | | | | | 1| | 22874 (100)| 3| | PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- | | | . b.0625 cell physical IO bytes saved by storage index 0 cell physical IO interconnect bytes returned by smart scan .statistic# = b.display_cursor('9fmuwnmmrvapv')). Explain Plan for Without SMART_SCAN -----------------------------------SQL> set timing off.name like 'cell phy%'). So query is getting almost every blocks from predicate offload.statistic# and 4 (a.value/1024/1024 MB 2 from v$sysstat a.0703125 physical write total bytes 0 cell physical IO interconnect bytes . SQL_ID ------------9fmuwnmmrvapv SQL> select plan_table_output from table (dbms_xplan. Smart scan is required to get only 0. SQL> select sql_id from v$sql where sql_text like '%NO_SMART_SCAN%' and sql_text not like '%like%'. 5 'physical write total bytes'.name in ('physical read total bytes'.181144714 cell IO uncompressed bytes 53.

display_cursor('8rb96afm261ry')) PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------SQL_ID 8rb96afm261ry.storage("CHANNEL_ID"=1) .|* 2 | TABLE ACCESS STORAGE FULL| SALES_SM_SC | 3545K| 10M| 22874 (2)|00:04:35 | ------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------2 . child number 0 ------------------------------------select /* WITH_SMART_SCAN */ count(*) from SALES_SM_SC where channel_id=1 Plan hash value: 1381054164 -----------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|Time | -----------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | 1 | SORT AGGREGATE | | | | | 1| | 22874 (100)| 3| | | | PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------|* 2 | TABLE ACCESS STORAGE FULL| SALES_SM_SC | 3545K| 10M| 22874 (2)|00:04:35 | ------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------2 .display_cursor('&SQLID')) new 1: select plan_table_output from table (dbms_xplan. SQL_ID ------------8rb96afm261ry SQL> select plan_table_output from table (dbms_xplan.filter("CHANNEL_ID"=1) 19 rows selected.display_cursor('&SQLID')). Enter value for sqlid: 8rb96afm261ry old 1: select plan_table_output from table (dbms_xplan. Explain Plan for SMART SCAN ----------------------------------------SQL> SQL> select sql_id from v$sql where sql_text like '%WITH_SMART_SCAN%' and sql_text not like '%like%'.

which is the reason for the reduced runtime. SQL> set autotrace on SQL> set timing on SQL> select count (*) from customers where cust_valid='B'.storage("CUST_VALID"='B') filter("CUST_VALID"='B') Statistics ---------------------------------------------------------1 recursive calls 0 db block gets 36884 consistent gets 36880 physical reads 0 redo size 525 bytes sent via SQL*Net to client 519 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed .08 Execution Plan ---------------------------------------------------------Plan hash value: 296924608 -------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 2 | 10245 (1)| 00:02:03 | | 1 | SORT AGGREGATE | | 1| 2| | | |* 2 | TABLE ACCESS STORAGE FULL| CUSTOMERS | 65588 | 128K| 10245 (1)| 00:02:03 | -------------------------------------------------------------------------------Predicate Information (identified by operation id): --------------------------------------------------2 . COUNT(*) ---------0 Elapsed: 00:00:07.filter("CHANNEL_ID"=1) 21 rows selected. NOTE: The Storage Layer did filter on the predicate channel_id=1 before transmitting the result to the Database Layer. ---------------------------------------2nd Example SMART SCAN --------------------------------------SQL> conn sh/sh Connected.

statistic# and (a. v$mystat b where a.070313 10 rows selected.484375 physical write total bytes 0 cell physical IO interconnect bytes 186.070313 cell physical IO bytes saved by storage index 0 cell physical IO interconnect bytes returned by smart scan .SQL> set autotrace off SQL> select a.01 SQL> select distinct event. average_wait/100 avgwait_secs from v$session_event e.SQL> 2 3 EVENT TOTAL_WAITS WAIT_SECS AVGWAIT_SECS ---------.---------------------------------------------------------------cell single block physical read 52 . Go to first session -------------------SQL> select count (*) from customers where cust_valid='B'.811409 ---->find2: more data to interconnect . total_waits.name like 'cell phy%').sid=s.0364 Elapsed: 00:00:00.02 .50 Open another Session.5*cust_credit_limit 3 where cust_id > 500000.statistic# = b.0217 cell smart table scan 191 6.name. 'cell IO uncompressed bytes') or a.25 physical write total bytes 0 cell physical IO interconnect bytes . COUNT(*) ---------0 Elapsed: 00:01:43. time_waited/100 wait_secs.96 .12 ======> Finding1 (more time to get query output) AME MB ---------------------------------------------------------------. 'physical write total bytes'. NAME MB ---------------------------------------------------------------. b.222740173 cell physical IO bytes sent directly to DB node to balanceCPU u 0 cell physical IO bytes saved during optimized file creation 0 cell physical IO bytes saved during optimized RMAN file restore 0 cell physical IO bytes eligible for predicate offload 288.value/1024/1024 MB from v$sysstat a.0113 cell multiblock physical read 1 .sid.---------physical read total bytes 607. Elapsed: 00:00:00.---------physical read total bytes 288.043052673 cell IO uncompressed bytes 288. update the query without commit: +++++++++++++++++++++++++++++++++++++++++++++ SQL> update customers 2 set cust_credit_limit=1. v$mystat s where event like 'cell%' and e.name in ('physical read total bytes'.59 .

sid.140625 10 rows selected.59sec] cell multiblock physical read cell smart table scan 1 375 . average_wait/100 avgwait_secs from v$session_event e. total_waits.sid=s.467659 ---->find3: More data was returned cell IO uncompressed bytes 576.0224 [Wait is more than .---------------------------------------------------------------cell single block physical read 4009 89.91 ---> find4 .0375 Elapsed: 00:00:00.14 Note: All because for uncommited transaction ---working as traditional buffer cache .cell physical IO bytes sent directly to DB node to balanceCPU u 0 cell physical IO bytes saved during optimized file creation 0 cell physical IO bytes saved during optimized RMAN file restore 0 cell physical IO bytes eligible for predicate offload 576.02 .06 .07 SQL> select distinct event. 2 3 EVENT TOTAL_WAITS WAIT_SECS AVGWAIT_SECS ---------.0217 14. v$mystat s where event like 'cell%' and e. Elapsed: 00:00:00. time_waited/100 wait_secs.140625 cell physical IO bytes saved by storage index 0 cell physical IO interconnect bytes returned by smart scan 155.