{"id":242,"date":"2011-10-27T23:48:20","date_gmt":"2011-10-27T15:48:20","guid":{"rendered":"https:\/\/yangtingkun.net\/?p=242"},"modified":"2011-10-28T00:07:28","modified_gmt":"2011-10-27T16:07:28","slug":"11g%e6%94%b9%e5%8f%98%e4%ba%86delete%e8%af%ad%e5%8f%a5%e7%9a%84%e6%89%a7%e8%a1%8c%e8%ae%a1%e5%88%92","status":"publish","type":"post","link":"https:\/\/yangtingkun.net\/?p=242","title":{"rendered":"11g\u6539\u53d8\u4e86DELETE\u8bed\u53e5\u7684\u6267\u884c\u8ba1\u5212"},"content":{"rendered":"<p>\u572811.2\u4e2d\uff0c\u5982\u679cDELETE\u7684\u65f6\u5019\u6ca1\u6709\u9650\u5236\u6761\u4ef6\uff0c\u4e14\u8868\u4e0a\u5b58\u5728\u4e3b\u952e\u7684\u8bdd\uff0c\u6267\u884c\u8ba1\u5212\u4f1a\u53d8\u4e3a\u7d22\u5f15\u5168\u626b\u3002<br \/>\n\u5728\u548c600\u804a\u5929\u7684\u65f6\u5019\u542c\u8bf4\u4e86\u8fd9\u4e2a\u73b0\u8c61\uff0c\u5f00\u59cb\u7684\u65f6\u5019\u8fd8\u4e0d\u662f\u5f88\u76f8\u4fe1\u3002\u5f53\u65f6600\u7279\u610f\u9a8c\u8bc1\u4e86\u4e00\u4e0b\uff0c\u4e8b\u5b9e\u786e\u5b9e\u5982\u6b64\u3002<br \/>\n\u4e8e\u662f\u7279\u610f\u81ea\u5df1\u4e5f\u505a\u4e86\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre lang='SQL'>SQL> select * from v$version;\r\nBANNER\r\n--------------------------------------------------------------------------------\r\nOracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production\r\nPL\/SQL Release 11.2.0.2.0 - Production\r\nCORE 11.2.0.2.0 Production\r\nTNS for Linux: Version 11.2.0.2.0 - Production\r\nNLSRTL Version 11.2.0.2.0 - Production\r\nSQL> create table t_del as select rownum id, a.* from dba_objects a, user_tables ;\r\nTable created.\r\nSQL> select count(*) from t_del;\r\n  COUNT(*)\r\n----------\r\n    110360\r\nSQL> alter table t_del add primary key (id);\r\nTable altered.\r\nSQL> explain plan for delete t_del;\r\nExplained.\r\nSQL> select * from table(dbms_xplan.display);\r\nPLAN_TABLE_OUTPUT\r\n---------------------------------------------------------------------------------\r\nPlan hash value: 1780357700\r\n--------------------------------------------------------------------------------\r\n| Id  | Operation        | Name        | Rows  | Bytes | Cost (%CPU)| Time     |\r\n--------------------------------------------------------------------------------\r\n|   0 | DELETE STATEMENT |             | 89885 |  1141K|   245   (1)| 00:00:03 |\r\n|   1 |  DELETE          | T_DEL       |       |       |            |          |\r\n|   2 |   INDEX FULL SCAN| SYS_C006177 | 89885 |  1141K|   245   (1)| 00:00:03 |\r\n--------------------------------------------------------------------------------\r\nNote\r\n-----\r\n   - dynamic sampling used for this statement (level=2)\r\n13 rows selected.\r\nSQL> explain plan for delete \/*+ full(t_del) *\/ t_del;\r\nExplained.\r\nSQL> select * from table(dbms_xplan.display);\r\nPLAN_TABLE_OUTPUT\r\n------------------------------------------------------------------------------\r\nPlan hash value: 2195693323\r\n----------------------------------------------------------------------------\r\n| Id  | Operation          | Name  | Rows  | Bytes | Cost (%CPU)| Time     |\r\n----------------------------------------------------------------------------\r\n|   0 | DELETE STATEMENT   |       | 89885 |  1141K|   426   (1)| 00:00:06 |\r\n|   1 |  DELETE            | T_DEL |       |       |            |          |\r\n|   2 |   TABLE ACCESS FULL| T_DEL | 89885 |  1141K|   426   (1)| 00:00:06 |\r\n----------------------------------------------------------------------------\r\nNote\r\n-----\r\n   - dynamic sampling used for this statement (level=2)\r\n13 rows selected.<\/pre>\n<p>Oracle\u8ba4\u4e3a\u5168\u7d22\u5f15\u626b\u63cf\u7684\u4ee3\u4ef7\u63a5\u8fd1\u5168\u8868\u626b\u63cf\u7684\u4e00\u534a\uff0c\u9884\u4f30\u65f6\u95f4\u4e5f\u53ea\u6709\u5168\u8868\u626b\u63cf\u7684\u4e00\u534a\u3002\u8fd9\u4e2d\u6267\u884c\u8ba1\u5212\u5bf9\u4e8e10g\u4ee5\u524d\u662f\u4e0d\u53ef\u60f3\u8c61\u7684\uff0c\u65e2\u7136\u6240\u6709\u7684\u8bb0\u5f55\u90fd\u8981\u5904\u7406\uff0c\u901a\u8fc7\u5168\u8868\u626b\u63cf\u663e\u7136\u662f\u6700\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u800c\u901a\u8fc7\u7d22\u5f15\u53bb\u5b9a\u4f4d\u6bcf\u6761\u8bb0\u5f55\u663e\u7136\u6548\u7387\u8981\u4f4e\u5f88\u591a\u3002<br \/>\n\u90a3\u4e48\u5230\u5e95\u662fOracle\u6539\u53d8\u4e86\u5b9e\u73b0\u65b9\u5f0f\uff0c\u8fd8\u662f11.2\u7684CBO\u5728\u8fd9\u91cc\u72af\u4e86\u9519\u8bef\u5462\uff0c\u771f\u6b63\u6267\u884c\u4e00\u4e0b\u770b\u770b\u6548\u679c\uff1a<\/p>\n<pre lang='SQL'>SQL> set timing on\r\nSQL> set autot trace\r\nSQL> delete t_del;\r\n110360 rows deleted.\r\nElapsed: 00:00:01.23\r\nExecution Plan\r\n----------------------------------------------------------\r\nPlan hash value: 1780357700\r\n--------------------------------------------------------------------------------\r\n| Id  | Operation        | Name        | Rows  | Bytes | Cost (%CPU)| Time     |\r\n--------------------------------------------------------------------------------\r\n|   0 | DELETE STATEMENT |             |     1 |    13 |   245   (1)| 00:00:03 |\r\n|   1 |  DELETE          | T_DEL       |       |       |            |          |\r\n|   2 |   INDEX FULL SCAN| SYS_C006177 |     1 |    13 |   245   (1)| 00:00:03 |\r\n--------------------------------------------------------------------------------\r\nNote\r\n-----\r\n   - dynamic sampling used for this statement (level=2)\r\n\r\nStatistics\r\n----------------------------------------------------------\r\n        247  recursive calls\r\n     124999  db block gets\r\n        395  consistent gets\r\n        270  physical reads\r\n   43099720  redo size\r\n        678  bytes sent via SQL*Net to client\r\n        585  bytes received via SQL*Net from client\r\n          3  SQL*Net roundtrips to\/from client\r\n          2  sorts (memory)\r\n          0  sorts (disk)\r\n     110360  rows processed\r\nSQL> rollback;\r\nRollback complete.\r\nElapsed: 00:00:00.92\r\nSQL> delete \/*+ full(t_del) *\/ t_del;\r\n110360 rows deleted.\r\nElapsed: 00:00:04.63\r\nExecution Plan\r\n----------------------------------------------------------\r\nPlan hash value: 2195693323\r\n----------------------------------------------------------------------------\r\n| Id  | Operation          | Name  | Rows  | Bytes | Cost (%CPU)| Time     |\r\n----------------------------------------------------------------------------\r\n|   0 | DELETE STATEMENT   |       |     1 |    13 |   425   (0)| 00:00:06 |\r\n|   1 |  DELETE            | T_DEL |       |       |            |          |\r\n|   2 |   TABLE ACCESS FULL| T_DEL |     1 |    13 |   425   (0)| 00:00:06 |\r\n----------------------------------------------------------------------------\r\nNote\r\n-----\r\n   - dynamic sampling used for this statement (level=2)\r\n\r\nStatistics\r\n----------------------------------------------------------\r\n        322  recursive calls\r\n     346841  db block gets\r\n       1731  consistent gets\r\n        593  physical reads\r\n   65160536  redo size\r\n        683  bytes sent via SQL*Net to client\r\n        604  bytes received via SQL*Net from client\r\n          3  SQL*Net roundtrips to\/from client\r\n          1  sorts (memory)\r\n          0  sorts (disk)\r\n     110360  rows processed\r\nSQL> rollback;\r\nRollback complete.\r\nElapsed: 00:00:01.69<\/pre>\n<p>\u663e\u7136\u65e0\u8bba\u4ece\u8fd0\u884c\u65f6\u95f4\uff0c\u8fd8\u662fdb block gets\u6570\u91cf\uff0c\u6216\u8005\u662f\u903b\u8f91\u8bfb\u6216\u7269\u7406\u8bfb\u7684\u6570\u91cf\uff0c11.2\u7684\u5168\u7d22\u5f15\u626b\u63cf\u6267\u884c\u8def\u5f84\u90fd\u8981\u8fdc\u5c0f\u4e8e\u5168\u8868\u626b\u63cf\u7684\u65b9\u5f0f\uff0c\u751a\u81f3\u8fde\u4ea7\u751f\u7684redo\u7684\u6570\u636e\u91cf\u90fd\u53ea\u6709\u5168\u8868\u626b\u63cf\u76842\/3\uff0c\u663e\u7136Oracle\u66f4\u6539\u4e86\u5220\u9664\u64cd\u4f5c\u7684\u5904\u7406\u673a\u5236\uff0c\u624d\u4f7f\u5f97\u5168\u7d22\u5f15\u626b\u63cf\u8fd9\u79cd\u770b\u4e0a\u53bb\u5b8c\u5168\u4e0d\u5408\u7406\u7684\u6267\u884c\u8ba1\u5212\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<br \/>\nDELETE\u64cd\u4f5c\u662fOracle\u6240\u6709DML\u4e2d\u4ee3\u4ef7\u6700\u5927\u7684\uff0c\u770b\u6765Oracle\u8ba4\u8bc6\u5230\u4e86\u8fd9\u4e00\u70b9\uff0c\u4e5f\u5728\u8bd5\u56fe\u6539\u53d8\u8fd9\u79cd\u60c5\u5f62\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u572811.2\u4e2d\uff0c\u5982\u679cDELETE\u7684\u65f6\u5019\u6ca1\u6709\u9650\u5236\u6761\u4ef6\uff0c\u4e14\u8868\u4e0a\u5b58\u5728\u4e3b\u952e\u7684\u8bdd\uff0c\u6267\u884c\u8ba1\u5212\u4f1a\u53d8\u4e3a\u7d22\u5f15\u5168\u626b\u3002 \u5728\u548c600\u804a\u5929\u7684\u65f6\u5019\u542c\u8bf4\u4e86\u8fd9\u4e2a\u73b0\u8c61\uff0c\u5f00\u59cb\u7684\u65f6\u5019\u8fd8\u4e0d\u662f\u5f88\u76f8\u4fe1\u3002\u5f53\u65f6600\u7279\u610f\u9a8c\u8bc1\u4e86\u4e00\u4e0b\uff0c\u4e8b\u5b9e\u786e\u5b9e\u5982\u6b64\u3002 \u4e8e\u662f\u7279\u610f\u81ea\u5df1\u4e5f\u505a\u4e86\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a SQL> select * from v$version; BANNER &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 &#8211; Production PL\/SQL Release 11.2.0.2.0 &#8211; Production CORE 11.2.0.2.0 Production TNS for Linux: Version 11.2.0.2.0 &#8211; Production NLSRTL Version 11.2.0.2.0 &#8211; Production SQL> &hellip; <a href=\"https:\/\/yangtingkun.net\/?p=242\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[20,173,175],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2yiY3-3U","_links":{"self":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts\/242"}],"collection":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=242"}],"version-history":[{"count":1,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts\/242\/revisions"}],"predecessor-version":[{"id":243,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts\/242\/revisions\/243"}],"wp:attachment":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}