Oracle数据库数据恢复、性能优化

找回密码
注册
搜索
热搜: 活动 交友 discuz
发新帖

0

积分

1

好友

29

主题
1#
发表于 2012-12-25 09:17:07 | 查看: 3477| 回复: 3
  select * from v$version;
1        Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
2        PL/SQL Release 10.2.0.3.0 - Production
3        CORE        10.2.0.3.0        Production
4        TNS for IBM/AIX RISC System/6000: Version 10.2.0.3.0 - Productio
5        NLSRTL Version 10.2.0.3.0 - Production

对于一张表的查询,表共94万行数据,查询语句中where中内容
where oola.ordered_quantity - nvl(to_number(oola.attribute10), 0) > 0

54 - filter("OOLA"."ORDERED_QUANTITY"-NVL(TO_NUMBER("OOLA"."ATTRIBUTE10"),0)>0)


执行计划走的全表扫描
|* 54 |        TABLE ACCESS FULL        | OE_ORDER_LINES_ALL           | 47455 |  1714K|       | 32754   (1)| 00:06:34 |
返回了4万行数据

oola表的ORDERED_QUANTITY和ATTRIBUTE10这两列适不适合建索引,让查询的时候用索引代替全表扫面
2#
发表于 2012-12-25 09:27:42
请学会使用code模式编辑日志 代码 执行计划
  1. 我是code模式
复制代码

回复 只看该作者 道具 举报

