[中文]
Author:
fuyuncat
Source:
www.HelloDBA.com
Date:
2009-12-25 01:21:17
To reduce workload in server, some features were introduced to move some jobs to client side. Row shipping is one of such features.
There are steps to process SQL, parsing -> optimzating -> Row Source generating -> result producting. In traditional mode, one job of Row Source gernerator is that choose the columns in SELECT clause from the rows return to client, which named Projection. We could find such information from output DBMS_XPLAN (10g later):
SQL代码
- HELLODBA.COM>create table WIDE_TBL as select * from sys.gv_$session;
- Table created.
- HELLODBA.COM>explain plan for select sid,audsid,serial# from WIDE_TBL;
- Explained.
- HELLODBA.COM>select * from table(dbms_xplan.display(null,null,'ADVANCED'));
- PLAN_TABLE_OUTPUT
- ---------------------------------------------------------------------------------------------------------
- Plan hash value: 1188828058
- ------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- ------------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 25 | 975 | 3 (0)| 00:00:01 |
- | 1 | TABLE ACCESS FULL| WIDE_TBL | 25 | 975 | 3 (0)| 00:00:01 |
- ------------------------------------------------------------------------------
- ...
- Column Projection Information (identified by operation id):
- -----------------------------------------------------------
- 1 - "SID"[NUMBER,22], "SERIAL#"[NUMBER,22], "AUDSID"[NUMBER,22]
- Note
- -----
- - dynamic sampling used for this statement
- 36 rows selected.
Projection will consume CPU, especailly for those "wide tables", who have a lots of columns. When Row Shipping active, it will transfer all of columns to client directly without projection, which will be proceed in client side instead. The parameter _enable_row_shipping decide if Row Shipping be enabled, while _row_shipping_threshold is the project columns threshold that the feature be active or not. Besides, another parameter _row_shipping_explain will control Row Shipping information be stored in v$sql_plan or not. However, this parameter will not affect the feature actually be active or not. Let look into its changes in SQL execution.
SQL代码
- HELLODBA.COM>analyze table WIDE_TBL compute statistics for table for all columns;
- Table analyzed.
- HELLODBA.COM>select num_rows*avg_row_len from dba_tables where table_name='WIDE_TBL';
- NUM_ROWS*AVG_ROW_LEN
- --------------------
- 8492
- HELLODBA.COM>set autot trace stat
- HELLODBA.COM>alter session set "_enable_row_shipping" = FALSE;
- Session altered.
- HELLODBA.COM>alter session set events '10079 trace name context forever, level 2';
- Session altered.
- HELLODBA.COM>select sid,audsid from WIDE_TBL;
- 22 rows selected.
- Statistics
- ----------------------------------------------------------
- 1 recursive calls
- 0 db block gets
- 6 consistent gets
- 0 physical reads
- 0 redo size
- 846 bytes sent via SQL*Net to client
- 396 bytes received via SQL*Net from client
- 3 SQL*Net roundtrips to/from client
- 0 sorts (memory)
- 0 sorts (disk)
- 22 rows processed
- HELLODBA.COM>alter session set events '10079 trace name context off';
- Session altered.
- HELLODBA.COM>conn demo/demo@erdb
- Connected.
- HELLODBA.COM>set autot trace
- HELLODBA.COM>alter session set "_enable_row_shipping" = TRUE;
- Session altered.
- HELLODBA.COM>alter session set "_row_shipping_explain" = TRUE;
- Session altered.
- HELLODBA.COM>alter session set "_row_shipping_threshold" = 2;
- Session altered.
- HELLODBA.COM>alter session set events '10079 trace name context forever, level 2';
- Session altered.
- HELLODBA.COM>select sid,audsid from WIDE_TBL;
- 22 rows selected.
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 1188828058
- ------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- ------------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 22 | 132 | 3 (0)| 00:00:01 |
- | 1 | TABLE ACCESS FULL| WIDE_TBL | 22 | 132 | 3 (0)| 00:00:01 |
- ------------------------------------------------------------------------------
- Note
- -----
- - row shipping is enabled for this statement
- Statistics
- ----------------------------------------------------------
- 358 recursive calls
- 0 db block gets
- 38 consistent gets
- 0 physical reads
- 0 redo size
- 9223 bytes sent via SQL*Net to client
- 396 bytes received via SQL*Net from client
- 3 SQL*Net roundtrips to/from client
- 6 sorts (memory)
- 0 sorts (disk)
- 22 rows processed
- HELLODBA.COM>alter session set events '10079 trace name context off';
- Session altered.
Compare the output, we can find the logical IO was not affected, because this featrue is to modify Row Source Generating operations. We can find the changes in the bytes transfered to client. Row Shipping transfered all of columns to client, with the columns meta infomation, it sent 9223 bytes to client. While in traditional mode, since it just transfered the projected columns, there was just 846 bytes be sent.
We could also look into the content transfered via SQLNet by 10079 event, saw Row Shipping transfered all columns.
SQL代码
- ...
- A798440 53038001 80015359 3016C506 FF2D2531 [...SYS.....01%-.]
- A798450 4E4908FF 49544341 44094556 43494445 [..INACTIVE.DEDIC]
- A798460 44455441 53038001 68075359 676E6175 [ATED...SYS.huang]
- A798470 32096465 3A363932 34343737 434F4F0E [ed.2296:7744.OOC]
- A798480 5C4D444C 4E415548 07444547 4E415548 [LDM\HUANGED.HUAN]
- A798490 0C444547 71736C70 7665646C 6578652E [GED.plsqldev.exe]
- A7984A0 45535504 01000152 04FFFF80 5432B92C [.USER.......,.2T]
- A7984B0 0423C506 0D146339 327A6E33 35763036 [..#.9c..3nz260v5]
- A7984C0 6E717764 FF800176 10FFFFFF 532F4C50 [dwqnv.......PL/S]
- A7984D0 44204C51 6C657665 7265706F 5B0CC506 [QL Developer...[]
- A7984E0 0C40430E 6E69614D 73657320 6E6F6973 [.C@.Main session]
- A7984F0 4A12C506 FF5B5020 480CC304 02C2031E [...J P[....H....]
- ...
Besides, in traditional mode, oracle will compress the package first when transfer data via SQLNet, while row shipping will not.
SQL代码
- HELLODBA.COM>create table WIDE_TBL2 as select a.* from WIDE_TBL a, WIDE_TBL b, WIDE_TBL c;
- Table created.
- HELLODBA.COM>analyze table WIDE_TBL2 compute statistics for table for all columns;
- Table analyzed.
- HELLODBA.COM>select num_rows*avg_row_len from dba_tables where table_name='WIDE_TBL2';
- NUM_ROWS*AVG_ROW_LEN
- --------------------
- 4110128
- HELLODBA.COM>conn demo/demo@erdb
- Connected.
- HELLODBA.COM>set autot trace stat
- HELLODBA.COM>alter session set "_enable_row_shipping" = TRUE;
- Session altered.
- HELLODBA.COM>select * from WIDE_TBL2;
- 10648 rows selected.
- Statistics
- ----------------------------------------------------------
- 0 recursive calls
- 0 db block gets
- 1268 consistent gets
- 0 physical reads
- 0 redo size
- 4260321 bytes sent via SQL*Net to client
- 8184 bytes received via SQL*Net from client
- 711 SQL*Net roundtrips to/from client
- 0 sorts (memory)
- 0 sorts (disk)
- 10648 rows processed
- HELLODBA.COM>alter session set "_enable_row_shipping" = FALSE;
- Session altered.
- HELLODBA.COM>select * from WIDE_TBL2;
- Statistics
- ----------------------------------------------------------
- 1 recursive calls
- 0 db block gets
- 1268 consistent gets
- 0 physical reads
- 0 redo size
- 258356 bytes sent via SQL*Net to client
- 8184 bytes received via SQL*Net from client
- 711 SQL*Net roundtrips to/from client
- 0 sorts (memory)
- 0 sorts (disk)
- 10648 rows processed
You can see, although all of data be returned, data size transfered by row shipping is actual table size plus meta data size, while data size compressed in tranditional mode is much less.
The outstanding benifit of Row Shipping is to reduce the Row Source Generating CPU workload, we may find such changes by compare the Row Source statistics data. However, if _rowsource_execution_statistics or SQL Trace (10046 event) be enabled, Row shipping will be turned of automaticly.
--- Fuyuncat Mark ---