{"id":282,"date":"2020-10-01T05:00:17","date_gmt":"2020-09-30T21:00:17","guid":{"rendered":"https:\/\/www.mengqingzhong.com\/?p=282"},"modified":"2024-01-14T11:38:31","modified_gmt":"2024-01-14T03:38:31","slug":"postgresql-index-gist-5","status":"publish","type":"post","link":"https:\/\/www.mengqingzhong.com\/2020\/10\/01\/postgresql-index-gist-5\/","title":{"rendered":"PostgreSQL\u7d22\u5f15(5) \u2013 GiST"},"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\u4e24\u79cdAM\uff08Hash\u7d22\u5f15\u3001B-tree\u7d22\u5f15\uff09\u3002\u672c\u6587\u5c06\u4ecb\u7ecdGiST\u7d22\u5f15\u3002<\/p>\n

GiST\u662fgeneralized search tree\u7684\u7b80\u79f0\uff0c\u5373\u901a\u7528\u641c\u7d22\u6811\u3002\u50cfB-tree\u4e00\u6837\uff0c\u5b83\u4e5f\u662f\u4e00\u9897\u5e73\u8861\u6811\u3002<\/p>\n

\u5b83\u4eec\u6709\u4ec0\u4e48\u533a\u522b\u5462\uff1fB-tree\u548c\u6bd4\u8f83<\/strong>\u7684\u8bed\u4e49\u5f3a\u5173\u8054\u5728\u4e00\u8d77\uff0c\u5373\u5b83\u53ea\u6709\u4f7f\u7528>\u3001>=\u3001=\u3001<=\u3001<\u8fd9\u4e94\u4e2a\u64cd\u4f5c\u7b26\u8fdb\u884c\u6bd4\u8f83\u7684\u80fd\u529b\uff0c\u5f53\u7136\u8fd9\u4e2a\u80fd\u529b\u5df2\u7ecf\u975e\u5e38\u5f3a\u5927\u3002\u4f46\u662f\uff0c\u73b0\u4ee3\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\u7ecf\u5e38\u5b58\u50a8\u4e00\u4e9b\u5728\u8fd95\u4e2a\u64cd\u4f5c\u7b26\u4e0a\u6ca1\u6709\u5b9e\u9645\u610f\u4e49\u7684\u6570\u636e\u7c7b\u578b\uff0c\u6bd4\u5982\u5730\u7406\u6570\u636e\u3001\u56fe\u50cf\u6570\u636e\u3001\u6587\u672c\u6570\u636e\u3002<\/p>\n

GiST\u7d22\u5f15\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5904\u7406\u8fd9\u4e9b\u6570\u636e\u7c7b\u578b\u3002\u5b83\u5141\u8bb8\u7528\u6237\u81ea\u5df1\u5b9a\u4e49\u4e00\u4e2a\u89c4\u5219\uff0c\u8fd9\u4e2a\u89c4\u5219\u53ef\u4ee5\u628a\u4efb\u610f\u6570\u636e\u7c7b\u578b\u7684\u6570\u636e\u5206\u5e03\u5728\u4e00\u9897\u5e73\u8861\u6811\u4e0a\u3002\u5e76\u4e14\u5b83\u63d0\u4f9b\u4e00\u79cd\u65b9\u6cd5\uff0c\u4e00\u4e9b\u64cd\u4f5c\u7b26\u53ef\u4ee5\u5229\u7528\u8fd9\u79cd\u65b9\u6cd5\u68c0\u7d22\u8fd9\u68f5\u6811\u3002\u4f8b\u5982\uff0c\u501f\u52a9\u4e8e\u76f8\u5bf9\u4f4d\u7f6e\uff08\u5728\u5de6\u8fb9\u3001\u5728\u53f3\u8fb9\u3001\u5305\u542b\u7b49\uff09\u64cd\u4f5c\u7b26\uff0cR-tree\u5c31\u53ef\u4ee5\u88ab\u5b58\u50a8\u5728GiST\u7d22\u5f15\u4e2d\uff0c\u7528\u6765\u5904\u7406\u7a7a\u95f4\u6570\u636e\uff1b\u501f\u52a9\u4e8e\u96c6\u5408\u7684\u4ea4\u3001\u5305\u542b\u64cd\u4f5c\u7b26\uff0cRD-tree\u4e5f\u53ef\u4ee5\u88ab\u5b58\u50a8\u5728GiST\u7d22\u5f15\u4e2d\u3002<\/p>\n

PG\u5177\u6709\u5f88\u597d\u7684\u6269\u5c55\u6027\uff0c\u901a\u8fc7\u524d\u51e0\u7bc7\u6587\u7ae0\u53ef\u77e5\uff0c\u6211\u4eec\u5b8c\u5168\u53ef\u4ee5\u4ece\u5934\u5b9e\u73b0\u4e00\u79cd\u65b0\u7684\u7d22\u5f15\u7c7b\u578b\u3002\u4e3a\u4e86\u8fbe\u5230\u8fd9\u4e2a\u76ee\u7684\uff0c\u6211\u4eec\u5fc5\u987b\u5b9e\u73b0\u4e00\u4e2a\u901a\u7528\u7d22\u5f15\u5f15\u64ce\u7684\u63a5\u53e3\u3002\u4f46\u662f\uff0c\u8fd9\u4ecd\u7136\u9700\u8981\u5f88\u5f3a\u7684\u4e13\u4e1a\u77e5\u8bc6\uff0c\u9700\u8981\u82b1\u8d39\u5927\u91cf\u7684\u4eba\u529b\uff0c\u56e0\u4e3a\u6211\u4eec\u4e0d\u4f46\u9700\u8981\u4e86\u89e3\u65b0\u7d22\u5f15\u672c\u8eab\u7684\u903b\u8f91\uff0c\u8fd8\u8981\u628a\u7d22\u5f15\u7684\u6570\u636e\u6620\u5c04\u5230PG\u7684\u9875\u9762\u4e2d\uff0c\u9700\u8981\u9ad8\u6548\u5730\u4f7f\u7528\u9501\uff0c\u9700\u8981\u8003\u8651redo\u65e5\u5fd7\u3002GiST\u7b80\u5316\u4e86\u6211\u4eec\u7684\u4efb\u52a1\uff0c\u5b83\u4e3a\u6211\u4eec\u5904\u7406\u4e86\u4e00\u4e9b\u5e95\u5c42\u7684\u95ee\u9898\uff0c\u5e76\u4e14\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5b83\u81ea\u5df1\u7684\u63a5\u53e3\uff1a\u4e0e\u5e94\u7528\u76f8\u5173\uff0c\u4f46\u662f\u4e0ePG\u5185\u90e8\u6280\u672f\u65e0\u5173\u7684\u63a5\u53e3\u3002\u4ece\u8fd9\u4e2a\u610f\u4e49\u4e0a\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u628aGiST\u770b\u4f5c\u4e00\u4e2a\u5b9e\u73b0\u65b0\u7d22\u5f15\u7c7b\u578b\u7684\u6846\u67b6\u3002<\/p>\n

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

GiST\u662f\u4e00\u9897\u5e73\u8861\u6811\uff0c\u5373\u4ece\u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9\u6240\u7ecf\u8fc7\u7684\u8282\u70b9\u6570\u90fd\u76f8\u540c\u3002\u8282\u70b9\u4e2d\u5305\u542b\u4e86\u7d22\u5f15\u7684\u6570\u636e\u884c\u3002<\/p>\n

\u901a\u5e38\u6765\u8bb2\uff0c\u53f6\u5b50\u8282\u70b9\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u4e00\u4e2a\u8c13\u8bcd\uff08bool\u7c7b\u578b\u7684\u8868\u8fbe\u5f0f\uff09\u548c\u4e00\u4e2a\u6307\u5411\u57fa\u8868\u7684TID\u3002\u7d22\u5f15\u6570\u636e\uff08key\uff09\u5fc5\u987b\u6ee1\u8db3\u8fd9\u4e2a\u8c13\u8bcd\u3002<\/p>\n

\u975e\u53f6\u5b50\u8282\u70b9\u7684\u6bcf\u4e00\u884c\u4e5f\u5305\u542b\u4e00\u4e2a\u8c13\u8bcd\u548c\u4e00\u4e2a\u6307\u5411\u5b69\u5b50\u8282\u70b9\u7684\u6307\u9488\uff0c\u8fd9\u4e2a\u5b69\u5b50\u8282\u70b9\u6240\u8868\u793a\u7684\u5b50\u6811\u4e2d\u7684\u6240\u6709\u6570\u636e\u90fd\u5fc5\u987b\u6ee1\u8db3\u8fd9\u4e2a\u8c13\u8bcd\u3002GiST\u8fd9\u4e2a\u91cd\u8981\u7684\u7279\u6027\u66ff\u6362\u4e86B-tree\u4e2d\u7b80\u5355\u7684\u6709\u5e8f\u6027\u8d28\u3002<\/p>\n

\u67e5\u8be2GiST\u6811\u9700\u8981\u4f7f\u7528\u4e00\u4e2a\u7279\u6b8a\u7684\u4e00\u81f4\u6027(consistent) \u51fd\u6570\uff0c\u8fd9\u662fGiST\u7684\u4e00\u4e2a\u63a5\u53e3\u51fd\u6570\uff0c\u53ef\u4ee5\u88ab\u5404\u79cd\u64cd\u4f5c\u7b26\u65cf\u81ea\u7531\u7684\u5b9e\u73b0\u3002<\/p>\n

GiST\u5728\u5904\u7406\u6bcf\u884c\u6570\u636e\u65f6\uff0c\u90fd\u4f1a\u8c03\u7528\u8fd9\u4e2a\u4e00\u81f4\u6027\u51fd\u6570\uff0c\u7528\u6765\u786e\u5b9a\u8fd9\u884c\u6570\u636e\u662f\u5426\u6ee1\u8db3\u8c13\u8bcd\u6761\u4ef6\uff08\u7531indexed-field operator expression\u6307\u5b9a\uff09\u3002\u5bf9\u975e\u53f6\u5b50\u8282\u70b9\u6765\u8bf4\uff0c\u8fd9\u4e2a\u51fd\u6570\u51b3\u5b9a\u662f\u5426\u6709\u5fc5\u8981\u5411\u4e0b\u641c\u7d22\u76f8\u5e94\u7684\u5b50\u6811\uff1b\u5bf9\u53f6\u5b50\u8282\u70b9\u6765\u8bf4\uff0c\u8fd9\u4e2a\u51fd\u6570\u51b3\u5b9a\u67d0\u884c\u7d22\u5f15\u6570\u636e\u662f\u5426\u6ee1\u8db3\u8c13\u8bcd\u6761\u4ef6\u3002<\/p>\n

\u4e0e\u4e00\u822c\u6811\u7684\u641c\u7d22\u7b97\u6cd5\u76f8\u540c\uff0c\u67e5\u8be2\u4ece\u6839\u8282\u70b9\u5f00\u59cb\u3002\u901a\u8fc7\u8c03\u7528\u4e00\u81f4\u6027\u51fd\u6570\uff0c\u53ef\u4ee5\u77e5\u9053\u7ee7\u7eed\u641c\u7d22\u54ea\u4e9b\u5b50\u6811\uff08\u53ef\u80fd\u6709\u591a\u4e2a\u5b50\u6811\u6ee1\u8db3\u6761\u4ef6\uff09\uff0c\u53ef\u4ee5\u6392\u9664\u54ea\u4e9b\u5b50\u6811\u3002\u5bf9\u6240\u6709\u7b26\u5408\u6761\u4ef6\u7684\u5b50\u8282\u70b9\uff0c\u91cd\u590d\u8fd9\u4e2a\u641c\u7d22\u8fc7\u7a0b\u3002\u5bf9\u53f6\u5b50\u8282\u70b9\uff0c\u5c06\u6ee1\u8db3\u4e00\u81f4\u6027\u51fd\u6570\u7684\u884c\u4f5c\u4e3a\u7ed3\u679c\u8fd4\u56de\u3002<\/p>\n

\u641c\u7d22\u8fc7\u7a0b\u4f7f\u7528\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u3002\u5c3d\u53ef\u80fd\u5feb\u7684\u5230\u8fbe\u53f6\u5b50\u8282\u70b9\uff0c\u4f7f\u5f97\u67e5\u8be2\u5c3d\u5feb\u8fd4\u56de\u7ed3\u679c\u3002\u8fd9\u5728\u7528\u6237\u4ec5\u4ec5\u9700\u8981\u90e8\u5206\u7ed3\u679c\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n

\u518d\u6b21\u5f3a\u8c03\u4e00\u4e0b\uff0c\u8fd9\u4e2a\u4e00\u81f4\u6027\u51fd\u6570\u4e0e>\u3001>=\u3001=\u3001<=\u3001<\u5b8c\u5168\u6ca1\u6709\u5173\u7cfb\u3002\u5404\u79cd\u4e0d\u540c\u7d22\u5f15\u4e4b\u95f4\u7684\u4e00\u81f4\u6027\u51fd\u6570\u7684\u542b\u4e49\u53ef\u80fd\u5b8c\u5168\u4e0d\u540c\uff0c\u56e0\u6b64\uff0c\u7d22\u5f15\u4e5f\u4e0d\u4fdd\u8bc1\u6309\u67d0\u79cd\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n

\u672c\u6587\u4e0d\u4f1a\u4ecb\u7ecdGiST\u7d22\u5f15\u7684\u63d2\u5165\u548c\u5220\u9664\u7b97\u6cd5\uff1a\u5904\u7406\u8fd9\u4e9b\u64cd\u4f5c\u7684\u662f\u5176\u5b83\u51e0\u4e2a\u63a5\u53e3\u3002\u7136\u800c\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5f53\u5411\u7d22\u5f15\u4e2d\u63d2\u5165\u4e00\u4e2a\u65b0\u503c\u65f6\uff0c\u63d2\u5165\u7684\u4f4d\u7f6e\u4f1a\u57fa\u4e8e\u8fd9\u6837\u7684\u539f\u5219\u8fdb\u884c\u9009\u62e9\uff1a\u63d2\u5165\u8fd9\u4e2a\u70b9\u540e\uff0c\u53ef\u4ee5\u8ba9\u7236\u8282\u70b9\u7684\u8c13\u8bcd\u6269\u5c55\u7684\u5c3d\u53ef\u80fd\u5c0f\u3002\u4f46\u662f\u5f53\u5220\u9664\u4e00\u4e2a\u503c\u65f6\uff0c\u7236\u8282\u70b9\u7684\u8c13\u8bcd\u6761\u4ef6\u7684\u8303\u56f4\u4e0d\u4f1a\u6536\u7f29\u3002\u6536\u7f29\u4ec5\u4ec5\u53d1\u751f\u5728\u8fd9\u4e9b\u573a\u666f\uff1a\u4e00\u4e2a\u9875\u9762\u88ab\u5206\u88c2\u6210\u4e24\u4e2a\uff08\u5f53\u4e00\u4e2a\u9875\u9762\u6ca1\u6709\u7a7a\u95f4\u5b58\u653e\u65b0\u503c\u65f6\uff09\u3001\u7d22\u5f15\u88ab\u91cd\u5efa\uff08reindex\u3001vacuum full\uff09\u65f6\u3002\u56e0\u6b64\uff0c\u5728\u9891\u7e41\u66f4\u65b0\u7684\u573a\u666f\u4e0b\uff0cGiST\u7684\u6548\u7387\u4f1a\u968f\u7740\u65f6\u95f4\u9010\u6e10\u4e0b\u964d\u3002<\/p>\n

\u4e0b\u6587\u901a\u8fc7\u5177\u4f53\u7684\u793a\u4f8b\u4ecb\u7ecd\u51e0\u79cd\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u7d22\u5f15\uff0c\u548c\u5b83\u4eec\u4e00\u4e9b\u6709\u7528\u7684\u6027\u8d28\uff1a<\/p>\n