3#
发表于 2012-12-25 14:30:18
test
  1. 1* select t1,t2 from comparetab where t1<t2
  2. SQL> /

  3. 99999 rows selected.


  4. Execution Plan
  5. ----------------------------------------------------------
  6. Plan hash value: 782809411

  7. --------------------------------------------------------------------------------
  8. | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
  9. --------------------------------------------------------------------------------
  10. |   0 | SELECT STATEMENT  |            | 87756 |  2228K|    47   (3)| 00:00:01 |
  11. |*  1 |  TABLE ACCESS FULL| COMPARETAB | 87756 |  2228K|    47   (3)| 00:00:01 |
  12. --------------------------------------------------------------------------------

  13. Predicate Information (identified by operation id):
  14. ---------------------------------------------------

  15.    1 - filter("T1"<"T2")

  16. Note
  17. -----
  18.    - dynamic sampling used for this statement (level=2)


  19. Statistics
  20. ----------------------------------------------------------
  21.           0  recursive calls
  22.           0  db block gets
  23.        6824  consistent gets
  24.          29  physical reads
  25.           0  redo size
  26.     1773851  bytes sent via SQL*Net to client
  27.       73869  bytes received via SQL*Net from client
  28.        6668  SQL*Net roundtrips to/from client
  29.           0  sorts (memory)
  30.           0  sorts (disk)
  31.       99999  rows processed

  32. SQL>
  33. SQL> create index ind_compare on comparetab(t1,t2);

  34. Index created.

  35. SQL> select t1,t2 from comparetab where t1<t2;

  36. 99999 rows selected.


  37. Execution Plan
  38. ----------------------------------------------------------
  39. Plan hash value: 782809411

  40. --------------------------------------------------------------------------------
  41. | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
  42. --------------------------------------------------------------------------------
  43. |   0 | SELECT STATEMENT  |            | 87756 |  2228K|    47   (3)| 00:00:01 |
  44. |*  1 |  TABLE ACCESS FULL| COMPARETAB | 87756 |  2228K|    47   (3)| 00:00:01 |
  45. --------------------------------------------------------------------------------

  46. Predicate Information (identified by operation id):
  47. ---------------------------------------------------

  48.    1 - filter("T1"<"T2")

  49. Note
  50. -----
  51.    - dynamic sampling used for this statement (level=2)


  52. Statistics
  53. ----------------------------------------------------------
  54.           5  recursive calls
  55.           0  db block gets
  56.        6881  consistent gets
  57.           0  physical reads
  58.           0  redo size
  59.     1773851  bytes sent via SQL*Net to client
  60.       73869  bytes received via SQL*Net from client
  61.        6668  SQL*Net roundtrips to/from client
  62.           0  sorts (memory)
  63.           0  sorts (disk)
  64.       99999  rows processed

  65. SQL> alter system flush shared_pool;

  66. System altered.

  67. SQL> select t1,t2 from comparetab where t1<t2;

  68. 99999 rows selected.


  69. Execution Plan
  70. ----------------------------------------------------------
  71. Plan hash value: 782809411

  72. --------------------------------------------------------------------------------
  73. | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
  74. --------------------------------------------------------------------------------
  75. |   0 | SELECT STATEMENT  |            | 87756 |  2228K|    47   (3)| 00:00:01 |
  76. |*  1 |  TABLE ACCESS FULL| COMPARETAB | 87756 |  2228K|    47   (3)| 00:00:01 |
  77. --------------------------------------------------------------------------------

  78. Predicate Information (identified by operation id):
  79. ---------------------------------------------------

  80.    1 - filter("T1"<"T2")

  81. Note
  82. -----
  83.    - dynamic sampling used for this statement (level=2)


  84. Statistics
  85. ----------------------------------------------------------
  86.          44  recursive calls
  87.           0  db block gets
  88.        6930  consistent gets
  89.           1  physical reads
  90.           0  redo size
  91.     1773851  bytes sent via SQL*Net to client
  92.       73869  bytes received via SQL*Net from client
  93.        6668  SQL*Net roundtrips to/from client
  94.           4  sorts (memory)
  95.           0  sorts (disk)
  96.       99999  rows processed

  97. SQL> select t1,t2 from comparetab where t1>t2;

  98. no rows selected


  99. Execution Plan
  100. ----------------------------------------------------------
  101. Plan hash value: 782809411

  102. --------------------------------------------------------------------------------
  103. | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
  104. --------------------------------------------------------------------------------
  105. |   0 | SELECT STATEMENT  |            |     2 |    52 |    47   (3)| 00:00:01 |
  106. |*  1 |  TABLE ACCESS FULL| COMPARETAB |     2 |    52 |    47   (3)| 00:00:01 |
  107. --------------------------------------------------------------------------------

  108. Predicate Information (identified by operation id):
  109. ---------------------------------------------------

  110.    1 - filter("T1">"T2")

  111. Note
  112. -----
  113.    - dynamic sampling used for this statement (level=2)


  114. Statistics
  115. ----------------------------------------------------------
  116.           5  recursive calls
  117.           0  db block gets
  118.         214  consistent gets
  119.           0  physical reads
  120.           0  redo size
  121.         402  bytes sent via SQL*Net to client
  122.         532  bytes received via SQL*Net from client
  123.           1  SQL*Net roundtrips to/from client
  124.           0  sorts (memory)
  125.           0  sorts (disk)
  126.           0  rows processed

  127. SQL> set arraysize 5000
  128. SQL> select t1,t2 from comparetab where t1<t2;

  129. 99999 rows selected.


  130. Execution Plan
  131. ----------------------------------------------------------
  132. Plan hash value: 782809411

  133. --------------------------------------------------------------------------------
  134. | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
  135. --------------------------------------------------------------------------------
  136. |   0 | SELECT STATEMENT  |            | 87756 |  2228K|    47   (3)| 00:00:01 |
  137. |*  1 |  TABLE ACCESS FULL| COMPARETAB | 87756 |  2228K|    47   (3)| 00:00:01 |
  138. --------------------------------------------------------------------------------

  139. Predicate Information (identified by operation id):
  140. ---------------------------------------------------

  141.    1 - filter("T1"<"T2")

  142. Note
  143. -----
  144.    - dynamic sampling used for this statement (level=2)


  145. Statistics
  146. ----------------------------------------------------------
  147.           0  recursive calls
  148.           0  db block gets
  149.         177  consistent gets
  150.           0  physical reads
  151.           0  redo size
  152.      504274  bytes sent via SQL*Net to client
  153.         752  bytes received via SQL*Net from client
  154.          21  SQL*Net roundtrips to/from client
  155.           0  sorts (memory)
  156.           0  sorts (disk)
  157.       99999  rows processed

  158. SQL>  select t1,t2 from comparetab where t1>t2;

  159. no rows selected


  160. Execution Plan
  161. ----------------------------------------------------------
  162. Plan hash value: 782809411

  163. --------------------------------------------------------------------------------
  164. | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
  165. --------------------------------------------------------------------------------
  166. |   0 | SELECT STATEMENT  |            |     2 |    52 |    47   (3)| 00:00:01 |
  167. |*  1 |  TABLE ACCESS FULL| COMPARETAB |     2 |    52 |    47   (3)| 00:00:01 |
  168. --------------------------------------------------------------------------------

  169. Predicate Information (identified by operation id):
  170. ---------------------------------------------------

  171.    1 - filter("T1">"T2")

  172. Note
  173. -----
  174.    - dynamic sampling used for this statement (level=2)


  175. Statistics
  176. ----------------------------------------------------------
  177.           4  recursive calls
  178.           0  db block gets
  179.         214  consistent gets
  180.           0  physical reads
  181.           0  redo size
  182.         402  bytes sent via SQL*Net to client
  183.         532  bytes received via SQL*Net from client
  184.           1  SQL*Net roundtrips to/from client
  185.           0  sorts (memory)
  186.           0  sorts (disk)
  187.           0  rows processed

  188. SQL>
  189. SQL> create index fun_ind on comparetab(t1-t2);

  190. Index created.

  191. SQL>
  192. SQL> select t1,t2 from comparetab where t1>t2;

  193. no rows selected


  194. Execution Plan
  195. ----------------------------------------------------------
  196. Plan hash value: 782809411

  197. --------------------------------------------------------------------------------
  198. | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
  199. --------------------------------------------------------------------------------
  200. |   0 | SELECT STATEMENT  |            |     2 |    52 |    47   (3)| 00:00:01 |
  201. |*  1 |  TABLE ACCESS FULL| COMPARETAB |     2 |    52 |    47   (3)| 00:00:01 |
  202. --------------------------------------------------------------------------------

  203. Predicate Information (identified by operation id):
  204. ---------------------------------------------------

  205.    1 - filter("T1">"T2")

  206. Note
  207. -----
  208.    - dynamic sampling used for this statement (level=2)


  209. Statistics
  210. ----------------------------------------------------------
  211.           5  recursive calls
  212.           0  db block gets
  213.         215  consistent gets
  214.           0  physical reads
  215.           0  redo size
  216.         402  bytes sent via SQL*Net to client
  217.         532  bytes received via SQL*Net from client
  218.           1  SQL*Net roundtrips to/from client
  219.           0  sorts (memory)
  220.           0  sorts (disk)
  221.           0  rows processed

  222. SQL>  select t1,t2 from comparetab where t1-t2>0;

  223. no rows selected


  224. Execution Plan
  225. ----------------------------------------------------------
  226. Plan hash value: 1278306072

  227. --------------------------------------------------------------------------------------------------
  228. | Id  | Operation                           | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
  229. --------------------------------------------------------------------------------------------------
  230. |   0 | SELECT STATEMENT                    |            |  4388 |   167K|     5   (0)| 00:00:01 |
  231. |   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| COMPARETAB |  4388 |   167K|     5   (0)| 00:00:01 |
  232. |*  2 |   INDEX RANGE SCAN                  | FUN_IND    |   790 |       |     3   (0)| 00:00:01 |
  233. --------------------------------------------------------------------------------------------------

  234. Predicate Information (identified by operation id):
  235. ---------------------------------------------------

  236.    2 - access("T1"-"T2">0)

  237. Note
  238. -----
  239.    - dynamic sampling used for this statement (level=2)


  240. Statistics
  241. ----------------------------------------------------------
  242.           6  recursive calls
  243.           0  db block gets
  244.          62  consistent gets
  245.           1  physical reads
  246.           0  redo size
  247.         402  bytes sent via SQL*Net to client
  248.         532  bytes received via SQL*Net from client
  249.           1  SQL*Net roundtrips to/from client
  250.           0  sorts (memory)
  251.           0  sorts (disk)
  252.           0  rows processed

  253. SQL> select t1,t2 from comparetab where t1-t2<0;

  254. 99999 rows selected.


  255. Execution Plan
  256. ----------------------------------------------------------
  257. Plan hash value: 1278306072

  258. --------------------------------------------------------------------------------------------------
  259. | Id  | Operation                           | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
  260. --------------------------------------------------------------------------------------------------
  261. |   0 | SELECT STATEMENT                    |            |  4388 |   167K|     5   (0)| 00:00:01 |
  262. |   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| COMPARETAB |  4388 |   167K|     5   (0)| 00:00:01 |
  263. |*  2 |   INDEX RANGE SCAN                  | FUN_IND    |   790 |       |     3   (0)| 00:00:01 |
  264. --------------------------------------------------------------------------------------------------

  265. Predicate Information (identified by operation id):
  266. ---------------------------------------------------

  267.    2 - access("T1"-"T2"<0)

  268. Note
  269. -----
  270.    - dynamic sampling used for this statement (level=2)


  271. Statistics
  272. ----------------------------------------------------------
  273.           4  recursive calls
  274.           0  db block gets
  275.         462  consistent gets
  276.         209  physical reads
  277.           0  redo size
  278.      504274  bytes sent via SQL*Net to client
  279.         752  bytes received via SQL*Net from client
  280.          21  SQL*Net roundtrips to/from client
  281.           0  sorts (memory)
  282.           0  sorts (disk)
  283.       99999  rows processed
复制代码

回复 只看该作者 道具 举报

您需要登录后才可以回帖 登录 | 注册

QQ|手机版|Archiver|Oracle数据库数据恢复、性能优化

GMT+8, 2024-11-16 04:16 , Processed in 0.045500 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部
TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569