{"id":371,"date":"2020-10-01T09:00:45","date_gmt":"2020-10-01T01:00:45","guid":{"rendered":"https:\/\/www.mengqingzhong.com\/?p=371"},"modified":"2024-01-14T11:38:32","modified_gmt":"2024-01-14T03:38:32","slug":"postgresql-index-brin-9","status":"publish","type":"post","link":"https:\/\/www.mengqingzhong.com\/2020\/10\/01\/postgresql-index-brin-9\/","title":{"rendered":"PostgreSQL\u7d22\u5f15(9) \u2013 BRIN"},"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\uff09\u3002\u8fd9\u7bc7\u6587\u7ae0\u5c06\u4ecb\u7ecdBRIN\u7d22\u5f15\u3002<\/p>\n

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

\u548c\u5df2\u7ecf\u4ecb\u7ecd\u8fc7\u7684\u7d22\u5f15\u4e0d\u540c\uff0cBRIN\u7d22\u5f15\u7684\u601d\u60f3\u662f\u5feb\u901f\u6392\u9664\u4e0d\u6ee1\u8db3\u67e5\u8be2\u6761\u4ef6\u7684\u884c\uff0c\u800c\u4e0d\u662f\u5feb\u901f\u627e\u5230\u5339\u914d\u7684\u884c\u3002\u5b83\u901a\u5e38\u90fd\u662f\u4e00\u4e2a\u4e0d\u7cbe\u786e\u7684\u7d22\u5f15\uff1a\u5b83\u5b8c\u5168\u4e0d\u5305\u542b\u57fa\u8868\u4e2d\u7684TID\u3002<\/p>\n

BRIN\u66f4\u9002\u5408\u5217\u503c\u4e0e\u7269\u7406\u4f4d\u7f6e\u76f8\u5173\u7684\u5217\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5373\u4f7f\u4e00\u4e2a\u67e5\u8be2\u6ca1\u6709order by\u5b50\u53e5\uff0c\u8fd9\u4e2a\u5217\u7684\u503c\u4e5f\u5927\u81f4\u6309\u5347\u5e8f\u6216\u964d\u5e8f\u6392\u5217\uff08\u8fd9\u4e2a\u5217\u4e0a\u6ca1\u6709\u7d22\u5f15\uff09\u3002<\/p>\n

BRIN\u7684\u4e00\u4e2a\u91cd\u8981\u7279\u5f81\u662f\uff0c\u5b83\u5141\u8bb8\u6211\u4eec\u5728\u8868\u4e0a\u521b\u5efa\u4e00\u4e2a\u5f88\u5c0f\u7684\u7d22\u5f15\uff0c\u4ec5\u589e\u52a0\u5f88\u5c0f\u7684\u7ef4\u62a4\u4ee3\u4ef7\u3002<\/p>\n

\u5b83\u7684\u5de5\u4f5c\u65b9\u5f0f\u5982\u4e0b\uff1a\u8868\u88ab\u5212\u5206\u6210\u4e00\u4e9b\u533a\u95f4\uff0c\u6bcf\u4e2a\u533a\u95f4\u5305\u542b\u4e00\u4e9b\u9875\u9762\uff08\u6570\u636e\u5757\uff09\u3002\u5b83\u4e5f\u56e0\u6b64\u800c\u5f97\u540d\uff1aBlock Range Index\uff0cBRIN\u3002\u7d22\u5f15\u5b58\u50a8\u4e86\u6bcf\u4e2a\u533a\u95f4\u7684\u6458\u8981\u4fe1\u606f\uff0c\u901a\u5e38\u6765\u8bb2\u662f\u8fd9\u4e2a\u533a\u95f4\u7684min\u548cmax\u503c\uff0c\u4e5f\u53ef\u80fd\u662f\u5176\u5b83\u4fe1\u606f\u3002\u5047\u5982\u67e5\u8be2\u7684\u5305\u542b\u4e00\u4e2a\u5217\uff0c\u5e76\u4e14\u8fd9\u4e2a\u67e5\u8be2\u7684\u5217\u503c\u4e0d\u4f1a\u843d\u5165\u67d0\u4e2a\u533a\u95f4\uff0c\u5219\u53ef\u4ee5\u8df3\u8fc7\u6574\u4e2a\u533a\u95f4\u3002\u5047\u5982\u4e0d\u80fd\u8df3\u8fc7\uff0c\u8fd9\u4e2a\u533a\u95f4\u4e2d\u7684\u6240\u6709\u884c\u90fd\u9700\u8981\u88ab\u626b\u63cf\u3002<\/p>\n

\u4e5f\u53ef\u4ee5\u8bf4BRIN\u4e0d\u662f\u4e00\u4e2a\u7d22\u5f15\uff0c\u53ea\u662f\u7d22\u5f15\u626b\u63cf\u7684\u52a0\u901f\u5668\u3002\u6211\u4eec\u53ef\u4ee5\u628aBRIN\u770b\u4f5c\u662f\u5bf9\u8868\u8fdb\u884c\u5206\u533a\u7684\u4e00\u79cd\u65b9\u5f0f\uff0c\u628a\u6bcf\u4e2arange\u662f\u4e00\u4e2a\u865a\u62df\u7684\u5206\u533a\u3002<\/p>\n

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

\u7b2c0\u9875\u662f\u5143\u9875\u9762\u3002\u4ece\u7b2c1\u9875\u5f00\u59cb\uff0c\u8fde\u7eedN\u9875\uff08N\u53d6\u51b3\u4e8e\u8868\u7684\u5927\u5c0f\uff0c\u5e76\u4e14\u53ef\u4ee5\u589e\u52a0\uff09\u88ab\u79f0\u4e3arevmap\u3002recvmap\u4e4b\u540e\uff0c\u662f\u6458\u8981\u9875\u9762\u3002<\/p>\n

recvmap\u7684\u6570\u91cf\u4e0e\u8868\u7684\u5927\u5c0f\u6709\u5173\uff0c\u5982\u679c\u6301\u7eed\u5411\u8868\u4e2d\u63d2\u5165\uff0crecvmap\u4e0d\u591f\u7528\u7684\u65f6\u5019\uff0c\u4f1a\u5411\u540e\u6269\u5c55\uff08\u5360\u7528\u4e00\u4e2a\u6458\u8981\u9875\u9762\uff0c\u8be5\u6458\u8981\u9875\u9762\u7684\u5185\u5bb9copy\u5230\u7d22\u5f15\u7684\u672b\u5c3e\uff09\u3002<\/p>\n

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

recvmap\u4e2d\u6709\u4e9b\u5e76\u6ca1\u6709\u6307\u5411\u4efb\u4f55\u6458\u8981\u9875\u9762\uff0c\u8bf4\u660e\u8fd9\u4e9b\u9875\u9762\u8fd8\u6ca1\u6709\u6458\u8981\u4fe1\u606f\u3002<\/p>\n

3. \u626b\u63cf\u7d22\u5f15<\/h1>\n

\u5982\u679c\u7d22\u5f15\u6ca1\u6709\u4fdd\u5b58\u6307\u5411\u57fa\u8868\u7684TID\uff0c\u8fd9\u4e2a\u7d22\u5f15\u5982\u4f55\u88ab\u4f7f\u7528\u5462\uff1f\u5b83\u5f53\u7136\u4e0d\u80fd\u4f9d\u6b21\u8fd4\u56de\u6bcf\u4e2aTID\uff0c\u4f46\u662f\u5b83\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2abitmap\u3002bitmap\u9875\u9762\u6709\u4e24\u79cd\uff1a\u7cbe\u786e\u7684\uff0c\u6307\u5411\u57fa\u8868\u5177\u4f53\u7684\u884c\uff1b\u975e\u7cbe\u786e\u7684\uff0c\u6307\u5411\u57fa\u8868\u7684\u9875\u9762\u3002BRIN\u4f7f\u7528\u7684\u662f\u975e\u7cbe\u786e\u7684bitmap\u3002<\/p>\n

\u626b\u63cf\u7b97\u6cd5\u5f88\u7b80\u5355\u3002\u6309\u987a\u5e8f\u626b\u63cf\u6240\u6709\u7684recv map\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u6309\u7167\u57fa\u8868\u4e2d\u7269\u7406\u987a\u8bbf\u95ee\u6bcf\u4e2arange\uff09\u3002\u6307\u9488\u6307\u5411\u6bcf\u4e2a\u6458\u8981\u9875\u9762\u4e0a\u7684\u6458\u8981\u3002\u5982\u679c\u67d0\u4e2a\u533a\u95f4\u90fd\u4e0d\u7b26\u5408\u67e5\u8be2\u6761\u4ef6\uff0c\u5219\u8df3\u8fc7\u6574\u4e2a\u533a\u95f4\u3002\u5982\u679c\u4e0d\u80fd\u6392\u9664\u8fd9\u4e2a\u533a\u95f4\uff08\u6216\u8005\u6ca1\u6709\u6458\u8981\u4fe1\u606f\uff09\uff0c\u8fd9\u4e2a\u533a\u95f4\u5185\u7684\u6240\u6709\u9875\u9762\u90fd\u8981\u88ab\u52a0\u5165\u5230bitmap\u4e2d\u3002\u8fd9\u4e2a\u4f4d\u56fe\uff0c\u5c31\u50cf\u5176\u5b83\u573a\u666f\u4e2d\u7684\u4f4d\u56fe\u4e00\u6837\u88ab\u4f7f\u7528\u3002<\/p>\n

4. \u66f4\u65b0\u7d22\u5f15<\/h1>\n

\u66f4\u6709\u610f\u601d\u7684\u662f\uff0c\u57fa\u8868\u6570\u636e\u53d8\u5316\u65f6\uff0c\u5982\u4f55\u66f4\u65b0\u7d22\u5f15\u3002<\/p>\n

\u5f53\u5411\u8868\u4e2d\u63d2\u5165\u4e00\u884c\u6570\u636e\u65f6\uff0c\u6211\u4eec\u5f88\u5bb9\u6613\u786e\u5b9a\u5b83\u5c5e\u4e8e\u54ea\u4e2a\u533a\u95f4\uff0c\u62ff\u5230\u8fd9\u4e2a\u533a\u95f4\u7684\u6458\u8981\u4fe1\u606f\u3002\u8fd9\u90fd\u662f\u4e00\u4e9b\u7b80\u5355\u7684\u6574\u6570\u8fd0\u7b97\u3002\u5047\u5982\uff0c\u6bcf\u4e2arange\u5305\u542b4\u4e2a\u9875\u9762\uff0c\u63d2\u5165\u7b2c13\u9875\u63d2\u516542\u3002range\u7684\u7f16\u53f7\u662f13\/4=3\uff0c\u56e0\u6b64\u6211\u4eec\u4f7f\u7528revmap\u4e2d\u504f\u79fb\u4e3a3\u7684\u6458\u8981\u4fe1\u606f\u3002<\/p>\n

\u8fd9\u4e2a\u533a\u95f4\u4e2d\u7684\u6700\u5c0f\u503c\u65f631\uff0c\u6700\u5927\u503c\u65f640\u3002\u63d2\u5165\u7684\u503c\u662f42\uff0c\u8d85\u51fa\u4e86\u8fd9\u4e2a\u533a\u95f4\uff0c\u56e0\u6b64\uff0c\u9700\u8981\u66f4\u65b0\u6700\u5927\u503c\uff08\u89c1\u56fe\u7247\uff09\u3002\u5982\u679c\u65b0\u63d2\u5165\u7684\u503c\u4ecd\u7136\u5728\u73b0\u5728\u7684\u8303\u56f4\u4e2d\uff0c\u7d22\u5f15\u5c31\u4e0d\u9700\u8981\u66f4\u65b0\u3002<\/p>\n

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

\u8fd9\u4e9b\u573a\u666f\u90fd\u662f\u65b0\u63d2\u5165\u7684\u503c\u6240\u5728\u7684\u533a\u95f4\u6709\u6458\u8981\u4fe1\u606f\u3002\u521b\u5efa\u7d22\u5f15\u65f6\uff0c\u4f1a\u4e3a\u6240\u6709\u53ef\u7528\u7684\u533a\u95f4\u8ba1\u7b97\u6458\u8981\u4fe1\u606f\uff0c\u4f46\u662f\u5f53\u8fd9\u4e2a\u8868\u6269\u5c55\u65f6\uff0c\u65b0\u9875\u9762\u53ef\u80fd\u4e0d\u5728\u5df2\u6709\u7684range\u4e2d\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u6709\u4e24\u79cd\u9009\u62e9\uff1a<\/p>\n