{"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

1. \u7ed3\u6784<\/h1>\n

1.1 \u57fa\u672c\u7406\u8bba<\/h2>\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

1.2 \u7d22\u5f15\u7ed3\u6784<\/h2>\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

1.3 \u6570\u636e\u7ed3\u6784\u6620\u5c04\u5230\u9875\u9762<\/h2>\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