QUERY PLAN \n-------------------------------------------------------------------------------\n Index Only Scan using t_a_idx on t (actual time=0.025..0.036 rows=99 loops=1)\n Index Cond: (a < 100)\n Heap Fetches: 0\n Planning time: 0.092 ms\n Execution time: 0.059 ms\n(5 rows)\n<\/code><\/pre>\n\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6ca1\u6709\u53bb\u8bbf\u95ee\u8868 (Heap Fetches: 0)\uff0c\u56e0\u4e3a\u521a\u521a\u505a\u8fc7Vacuum\u3002\u901a\u5e38\u6765\u8bf4\uff0c\u8bbf\u95ee\u6b21\u6570\u8d8a\u5c11\u8d8a\u597d\u3002<\/p>\n
\u5e76\u975e\u6240\u6709\u7684\u7d22\u5f15\u90fd\u5b58\u50a8\u7d22\u5f15\u5217\u7684\u503c\u548cTID\u3002\u5982\u679cAM\u4e0d\u80fd\u8fd4\u56de\u7cbe\u786e\u7684\u5217\u503c\uff0c\u5219\u4e0d\u80fd\u7528\u4f5cIndex Only Scan\uff0c\u6bd4\u5982Hash\u7d22\u5f15\u3002\u5b83\u5c06\u5217\u503c\u8ba1\u7b97\u51fa\u4e00\u4e2aHash\u503c\u5b58\u653e\u5728\u7d22\u5f15\u4e2d\uff0cHash\u7684\u8fc7\u7a0b\u4e0d\u53ef\u9006\uff0c\u56e0\u6b64\u65e0\u6cd5\u83b7\u53d6\u539f\u59cb\u7684\u5217\u503c\u3002<\/p>\n
PG 11 \u589e\u52a0\u4e86\u4e00\u4e2a\u65b0\u7279\u6027\uff1aINCLUDE-indexes\u3002\u5982\u679c\u4e00\u4e2a\u552f\u4e00\u7d22\u5f15\u7f3a\u5c11\u4e00\u4e9b\u5217\uff0c\u4f7f\u5f97\u5b83\u4e0d\u80fd\u6210\u4e3a\u4e00\u4e9b\u67e5\u8be2\u7684Covering Index\uff0c\u5e94\u8be5\u600e\u4e48\u529e\uff1f\u4f60\u4e0d\u80fd\u7b80\u5355\u7684\u628a\u8fd9\u4e9b\u5217\u52a0\u5230\u8fd9\u4e2a\u7d22\u5f15\u4e2d\uff0c\u56e0\u4e3a\u8fd9\u4f1a\u7834\u574f\u7d22\u5f15\u7684\u552f\u4e00\u6027\uff08\u5141\u8bb8\u5728\u52a0\u5217\u4e4b\u524d\u7684\u7d22\u5f15\u4e0a\u6709\u91cd\u590d\u503c\uff09\u3002\u8fd9\u4e2a\u7279\u6027\u5141\u8bb8\u589e\u52a0\u4e00\u4e9bNon-Key\u5217\uff0c\u8fd9\u4e9b\u5217\u4e0d\u4f1a\u5f71\u54cd\u7d22\u5f15\u7684\u552f\u4e00\u6027\uff0c\u4e0d\u80fd\u7528\u4f5c\u7d22\u5f15\u7684\u641c\u7d22\u6761\u4ef6\uff0c\u4f46\u662f\u53ef\u4ee5\u5728Index Only Scan\u4e2d\u88ab\u4f7f\u7528\u3002<\/p>\n
2.3 NULL<\/h2>\n
NULL\u503c\u5728\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e2d\u626e\u6f14\u7740\u91cd\u8981\u7684\u89d2\u8272\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u8868\u793a\u4e0d\u5b58\u5728\u6216\u672a\u77e5\u503c\u7684\u65b9\u5f0f\u3002<\/p>\n
\u4f46\u662f\u8fd9\u4e2a\u7279\u6b8a\u503c\u9700\u8981\u88ab\u7279\u6b8a\u5904\u7406\u3002\u5e38\u89c4\u7684\u5e03\u5c14\u4ee3\u6570\u53d8\u6210\u4e86\u4e09\u5143\uff08\u771f\u3001\u5047\u3001NULL\uff09\uff1b\u6211\u4eec\u4e0d\u77e5\u9053NULL\u6bd4\u6b63\u5e38\u503c\u5927\u8fd8\u662f\u5c0f\uff08\u5bf9\u6392\u5e8f\u6765\u8bf4\uff0c\u8fd9\u9700\u8981\u7279\u6b8a\u7684\u8003\u8651\uff0cNULLS FIRST\u548cNULLS LAST\uff09\uff1b\u805a\u96c6\u51fd\u6570\u662f\u5426\u9700\u8981\u8003\u8651NULL\u503c\u4e5f\u5e76\u4e0d\u660e\u663e\uff1b\u4f18\u5316\u5668\u9700\u8981\u4e3aNULL\u503c\u4fdd\u5b58\u7279\u6b8a\u7684\u7edf\u8ba1\u4fe1\u606f\uff0c\u7b49\u7b49\u2026\u2026<\/p>\n
\u4ece\u7d22\u5f15\u652f\u6301\u7684\u89d2\u5ea6\u8003\u8651\uff0c\u4e5f\u4e0d\u6e05\u695a\u662f\u5426\u5e94\u8be5\u7d22\u5f15\u8fd9\u4e9bNULL\u503c\u3002\u5982\u679c\u4e0d\u7d22\u5f15NULL\u503c\uff0c\u7d22\u5f15\u4f1a\u6bd4\u8f83\u7d27\u51d1\u3002\u5982\u679c\u7d22\u5f15NULL\u503c\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u56de\u7b54\u201cindexed-field IS [NOT] NULL\u201d\u8fd9\u79cd\u67e5\u8be2\uff0c\u800c\u4e14\u53ef\u4ee5\u5728\u4e0d\u6307\u5b9a\u4efb\u4f55\u6761\u4ef6\u65f6\u88ab\u5f53\u505aCovering Index\uff08\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u7d22\u5f15\u5fc5\u987b\u8fd4\u56de\u8868\u4e2d\u6240\u6709\u7684\u6570\u636e\uff0c\u5305\u62ecNULLs\uff09\u3002<\/p>\n
\u5bf9\u6bcf\u79cdAM\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u81ea\u884c\u51b3\u7b56\u662f\u5426\u7d22\u5f15NULL\u3002\u5927\u591a\u6570AM\u4e2d\uff0cNULL\u503c\u4f1a\u88ab\u7d22\u5f15\u3002<\/p>\n
2.4 \u591a\u5217\u7d22\u5f15<\/h2>\n
\u4e3a\u4e86\u652f\u6301\u4f7f\u7528\u5305\u542b\u591a\u4e2a\u5217\u7684\u6761\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u5217\u7d22\u5f15\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8868\u4e2d\u7684\u4e24\u4e2a\u5217\u5efa\u7acb\u4e00\u4e2a\u7d22\u5f15\uff1a<\/p>\n
create index on t(a,b);\nanalyze t;\n<\/code><\/pre>\n\u4f18\u5316\u5668\u66f4\u53ef\u80fd\u503e\u5411\u4e8e\u4f7f\u7528\u8fd9\u4e2a\u7d22\u5f15\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u4e24\u4e2a\u4f4d\u56fe\uff0c\u56e0\u4e3a\u5728\u8fd9\u4e00\u4e2a\u7d22\u5f15\u4e2d\u5c31\u53ef\u4ee5\u5f97\u5230\u6240\u9700\u7684TID\uff0c\u65e0\u9700\u5176\u5b83\u64cd\u4f5c\u3002<\/p>\n
explain (costs off) select * from t where a <= 100 and b = 'a';\n<\/code><\/pre>\n QUERY PLAN \n------------------------------------------------\n Index Scan using t_a_b_idx on t\n Index Cond: ((a <= 100) AND (b = 'a'::text))\n(2 rows)\n<\/code><\/pre>\n\u5982\u679c\u4e00\u4e2a\u6761\u4ef6\u4e2d\u4ec5\u4ec5\u4f7f\u7528\u4e86\u4e00\u4e2a\u591a\u5217\u7d22\u5f15\u4e2d\u7684\u90e8\u5206\u5217\uff0c\u5e76\u4e14\u4f7f\u7528\u4e86\u4ece\u7b2c\u4e00\u4e2a\u7d22\u5f15\u5217\u5f00\u59cb\u7684\u67d0\u4e9b\u5217\uff0c\u8fd9\u4e2a\u591a\u5217\u7d22\u5f15\u4e5f\u53ef\u4ee5\u88ab\u67e5\u8be2\u4f7f\u7528\u3002<\/p>\n
explain (costs off) select * from t where a <= 100;\n<\/code><\/pre>\n QUERY PLAN \n--------------------------------------\n Bitmap Heap Scan on t\n Recheck Cond: (a <= 100)\n -> Bitmap Index Scan on t_a_b_idx\n Index Cond: (a <= 100)\n(4 rows)\n<\/code><\/pre>\n\u901a\u5e38\u6765\u8bb2\uff0c\u5982\u679c\u6761\u4ef6\u6ca1\u6709\u4f7f\u7528\u7b2c\u4e00\u4e2a\u7d22\u5f15\u5217\uff0c\u8fd9\u4e2a\u7d22\u5f15\u4e0d\u4f1a\u88ab\u4f7f\u7528\u3002\u4f46\u662f\u5728\u67d0\u4e9b\u573a\u666f\u4e0b\uff0c\u4f18\u5316\u5668\u53ef\u80fd\u4f1a\u8ba4\u4e3a\u4f7f\u7528\u7d22\u5f15\u4f1a\u6bd4\u5168\u8868\u626b\u63cf\u66f4\u52a0\u9ad8\u6548\u3002\u6211\u4eec\u5c06\u5728\u8bb2\u89e3Btree\u7d22\u5f15\u65f6\u5c55\u5f00\u8fd9\u4e2a\u8bdd\u9898\u3002<\/p>\n
\u4e0d\u662f\u6240\u6709\u7684AM\u90fd\u652f\u6301\u591a\u5217\u7d22\u5f15\u3002<\/p>\n
2.5 \u8868\u8fbe\u5f0f\u7d22\u5f15<\/h2>\n
\u6211\u4eec\u63d0\u5230\u8fc7\uff0c\u641c\u7d22\u6761\u4ef6\u5fc5\u987b\u8981\u7b26\u5408indexed-field operator expression\u7684\u5f62\u5f0f\u3002\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u7d22\u5f15\u4e0d\u80fd\u88ab\u4f7f\u7528\uff0c\u56e0\u4e3a\u5b83\u4f7f\u7528\u4e86\u4e00\u4e2a\u5305\u542b\u7d22\u5f15\u5217\u7684\u8868\u8fbe\u5f0f\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u4f7f\u7528\u5217\u540d\u672c\u8eab\u3002<\/p>\n
explain (costs off) select * from t where lower(b) = 'a';\n<\/code><\/pre>\n QUERY PLAN \n------------------------------------------\n Seq Scan on t\n Filter: (lower((b)::text) = 'a'::text)\n(2 rows)\n<\/code><\/pre>\n\u5bf9\u8fd9\u4e2a\u8bed\u53e5\u6765\u8bf4\uff0c\u5f88\u5bb9\u6613\u5c06\u5b83\u6539\u5199\u6210\u7b26\u5408\u4f7f\u7528\u7d22\u5f15\u6761\u4ef6\u7684\u8bed\u53e5\u3002\u4f46\u662f\u5f53\u67d0\u4e9b\u67e5\u8be2\u4e0d\u80fd\u88ab\u6539\u5199\u65f6\uff0c\u8868\u8fbe\u5f0f\u7d22\u5f15\uff08\u51fd\u6570\u7d22\u5f15\uff09\u5c31\u53ef\u4ee5\u88ab\u6d3e\u4e0a\u7528\u573a\u3002<\/p>\n
create index on t(lower(b));\nanalyze t;\nexplain (costs off) select * from t where lower(b) = 'a';\n<\/code><\/pre>\n QUERY PLAN \n----------------------------------------------------\n Bitmap Heap Scan on t\n Recheck Cond: (lower((b)::text) = 'a'::text)\n -> Bitmap Index Scan on t_lower_idx\n Index Cond: (lower((b)::text) = 'a'::text)\n(4 rows)\n<\/code><\/pre>\n\u51fd\u6570\u7d22\u5f15\u4e0d\u662f\u5efa\u7acb\u8868\u7684\u67d0\u5217\u4e0a\uff0c\u800c\u662f\u5efa\u7acb\u5728\u4efb\u610f\u8868\u8fbe\u5f0f\u4e0a\u3002\u4f18\u5316\u5668\u4f1a\u5bf9\u7b26\u5408indexed-expression operator expression\u5f62\u5f0f\u7684\u6761\u4ef6\u5c1d\u8bd5\u4f7f\u7528\u8fd9\u79cd\u7d22\u5f15\u3002\u5982\u679c\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u7684\u8ba1\u7b97\u975e\u5e38\u8017\u8d39\u8d44\u6e90\uff0c\u66f4\u65b0\u7d22\u5f15\u65f6\u5c31\u9700\u8981\u6d88\u8017\u76f8\u5f53\u53ef\u89c2\u7684\u8d44\u6e90\u3002<\/p>\n
\u8bf7\u6ce8\u610f\uff0c\u8868\u8fbe\u5f0f\u7d22\u5f15\u7684\u7edf\u8ba1\u4fe1\u606f\u4f1a\u88ab\u5355\u72ec\u7684\u6536\u96c6\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u7684\u540d\u5b57\u4ecepg_stats\u89c6\u56fe\u4e2d\u67e5\u8be2\uff1a<\/p>\n
\\d t\n\n Table \"public.t\"\n Column | Type | Modifiers\n--------+---------+-----------\n a | integer |\n b | text |\n c | boolean |\nIndexes:\n \"t_a_b_idx\" btree (a, b)\n \"t_a_idx\" btree (a)\n \"t_b_idx\" btree (b)\n \"t_lower_idx\" btree (lower(b))\n<\/code><\/pre>\nselect * from pg_stats where tablename = 't_lower_idx';\n<\/code><\/pre>\n\u5982\u679c\u6709\u5fc5\u8981\uff0c\u4e5f\u53ef\u4ee5\u6539\u53d8\u76f4\u65b9\u56fe\u4e2dbucket\u7684\u6570\u91cf\uff0c\u5c31\u50cf\u64cd\u4f5c\u666e\u901a\u6570\u636e\u7c7b\u578b\u4e00\u6837\uff08\u6ce8\u610f\u5217\u540d\u53ef\u80fd\u56e0\u7d22\u5f15\u8868\u8fbe\u5f0f\u7684\u4e0d\u540c\u800c\u4e0d\u540c\uff09\uff1a<\/p>\n
\\d t_lower_idx\n\n Index \"public.t_lower_idx\"\n Column | Type | Definition\n--------+------+------------\n lower | text | lower(b)\nbtree, for table \"public.t\"\n<\/code><\/pre>\nalter index t_lower_idx alter column \"lower\" set statistics 69;\n<\/code><\/pre>\nPG 11\u53ef\u4ee5\u4f7f\u7528\u4e00\u79cd\u66f4\u52a0\u6e05\u6670\u7684\u65b9\u5f0f\u63a7\u5236\u7d22\u5f15\u7684\u7edf\u8ba1\u4fe1\u606f\uff0c\u8bed\u6cd5\u4e3aALTER INDEX … SET STATISTICS\u3002<\/p>\n
2.6 \u90e8\u5206\u7d22\u5f15<\/h2>\n
\u6709\u65f6\u6211\u4eec\u4ec5\u4ec5\u9700\u8981\u5bf9\u8868\u4e2d\u90e8\u5206\u6570\u636e\u5efa\u7acb\u7d22\u5f15\u3002\u8fd9\u5728\u6570\u636e\u5206\u5e03\u4e25\u91cd\u4e0d\u5747\u7684\u60c5\u51b5\u4e0b\u6bd4\u8f83\u6709\u7528\uff1a\u4f7f\u7528\u7d22\u5f15\u67e5\u627e\u51fa\u73b0\u9891\u7387\u8f83\u4f4e\u7684\u503c\uff0c\u4f7f\u7528\u5168\u8868\u626b\u63cf\u67e5\u627e\u51fa\u73b0\u9891\u7387\u8f83\u9ad8\u7684\u503c\u3002<\/p>\n
\u6211\u4eec\u53ef\u4ee5\u5728c\u5217\u4e0a\u5efa\u7acb\u4e00\u4e2a\u7d22\u5f15\uff1a<\/p>\n
create index on t(c);\nanalyze t;\nexplain (costs off) select * from t where c;\n<\/code><\/pre>\n QUERY PLAN \n-------------------------------\n Index Scan using t_c_idx on t\n Index Cond: (c = true)\n Filter: c\n(3 rows)\n<\/code><\/pre>\nexplain (costs off) select * from t where not c;\n<\/code><\/pre>\n QUERY PLAN \n-------------------\n Seq Scan on t\n Filter: (NOT c)\n(2 rows)\n<\/code><\/pre>\n\u7d22\u5f15\u5360\u7528\u4e86276\u4e2a\u9875\u9762<\/p>\n
select relpages from pg_class where relname='t_c_idx';\n<\/code><\/pre>\n relpages\n----------\n 276\n(1 row)\n<\/code><\/pre>\n\u4f46\u662f\u56e0\u4e3ac\u5217\u53ea\u67091%\u7684\u884c\u4e3atrue\uff0c99%\u7684\u7d22\u5f15\u5e76\u6ca1\u6709\u88ab\u4f7f\u7528\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u5efa\u7acb\u4e00\u4e2a\u90e8\u5206\u7d22\u5f15\uff1a<\/p>\n
create index on t(c) where c;\nanalyze t;\n<\/code><\/pre>\n\u7d22\u5f15\u5360\u7528\u7684\u9875\u9762\u6570\u51cf\u5c11\u52305\u4e2a\u3002<\/p>\n
select relpages from pg_class where relname='t_c_idx1';\n<\/code><\/pre>\n relpages\n----------\n 5\n(1 row)\n<\/code><\/pre>\n\u6709\u65f6\u5019\uff0c\u7a7a\u95f4\u5360\u7528\u548c\u6027\u80fd\u53ef\u80fd\u90fd\u5f88\u91cd\u8981\u3002<\/p>\n
2.7 \u6392\u5e8f<\/h2>\n
\u5982\u679c\u4e00\u4e2aAM\u53ef\u4ee5\u6309\u7167\u67d0\u79cd\u987a\u5e8f\u8fd4\u56deTID\uff0c\u5c31\u53ef\u4ee5\u4e3a\u4f18\u5316\u5668\u63d0\u4f9b\u66f4\u591a\u7684\u9009\u62e9\u6765\u4f18\u5316\u8fd9\u4e2a\u67e5\u8be2\u3002<\/p>\n
\u6211\u4eec\u53ef\u4ee5\u5148\u626b\u63cf\u5168\u8868\uff0c\u7136\u540e\u6392\u5e8f\uff1a<\/p>\n
set enable_indexscan=off;\n\nexplain (costs off) select * from t order by a;\n<\/code><\/pre>\n QUERY PLAN \n---------------------\n Sort\n Sort Key: a\n -> Seq Scan on t\n(3 rows)\n<\/code><\/pre>\n\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5df2\u7ecf\u6309\u9700\u6392\u5e8f\u7684\u7d22\u5f15\u76f4\u63a5\u8bfb\u53d6\u6570\u636e\uff1a<\/p>\n
set enable_indexscan=on;\nexplain (costs off) select * from t order by a;\n<\/code><\/pre>\n QUERY PLAN \n-------------------------------\n Index Scan using t_a_idx on t\n(1 row)\n<\/code><\/pre>\n\u5728\u6240\u6709\u7684AM\u4e2d\uff0c\u53ea\u6709Btree\u7d22\u5f15\u53ef\u4ee5\u8fd4\u56de\u6709\u5e8f\u7684\u6570\u636e\uff0c\u6240\u4ee5\u6211\u4eec\u5c06\u5728\u4ecb\u7ecdBtree\u7d22\u5f15\u65f6\u5bf9\u6b64\u95ee\u9898\u8fdb\u884c\u66f4\u8be6\u7ec6\u7684\u4ecb\u7ecd\u3002<\/p>\n
2.8 \u5e76\u884c\u521b\u5efa<\/h2>\n
\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u5efa\u7acb\u7d22\u5f15\u9700\u8981\u5bf9\u8868\u52a0Share\u9501\u3002\u8fd9\u4e2a\u9501\u5141\u8bb8\u5176\u5b83\u4e8b\u52a1\u4ece\u8868\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u4f46\u662f\u5728\u7d22\u5f15\u521b\u5efa\u671f\u95f4\u7981\u6b62\u5176\u5b83\u4e8b\u52a1\u5411\u8868\u4e2d\u63d2\u5165\u6570\u636e\u3002<\/p>\n
\u6211\u4eec\u53ef\u4ee5\u5728\u7ed9\u8868t\u5efa\u7acb\u7d22\u5f15\u671f\u95f4\uff0c\u5728\u53e6\u4e00\u4e2asession\u8fdb\u884c\u4e0b\u9762\u7684\u67e5\u8be2\uff1a<\/p>\n
select mode, granted from pg_locks where relation = 't'::regclass;\n<\/code><\/pre>\n mode | granted\n-----------+---------\n ShareLock | t\n(1 row)\n<\/code><\/pre>\n\u5982\u679c\u8fd9\u4e2a\u8868\u7279\u522b\u5927\uff0c\u5e76\u4e14\u9700\u8981\u7ecf\u5e38\u8fdb\u884c\u589e\u5220\u6539\uff0c\u4e8b\u52a1\u957f\u65f6\u95f4\u6301\u6709Share\u9501\u4f1a\u53d8\u5f97\u4e0d\u53ef\u63a5\u53d7\uff0c\u56e0\u4e3a\u5199\u4e8b\u52a1\u5fc5\u987b\u957f\u65f6\u95f4\u7b49\u5f85\uff0c\u76f4\u5230Share\u9501\u88ab\u91ca\u653e\u3002<\/p>\n
\u8fd9\u79cd\u573a\u666f\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5e76\u884c\u521b\u5efa\u7d22\u5f15\u7684\u529f\u80fd\uff1a<\/p>\n
create index concurrently on t(a);\n<\/code><\/pre>\n\u8fd9\u4e2a\u547d\u4ee4\u5bf9\u8868\u52a0SHARE UPDATE EXCLUSIV\u9501\uff0c\u5b83\u5141\u8bb8\u8868\u88ab\u8bfb\u53d6\u548c\u66f4\u65b0\uff08\u4ec5\u4ec5\u7981\u6b62\u6539\u53d8\u8868\u5b9a\u4e49\u3001Vacuum\u3001Analyze\u548c\u540c\u65f6\u5728\u8fd9\u4e2a\u8868\u4e0a\u201c\u5e76\u884c\u521b\u5efa\u201d\u5176\u5b83\u7d22\u5f15\u3002\u8bf7\u53c2\u8003PG\u76844\u53f7\u9501\uff09\u3002<\/p>\n
\u7136\u800c\uff0c\u8fd9\u4e5f\u6709\u4e0d\u5229\u7684\u4e00\u9762\u3002\u9996\u5148\uff0c\u8fd9\u4e2a\u7d22\u5f15\u4f1a\u521b\u5efa\u7684\u6bd4\u8f83\u6162\u3002\u56e0\u4e3a\u8fd9\u4e2a\u8fc7\u7a0b\u9700\u8981\uff1a<\/p>\n
\n- \u4e24\u6b21\u5168\u8868\u626b\u63cf\uff0c\u800c\u4e0d\u662f\u4e00\u904d<\/li>\n
- \u7b49\u5f85\u7d22\u5f15\u521b\u5efa\u671f\u95f4\u7684\u5199\u4e8b\u52a1\u7ed3\u675f\u3002<\/li>\n<\/ul>\n
\u5176\u6b21\uff0c\u5e76\u884c\u521b\u5efa\u6267\u884c\u671f\u95f4\uff0c\u53ef\u80fd\u4f1a\u53d1\u751f\u6b7b\u9501\uff0c\u6216\u8005\u8fdd\u53cd\u4e00\u81f4\u6027\u7ea6\u675f\u3002\u7136\u800c\uff0c\u7d22\u5f15\u8fd8\u662f\u4f1a\u88ab\u521b\u5efa\u51fa\u6765\uff0c\u867d\u7136\u8fd9\u6837\u7684\u7d22\u5f15\u4e0d\u80fd\u7528\u3002\u8fd9\u79cd\u7d22\u5f15\u5fc5\u987b\u88ab\u624b\u5de5\u5220\u9664\u6216\u91cd\u5efa\u3002\u5728psql\u7684\d\u547d\u4ee4\u7684\u8f93\u51fa\u4e2d\uff0c\u8fd9\u4e9b\u4e0d\u80fd\u7528\u7684\u7d22\u5f15\u4f1a\u88ab\u6807\u8bb0\u4e3aINVALID\uff0c\u4e0b\u9762\u7684sql\u8bed\u53e5\u53ef\u4ee5\u67e5\u8be2\u5230\u8fd9\u79cd\u7d22\u5f15\u7684\u5b8c\u6574\u5217\u8868\uff1a<\/p>\n
select indexrelid::regclass index_name, indrelid::regclass table_name\nfrom pg_index where not indisvalid;\n<\/code><\/pre>\n index_name | table_name\n------------+------------\n t_a_idx | t\n(1 row)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u6458\u8981\uff1a<\/b>PostgreSQL\u652f\u6301\u591a\u79cd\u7d22\u5f15\u7c7b\u578b\uff0c\u6bcf\u79cd\u7d22\u5f15\u7c7b\u578b\u88ab\u79f0\u4e3a\u4e00\u79cd\u5b58\u53d6\u65b9\u6cd5\uff08Access Method\uff0c\u7b80\u79f0AM\uff09\u3002\u4e3a\u4e86\u7edf\u4e00\u8fd9\u4e9bAM\uff0cPG\u5728AM\u5c42\u4e4b\u4e0a\u5b9e\u73b0\u4e86\u4e00\u4e2a\u901a\u7528\u7d22\u5f15\u5f15\u64ce\u3002\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u901a\u7528\u7d22\u5f15\u5f15\u64ce\u548cAM\u7684\u8d23\u4efb\u5212\u5206\u3001\u901a\u7528\u7d22\u5f15\u5f15\u64ce\u7684\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/posts\/108"}],"collection":[{"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":69,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":620,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/posts\/108\/revisions\/620"}],"wp:attachment":[{"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}