{"id":1577,"date":"2025-02-12T22:19:12","date_gmt":"2025-02-12T14:19:12","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=1577"},"modified":"2025-02-12T22:19:14","modified_gmt":"2025-02-12T14:19:14","slug":"%e6%95%b0%e6%8d%ae%e5%ba%93%e8%ae%be%e8%ae%a1%e4%b8%8e%e4%bc%98%e5%8c%96%ef%bc%9aoracle-%e6%80%a7%e8%83%bd%e6%8f%90%e5%8d%87%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/02\/12\/%e6%95%b0%e6%8d%ae%e5%ba%93%e8%ae%be%e8%ae%a1%e4%b8%8e%e4%bc%98%e5%8c%96%ef%bc%9aoracle-%e6%80%a7%e8%83%bd%e6%8f%90%e5%8d%87%e6%8a%80%e5%b7%a7\/","title":{"rendered":"\u6570\u636e\u5e93\u8bbe\u8ba1\u4e0e\u4f18\u5316\uff1aOracle \u6027\u80fd\u63d0\u5347\u6280\u5de7"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">1. <strong>\u6570\u636e\u5e93\u8bbe\u8ba1\u7406\u8bba<\/strong><\/h4>\n\n\n\n<p>\u6570\u636e\u5e93\u8bbe\u8ba1\u662f\u786e\u4fdd\u6570\u636e\u5e93\u9ad8\u6548\u3001\u53ef\u7ef4\u62a4\u3001\u53ef\u6269\u5c55\u7684\u57fa\u7840\u3002\u5408\u7406\u7684\u6570\u636e\u5e93\u8bbe\u8ba1\u80fd\u6781\u5927\u63d0\u5347\u6570\u636e\u5e93\u7684\u6027\u80fd\uff0c\u51cf\u5c11\u5197\u4f59\u6570\u636e\uff0c\u5e76\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6b63\u89c4\u5316\u4e0e\u53cd\u6b63\u89c4\u5316<\/strong>\uff1a<\/li>\n\n\n\n<li><strong>\u6b63\u89c4\u5316<\/strong>\uff1a\u662f\u5c06\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u5206\u89e3\u6210\u591a\u4e2a\u8868\uff0c\u51cf\u5c11\u6570\u636e\u5197\u4f59\uff0c\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027\u3002\u5e38\u89c1\u7684\u6b63\u89c4\u5316\u8303\u5f0f\u5305\u62ec 1NF\u30012NF\u30013NF \u7b49\u3002<\/li>\n\n\n\n<li><strong>\u53cd\u6b63\u89c4\u5316<\/strong>\uff1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4e3a\u4e86\u4f18\u5316\u67e5\u8be2\u6027\u80fd\uff0c\u53ef\u80fd\u4f1a\u5c06\u4e00\u4e9b\u8868\u5408\u5e76\uff0c\u4ee5\u51cf\u5c11 JOIN \u64cd\u4f5c\uff0c\u63d0\u5347\u67e5\u8be2\u901f\u5ea6\u3002\u4f46\u8fd9\u53ef\u80fd\u5e26\u6765\u6570\u636e\u5197\u4f59\uff0c\u9700\u8981\u5728\u6027\u80fd\u548c\u4e00\u81f4\u6027\u4e4b\u95f4\u627e\u5230\u5e73\u8861\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b<\/strong>\uff1a<br>\u6b63\u89c4\u5316\u540e\u7684\u5458\u5de5\u4fe1\u606f\u8868\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE employees (\n    employee_id INT PRIMARY KEY,\n    first_name VARCHAR(50),\n    last_name VARCHAR(50),\n    department_id INT,\n    salary DECIMAL(10,2)\n);<\/code><\/pre>\n\n\n\n<p>\u53cd\u6b63\u89c4\u5316\u540e\u7684\u5458\u5de5\u548c\u90e8\u95e8\u4fe1\u606f\u8868\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE employee_department (\n    employee_id INT PRIMARY KEY,\n    first_name VARCHAR(50),\n    last_name VARCHAR(50),\n    department_name VARCHAR(100),\n    salary DECIMAL(10,2)\n);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>ER \u6a21\u578b\u4e0e\u5173\u7cfb\u6a21\u578b<\/strong>\uff1a<\/li>\n\n\n\n<li><strong>ER\uff08\u5b9e\u4f53\u5173\u7cfb\uff09\u6a21\u578b<\/strong>\uff1a\u662f\u6570\u636e\u5e93\u8bbe\u8ba1\u7684\u8d77\u70b9\uff0c\u7528\u4e8e\u5c55\u793a\u5b9e\u4f53\u53ca\u5176\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/li>\n\n\n\n<li><strong>\u5173\u7cfb\u6a21\u578b<\/strong>\uff1a\u5728 ER \u6a21\u578b\u7684\u57fa\u7840\u4e0a\uff0c\u8f6c\u6362\u6210\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ed3\u6784\uff0c\u4ee5\u8868\u683c\u7684\u5f62\u5f0f\u8868\u793a\u5b9e\u4f53\u548c\u5173\u7cfb\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong>\u4e3b\u952e\u3001\u5916\u952e\u4e0e\u8868\u7684\u8bbe\u8ba1<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e3b\u952e\uff08Primary Key\uff09<\/strong>\uff1a\u786e\u4fdd\u6bcf\u6761\u8bb0\u5f55\u7684\u552f\u4e00\u6027\uff0c\u4e0d\u80fd\u91cd\u590d\uff0c\u4e14\u4e0d\u80fd\u4e3a NULL\u3002<\/li>\n\n\n\n<li><strong>\u5916\u952e\uff08Foreign Key\uff09<\/strong>\uff1a\u786e\u4fdd\u8868\u4e4b\u95f4\u7684\u6570\u636e\u4e00\u81f4\u6027\uff0c\u8868\u793a\u4e00\u5f20\u8868\u4e0e\u53e6\u4e00\u5f20\u8868\u7684\u5173\u7cfb\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE departments (\n    department_id INT PRIMARY KEY,\n    department_name VARCHAR(100)\n);\n\nCREATE TABLE employees (\n    employee_id INT PRIMARY KEY,\n    first_name VARCHAR(50),\n    last_name VARCHAR(50),\n    department_id INT,\n    salary DECIMAL(10,2),\n    FOREIGN KEY (department_id) REFERENCES departments(department_id)\n);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">3. <strong>\u7d22\u5f15\u4e0e\u6027\u80fd\u4f18\u5316<\/strong><\/h4>\n\n\n\n<p><strong>\u7d22\u5f15<\/strong>\u662f\u63d0\u9ad8\u6570\u636e\u5e93\u67e5\u8be2\u901f\u5ea6\u7684\u6709\u6548\u624b\u6bb5\u3002\u5408\u7406\u7684\u7d22\u5f15\u8bbe\u8ba1\u53ef\u4ee5\u6781\u5927\u63d0\u5347\u67e5\u8be2\u6548\u7387\uff0c\u4f46\u8fc7\u591a\u7684\u7d22\u5f15\u4f1a\u5f71\u54cd\u6570\u636e\u63d2\u5165\u3001\u66f4\u65b0\u548c\u5220\u9664\u64cd\u4f5c\u7684\u6027\u80fd\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u521b\u5efa\u7d22\u5f15\u4e0e\u4f7f\u7528\u7d22\u5f15<\/strong>\uff1a<br>\u7d22\u5f15\u901a\u5e38\u7528\u4e8e\u52a0\u901f WHERE \u5b50\u53e5\u3001JOIN \u548c ORDER BY \u64cd\u4f5c\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE INDEX idx_employee_name ON employees (first_name, last_name);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7d22\u5f15\u7c7b\u578b<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>B-Tree \u7d22\u5f15<\/strong>\uff1a\u9002\u7528\u4e8e\u5927\u591a\u6570\u67e5\u8be2\u64cd\u4f5c\uff0c\u652f\u6301\u8303\u56f4\u67e5\u8be2\u548c\u7b49\u503c\u67e5\u8be2\u3002<\/li>\n\n\n\n<li><strong>Bitmap \u7d22\u5f15<\/strong>\uff1a\u9002\u7528\u4e8e\u5217\u7684\u503c\u6570\u76ee\u8f83\u5c11\u7684\u60c5\u51b5\uff0c\u4f8b\u5982\u6027\u522b\u3001\u72b6\u6001\u7b49\u5b57\u6bb5\u3002<\/li>\n\n\n\n<li><strong>Clustered \u7d22\u5f15<\/strong>\uff1a\u6309\u7167\u7d22\u5f15\u7684\u987a\u5e8f\u5b58\u50a8\u6570\u636e\u3002\u9002\u7528\u4e8e\u8303\u56f4\u67e5\u8be2\u7684\u573a\u666f\u3002<\/li>\n\n\n\n<li><strong>Function-based \u7d22\u5f15<\/strong>\uff1a\u57fa\u4e8e\u8868\u8fbe\u5f0f\u521b\u5efa\u7684\u7d22\u5f15\uff0c\u9002\u7528\u4e8e\u5bf9\u67d0\u4e9b\u5217\u8fdb\u884c\u51fd\u6570\u5904\u7406\u7684\u67e5\u8be2\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>B-Tree \u7d22\u5f15<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  CREATE INDEX idx_employee_salary ON employees (salary);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Bitmap \u7d22\u5f15<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  CREATE BITMAP INDEX idx_gender ON employees (gender);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Function-based \u7d22\u5f15<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  CREATE INDEX idx_upper_name ON employees (UPPER(first_name));<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">4. <strong>\u67e5\u8be2\u4f18\u5316\u4e0e\u6267\u884c\u8ba1\u5212\u5206\u6790<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u67e5\u8be2\u4f18\u5316\u6280\u5de7<\/strong>\uff1a<\/li>\n\n\n\n<li><strong>\u9009\u62e9\u6027\u7d22\u5f15<\/strong>\uff1a\u4f7f\u7528\u7d22\u5f15\u5217\u5728 WHERE \u5b50\u53e5\u4e2d\u8fdb\u884c\u7b5b\u9009\uff0c\u907f\u514d\u5168\u8868\u626b\u63cf\u3002<\/li>\n\n\n\n<li><strong>\u907f\u514d SELECT * \u67e5\u8be2<\/strong>\uff1a\u4ec5\u67e5\u8be2\u9700\u8981\u7684\u5217\uff0c\u51cf\u5c11\u6570\u636e\u4f20\u8f93\u91cf\u3002<\/li>\n\n\n\n<li><strong>\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6392\u5e8f<\/strong>\uff1a\u53ea\u6709\u5728\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f\u65f6\u624d\u4f7f\u7528 ORDER BY\u3002<\/li>\n\n\n\n<li><strong>\u907f\u514d\u4e34\u65f6\u8868<\/strong>\uff1a\u5c3d\u91cf\u907f\u514d\u5728\u67e5\u8be2\u4e2d\u4f7f\u7528\u4e34\u65f6\u8868\uff0c\u5c24\u5176\u662f\u5927\u6570\u636e\u91cf\u7684\u60c5\u51b5\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528 EXPLAIN PLAN \u5206\u6790 SQL \u8bed\u53e5<\/strong>\uff1a<br><code>EXPLAIN PLAN<\/code> \u7528\u6765\u5c55\u793a SQL \u8bed\u53e5\u7684\u6267\u884c\u8ba1\u5212\uff0c\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u7406\u89e3\u67e5\u8be2\u7684\u6267\u884c\u8def\u5f84\uff0c\u627e\u51fa\u6f5c\u5728\u7684\u6027\u80fd\u74f6\u9888\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>EXPLAIN PLAN FOR\nSELECT first_name, last_name, salary\nFROM employees\nWHERE department_id = 10;<\/code><\/pre>\n\n\n\n<p>\u6267\u884c\u540e\uff0c\u4f7f\u7528 <code>SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY)<\/code> \u67e5\u770b\u6267\u884c\u8ba1\u5212\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">5. <strong>\u6570\u636e\u5e93\u7f13\u5b58\u4e0e\u5185\u5b58\u4f18\u5316<\/strong><\/h4>\n\n\n\n<p>Oracle \u4f7f\u7528 <strong>\u7f13\u5b58\u673a\u5236<\/strong> \u6765\u51cf\u5c11\u78c1\u76d8 I\/O\uff0c\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3002\u901a\u8fc7\u5408\u7406\u914d\u7f6e\u6570\u636e\u5e93\u7f13\u5b58\uff08\u5982 DB_CACHE_SIZE\uff09\uff0c\u53ef\u4ee5\u6709\u6548\u63d0\u9ad8\u6570\u636e\u8bbf\u95ee\u901f\u5ea6\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8c03\u6574\u7f13\u5b58\u5927\u5c0f<\/strong>\uff1a<br>\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 <code>SGA<\/code>\uff08\u7cfb\u7edf\u5168\u5c40\u533a\u57df\uff09\u548c <code>PGA<\/code>\uff08\u7a0b\u5e8f\u5168\u5c40\u533a\u57df\uff09\u7684\u5927\u5c0f\u6765\u4f18\u5316\u5185\u5b58\u4f7f\u7528\uff0c\u8fdb\u800c\u63d0\u5347\u6027\u80fd\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER SYSTEM SET db_cache_size = 2G;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u51cf\u5c11\u78c1\u76d8 I\/O<\/strong>\uff1a<br>\u4f7f\u7528 <strong>\u67e5\u8be2\u7f13\u5b58<\/strong> \u548c <strong>\u8868\u7a7a\u95f4\u7f13\u5b58<\/strong> \u6765\u51cf\u5c11\u9891\u7e41\u7684\u6570\u636e\u8bbf\u95ee\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">6. <strong>\u4f7f\u7528 Hint \u63d0\u793a\u4f18\u5316 SQL \u8bed\u53e5<\/strong><\/h4>\n\n\n\n<p><strong>Hint<\/strong> \u63d0\u793a\u7528\u4e8e\u544a\u77e5\u6570\u636e\u5e93\u4f18\u5316\u5668\u4f7f\u7528\u7279\u5b9a\u7684\u6267\u884c\u8ba1\u5212\u7b56\u7565\u3002\u901a\u8fc7\u4f7f\u7528 Hint\uff0c\u53ef\u4ee5\u5f3a\u5236\u6570\u636e\u5e93\u4f18\u5316\u5668\u6267\u884c\u67d0\u79cd\u67e5\u8be2\u8def\u5f84\uff0c\u63d0\u5347\u67e5\u8be2\u6027\u80fd\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5e38\u89c1\u7684 Hint<\/strong>\uff1a<\/li>\n\n\n\n<li><strong>ALL_ROWS<\/strong>\uff1a\u4f18\u5316\u67e5\u8be2\u7684\u603b\u541e\u5410\u91cf\uff0c\u9002\u7528\u4e8e\u9700\u8981\u8fd4\u56de\u5927\u91cf\u6570\u636e\u7684\u67e5\u8be2\u3002<\/li>\n\n\n\n<li><strong>FIRST_ROWS<\/strong>\uff1a\u4f18\u5316\u8fd4\u56de\u7684\u524d\u51e0\u884c\u6570\u636e\uff0c\u9002\u7528\u4e8e\u9700\u8981\u5feb\u901f\u54cd\u5e94\u7684\u67e5\u8be2\u3002<\/li>\n\n\n\n<li><strong>USE_NL<\/strong>\uff1a\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u8fde\u63a5\u3002<\/li>\n\n\n\n<li><strong>USE_HASH<\/strong>\uff1a\u4f7f\u7528\u54c8\u5e0c\u8fde\u63a5\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \/*+ FIRST_ROWS *\/ first_name, last_name, salary\nFROM employees\nWHERE department_id = 10;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e0a\u8ff0\u67e5\u8be2\u4f1a\u4f18\u5148\u4f18\u5316\u8fd4\u56de\u524d\u51e0\u884c\u6570\u636e\u7684\u901f\u5ea6\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u8fd9\u4e9b\u6570\u636e\u5e93\u8bbe\u8ba1\u4e0e\u4f18\u5316\u6280\u5de7\u5e2e\u52a9\u4f60\u5728 Oracle \u6570\u636e\u5e93\u4e2d\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\uff0c\u964d\u4f4e\u8d44\u6e90\u6d88\u8017\uff0c\u5e76\u4fdd\u6301\u6570\u636e\u5e93\u7684\u7a33\u5b9a\u6027\u548c\u9ad8\u6548\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u6570\u636e\u5e93\u8bbe\u8ba1\u7406\u8bba \u6570\u636e\u5e93\u8bbe\u8ba1\u662f\u786e\u4fdd\u6570\u636e\u5e93\u9ad8\u6548\u3001\u53ef\u7ef4\u62a4\u3001\u53ef\u6269\u5c55\u7684\u57fa\u7840\u3002\u5408\u7406\u7684\u6570\u636e\u5e93\u8bbe\u8ba1\u80fd\u6781\u5927\u63d0\u5347\u6570\u636e\u5e93\u7684\u6027\u80fd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-1577","post","type-post","status-publish","format-standard","hentry","category-oracle"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=1577"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1577\/revisions"}],"predecessor-version":[{"id":1578,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1577\/revisions\/1578"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=1577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=1577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=1577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}