{"id":213,"date":"2020-10-01T03:00:54","date_gmt":"2020-09-30T19:00:54","guid":{"rendered":"https:\/\/www.mengqingzhong.com\/?p=213"},"modified":"2024-01-14T11:38:30","modified_gmt":"2024-01-14T03:38:30","slug":"postgresql-index-hash-3","status":"publish","type":"post","link":"https:\/\/www.mengqingzhong.com\/2020\/10\/01\/postgresql-index-hash-3\/","title":{"rendered":"PostgreSQL\u7d22\u5f15(3) \u2013 Hash"},"content":{"rendered":"
\n\u672c\u6587\u7ffb\u8bd1\u81eaEgor Rogov\u7684\u82f1\u6587\u535a\u5ba2<\/a>\uff0c\u4e14\u5df2\u5f81\u5f97Egor Rogov\u7684\u540c\u610f\u3002\u8bd1\u8005\u505a\u4e86\u5c11\u91cf\u4fee\u6539\u3002\n<\/p>\n \n\u5ba1\u6821\uff1a\u7eaa\u6600\u7ea2\uff0c\u4e2d\u56fd\u4eba\u6c11\u5927\u5b66\u4fe1\u606f\u5b66\u9662\u5728\u8bfb\u535a\u58eb\u751f\u3002\n<\/p>\n \u5f88\u591a\u73b0\u4ee3\u7f16\u7a0b\u8bed\u8a00\u90fd\u628aHash\u8868\u4f5c\u4e3a\u4e00\u79cd\u5185\u7f6e\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u3002\u4ece\u5916\u90e8\u6765\u770b\uff0cHash\u8868\u5c31\u50cf\u666e\u901a\u7684\u6570\u7ec4\uff0c\u6570\u7ec4\u7684\u4e0b\u6807\u53ef\u4ee5\u662f\u4efb\u610f\u7684\u6570\u636e\u7c7b\u578b\uff08\u6bd4\u5982\uff0c\u5b57\u7b26\u4e32\uff09\uff0c\u5e76\u975e\u53ea\u80fd\u662f\u4e00\u4e2a\u6574\u6570\u3002PG\u7684Hash\u7d22\u5f15\u5177\u6709\u7c7b\u4f3c\u7684\u7ed3\u6784\uff0c\u5b83\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u5462\uff1f<\/p>\n \u901a\u5e38\u6765\u8bb2\uff0c\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u7684\u503c\u57df\u5177\u6709\u76f8\u5f53\u5927\u7684\u8303\u56f4\uff1a\u4e00\u4e2atext\u7c7b\u578b\u7684\u5217\u4e2d\u53ef\u80fd\u4f1a\u6709\u591a\u5c11\u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\uff1f\u4f46\u662f\uff0c\u73b0\u5b9e\u751f\u6d3b\u4e2d\uff0c\u8868\u4e2d\u4e00\u4e2atext\u7c7b\u578b\u7684\u5217\u4e2d\u5b9e\u9645\u4f1a\u6709\u591a\u4e2a\u4e0d\u540c\u7684\u503c\uff1f\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u5e76\u4e0d\u662f\u5f88\u591a\u3002<\/p>\n Hash\u7684\u601d\u60f3\u662f\u628a\u4efb\u610f\u6570\u636e\u7c7b\u578b\u7684\u4e00\u4e2a\u503c\u4e0e\u4e00\u4e2a\u6574\u6570\u76f8\u5173\u8054\uff08\u4ece0\u5230N-1\uff0c\u5171N\u4e2a\u503c\uff09\u3002\u8fd9\u4e2a\u5173\u8054\u8fc7\u7a0b\u7531Hash\u51fd\u6570\u5b8c\u6210\u3002\u5f97\u5230\u7684\u8fd9\u4e2a\u6574\u6570\u53ef\u4ee5\u7528\u4f5c\u6570\u7ec4\u7684\u4e0b\u6807\uff0c\u8fd9\u4e2a\u6570\u7ec4\u4e2d\u5b58\u50a8\u4e86\u5927\u91cf\u6307\u5411\u8868\u4e2d\u884c\u7684TID\u3002\u8fd9\u4e2a\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u88ab\u79f0\u4f5cHash\u8868\u7684\u6876 \u2014\u2014 \u4e00\u4e2a\u6876\u4e2d\u53ef\u4ee5\u5b58\u50a8\u591a\u4e2aTID\uff0c\u5982\u679c\u76f8\u540c\u7684\u5217\u503c\u5728\u8868\u4e2d\u4e0d\u540c\u884c\u51fa\u73b0\u591a\u6b21\u3002<\/p>\n Hash\u51fd\u6570\u5c06\u5217\u503c\u5728\u4e0d\u540c\u7684\u6876\u4e2d\u5206\u5e03\u7684\u8d8a\u5747\u5300\uff0c\u5219\u8fd9\u4e2aHash\u51fd\u6570\u8d8a\u597d\u3002\u4f46\u662f\uff0c\u5373\u4f7f\u662f\u4e00\u4e2a\u597d\u7684Hash\u51fd\u6570\uff0c\u6709\u65f6\u4e5f\u4f1a\u628a\u4e0d\u540c\u7684\u5217\u503c\u8ba1\u7b97\u51fa\u76f8\u540c\u7684Hash\u503c \u2014\u2014 \u5373\u53d1\u751f\u4e86\u51b2\u7a81\u3002\u6240\u4ee5\uff0c\u4e00\u4e2a\u6876\u4e2d\u53ef\u80fd\u5b58\u50a8\u4e86\u4e0d\u540c\u5217\u503c\u7684TID\uff0c\u56e0\u6b64\uff0c\u4eceHash\u7d22\u5f15\u4e2d\u67e5\u51fa\u7684TID\u9700\u8981\u88ab\u91cd\u65b0\u68c0\u67e5\u3002<\/p>\n \u968f\u4fbf\u4e3e\u4e2a\u4f8b\u5b50\uff1a\u5bf9\u5b57\u7b26\u4e32\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ec0\u4e48Hash\u51fd\u6570\uff1f\u5047\u8bbe\u6876\u7684\u6570\u91cf\u4e3a256\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff08\u5047\u8bbe\u4f7f\u7528\u5355\u5b57\u8282\u7f16\u7801\uff09\u7684asiic\u7801\u503c\u4f5c\u4e3aHash\u503c\u3002\u8fd9\u662f\u4e00\u4e2a\u597d\u7684Hash\u51fd\u6570\u5417\uff1f\u5f53\u7136\u4e0d\u662f\uff1a\u5982\u679c\u6240\u6709\u7684\u5b57\u7b26\u4e32\u90fd\u4ee5\u76f8\u540c\u7684\u5b57\u7b26\u5f00\u5934\uff0c\u5b83\u4eec\u88ab\u5b58\u50a8\u5230\u540c\u4e00\u4e2a\u6876\uff0c\u6240\u6709\u7684\u503c\u90fd\u9700\u8981\u88ab\u91cd\u65b0\u68c0\u67e5\uff0cHash\u53d8\u5f97\u6ca1\u6709\u4efb\u4f55\u610f\u4e49\u3002\u5047\u8bbe\u628a\u6240\u6709\u5b57\u7b26\u7684asiic\u7801\u503c\u6c42\u548c\uff0c\u518d\u5bf9256\u53d6\u6a21\u5462\uff1f\u8fd9\u53ef\u80fd\u4f1a\u597d\u4e00\u4e9b\uff0c\u4f46\u662f\u8ddd\u79bb\u9884\u671f\u8fd8\u6709\u5f88\u8fdc\u3002\u5982\u679c\u4f60\u5bf9PG\u5185\u90e8\u5b9e\u73b0\u4e2d\u7684Hash\u51fd\u6570\u611f\u5174\u8da3\uff0c\u8bf7\u67e5\u770bhashfunc.c<\/a>\u4e2dhash_any()\u51fd\u6570\u7684\u5b9e\u73b0\u3002<\/p>\n \u6211\u4eec\u56de\u5230Hash\u7d22\u5f15\u3002\u5bf9\u67d0\u4e2a\u6570\u636e\u7c7b\u578b\u7684\u4e00\u4e2a\u503c\uff08\u7d22\u5f15\u5217\u7684\u503c\uff09\uff0c\u6211\u4eec\u7684\u4efb\u52a1\u662f\u5feb\u901f\u627e\u5230\u5b83\u5bf9\u5e94\u7684TID\u3002<\/p>\n \u5f53\u5411\u7d22\u5f15\u4e2d\u63d2\u5165\u65f6\uff0c\u6211\u4eec\u4f1a\u5bf9\u5217\u503c\u8ba1\u7b97Hash\u503c\u3002PG\u4e2d\u7684Hash\u51fd\u6570\u901a\u5e38\u8fd4\u56de\u4e00\u4e2a\u6574\u578b\uff0c\u5b83\u7684\u8303\u56f4\u5927\u7ea6\u4e3a232<\/sup> \u2248 42\u4ebf\u3002\u6876\u7684\u6570\u91cf\u521d\u59cb\u4e3a2\uff0c\u968f\u7740\u6570\u636e\u91cf\u7684\u589e\u52a0\u800c\u52a8\u6001\u589e\u52a0\u3002\u6876\u7684\u7f16\u53f7\u53ef\u4ee5\u901a\u8fc7\u5bf9Hash\u503c\u505a\u4f4d\u8fd0\u7b97\u5f97\u51fa\uff0c\u8fd9\u4e2a\u6876\u5c31\u662f\u5b58\u653eTID\u7684\u6876\u3002<\/p>\n \u4f46\u8fd9\u8fd8\u4e0d\u591f\uff0c\u56e0\u4e3a\u4e0d\u540c\u7684\u5217\u503c\u5bf9\u5e94\u7684TID\u53ef\u80fd\u4f1a\u88ab\u5b58\u653e\u5230\u76f8\u540c\u7684\u6876\u4e2d\u3002\u6211\u4eec\u5e94\u8be5\u600e\u4e48\u529e\u5462\uff1f\u4e00\u79cd\u53ef\u80fd\u7684\u5b9e\u73b0\u65b9\u5f0f\u662f\u628a\u539f\u59cb\u7684\u5217\u503c\u548cTID\u4e00\u8d77\u5b58\u653e\u5728\u6876\u4e2d\uff0c\u4f46\u8fd9\u5c06\u5927\u5927\u589e\u52a0\u7d22\u5f15\u6240\u5360\u7684\u7a7a\u95f4\u3002\u56e0\u6b64\uff0c\u4e3a\u4e86\u8282\u7701\u7a7a\u95f4\uff0c\u6876\u4e2d\u5b58\u653e\u7684\u662f\u5217\u503c\u7684Hash\u503c\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u5b58\u653e\u5217\u503c\u3002<\/p>\n \u5f53\u5728\u7d22\u5f15\u4e2d\u67e5\u627e\u65f6\uff0c\u6211\u4eec\u5bf9\u5217\u503c\u8ba1\u7b97Hash\u503c\uff0c\u5f97\u5230\u6876\u7684\u7f16\u53f7\u3002\u7136\u540e\uff0c\u904d\u5386\u6876\u4e2d\u7684\u5143\u7d20\uff0c\u4ec5\u8fd4\u56de\u76f8\u5e94Hash\u503c\u5f97TID\u3002\u8fd9\u53ef\u4ee5\u9ad8\u6548\u7684\u5b8c\u6210\uff0c\u56e0\u4e3a<Hash\u503c, TID>\u88ab\u6709\u5e8f\u7684\u5b58\u50a8\u3002<\/p>\n \u7136\u800c\uff0c\u6709\u65f6\u4e24\u4e2a\u4e0d\u540c\u7684key\u4e0d\u4ec5\u88ab\u5b58\u50a8\u5728\u76f8\u540c\u7684\u6876\u4e2d\uff0c\u800c\u4e14\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684Hash\u503c\u3002\u56e0\u6b64\uff0cAM\u4f1a\u8ba9\u7d22\u5f15\u5f15\u64ce\u91cd\u65b0\u68c0\u67e5\uff08\u7d22\u5f15\u5f15\u64ce\u53ef\u4ee5\u5728\u68c0\u67e5\u53ef\u89c1\u6027\u65f6\u987a\u4fbf\u505a\u8fd9\u4ef6\u4e8b\uff09\u7d22\u5f15\u6761\u4ef6\uff0c\u7528\u6765\u786e\u8ba4TID\u662f\u5426\u771f\u7684\u6ee1\u8db3\u7d22\u5f15\u6761\u4ef6\u3002<\/p>\n \u5982\u679c\u6211\u4eec\u4ece\u7f13\u51b2\u533a\u7ba1\u7406\u5668\u7684\u89d2\u5ea6\u770b\u4e00\u4e2a\u7d22\u5f15\uff0c\u800c\u4e0d\u662f\u4ece\u67e5\u8be2\u4f18\u5316\u5668\u548c\u6267\u884c\u5668\u7684\u89d2\u5ea6\u770b\uff0c\u4f1a\u53d1\u73b0\u6240\u6709\u7684\u4fe1\u606f\u3001\u6240\u6709\u7684\u7d22\u5f15\u9879\u90fd\u5fc5\u987b\u6309\u4e00\u5b9a\u89c4\u5219\u5b58\u653e\u5728\u9875\u9762\u4e2d\u3002\u8fd9\u6837\uff0c\u7d22\u5f15\u9875\u9762\u53ef\u4ee5\u88ab\u52a0\u8f7d\u8fdb\u7f13\u51b2\u533a\uff0c\u4e5f\u53ef\u4ee5\u4ece\u7f13\u51b2\u533a\u6362\u51fa\uff0c\u5c31\u50cf\u7ba1\u7406\u8868\u4e2d\u7684\u9875\u9762\u4e00\u6837\u3002<\/p>\n <\/a><\/p>\n \u5982\u4e0a\u56fe\u6240\u793a\uff0cHash\u7d22\u5f15\u5171\u4f7f\u7528\u4e864\u79cd\u9875\u9762\uff08\u7070\u8272\u77e9\u5f62\uff09\u3002<\/p>\n \u7d22\u5f15\u9875\u4e2d\u5411\u4e0b\u7684\u7bad\u5934\u8868\u793aTID\uff0c\u6307\u5411\u8868\u4e2d\u7684\u884c\u3002<\/p>\n \u6bcf\u6b21\u7d22\u5f15\u7a7a\u95f4\u589e\u52a0\u65f6\uff0cPG\u751f\u6210\u7684\u6876\u6570\u90fd\u662f\u4e0a\u6b21\u751f\u6210\u6876\u6570\u76842\u500d\u3002\u4e3a\u4e86\u907f\u514d\u4e00\u6b21\u6027\u5206\u914d\u5927\u91cf\u9875\u9762\uff0cPG 10\u6269\u5c55\u7a7a\u95f4\u65f6\u66f4\u52a0\u5e73\u7f13\u3002\u81f3\u4e8e\u6ea2\u51fa\u9875\uff0c\u5219\u6309\u9700\u5206\u914d\uff0c\u88ab\u4f4d\u56fe\u9875\u8ddf\u8e2a\u3002\u4f4d\u56fe\u9875\u4e5f\u6309\u9700\u5206\u914d\u3002<\/p>\n \u6ce8\u610f\uff0cHash\u7d22\u5f15\u4e0d\u80fd\u7f29\u5c0f\u4f53\u79ef\u3002\u5982\u679c\u5220\u9664\u4e86\u4e00\u4e9b\u7d22\u5f15\u884c\uff0c\u5df2\u7ecf\u88ab\u5206\u914d\u7684\u9875\u9762\u4e0d\u80fd\u5f52\u8fd8\u7ed9\u64cd\u4f5c\u7cfb\u7edf\uff0c\u4f46\u662f\u53ef\u4ee5\u5728Vacuum\u4e4b\u540e\u7528\u6765\u5b58\u653e\u65b0\u6570\u636e\u3002\u51cf\u5c0f\u7d22\u5f15\u4f53\u79ef\u7684\u552f\u4e00\u65b9\u6cd5\u662f\u7528reindex\u6216vacuum full\u547d\u4ee4\u91cd\u5efa\u7d22\u5f15\u3002<\/p>\n \u6211\u4eec\u770b\u4e00\u4e0bHash\u7d22\u5f15\u7684\u521b\u5efa\u3002\u4e3a\u4e86\u907f\u514d\u91cd\u65b0\u8bbe\u8ba1\u8868\u7ed3\u6784\uff0c\u6211\u4eec\u76f4\u63a5\u4f7f\u7528\u4e0a\u7bc7\u4ecb\u7ecd\u8fc7\u7684demo\u6570\u636e\u5e93<\/a>\uff0c\u672c\u6b21\u4f7f\u7528flights\u8868\u3002<\/p>\n PG 9.6\u53ca\u4e4b\u524d\uff0cHash\u7d22\u5f15\u4e2d\u7684\u64cd\u4f5c\u90fd\u4e0d\u5199XLOG\uff0c\u8bf7\u6ce8\u610f\u521b\u5efaHash\u7d22\u5f15\u65f6PG\u7684WARNING\uff08PG 9.5\u548cPG 9.6\u4e24\u4e2a\u7248\u672c\u4f1a\u62a5\u4e0a\u9762\u7684WARNING\uff0cPG 9.4\u4e0d\u62a5\uff09\u3002\u8fd9\u5bfc\u81f4\u5b95\u673a\u540eHash\u7d22\u5f15\u4e0d\u80fd\u6062\u590d\uff0c\u5e76\u4e14\u4e0d\u80fd\u53c2\u4e0e\u590d\u5236\uff08replication\uff09\u3002\u800c\u4e14\uff0cHash\u7d22\u5f15\u8fdc\u4e0d\u5982Btree\u7d22\u5f15\u5177\u6709\u901a\u7528\u6027\uff0c\u5b83\u7684\u6548\u7387\u4e5f\u503c\u5f97\u6000\u7591\u3002\u6240\u4ee5\u5b9e\u9645\u4e2d\u5e76\u4e0d\u503c\u5f97\u4f7f\u7528\u8fd9\u79cd\u7d22\u5f15\u3002<\/p>\n \u81ea\u4ecePG 10\u5f00\u59cb\uff0cHash\u7d22\u5f15\u5df2\u7ecf\u652f\u6301XLOG\uff0c\u5e76\u4e14\u5bf9\u5185\u5b58\u5206\u914d\u505a\u4e86\u4f18\u5316\uff0c\u5e76\u53d1\u573a\u666f\u66f4\u52a0\u9ad8\u6548\u3002\u73b0\u5728\u521b\u5efaHash\u7d22\u5f15\uff0c\u4e5f\u4e0d\u518d\u6253\u5370\u4e0a\u9762\u7684WARNING\u3002\u53ef\u53c2\u8003\u4e0b\u9762\u4e24\u7bc7\u535a\u5ba2\uff1aPostgreSQL 10 features: Hash indexes<\/a>\u3001PostgreSQL Indexes: Hash Indexes are Faster than Btree Indexes?<\/a>\u3002<\/p>\n \u6bcf\u79cd\u6570\u636e\u7c7b\u578b\u4f7f\u7528\u7684Hash\u51fd\u6570\u88ab\u5b58\u653e\u5728\u7cfb\u7edf\u8868\u4e2d\u3002<\/p>\n \u867d\u7136\u8fd9\u4e9b\u51fd\u6570\u6ca1\u6709\u5728\u6587\u6863\u4e2d\u8bf4\u660e\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5b83\u4eec\u8ba1\u7b97\u5bf9\u5e94\u7c7b\u578b\u7684Hash\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n \u6211\u4eec\u6765\u770b\u4e00\u4e0bHash\u7d22\u5f15\u7684\u5c5e\u6027\u3002\u67e5\u8be2\u8bed\u53e5\u89c1\u4e0a\u4e00\u7bc7\u6587\u7ae0<\/a>\uff0c\u8fd9\u91cc\u76f4\u63a5\u5c55\u793a\u7ed3\u679c\u3002<\/p>\n \u901a\u8fc7\u6bd4\u8f83\u4e24\u4e2a\u5217\u503c\u7684Hash\u503c\u7684\u5927\u5c0f\uff0c\u65e0\u6cd5\u63a8\u65ad\u51fa\u4e24\u4e2a\u5217\u503c\u8c01\u5927\u8c01\u5c0f\u3002\u56e0\u6b64\uff0c\u901a\u5e38\u6765\u8bb2\uff0cHash\u7d22\u5f15\u4ec5\u652f\u6301\u7b49\u503c\u67e5\u8be2\u3002<\/p>\n \u56e0\u6b64\uff0cHash\u7d22\u5f15\u4e0d\u80fd\u8fd4\u56de\u6709\u5e8f\u7684\u7ed3\u679c\uff08can_order\u3001orderable\uff09\u3002\u57fa\u4e8e\u76f8\u540c\u7684\u539f\u56e0\uff0cHash\u7d22\u5f15\u4e0d\u5904\u7406NULL\u503c\uff1b\u201c\u76f8\u7b49\u201d\u5bf9NULL\u503c\u6765\u8bf4\u6ca1\u6709\u610f\u4e49\uff08search_nulls\uff09\u3002<\/p>\n \u56e0\u4e3aHash\u7d22\u5f15\u4e0d\u5b58\u50a8\u5217\u503c\uff08\u4ec5\u5b58\u50a8\u5217\u503c\u7684Hash\u503c\uff09\uff0c\u56e0\u6b64\u5b83\u4e0d\u652f\u6301Index Only Scan\uff08returnable\uff09\u3002<\/p>\n Hash\u7d22\u5f15\u9875\u4e5f\u4e0d\u652f\u6301\u591a\u5217\u7d22\u5f15\uff08can_multi_col\uff09\u3002<\/p>\n \u4ecePG 10\u5f00\u59cb\uff0c\u53ef\u4ee5\u4f7f\u7528pageinspect\u63d2\u4ef6\u7814\u7a76Hash\u7d22\u5f15\u7684\u5185\u90e8\u5b9e\u73b0\u3002<\/p>\n \u5143\u9875\u9762\uff08\u53ef\u4ee5\u67e5\u51fa\u7d22\u5f15\u4e2d\u7684\u884c\u6570\uff0c\u88ab\u4f7f\u7528\u7684\u6876\u7684\u6700\u5927\u7f16\u53f7\uff09\uff1a<\/p>\n \u4e00\u4e2a\u6876\u9875\uff08\u53ef\u4ee5\u67e5\u51fa\u9875\u9762\u4e2dlive tuple\u548cdead tuple\u7684\u6570\u91cf\uff0cdead tuple\u5360\u7528\u7684\u7a7a\u95f4\u53ef\u4ee5\u88abvacuum\u56de\u6536\uff09\uff1a<\/p>\n \u5982\u679c\u4e0d\u7814\u7a76\u6e90\u4ee3\u7801\uff0c\u5f88\u96be\u5c06\u6240\u6709\u5b57\u6bb5\u7684\u542b\u4e49\u5f04\u6e05\u695a\u3002\u5982\u679c\u4f60\u613f\u610f\uff0c\u4f60\u53ef\u4ee5\u4ece\u8fd9\u4e2aREADME<\/a>\u5f00\u59cb\u3002pageinspect\u7684\u6587\u6863\u5728\u8fd9\u91cc<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" \u672c\u6587\u4e3b\u8981\u4ecb\u7ecdPostgreSQL\u4e2dHash\u7d22\u5f15\u7684\u7279\u70b9\u548c\u7ec4\u7ec7\u65b9\u5f0f\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\/213"}],"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=213"}],"version-history":[{"count":14,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":458,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/posts\/213\/revisions\/458"}],"wp:attachment":[{"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/tags?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}1. \u7ed3\u6784<\/h1>\n
1.1 \u57fa\u672c\u7406\u8bba<\/h2>\n
1.2 \u7d22\u5f15\u7ed3\u6784<\/h2>\n
1.3 \u6570\u636e\u7ed3\u6784\u6620\u5c04\u5230\u9875\u9762<\/h2>\n
\n
2. \u793a\u4f8b<\/h1>\n
create index on flights using hash(flight_no);\n<\/code><\/pre>\n
WARNING: hash indexes are not WAL-logged and their use is discouraged\nCREATE INDEX\n<\/code><\/pre>\n
explain (costs off) select * from flights where flight_no = 'PG0001';\n QUERY PLAN \n----------------------------------------------------\n Bitmap Heap Scan on flights\n Recheck Cond: (flight_no = 'PG0001'::bpchar)\n -> Bitmap Index Scan on flights_flight_no_idx\n Index Cond: (flight_no = 'PG0001'::bpchar)\n(4 rows)\n<\/code><\/pre>\n
3. Hash\u51fd\u6570<\/h1>\n
select opf.opfname as opfamily_name,\n amproc.amproc::regproc AS opfamily_procedure\nfrom pg_am am,\n pg_opfamily opf,\n pg_amproc amproc\nwhere opf.opfmethod = am.oid\nand amproc.amprocfamily = opf.oid\nand am.amname = 'hash'\norder by opfamily_name,\n opfamily_procedure;\n<\/code><\/pre>\n
opfamily_name | opfamily_procedure \n--------------------+--------------------\n abstime_ops | hashint4\n aclitem_ops | hash_aclitem\n array_ops | hash_array\n bool_ops | hashchar\n bpchar_ops | hashbpchar\n bpchar_pattern_ops | hashbpchar\n bytea_ops | hashvarlena\n char_ops | hashchar\n cid_ops | hashint4\n date_ops | hashint4\n enum_ops | hashenum\n float_ops | hashfloat4\n float_ops | hashfloat8\n integer_ops | hashint2\n integer_ops | hashint4\n integer_ops | hashint8\n interval_ops | interval_hash\n jsonb_ops | jsonb_hash\n macaddr8_ops | hashmacaddr8\n macaddr_ops | hashmacaddr\n name_ops | hashname\n network_ops | hashinet\n numeric_ops | hash_numeric\n oid_ops | hashoid\n oidvector_ops | hashoidvector\n pg_lsn_ops | pg_lsn_hash\n range_ops | hash_range\n reltime_ops | hashint4\n text_ops | hashtext\n text_pattern_ops | hashtext\n time_ops | time_hash\n timestamp_ops | timestamp_hash\n timestamptz_ops | timestamp_hash\n timetz_ops | timetz_hash\n uuid_ops | uuid_hash\n xid_ops | hashint4\n(36 rows)\n<\/code><\/pre>\n
select hashtext('one');\n<\/code><\/pre>\n
hashtext \n-----------\n 127722028\n(1 row)\n<\/code><\/pre>\n
select hashtext('two');\n<\/code><\/pre>\n
hashtext \n-----------\n 345620034\n(1 row)\n<\/code><\/pre>\n
4. \u5c5e\u6027<\/h1>\n
name | pg_indexam_has_property\n---------------+-------------------------\n can_order | f\n can_unique | f\n can_multi_col | f\n can_exclude | t\n\n name | pg_index_has_property\n---------------+-----------------------\n clusterable | f\n index_scan | t\n bitmap_scan | t\n backward_scan | t\n\n name | pg_index_column_has_property \n--------------------+------------------------------\n asc | f\n desc | f\n nulls_first | f\n nulls_last | f\n orderable | f\n distance_orderable | f\n returnable | f\n search_array | f\n search_nulls | f\n<\/code><\/pre>\n
select opf.opfname AS opfamily_name,\n amop.amopopr::regoperator AS opfamily_operator\nfrom pg_am am,\n pg_opfamily opf,\n pg_amop amop\nwhere opf.opfmethod = am.oid\nand amop.amopfamily = opf.oid\nand am.amname = 'hash'\norder by opfamily_name,\n opfamily_operator;\n<\/code><\/pre>\n
opfamily_name | opfamily_operator \n--------------------+------------------------------------------------------------\n abstime_ops | =(abstime,abstime)\n aclitem_ops | =(aclitem,aclitem)\n array_ops | =(anyarray,anyarray)\n bool_ops | =(boolean,boolean)\n bpchar_ops | =(character,character)\n bpchar_pattern_ops | =(character,character)\n bytea_ops | =(bytea,bytea)\n char_ops | =(\"char\",\"char\")\n cid_ops | =(cid,cid)\n date_ops | =(date,date)\n enum_ops | =(anyenum,anyenum)\n float_ops | =(real,real)\n float_ops | =(double precision,double precision)\n float_ops | =(real,double precision)\n float_ops | =(double precision,real)\n integer_ops | =(integer,bigint)\n integer_ops | =(smallint,smallint)\n integer_ops | =(integer,integer)\n integer_ops | =(bigint,bigint)\n integer_ops | =(bigint,integer)\n integer_ops | =(smallint,integer)\n integer_ops | =(integer,smallint)\n integer_ops | =(smallint,bigint)\n integer_ops | =(bigint,smallint)\n interval_ops | =(interval,interval)\n jsonb_ops | =(jsonb,jsonb)\n macaddr8_ops | =(macaddr8,macaddr8)\n macaddr_ops | =(macaddr,macaddr)\n name_ops | =(name,name)\n network_ops | =(inet,inet)\n numeric_ops | =(numeric,numeric)\n oid_ops | =(oid,oid)\n oidvector_ops | =(oidvector,oidvector)\n pg_lsn_ops | =(pg_lsn,pg_lsn)\n range_ops | =(anyrange,anyrange)\n reltime_ops | =(reltime,reltime)\n text_ops | =(text,text)\n text_pattern_ops | =(text,text)\n time_ops | =(time without time zone,time without time zone)\n timestamp_ops | =(timestamp without time zone,timestamp without time zone)\n timestamptz_ops | =(timestamp with time zone,timestamp with time zone)\n timetz_ops | =(time with time zone,time with time zone)\n uuid_ops | =(uuid,uuid)\n xid_ops | =(xid,xid)\n(44 rows)\n<\/code><\/pre>\n
5. \u5185\u90e8\u5b9e\u73b0<\/h1>\n
create extension pageinspect;\n<\/code><\/pre>\n
select hash_page_type(get_raw_page('flights_flight_no_idx',0));\n<\/code><\/pre>\n
hash_page_type \n----------------\n metapage\n(1 row)\n<\/code><\/pre>\n
select ntuples, maxbucket\nfrom hash_metapage_info(get_raw_page('flights_flight_no_idx',0));\n<\/code><\/pre>\n
ntuples | maxbucket \n---------+-----------\n 33121 | 127 \n(1 row)\n<\/code><\/pre>\n
select hash_page_type(get_raw_page('flights_flight_no_idx',1));\n<\/code><\/pre>\n
hash_page_type\n----------------\n bucket\n(1 row)\n<\/code><\/pre>\n
select live_items, dead_items\nfrom hash_page_stats(get_raw_page('flights_flight_no_idx',1));\n<\/code><\/pre>\n
live_items | dead_items\n------------+------------\n 407 | 0\n(1 row)\n<\/code><\/pre>\n