{"id":378,"date":"2020-10-01T10:00:07","date_gmt":"2020-10-01T02:00:07","guid":{"rendered":"https:\/\/www.mengqingzhong.com\/?p=378"},"modified":"2024-01-14T11:37:31","modified_gmt":"2024-01-14T03:37:31","slug":"postgresql-index-bloom-10","status":"publish","type":"post","link":"https:\/\/www.mengqingzhong.com\/2020\/10\/01\/postgresql-index-bloom-10\/","title":{"rendered":"PostgreSQL\u7d22\u5f15(10) \u2013 Bloom"},"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

\u5728\u524d\u9762\u51e0\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u8ba8\u8bba\u4e86\u901a\u7528\u7d22\u5f15\u5f15\u64ce\u3001AM\u7684\u63a5\u53e3\u548c\u516d\u79cdAM\uff08Hash\u7d22\u5f15\u3001B-tree\u7d22\u5f15\u3001GiST\u7d22\u5f15\u3001SP-GiST\u7d22\u5f15\u3001GIN\u7d22\u5f15\u3001RUM\u7d22\u5f15\u3001BRIN\u7d22\u5f15\uff09\u3002\u8fd9\u7bc7\u6587\u7ae0\u5c06\u4ecb\u7ecdBloom\u7d22\u5f15\u3002<\/p>\n

1. \u57fa\u672c\u6982\u5ff5<\/h1>\n

\u4e00\u4e2a\u7ecf\u5178\u7684Bloom filter\u662f\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\uff0c\u4f7f\u7528\u5b83\u53ef\u4ee5\u5feb\u901f\u7684\u68c0\u67e5\u4e00\u4e2a\u5143\u7d20\u662f\u5426\u5c5e\u4e8e\u4e00\u4e2a\u96c6\u5408\u3002\u8fc7\u6ee4\u5668\u88ab\u9ad8\u5ea6\u538b\u7f29\uff0c\u4f46\u662f\u5b83\u53ef\u80fd\u4f1a\u4ea7\u751f\u5047\u9633\u6027\u7684\u7ed3\u679c\uff1a\u5b83\u53ef\u80fd\u4f1a\u8bef\u8ba4\u4e3a\u4e00\u4e2a\u5143\u7d20\u5728\u96c6\u5408\u4e2d\u5b58\u5728\uff0c\u5b9e\u9645\u8fd9\u4e2a\u5143\u7d20\u5728\u96c6\u5408\u4e2d\u5e76\u4e0d\u5b58\u5728\u3002\u5982\u679c\u5b83\u8ba4\u4e3a\u4e00\u4e2a\u5143\u7d20\u5728\u96c6\u5408\u4e2d\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5143\u7d20\u5728\u96c6\u5408\u4e2d\u80af\u5b9a\u4e0d\u5b58\u5728\u3002<\/p>\n

\u8fc7\u6ee4\u5668\u662f\u4e00\u4e2a\u7531\u6bd4\u7279\u4f4d\u7ec4\u6210\u7684\u6570\u7ec4\uff08\u4e5f\u88ab\u79f0\u4e3a\u7b7e\u540d\uff09\uff0c\u6240\u6709\u6bd4\u7279\u6700\u521d\u90fd\u88ab\u521d\u59cb\u5316\u6210\u96f6\u3002\u5f53\u5411\u96c6\u5408\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\u65f6\uff0c\u6211\u4eec\u4f1a\u4f7f\u7528\u591a\u4e2ahash\u51fd\u6570\u5bf9\u8fd9\u4e2a\u5143\u7d20\u8ba1\u7b97hash\u503c\uff0c\u628a\u6bcf\u4e2ahash\u503c\u5bf9\u5e94\u7684\u6bd4\u7279\u4f4d\u7f6e\u4e3a1\u3002\u6240\u4ee5\uff0c\u5f53\u4e00\u4e2a\u5143\u7d20\u5bf9\u5e94\u7684\u6240\u6709\u6bd4\u7279\u4f4d\u90fd\u4e3a1\u65f6\uff0c\u8fd9\u4e2a\u5143\u7d20\u53ef\u80fd\u5c5e\u4e8e\u8fd9\u4e2a\u96c6\u5408\u3002\u4f46\u662f\u5f53\u4efb\u610f\u4e00\u4f4d\u4e3a0\u65f6\uff0c\u5219\u8fd9\u4e2a\u5143\u7d20\u80af\u5b9a\u4e0d\u5c5e\u4e8e\u8fd9\u4e2a\u96c6\u5408\u3002<\/p>\n

\u901a\u8fc7\u6539\u53d8\u7b7e\u540d\u7684\u957f\u5ea6\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u7d22\u5f15\u4f53\u79ef\u548c\u5047\u9633\u6027\u7684\u6982\u7387\u4e4b\u95f4\u5f97\u5230\u4e00\u4e2a\u5e73\u8861\u3002Bloom\u7d22\u5f15\u7684\u5e94\u7528\u975e\u5e38\u5e7f\u6cdb\uff0c\u76f8\u5f53\u591a\u7684\u5bbd\u8868\u90fd\u5728\u6bcf\u4e2a\u5b57\u6bb5\u4e0a\u4f7f\u7528\u8fc7\u6ee4\u5668\u3002\u8fd9\u79cdAM\uff0c\u548cBRIN\u7c7b\u4f3c\uff0c\u4e5f\u53ef\u4ee5\u88ab\u770b\u4f5c\u662f\u987a\u5e8f\u626b\u63cf\u7684\u52a0\u901f\u5668\uff1a\u7d22\u5f15\u8fd4\u56de\u7684\u6240\u6709\u5143\u7ec4\uff0c\u90fd\u9700\u8981\u88abrecheck\uff0c\u4f46\u662f\u6709\u53ef\u80fd\u907f\u514d\u626b\u63cf\u5927\u90e8\u5206\u4e0d\u6ee1\u8db3\u6761\u4ef6\u7684\u5143\u7ec4\u3002<\/p>\n

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

\u6211\u4eec\u5728GiST\u7d22\u5f15\u4e2d\u8ba8\u8bba\u8fc7\u7b7e\u540d\u3002\u548c\u8fd9\u4e9b\u6811\u4e0d\u540c\uff0cBloom filter\u662f\u4e00\u4e2a\u5e73\u5766\u7684\u7ed3\u6784\u3002\u5b83\u7684\u7b2c0\u9875\u662f\u5143\u9875\u9762\uff0c\u540e\u9762\u6240\u6709\u7684\u9875\u9762\u90fd\u662f\u5305\u542b\u7d22\u5f15\u884c\u7684\u5e38\u89c4\u9875\u9762\u3002\u6bcf\u4e2a\u7d22\u5f15\u884c\u5305\u542b\u4e00\u4e2a\u7b7e\u540d\u548c\u4e00\u4e2a\u6307\u5411\u8868\u4e2d\u884c\u7684TID\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n

\"\"<\/a><\/p>\n

2.1 \u53c2\u6570<\/h2>\n

\u5728\u521b\u5efaBloom\u7d22\u5f15\u65f6\uff0c\u53ef\u4ee5\u6307\u5b9a\u6bcf\u4e2a\u7b7e\u540d\u7684\u603b\u957f\u5ea6\uff0c\u4e5f\u53ef\u4ee5\u6307\u5b9a\u6bcf\u4e2a\u5b57\u6bb5\u9700\u8981\u5c06\u7b7e\u540d\u4e2d\u591a\u5c11\u4f4d\u7f6e1\u3002<\/p>\n

create index on ... using bloom(...) with (length=..., col1=..., col2=..., ...);\n<\/code><\/pre>\n

\u6211\u4eec\u5e94\u8be5\u600e\u6837\u9009\u53d6\u5408\u9002\u7684\u503c\u5462\uff1f\u7406\u8bba\u8868\u660e<\/a>\uff0c\u7ed9\u5b9a\u4e00\u4e2a\u5047\u9633\u6027\u7684\u6982\u7387\uff0c\u7b7e\u540d\u7684\u6700\u4f18\u957f\u5ea6\u53ef\u4ee5\u7528$m=-n\\log_2 p\/\\ln 2$\u4f30\u8ba1\uff0c\u5176\u4e2d$n$\u662f\u7d22\u5f15\u4e2d\u5b57\u6bb5\u7684\u4e2a\u6570\uff0c\u7b7e\u540d\u4e2d\u9700\u8981\u8bbe\u7f6e\u4e3a1\u7684\u4f4d\u6570$k$\u4e3a$k=-\\log_2 p$\u3002<\/p>\n

\u7b7e\u540d\u7684\u957f\u5ea6\u4f1a\u88ab\u5411\u4e0a\u53d6\u6574\u52302\u5b57\u8282\u7684\u500d\u6570\u3002<\/p>\n

\u9700\u8981\u6ce8\u610f\u51e0\u70b9\uff1a<\/p>\n