{"id":114596,"date":"2019-05-22T10:58:04","date_gmt":"2019-05-22T02:58:04","guid":{"rendered":"http:\/\/www.fagao.me\/?p=114596"},"modified":"2019-05-22T10:58:04","modified_gmt":"2019-05-22T02:58:04","slug":"%e5%be%ae%e4%bf%a1%e5%85%a8%e6%96%87%e6%90%9c%e7%b4%a2%e4%bc%98%e5%8c%96%e4%b9%8b%e8%b7%af","status":"publish","type":"post","link":"https:\/\/www.fagao.me\/p\/114596.htm","title":{"rendered":"\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u4f18\u5316\u4e4b\u8def"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.fagao.me\/images\/uploads\/2021_020.jpg\" alt=\"\"><\/p>\n<div class=\"focusup\"><\/div>\n<p><strong><span style=\"font-size: 16px;\">\u524d\u8a00<\/span><\/strong><\/p>\n<p>\u57fa\u4e8e\u672c\u5730\u6570\u636e\u7684\u5168\u6587\u641c\u7d22\uff08Full-Text-Search\uff0c\u7b80\u79f0 FTS\uff09\u5728\u79fb\u52a8\u5e94\u7528\u4e0a\u626e\u6f14\u7740\u91cd\u8981\u89d2\u8272\uff0c\u4e0e\u57fa\u4e8e\u670d\u52a1\u7aef\u63d0\u4f9b\u7684\u641c\u7d22\u670d\u52a1\u4e0d\u540c\uff0c\u79fb\u52a8\u7aef\u53d7\u786c\u4ef6\u6761\u4ef6\u9650\u5236\uff0c\u5c24\u5176\u5728\u6570\u636e\u91cf\u76f8\u5bf9\u8f83\u5927\u7684\u60c5\u51b5\u4e0b\uff0c\u641c\u7d22\u6027\u80fd\u95ee\u9898\u8868\u73b0\u5f97\u5341\u5206\u7a81\u51fa\u3002\u672c\u6587\u4ee5\u79fb\u52a8\u5e73\u53f0\u5e7f\u6cdb\u91c7\u7528\u7684 SQLite FTS Extension \u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u4e86\u79fb\u52a8\u5e73\u53f0 FTS \u7684\u57fa\u672c\u539f\u7406\uff0c\u5e76\u7ed3\u5408\u5fae\u4fe1 Android \u5ba2\u6237\u7aef\u81ea\u8eab\u5b9e\u8df5\uff0c\u91cd\u70b9\u8bb2\u8ff0\u5fae\u4fe1\u5728 FTS \u4e0a\u7684\u4e00\u4e9b\u6027\u80fd\u4f18\u5316\u7ecf\u9a8c\u3002<\/p>\n<p><strong><span style=\"font-size: 16px;\">SQLite FTS Extension<\/span><\/strong><\/p>\n<p>SQLite FTS Extension \u662f SQLite \u4e3a\u5168\u6587\u641c\u7d22\u5f00\u53d1\u7684\u63d2\u4ef6\uff0c\u5185\u5d4c\u5728\u6807\u51c6\u7684 SQLite \u53d1\u5e03\u7248\u672c\u5f53\u4e2d\uff0c\u4e3b\u8981\u5177\u6709\u5982\u4e0b\u7279\u70b9\uff1a<\/p>\n<ul>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>\u641c\u7d22\u901f\u5ea6\u5feb\uff1a<\/strong>\u4f7f\u7528\u5012\u6392\u7d22\u5f15\u52a0\u901f\u67e5\u627e\u8fc7\u7a0b\uff1b<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>\u7a33\u5b9a\u6027\u597d\uff1a<\/strong>\u76ee\u524d SQLite \u5728\u79fb\u52a8\u7aef\u7684\u7a33\u5b9a\u6027\u8f83\u4e3a\u826f\u597d\uff0cFTS Extension \u5373\u662f\u5728 SQLite \u57fa\u7840\u4e0a\u642d\u5efa\u800c\u6210\u7684\uff1b<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>\u63a5\u5165\u7b80\u5355\uff1a<\/strong>Android \u548c iOS \u5e73\u53f0\u672c\u8eab\u5c31\u652f\u6301 SQLite\uff0c\u4e14 FTS Extension \u7684\u4f7f\u7528\u4e0e SQLite \u8868\u65e0\u5f02\uff1b<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>\u517c\u5bb9\u6027\u597d\uff1a<\/strong>\u5f97\u76ca\u4e8e SQLite \u672c\u8eab\u826f\u597d\u7684\u517c\u5bb9\u6027\uff0cSQLite FTS Extension \u4e5f\u62e5\u6709\u5f88\u597d\u7684\u517c\u5bb9\u6027\u3002<\/span><\/p>\n<\/li>\n<\/ul>\n<p>\u76ee\u524d SQLite FTS Extension \u5df2\u7ecf\u53d1\u5e03\u4e86 5 \u4e2a\u7248\u672c\uff0c\u5728\u6b64\u7b80\u5355\u4ecb\u7ecd\u4e0b\u4e3b\u6d41\u7684 3 \u4e2a\u7248\u672c\uff1a<\/p>\n<ul>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>FTS3\uff1a<\/strong>\u57fa\u7840\u7248\u672c\uff0c\u5177\u6709\u5b8c\u6574\u7684 FTS \u7279\u6027\uff0c\u652f\u6301\u81ea\u5b9a\u4e49\u5206\u8bcd\u5668\uff0c\u5e93\u51fd\u6570\u5305\u62ec Offsets\u3001Snippet\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>FTS4\uff1a<\/strong>\u5728 FTS3 \u7684\u57fa\u7840\u4e0a\uff0c\u6027\u80fd\u6709\u8f83\u5927\u4f18\u5316\uff0c\u589e\u52a0\u76f8\u5173\u6027\u51fd\u6570\u8ba1\u7b97 MatchInfo\uff1b<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>FTS5\uff1a<\/strong>\u548c FTS4 \u76f8\u6bd4\u6709\u8f83\u5927\u53d8\u52a8\uff0c\u50a8\u5b58\u683c\u5f0f\u4e0a\u6709\u8f83\u5927\u6539\u8fdb\uff0c\u6700\u660e\u663e\u5c31\u662f Instance-List \u7684\u5206\u6bb5\u5b58\u50a8\uff0c\u80fd\u591f\u652f\u6301\u66f4\u5927\u7684 Instance-List \u5b58\u50a8\uff1b\u5e76\u4e14\u5f00\u653e ExtensionAPI\uff0c\u652f\u6301\u81ea\u5b9a\u4e49\u8f85\u52a9\u51fd\u6570\u3002<\/span><\/p>\n<\/li>\n<\/ul>\n<p><strong><span style=\"font-size: 16px;\">\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u5b58\u50a8\u67b6\u6784<\/span><\/strong><\/p>\n<p>\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u6700\u521d\u4e3b\u8981\u670d\u52a1\u4e8e\u8054\u7cfb\u4eba\u548c\u804a\u5929\u8bb0\u5f55\u7684\u4e1a\u52a1\u641c\u7d22\u3002\u5728\u65b9\u6848\u8bbe\u8ba1\u4e4b\u521d\uff0c\u4e3a\u4e86\u8ba9\u8fd9\u4e2a\u529f\u80fd\u6709\u5f88\u597d\u7684\u4f53\u9a8c\uff0c\u540c\u65f6\u8003\u8651\u5230\u672a\u6765\u63a5\u5165\u4e1a\u52a1\u4f1a\u4e0d\u65ad\u589e\u591a\uff0c\u6211\u4eec\u5c06\u8bbe\u8ba1\u76ee\u6807\u5b9a\u4e3a\uff1a<\/p>\n<p><span style=\"font-size: 16px;\"><strong>1. \u641c\u7d22\u901f\u5ea6\u5feb<\/strong><\/span><\/p>\n<p>\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u4f7f\u7528 SQLite FTS4 Extension\uff0c\u901a\u8fc7\u5012\u6392\u7d22\u5f15\u63d0\u9ad8\u641c\u7d22\u901f\u5ea6\u3002<\/p>\n<p><strong><span style=\"font-size: 16px;\">2. \u4e1a\u52a1\u72ec\u7acb\u6027<\/span><\/strong><\/p>\n<p>\u5fae\u4fe1\u7684\u6838\u5fc3\u4e1a\u52a1\u662f\u8054\u7cfb\u4eba\u548c\u6d88\u606f\uff0c\u800c\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u65e0\u8bba\u662f\u5728\u5efa\u7acb\u7d22\u5f15\u3001\u66f4\u65b0\u7d22\u5f15\u6216\u8005\u5220\u9664\u7d22\u5f15\u65f6\uff0c\u90fd\u9700\u8981\u5904\u7406\u5927\u91cf\u6570\u636e\uff0c\u4e3a\u4e86\u4f7f\u5168\u6587\u641c\u7d22\u4e0d\u5f71\u54cd\u5fae\u4fe1\u7684\u6838\u5fc3\u4e1a\u52a1\uff0c\u91c7\u7528\u4e86\u5982\u56fe 1 \u6240\u793a\u7684\u5b58\u50a8\u67b6\u6784\u3002<\/p>\n<\/p>\n<p>\u56fe 1 \u5fae\u4fe1\u5168\u6587\u641c\u7d22\u603b\u4f53\u67b6\u6784\u56fe <\/p>\n<p>\u5177\u4f53\u4f53\u73b0\u4e3a\uff1a<\/p>\n<ul>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>\u72ec\u7acb DB\u3001\u8bfb\u5199\u5206\u79bb\uff1a<\/strong>\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u5728\u6574\u4f53\u67b6\u6784\u4e0a\u72ec\u7acb\u4e8e\u4e3b\u4e1a\u52a1\uff0c\u641c\u7d22 DB \u4e5f\u662f\u72ec\u7acb\u4e8e\u4e3b\u4e1a\u52a1 DB\uff1b\u5f53\u4e3b\u4e1a\u52a1\u6570\u636e\u53d1\u751f\u66f4\u65b0\u65f6\uff0c\u4e3b\u4e1a\u52a1\u901a\u8fc7 EventBus \u65b9\u5f0f\u901a\u77e5\u641c\u7d22\u5bf9\u5e94\u7684\u4e1a\u52a1\u6570\u636e\u5904\u7406\u6a21\u5757\uff0c\u8be5\u6a21\u5757\u4f1a\u901a\u8fc7\u4e00\u4e2a\u72ec\u7acb\u7684 ReadOnly \u6570\u636e\u5e93\u8fde\u63a5\u8bbf\u95ee\u4e3b\u4e1a\u52a1\u6570\u636e\u5e93\uff0c\u4e0d\u548c\u4e3b\u4e1a\u52a1\u5b58\u50a8\u5c42\u5171\u4eab\u6570\u636e\u5e93\u8fde\u63a5\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>\u51cf\u5c11\u6570\u636e\u5e93\u64cd\u4f5c\uff1a<\/strong>\u5728\u641c\u7d22\u6a21\u5757\u4e2d\uff0c\u4f1a\u6709\u4e13\u95e8\u5904\u7406\u4e1a\u52a1\u6570\u636e\u7684\u6a21\u5757\uff0c\u5bf9\u4e00\u4e9b\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\u8fdb\u884c\u7279\u6b8a\u5904\u7406\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u4e00\u4e2a 500 \u4eba\u7684\u7fa4\u804a\uff0c\u5982\u679c\u5c06\u6240\u6709\u6210\u5458\u5206\u6b21\u63d2\u5165\u641c\u7d22 DB \u4e2d\uff0c\u4f1a\u9020\u6210\u8fc7\u591a\u7684\u6570\u636e\u5e93\u64cd\u4f5c\u3002\u6240\u4ee5\uff0c\u5fae\u4fe1\u4f1a\u628a\u6240\u6709\u7684\u7fa4\u6210\u5458\u62fc\u63a5\u4e3a\u5355\u4e2a\u5b57\u7b26\u4e32\uff0c\u63d2\u5165\u641c\u7d22 DB \u4e2d\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>\u70ed\u6570\u636e\u5ef6\u8fdf\u66f4\u65b0\uff1a<\/strong>\u9488\u5bf9\u66f4\u65b0\u9891\u7387\u975e\u5e38\u9ad8\u7684\u70ed\u6570\u636e\uff0c\u91c7\u7528\u5ef6\u8fdf\u66f4\u65b0\u7b56\u7565\u3002\u6240\u6709\u7684\u7d22\u5f15\u6570\u636e\u5206\u4e3a\u6b63\u5e38\u6570\u636e\u548c\u810f\u6570\u636e\uff0c\u5f53\u6570\u636e\u53d1\u751f\u66f4\u65b0\u65f6\uff0c\u5148\u628a\u5bf9\u5e94\u7684\u6570\u636e\u6807\u8bb0\u4e3a\u810f\u6570\u636e\uff0c\u7136\u540e\u6709\u4e00\u4e2a\u5b9a\u65f6\u5668\uff0c\u6bcf\u9694 10min \u5c06\u6570\u636e\u66f4\u65b0\u5230\u7d22\u5f15\u4e2d\u3002<\/span><\/p>\n<\/li>\n<\/ul>\n<p><strong><span style=\"font-size: 16px;\">3. \u53ef\u6269\u5c55\u6027\u9ad8<\/span><\/strong><\/p>\n<p>\u9ad8\u53ef\u6269\u5c55\u6027\u8981\u6c42\u641c\u7d22\u8868\u7ed3\u6784\u548c\u4e1a\u52a1\u89e3\u8026\u3002SQLite FTS \u5b98\u7f51\u4e0a\u7684\u4f8b\u5b50\uff0c\u90fd\u662f\u4ee5\u5355\u7d22\u5f15\u8868\u7684\u65b9\u5f0f\uff0c\u6bcf\u4e00\u5217\u5bf9\u5e94\u4e1a\u52a1\u7684\u67d0\u4e00\u4e2a\u5c5e\u6027\uff0c\u5f53\u5bf9\u5e94\u4e1a\u52a1\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u5c31\u9700\u8981\u4fee\u6539\u7d22\u5f15\u8868\u7684\u7ed3\u6784\u3002\u4e3a\u4e86\u89e3\u51b3\u4e1a\u52a1\u53d8\u5316\u800c\u5e26\u6765\u7684\u8868\u7ed3\u6784\u4fee\u6539\u95ee\u9898\uff0c\u5fae\u4fe1\u5c06\u4e1a\u52a1\u5c5e\u6027\u6570\u5b57\u5316\uff0c\u8bbe\u8ba1\u51fa\u5982\u8868 1 \u548c\u8868 2 \u7684\u8868\u7ed3\u6784\u3002<\/p>\n<p>\u8868 1 \u7d22\u5f15\u8868-IndexTable <\/p>\n<\/p>\n<p>\u8868 2 \u6570\u636e\u8868-MetaTable <\/p>\n<\/p>\n<p><span>\u5176\u4e2d\uff0cIndexTable \u8d1f\u8d23\u5168\u6587\u641c\u7d22\u7684\u7d22\u5f15\u5efa\u7acb\uff0c\u5b83\u548c\u903b\u8f91\u65e0\u5173\uff0c\u5728\u641c\u7d22\u5173\u952e\u8bcd\u65f6\uff0c\u53ea\u9700\u8981\u627e\u5230\u5bf9\u5e94\u7684 DocId \u5373\u53ef\u3002MetaTable \u8d1f\u8d23\u4e1a\u52a1\u903b\u8f91\u7684\u8fc7\u6ee4\uff0c\u901a\u8fc7 Type \u548c SubType \u6765\u8fc7\u6ee4\u5bf9\u5e94\u4e1a\u52a1\u7684\u6570\u636e\uff0c\u6700\u540e\u8f93\u51fa BusItemId\u3002<\/span><\/p>\n<p><strong><span style=\"font-size: 16px;\">\u641c\u7d22\u4f18\u5316<\/span><\/strong><\/p>\n<p>\u4ece 2014 \u5e74 1 \u6708 5.4 \u7248\u5230 2017 \u5e74\u6625\u8282\u540e\u7684 6.5.7 \u7248\uff0c\u5fae\u4fe1\u603b\u4f53\u7528\u6237\u91cf\u4ece 4 \u4ebf\u589e\u52a0\u5230 9 \u4ebf\uff0c\u4f34\u968f\u7740\u91cd\u5ea6\u7528\u6237\u6570\u91cf\u7684\u5927\u5e45\u589e\u957f\uff0c\u5fae\u4fe1\u672c\u5730\u641c\u7d22\u7684\u6570\u636e\u91cf\u4e5f\u5927\u5e45\u79ef\u7d2f\u4e0b\u6765\uff0c\u5bfc\u81f4\u641c\u7d22\u901f\u5ea6\u4e0d\u65ad\u4e0b\u964d\uff0c\u7528\u6237\u6295\u8bc9\u6301\u7eed\u589e\u52a0\u3002\u636e\u7edf\u8ba1\uff0c\u5728 5.4 \u7248\u672c\u5230 6.5.7 \u7248\u672c\u671f\u95f4\uff0c\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u5404\u4e2a\u4efb\u52a1\u7684\u5e73\u5747\u641c\u7d22\u65f6\u95f4\uff0c\u589e\u957f\u8d85\u8fc7 10 \u500d\uff0c\u7ed9\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u5e26\u6765\u5de8\u5927\u6311\u6218\u3002<\/p>\n<p>\u4e3a\u4e86\u4f18\u5316\u641c\u7d22\u65f6\u957f\uff0c\u5148\u770b\u4e0b\u5982\u56fe 2 \u6240\u793a\u7684\u641c\u7d22\u6d41\u7a0b\u3002<\/p>\n<\/p>\n<p>\u56fe 2 \u641c\u7d22\u8fc7\u7a0b <\/p>\n<p><span>\u901a\u8fc7\u6bcf\u4e2a\u9636\u6bb5\u7684\u8017\u65f6\uff0c\u53d1\u73b0\u5728\u53d6\u6570\u636e\u9636\u6bb5\uff0c\u65f6\u95f4\u5360\u6bd4\u8fbe\u5230 80%\u4ee5\u4e0a\uff0c\u5e76\u4e14\u641c\u7d22\u7684\u7ed3\u679c\u96c6\u6570\u636e\u91cf\u8d8a\u5927\uff0c\u65f6\u95f4\u5360\u6bd4\u8d8a\u9ad8\uff0c\u6700\u9ad8\u53ef\u8fbe 95%\u3002\u53d6\u6570\u636e\u9636\u6bb5\u662f\u4e00\u4e2a\u5faa\u73af\u7684\u8fc7\u7a0b\uff0c\u6240\u4ee5\u4f18\u5316\u4e00\u4e2a\u5faa\u73af\u9700\u8981\u4ece\u4e24\u65b9\u9762\u7740\u624b\uff0c\u51cf\u5c11\u5355\u6b21\u5faa\u73af\u8017\u65f6\u548c\u603b\u4f53\u5faa\u73af\u6b21\u6570\u3002<\/span><\/p>\n<p><strong><span style=\"font-size: 16px;\">\u51cf\u5c11\u5355\u6b21\u5faa\u73af\u6267\u884c\u8017\u65f6<\/span><\/strong><\/p>\n<p>\u6df1\u5165 SQLite FTS4 Extension \u6e90\u7801\uff0c\u53d1\u73b0 FTS4 \u7684\u5e93\u51fd\u6570 Offsets \u8017\u65f6\u5360\u5355\u6b21\u5faa\u73af\u6267\u884c\u8017\u65f6 70%\u4ee5\u4e0a\uff0c\u5e76\u4e14\u6570\u636e\u91cf\u8d8a\u5927\u8017\u65f6\u8d8a\u957f\u3002<\/p>\n<p><strong>FTS4 \u5e93\u51fd\u6570 Offsets\uff1a<\/strong>\u7528\u4e8e\u628a\u8bcd\u8bed\u504f\u79fb\u8f6c\u4e3a\u5b57\u8282\u504f\u79fb\uff0c\u5fae\u4fe1\u5f53\u4e2d\u4f7f\u7528\u5b57\u8282\u505a\u7ed3\u679c\u6392\u5e8f\u53ca\u9ad8\u4eae\u3002<\/p>\n<p>\u51fd\u6570\u8f93\u5165\uff1a<\/p>\n<ul>\n<li>\n<p><span style=\"font-size: 16px;\">Query\uff1a\u7528\u6237\u67e5\u627e\u7684\u5173\u952e\u8bcd\uff1b<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\">\u547d\u4e2d Doc\uff1a\u5173\u952e\u8bcd\u6240\u547d\u4e2d\u7684\u6587\u6863\uff0c\u5373\u5168\u6587\u641c\u7d22\u4e2d\u7684\u57fa\u672c\u5355\u4f4d\uff0c\u53ef\u4ee5\u662f\u4e00\u4e2a\u7f51\u9875\uff0c\u4e00\u7bc7\u6587\u7ae0\u6216\u4e00\u6761\u804a\u5929\u8bb0\u5f55\uff1b<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\">\u76ee\u6807\u8bcd\u8bed\u504f\u79fb\uff1a\u5728\u641c\u7d22\u9636\u6bb5\uff0c\u901a\u8fc7\u5173\u952e\u8bcd\u67e5\u627e\u641c\u7d22\u7d22\u5f15\u53ef\u4ee5\u62ff\u5230\u76ee\u6807\u8bcd\u8bed\u504f\u79fb\u3002<\/span><\/p>\n<\/li>\n<\/ul>\n<p>\u51fd\u6570\u8f93\u51fa\uff1a<\/p>\n<ul>\n<li>\n<p>\u76ee\u6807\u5b57\u8282\u504f\u79fb\uff1a\u8868\u793a\u5173\u952e\u8bcd\u5728\u547d\u4e2d Doc \u4e2d\u7684\u5b57\u8282\u504f\u79fb\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a<\/p>\n<blockquote>\n<p><span>Query<\/span><span>=<\/span><span>\u6211 \u547d\u4e2d Doc=\u6211\u548c\u6211\u5f1f\u5f1f\u53bb\u901b\u8857 \u76ee\u6807\u8bcd\u8bed\u504f\u79fb=0\u30012<\/span><\/p>\n<\/blockquote>\n<p>\u5c06\u547d\u4e2d Doc \u7ecf\u8fc7\u5206\u8bcd\u5668\u5206\u8bcd\uff0c\u53ef\u4ee5\u5f97\u5230\u8868 3\u3002\u6700\u540e\u8ba1\u7b97\u53ef\u4ee5\u5f97\u51fa\uff0c\u76ee\u6807\u5b57\u8282\u504f\u79fb=0\u30016\u3002<\/p>\n<p>\u8868 3 \u8bcd\u8bed\u504f\u79fb\u548c\u5b57\u8282\u504f\u79fb\u5bf9\u5e94\u8868 <\/p>\n<\/p>\n<p><span>\u5982\u56fe 3 \u6240\u793a\u662f Offsets \u51fd\u6570\u5904\u7406\u547d\u4e2d Doc \u5b57\u8282\u6570\u548c\u8017\u65f6\u7684\u5173\u7cfb\u3002Offsets \u51fd\u6570\u7684\u5904\u7406\u8fc7\u7a0b\u4e2d\u5305\u62ec\u5206\u8bcd\uff0c\u6240\u4ee5\u7b2c\u4e00\u6b65\u5c31\u4f18\u5316\u5206\u8bcd\u5668\u3002<\/span><\/p>\n<\/p>\n<p>\u56fe 3 Offset \u51fd\u6570\u5904\u7406\u8017\u65f6 <\/p>\n<p>\u8981\u4f18\u5316\u5206\u8bcd\u5668\uff0c\u5206\u8bcd\u89c4\u5219\u662f\u91cd\u4e2d\u4e4b\u91cd\u3002\u5fae\u4fe1\u7684\u5206\u8bcd\u89c4\u5219\u4e3a\u82f1\u6587\u548c\u6570\u5b57\u5408\u5e76\u5206\u8bcd\uff0c\u975e\u82f1\u6587\u548c\u6570\u5b57\u5355\u72ec\u5206\u8bcd\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u5bf9\u4e8e\u6635\u79f0\u201cHello520 \u4e2d\u56fd\u201d\uff0c\u5206\u8bcd\u7ed3\u679c\u4e3a\u201cHello\u201d\u3001\u201c520\u201d\u3001\u201c\u4e2d\u201d\u3001\u201c\u56fd\u201d\u3002\u8fd9\u4e2a\u5206\u8bcd\u89c4\u5219\u7684\u539f\u56e0\u8981\u5f52\u7ed3\u4e8e\u5fae\u4fe1\u5bf9\u5168\u6587\u641c\u7d22\u7684\u7ed3\u679c\u6392\u5e8f\u9700\u6c42\u4e3b\u8981\u662f\u5176\u4ed6\u7684\u5c5e\u6027\u6392\u5e8f\uff0c\u800c\u975e\u4f9d\u636e\u6587\u6863\u7684\u76f8\u5173\u6027\u6392\u5e8f\u3002\u5373\uff0c\u5168\u6587\u641c\u7d22\u90e8\u5206\u53ea\u9700\u8981\u627e\u5230\u5b58\u5728\u5173\u952e\u8bcd\u7684\u6587\u6863\uff0c\u5e76\u4e0d\u5173\u5fc3\u6587\u6863\u4e2d\u5b58\u5728\u51e0\u4e2a\u5173\u952e\u8bcd\u3002\u4e14\u7528\u6237\u7684\u8f93\u5165 Query \u5927\u90e8\u5206\u60c5\u51b5\u90fd\u4e0d\u80fd\u7ec4\u6210\u8bcd\u8bed\uff0c\u5b58\u5728\u65b9\u8a00\uff0c\u6240\u4ee5\u628a\u6574\u4e2a\u8bcd\u8bed\u5168\u90e8\u62c6\u5f00\u5efa\u7acb\u7d22\u5f15\u662f\u6700\u4f73\u7684\u5904\u7406\u65b9\u5f0f\u3002<\/p>\n<p>\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u5f00\u53d1\u8d77\u59cb\u4e8e 2013 \u5e74\u5e74\u5e95\uff0c\u5f53\u65f6\u53ea\u80fd\u4f7f\u7528 FTS4\uff0c\u4f46\u5176\u81ea\u5e26\u7684\u5206\u8bcd\u5668\u65e0\u6cd5\u826f\u597d\u5730\u652f\u6301\u4e2d\u6587\uff0c\u53ea\u80fd\u4f7f\u7528 ICU \u5206\u8bcd\u5668\u3002\u4e14\u76f8\u5bf9\u6765\u8bf4\uff0cICU \u5206\u8bcd\u5668\u63a5\u5165\u6bd4\u8f83\u7b80\u5355\uff0c\u5bf9\u4e2d\u6587\u652f\u6301\u8f83\u597d\u3002\u5982\u56fe 4 \u6240\u793a\uff0c\u6635\u79f0\u201cHello520 \u4e2d\u56fd\u201d\u8f93\u5165\u5206\u8bcd\u5668\u4e2d\uff0c\u4ece\u5f00\u59cb\u7684 UTF8 \u7f16\u7801\uff0c\u5206\u8bcd\u5668\u4f1a\u5c06\u5176\u8f6c\u5316\u4e3a Unicode \u7f16\u7801\uff0c\u7d27\u63a5\u7740\u67e5\u627e\u8bcd\u5178\uff0c\u6700\u540e\u8fdb\u884c\u540e\u5904\u7406\u8f93\u51fa\u5f97\u5230\u5206\u8bcd\u7ed3\u679c\u3002\u4f46\u4ece\u8f93\u5165\u8f93\u51fa\u4e2d\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u8f6c\u5316\u7f16\u7801\u548c\u67e5\u627e\u8bcd\u5178\u8fd9\u4e24\u6b65\u5176\u5b9e\u662f\u591a\u4f59\u7684\u3002<\/p>\n<\/p>\n<p>\u56fe 4 \u5fae\u4fe1 ICU \u5206\u8bcd\u5904\u7406\u8fc7\u7a0b <\/p>\n<p>\u56e0\u6b64\uff0c\u6700\u7ec8\u5fae\u4fe1\u820d\u5f03\u4e86 ICU \u5206\u8bcd\u5668\uff0c\u8f6c\u800c\u81ea\u5b9a\u4e49\u4e86 Simple \u5206\u8bcd\u5668\u3002\u5982\u56fe 5 \u6240\u793a\uff0cSimple \u5206\u8bcd\u5668\u76f4\u63a5\u5904\u7406 UTF8 \u7f16\u7801\u7684 Doc \u5185\u5bb9\uff0c\u901a\u8fc7\u5355\u4e2a Char\uff0c\u5224\u65ad\u5f53\u524d\u5b57\u7b26\u7684 Unicode \u7f16\u7801\u8303\u56f4\u53ca\u957f\u5ea6\uff0c\u5e76\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u505a\u51fa\u4e0d\u540c\u7684\u5904\u7406\u3002<\/p>\n<\/p>\n<p>\u56fe 5 Simple \u5206\u8bcd\u5668\u5206\u8bcd\u8fc7\u7a0b <\/p>\n<p>\u5728\u7ecf\u8fc7\u5206\u8bcd\u5668\u4f18\u5316\u540e\uff0cOffsets \u51fd\u6570\u8017\u65f6\u6709\u4e86\u663e\u8457\u964d\u4f4e\uff0c\u4ece\u56fe 6 \u53ef\u89c1\uff0c\u5904\u7406 10 \u4e07 Byte \u7684\u8017\u65f6\u5df2\u7ecf\u964d\u4f4e\u81f3 21ms\u3002\u4f46\u8fd9\u6837\u7684\u4f18\u5316\u8fd8\u8fdc\u8fdc\u4e0d\u591f\uff0c\u5f53\u5904\u7406\u8d85\u8fc7 10 \u4e2a 10W \u7ed3\u679c Doc \u65f6\uff0c\u4ecd\u7136\u4f1a\u8d85\u8fc7 200ms\uff0c\u6240\u4ee5\u4e5f\u5c31\u6709\u4e86\u4e0b\u4e00\u6b65\u7684\u4f18\u5316\u3002<\/p>\n<\/p>\n<p>\u56fe 6 \u4f18\u5316\u5206\u8bcd\u5668\u540e\u7684 Offsets \u51fd\u6570\u5904\u7406\u8017\u65f6 <\/p>\n<p>\u5728\u79fb\u52a8\u7aef\uff0c\u7531\u4e8e\u5c4f\u5e55\u7684\u9650\u5236\uff0c\u5f80\u5f80\u5728\u6700\u540e\u663e\u793a\u641c\u7d22\u7ed3\u679c\u65f6\uff0c\u53ea\u4f1a\u9ad8\u4eae\u5c11\u91cf\u547d\u4e2d\u7684\u5173\u952e\u8bcd\uff0c\u800c Offsets \u51fd\u6570\u4f1a\u8ba1\u7b97\u547d\u4e2d Doc \u4e2d\u6240\u6709\u76ee\u6807\u8bcd\u8bed\u504f\u79fb\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u5bf9 Offsets \u51fd\u6570\u8fdb\u884c\u6539\u9020\u3002<\/p>\n<p>\u6700\u5f00\u59cb\uff0c\u6211\u4eec\u5c1d\u8bd5\u7684\u65b9\u6848\u662f\u76f4\u63a5\u4fee\u6539 Offsets \u51fd\u6570\u6e90\u7801\uff0c\u4f46\u4e0d\u5e78\u5730\u53d1\u73b0 FTS4 \u5bf9 API \u7684\u5c01\u88c5\u8f83\u96be\u4f7f\u7528\uff0c\u4e14 Offsets \u51fd\u6570\u7684\u4f9d\u8d56\u4e5f\u8f83\u591a\uff0c\u4fee\u6539\u51fa\u6765\u7684\u4ee3\u7801\u5f88\u96be\u7ef4\u62a4\uff0c\u53ef\u8bfb\u6027\u4e5f\u4e0d\u597d\uff0c\u6240\u4ee5\u9700\u8981\u5bfb\u627e\u65b0\u7684\u65b9\u6cd5\u6765\u4f18\u5316\u3002\u5728\u7ecf\u8fc7\u4e00\u756a\u7814\u7a76\u540e\uff0c\u6211\u4eec\u53d1\u73b0 FTS5 \u652f\u6301\u81ea\u5b9a\u4e49\u8f85\u52a9\u51fd\u6570\uff0c\u4e14\u6709\u7740\u8f83\u597d\u7684 API \u5c01\u88c5\uff0c\u6240\u4ee5\u6700\u540e\u4f7f\u7528 FTS5 \u81ea\u5b9a\u4e49\u8f85\u52a9\u51fd\u6570\uff08MMHighLight\uff09\u91cd\u65b0\u5b9e\u73b0 Offsets \u51fd\u6570\u7684\u529f\u80fd\uff0c\u5e76\u52a0\u5165\u4e86\u4f18\u5316\u903b\u8f91\u3002<\/p>\n<p>\u518d\u4ee5\u524d\u6587\u793a\u4f8b\u6765\u770b\uff0c\u8f93\u5165\uff1a<\/p>\n<blockquote>\n<p><span>Query<\/span><span>=<\/span><span>\u6211 \u547d\u4e2d Doc=\u6211\u548c\u6211\u5f1f\u5f1f\u53bb\u901b\u8857 \u76ee\u6807\u8bcd\u8bed\u504f\u79fb=0\u30012 \u76ee\u6807\u8fd4\u56de\u4e2a\u6570=1<\/span><\/p>\n<\/blockquote>\n<p>\u6b64\u65f6\u5206\u8bcd\u5668\u5206\u6b65\u56de\u8c03\uff0c\u5f53\u5206\u8bcd\u5668\u7b2c\u4e00\u6b21\u8fd4\u56de\u201c\u6211\u201d\uff0c\u7b26\u5408\u76ee\u6807\u8bcd\u8bed\u504f\u79fb\u7684\u7b2c\u4e00\u4e2a 0\uff0c\u5e76\u4e14\u6b64\u65f6\u5df2\u7ecf\u6ee1\u8db3\u76ee\u6807\u8fd4\u56de\u4e2a\u6570 1\uff0c\u51fd\u6570\u76f4\u63a5\u8fd4\u56de\u76ee\u6807\u5b57\u8282\u504f\u79fb=0\uff0c\u5982\u56fe 7 \u6240\u793a\uff0c\u8017\u65f6\u5b9e\u73b0\u4e86 10 \u4e07 Byte \u4f4e\u81f3 2ms \u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p>\u56fe 7 MMHighLight \u51fd\u6570\u5904\u7406\u8017\u65f6 <strong><span style=\"font-size: 16px;\">\u51cf\u5c11\u603b\u4f53\u5faa\u73af\u6b21\u6570<\/span><\/strong><\/p>\n<p>\u51cf\u5c11\u53d6\u6570\u636e\u9636\u6bb5\u7684\u603b\u4f53\u5faa\u73af\u6b21\u6570\uff0c\u6bd4\u8f83\u5bb9\u6613\u60f3\u5230\u7684\u662f\u5728 SQL \u5c42\u505a\u6570\u636e\u7684\u5206\u9875\u8fd4\u56de\u3002\u8fd9\u4e5f\u5c31\u610f\u5473\u7740\u6211\u4eec\u9700\u8981\u5728 DB \u5c42\u6392\u5e8f\uff0c\u800c\u5176\u51b3\u5b9a\u56e0\u7d20\u5219\u4e3a\u6392\u5e8f\u56e0\u5b50\u3002\u4f46\u662f\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u9762\u5bf9\u7684\u4e1a\u52a1\u6392\u5e8f\u56e0\u5b50\u975e\u5e38\u7e41\u6742\uff0c\u65e0\u6cd5\u76f4\u63a5\u4f7f\u7528 SQL \u4e2d\u7684 ORDER BY\uff0c\u6240\u4ee5\u9700\u8981\u901a\u8fc7\u4e00\u4e2a\u4e2d\u95f4\u51fd\u6570\u8f6c\u5316\uff0c\u5c06\u6240\u6709\u7684\u6392\u5e8f\u56e0\u5b50\u901a\u8fc7\u4e00\u4e2a\u53ef\u6bd4\u8f83\u7684\u6570\u5b57\u4f53\u73b0\uff0c\u6700\u540e\u518d\u4f7f\u7528 ORDER BY \u6392\u5e8f\u3002<\/p>\n<p>\u6bd4\u8f83\u590d\u6742\u7684\u6392\u5e8f\u56e0\u5b50\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>\u65f6\u95f4\u5206\u6bb5\u6392\u5e8f\uff1a<\/strong>\u65f6\u95f4\u8303\u56f4\u5728\u534a\u5e74\u5185\uff0c\u6392\u5e8f\u56e0\u5b50\u53d6\u51b3\u4e8e\u4e0b\u4e00\u7ea7\u6392\u5e8f\u56e0\u5b50\uff1b\u65f6\u95f4\u8303\u56f4\u5728\u534a\u5e74\u5916\uff0c\u53d6\u51b3\u4e8e\u65f6\u95f4\u7684\u8fdc\u8fd1\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\"><strong>\u51fd\u6570\u7ed3\u679c\u6392\u5e8f\uff1a<\/strong>\u6392\u5e8f\u56e0\u5b50\u662f\u4e00\u4e2a\u51fd\u6570\u8ba1\u7b97\u7684\u7ed3\u679c\uff0c\u800c\u975e\u4e00\u4e2a\u76f4\u63a5\u7684\u6570\u636e\u5e93 Column\uff0c\u5e76\u4e14\u51fd\u6570\u8ba1\u7b97\u7ed3\u679c\u4e0d\u53ef\u76f4\u63a5\u4f7f\u7528 ORDER BY\uff0c\u4f8b\u5982\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u6570\u5b57\u3002<\/span><\/p>\n<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u7684\u5206\u6790\uff0c\u51cf\u5c11\u603b\u4f53\u5faa\u73af\u6b21\u6570\u7684\u6838\u5fc3\u70b9\u5c31\u5728\u4e8e\uff0c\u5c06 Java \u5c42\u7684\u6392\u5e8f\u8f6c\u79fb\u5230 SQL \u5c42\u53bb\u505a\uff0c\u4f18\u70b9\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\n<p><span style=\"font-size: 16px;\">\u51cf\u5c11 I\/O\uff1b<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\">\u51cf\u5c11 C \u5c42\u5230 Java \u5c42\u7684\u6570\u636e\u62f7\u8d1d\u3002<\/span><\/p>\n<\/li>\n<\/ol>\n<p>\u6240\u4ee5\uff0c\u8fd9\u91cc\u5173\u952e\u7684\u5b9e\u73b0\u70b9\u5728\u4e8e\u4e2d\u95f4\u8f6c\u5316\u51fd\u6570\uff0c\u5fae\u4fe1\u7684\u4e2d\u95f4\u8f6c\u5316\u51fd\u6570 MMRank \u662f\u901a\u8fc7 FTS5 \u7684\u8f85\u52a9\u51fd\u6570\u5b9e\u73b0\u7684\u3002<\/p>\n<\/p>\n<p><span>\u56fe 8 MMRank \u5b9e\u73b0<\/span><\/p>\n<p>\u5982\u56fe 8 \u6240\u793a\uff0cMMRank \u7684\u5b9e\u73b0\u539f\u7406\u5c31\u662f\u901a\u8fc7\u628a\u6240\u6709\u7684\u6392\u5e8f\u56e0\u5b50\u8f6c\u5316\u5230\u4e00\u4e2a 64 \u4f4d\u7684 Long \u6570\u503c\u5f53\u4e2d\uff0c\u9ad8\u4f18\u5148\u7ea7\u7684\u6392\u5e8f\u56e0\u5b50\u7f6e\u9ad8\u4f4d\uff0c\u4f4e\u4f18\u5148\u7ea7\u7684\u6392\u5e8f\u56e0\u5b50\u7f6e\u4f4e\u4f4d\u3002\u6700\u540e\u7684 SQL \u5982\u4e0b\uff1a<\/p>\n<blockquote>\n<p><span>SELECT<\/span><span>MMRank(A1, A2, A3, A4) <\/span><span>AS<\/span><span>Rank <\/span><span>FROM<\/span><span>IndexTable <\/span><span>ORDER<\/span><span><\/span><span>BY<\/span><span>RANK <\/span><span>DESC<\/span><span>;<\/span><\/p>\n<\/blockquote>\n<p><strong><span style=\"font-size: 16px;\">\u7279\u6b8a\u4f18\u5316\u2014\u2014\u804a\u5929\u8bb0\u5f55\u641c\u7d22\u4f18\u5316<\/span><\/strong><\/p>\n<p>\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u4e2d\u6709\u4e00\u4e2a\u6bd4\u8f83\u7279\u6b8a\u7684\u641c\u7d22\u4efb\u52a1\uff0c\u5c31\u662f\u804a\u5929\u8bb0\u5f55\u3002\u5982\u56fe 9 \u6240\u793a\uff0c\u7ea2\u8272\u5708\u5185\u7684\u6570\u5b57\u8868\u793a\uff0c\u6b64\u4f1a\u8bdd\u4e2d\uff0c\u5305\u542b\u5173\u952e\u5b57\u201c\u6211\u201d\u7684\u804a\u5929\u8bb0\u5f55\u7684\u4e2a\u6570\uff0c\u800c\u4f1a\u8bdd\u7684\u6392\u5e8f\u89c4\u5219\u5c31\u662f\u4f1a\u8bdd\u7684\u6d3b\u8dc3\u65f6\u95f4\u3002<\/p>\n<\/p>\n<p>\u56fe 9 \u5fae\u4fe1\u804a\u5929\u8bb0\u5f55\u641c\u7d22 <\/p>\n<p>\u5fae\u4fe1\u804a\u5929\u8bb0\u5f55\u7684\u641c\u7d22\u6709\u4ee5\u4e0b\u4e24\u4e2a\u7279\u70b9\uff1a<\/p>\n<ol>\n<li>\n<p><span style=\"font-size: 16px;\">\u6709\u7edf\u8ba1\u5c5e\u6027\uff1b<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\">\u6570\u91cf\u975e\u5e38\u591a\uff08\u5355\u5173\u952e\u8bcd\u547d\u4e2d\u6700\u9ad8\u53ef\u8fbe\u5230 20 \u4e07\u6761\uff09\u3002<\/span><\/p>\n<\/li>\n<\/ol>\n<p>\u4ece\u524d\u6587\u641c\u7d22\u6d41\u7a0b\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u5fae\u4fe1\u6700\u521d\u91c7\u7528\u7684\u65b9\u6848\u662f\u5728 Java \u5c42\u7edf\u8ba1\u4e2a\u6570\u548c\u6392\u5e8f\uff0c\u6b64\u65b9\u6cd5\u5728\u5927\u6570\u636e\u7684\u60c5\u51b5\u4e0b\u4e0d\u53ef\u53d6\u3002\u9274\u4e8e\u4e4b\u524d\u5206\u6790\u8fc7\u51cf\u5c11\u5faa\u73af\u6b21\u6570\u53ef\u4ee5\u901a\u8fc7\u5206\u9875\u8fd4\u56de\uff0c\u5176\u6838\u5fc3\u70b9\u5728\u4e8e\u628a\u6392\u5e8f\u4ece Java \u5c42\u8f6c\u79fb\u5230 SQL \u5c42\uff0c\u6240\u4ee5\u5c31\u6709\u4e86\u4f18\u5316\u65b9\u6848\u4e00\u3002<\/p>\n<p><strong><span style=\"font-size: 16px;\">\u4f18\u5316\u65b9\u6848\u4e00\uff1aGroup By<\/span><\/strong><\/p>\n<p>\u5b9e\u73b0 SQL \u5982\u4e0b\uff1a<\/p>\n<p><span style=\"font-size: 16px;\"><span>SELECT<\/span>count(conv), MAX(<span>timestamp<\/span>) <span>AS<\/span>MaxTime <span>FROM<\/span>IndexTable <span>GROUP<\/span><span>BY<\/span>conv <span>ORDER<\/span><span>BY<\/span>MaxTime <span>DESC<\/span>LIMIT <span>4<\/span>;<\/span><\/p>\n<p>\u6b64\u65b9\u6848\u901a\u8fc7 Group By \u5728 SQL \u5c42\u76f4\u63a5\u7edf\u8ba1\u51fa\u547d\u4e2d\u804a\u5929\u8bb0\u5f55\u7684\u4e2a\u6570\uff0c\u5e76\u6309\u7167\u6700\u8fd1\u7684\u65f6\u95f4\u6392\u5e8f\uff0c\u4f46\u662f\u4e5f\u6709\u660e\u663e\u7f3a\u9677\uff1a<\/p>\n<ol>\n<li>\n<p><span style=\"font-size: 16px;\">\u65e0\u6cd5\u4f7f\u7528\u7d22\u5f15\u52a0\u901f\uff1a\u5f53 Group By \u548c Order By \u540c\u65f6\u4f7f\u7528\u65f6\uff0cOrder By \u4e2d\u5fc5\u987b\u5305\u542b Group By \u7684\u5b57\u6bb5\u624d\u53ef\u4ee5\u547d\u4e2d\u7d22\u5f15\uff0c\u539f\u56e0\u662f\u4f7f\u7528 Group By \u4f1a\u751f\u6210\u4e2d\u95f4\u5b50\u8868\uff1b<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 16px;\">\u5168\u91cf\u8ba1\u7b97\uff1aGroup By \u5728 SQL \u5c42\u7edf\u8ba1\u547d\u4e2d\u804a\u5929\u8bb0\u5f55\u4e2a\u6570\u662f\u7edf\u8ba1\u4e86\u6240\u6709\u4f1a\u8bdd\uff0c\u56fe 9 \u4e2d\u53ea\u9700\u8981\u7edf\u8ba1 3 \u4e2a\u4f1a\u8bdd\uff0c\u6d6a\u8d39\u4e86\u5927\u91cf\u8d44\u6e90\u3002<\/span><\/p>\n<\/li>\n<\/ol>\n<p><strong><span style=\"font-size: 16px;\">\u4f18\u5316\u65b9\u6848\u4e8c\uff1a\u5206\u6b65\u8ba1\u7b97<\/span><\/strong><\/p>\n<p>\u9274\u4e8e\u65b9\u6848\u4e00\u5168\u91cf\u8ba1\u7b97\u7684\u95ee\u9898\uff0c\u6211\u4eec\u91c7\u7528\u5206\u6b65\u8ba1\u7b97\u7684\u65b9\u5f0f\u3002<\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u627e\u51fa\u6700\u8fd1\u6d3b\u8dc3\u7684 3 \u4e2a\u4f1a\u8bdd\u3002<\/p>\n<p><span style=\"font-size: 16px;\"><span>SELECT<\/span>count(*) <span>FROM<\/span>IndexTable <span>ORDER<\/span><span>BY<\/span><span>timestamp<\/span><span>DESC<\/span>LIMIT <span>3<\/span>;<\/span><\/p>\n<p>\u5f97\u5230\u4f1a\u8bdd conv1\u3001conv2\u3001conv3\uff0c\u7136\u540e\u6267\u884c\u4ee5\u4e0b SQL \u547d\u4ee4\uff0c\u53ef\u4ee5\u5206\u522b\u5f97\u5230 3 \u4e2a\u4f1a\u8bdd\u7684\u547d\u4e2d\u4e2a\u6570\u3002<\/p>\n<p><span style=\"font-size: 16px;\"><span>SELECT<\/span>count(*) <span>FROM<\/span>IndexTable <span>WHERE<\/span>conv=<span>&#8216;conv1&#8217;<\/span>; <span>SELECT<\/span>count(*) <span>FROM<\/span>IndexTable <span>WHERE<\/span>conv=<span>&#8216;conv2&#8217;<\/span>; <span>SELECT<\/span>count(*) <span>FROM<\/span>IndexTable <span>WHERE<\/span>conv=<span>&#8216;conv3&#8217;<\/span>;<\/span><\/p>\n<p>\u4f46\u662f\u8fd9\u79cd\u65b9\u6cd5\u4e5f\u5b58\u5728\u95ee\u9898\uff0c\u9700\u8981\u6267\u884c\u591a\u6761 SQL\uff0c\u5b58\u5728\u591a\u6b21 I\/O\u3002<\/p>\n<p><strong><span style=\"font-size: 16px;\">\u4f18\u5316\u65b9\u6848\u4e09\uff1aMessageCount<\/span><\/strong><\/p>\n<p>\u9274\u4e8e\u65b9\u6848\u4e8c\u9700\u8981\u591a\u6761 SQL \u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u901a\u8fc7\u81ea\u5b9a\u4e49\u805a\u5408\u51fd\u6570\u5b9e\u73b0\u4e00\u6b21\u6027\u7edf\u8ba1\u3002\u6267\u884c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u627e\u51fa\u6700\u8fd1\u6d3b\u8dc3\u7684 3 \u4e2a\u4f1a\u8bdd\u3002<\/p>\n<p><span style=\"font-size: 16px;\"><span>SELECT<\/span>count(*) <span>FROM<\/span>IndexTable <span>ORDER<\/span><span>BY<\/span><span>timestamp<\/span><span>DESC<\/span>LIMIT <span>3<\/span>;<\/span><\/p>\n<p>\u5f97\u5230\u4f1a\u8bdd conv1\u3001conv2\u3001conv3\uff0c\u7136\u540e\u6267\u884c\u4ee5\u4e0b SQL\u3002<\/p>\n<p><span style=\"font-size: 16px;\"><span>SELECT<\/span>MessageCount(<span>3<\/span>) <span>FROM<\/span>IndexTable <span>WHERE<\/span>conv <span>IN<\/span>(<span>&#8216;conv1&#8217;<\/span>,<span>&#8216;conv2&#8217;<\/span>,<span>&#8216;conv3&#8217;<\/span>);<\/span><\/p>\n<p>\u53ef\u4ee5\u4e00\u6b21\u6027\u5f97\u5230 3 \u4e2a\u4f1a\u8bdd\u7684\u547d\u4e2d\u4e2a\u6570\u3002<\/p>\n<p><strong><span style=\"font-size: 16px;\">\u603b\u7ed3<\/span><\/strong><\/p>\n<p>\u7ecf\u8fc7\u4e00\u7cfb\u5217\u4f18\u5316\u540e\uff0c\u5fae\u4fe1\u5168\u6587\u641c\u7d22\u5168\u4f53\u7528\u6237\u5404\u4e2a\u4efb\u52a1\u5e73\u5747\u8017\u65f6\u90fd\u5728 50ms \u4ee5\u4e0b\uff0c\u800c\u91cd\u5ea6\u7528\u6237\u5404\u4e2a\u4efb\u52a1\u7684\u5e73\u5747\u641c\u7d22\u8017\u65f6\u90fd\u5728 200ms \u4ee5\u4e0b\uff0c\u5e73\u5747\u65f6\u95f4\u4f18\u5316\u7684\u5e45\u5ea6\u8fbe\u5230 5 \u500d\u4ee5\u4e0a\u3002\u4f46\u540e\u7eed\u8fd8\u662f\u6709\u5f88\u591a\u503c\u5f97\u4f18\u5316\u7684\u5730\u65b9\uff0c\u8b6c\u5982\u5728\u8ba1\u7b97\u9ad8\u4eae\u65f6\uff0c\u5982\u679c\u5728 DocList \u7684\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u76f4\u63a5\u52a0\u5165\u5b57\u8282\u504f\u79fb\uff0c\u8fd8\u53ef\u4ee5\u8282\u7701\u4e00\u90e8\u5206\u65f6\u95f4\u3002\u6700\u540e\uff0c\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u7684\u4e00\u4e9b\u7ecf\u9a8c\u6478\u7d22\u80fd\u591f\u5bf9\u5927\u5bb6\u5728\u5b9e\u9645\u7684\u7814\u53d1\u5de5\u4f5c\u4e2d\u6709\u6240\u88e8\u76ca\u3002<\/p>\n<blockquote>\n<ul>\n<li>\n<p><strong>\u4f5c\u8005\uff1a<\/strong>\u9648\u5bb6\u654f\uff0c\u5fae\u4fe1\u7ec8\u7aef\u5f00\u53d1\u5de5\u7a0b\u5e08\uff0c\u76ee\u524d\u4e3b\u8981\u8d1f\u8d23\u5fae\u4fe1 Android \u5ba2\u6237\u7aef\u5168\u6587\u641c\u7d22\u3001\u5fae\u4fe1\u8fd0\u52a8\u7684\u5f00\u53d1\u5de5\u4f5c\u3002\u5148\u540e\u53c2\u4e0e\u4e86\u5fae\u4fe1\u591a\u4eba\u901a\u8bdd\u3001\u5fae\u4fe1\u641c\u4e00\u641c\u4ee5\u53ca\u5fae\u4fe1\u5b89\u5168\u6a21\u5f0f\u7684\u5f00\u53d1\u3002 <\/p>\n<\/li>\n<li>\n<p><strong>\u8d23\u7f16\uff1a<\/strong>\u5510\u5c0f\u5f15\uff08tangxy@csdn.net\uff09<\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n<div class=\"articleend\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u57fa\u4e8e\u672c\u5730\u6570\u636e\u7684\u5168\u6587\u641c\u7d22\uff08Full-Text-Search\uff0c\u7b80\u79f0 FTS\uff09\u5728\u79fb\u52a8\u5e94\u7528\u4e0a\u626e\u6f14\u7740\u91cd\u8981\u89d2\u8272\uff0c\u4e0e\u57fa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[177],"class_list":["post-114596","post","type-post","status-publish","format-standard","hentry","category-news","tag-177"],"_links":{"self":[{"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/posts\/114596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/comments?post=114596"}],"version-history":[{"count":0,"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/posts\/114596\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/media?parent=114596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/categories?post=114596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/tags?post=114596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}