<\/a><\/p>\n\u7070\u8272\u65b9\u5757\u8868\u793a\u4f4d\u7f6e\u4fe1\u606f\u3002<\/p>\n
select ctid, left(doc,20), doc_tsv from ts;\n<\/code><\/pre>\n ctid | left | doc_tsv \n-------+----------------------+---------------------------------------------------------\n (0,1) | Can a sheet slitter | 'sheet':3,6 'slit':5 'slitter':4\n (0,2) | How many sheets coul | 'could':4 'mani':2 'sheet':3,6 'slit':8 'slitter':7\n (0,3) | I slit a sheet, a sh | 'sheet':4,6 'slit':2,8\n (1,1) | Upon a slitted sheet | 'sheet':4 'sit':6 'slit':3 'upon':1\n (1,2) | Whoever slit the she | 'good':7 'sheet':4,8 'slit':2 'slitter':9 'whoever':1\n (1,3) | I am a sheet slitter | 'sheet':4 'slitter':5\n (2,1) | I slit sheets. | 'sheet':3 'slit':2\n (2,2) | I am the sleekest sh | 'ever':8 'sheet':5,10 'sleekest':4 'slit':9 'slitter':6\n (2,3) | She slits the sheet | 'sheet':4 'sit':6 'slit':2\n(9 rows)\n<\/code><\/pre>\nGIN\u63d0\u4f9b\u4e86fastupdate\u53c2\u6570\uff0cRUM\u5220\u9664\u4e86\u8fd9\u4e2a\u53c2\u6570\u3002<\/p>\n
\u6211\u4eec\u7ee7\u7eed\u4f7f\u7528pgsql-hackers\u90ae\u4ef6\u5217\u8868\u4f5c\u4e3a\u793a\u4f8b\u3002<\/p>\n
alter table mail_messages add column tsv tsvector;\nset default_text_search_config = default;\nupdate mail_messages\nset tsv = to_tsvector(body_plain);\n<\/code><\/pre>\n...\nUPDATE 356125\n<\/code><\/pre>\n\u4f7f\u7528GIN\u7d22\u5f15\u65f6\uff0c\u67e5\u8be2\u662f\u8fd9\u6837\u6267\u884c\u7684\uff1a<\/p>\n
create index tsv_gin on mail_messages using gin(tsv);\nexplain (costs off, analyze)\nselect * from mail_messages\nwhere tsv @@ to_tsquery('hello <-> hackers');\n<\/code><\/pre>\n QUERY PLAN \n---------------------------------------------------------------------------------\n Bitmap Heap Scan on mail_messages (actual time=2.490..18.088 rows=259 loops=1)\n Recheck Cond: (tsv @@ to_tsquery('hello <-> hackers'::text))\n Rows Removed by Index Recheck: 1517\n Heap Blocks: exact=1503\n -> Bitmap Index Scan on tsv_gin (actual time=2.204..2.204 rows=1776 loops=1)\n Index Cond: (tsv @@ to_tsquery('hello <-> hackers'::text))\n Planning time: 0.266 ms\n Execution time: 18.151 ms\n(8 rows)\n<\/code><\/pre>\n\u4ece\u8ba1\u5212\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0cGIN\u7d22\u5f15\u88ab\u4f7f\u7528\u4e86\uff0c\u4f46\u662f\u5b83\u8fd4\u56de\u4e861776\u6761\u5019\u9009\uff0c\u6700\u7ec8\u88ab\u6dd8\u6c701517\u6761\uff0c\u53ea\u5269\u4e0b259\u6761\u3002<\/p>\n
\u8ba9\u6211\u4eec\u5220\u9664GIN\u7d22\u5f15\uff0c\u5efa\u7acbRUM\u7d22\u5f15\u3002<\/p>\n
drop index tsv_gin;\ncreate index tsv_rum on mail_messages using rum(tsv);\n<\/code><\/pre>\n\u8fd9\u4e2a\u7d22\u5f15\u5305\u542b\u4e86\u6240\u6709\u6240\u9700\u7684\u4fe1\u606f\uff0c\u67e5\u8be2\u975e\u5e38\u7cbe\u786e\uff1a<\/p>\n
explain (costs off, analyze)\nselect * from mail_messages\nwhere tsv @@ to_tsquery('hello <-> hackers');\n<\/code><\/pre>\n QUERY PLAN \n--------------------------------------------------------------------------------\n Bitmap Heap Scan on mail_messages (actual time=2.798..3.015 rows=259 loops=1)\n Recheck Cond: (tsv @@ to_tsquery('hello <-> hackers'::text))\n Heap Blocks: exact=250\n -> Bitmap Index Scan on tsv_rum (actual time=2.768..2.768 rows=259 loops=1)\n Index Cond: (tsv @@ to_tsquery('hello <-> hackers'::text))\n Planning time: 0.245 ms\n Execution time: 3.053 ms\n(7 rows)\n<\/code><\/pre>\n3. \u6309\u76f8\u5173\u6027\u6392\u5e8f<\/h1>\n
\u4e3a\u4e86\u5feb\u901f\u6309\u7167\u6240\u9700\u7684\u987a\u5e8f\u8fd4\u56de\u6587\u6863\uff0cRUM\u652f\u6301\u6392\u5e8f\u64cd\u4f5c\u7b26\uff0c\u5728GiST\u6587\u6863\u4e2d\u63cf\u8ff0\u8fc7\u3002RUM\u63d2\u4ef6\u5b9a\u4e49\u4e86\u8fd9\u4e2a\u64cd\u4f5c\u7b26\uff0c<=>\uff0c\u5b83\u53ef\u4ee5\u8fd4\u56de\u6587\u6863(tsvector)\u548c\u67e5\u8be2(tsquery)\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002\u4f8b\u5982\uff1a<\/p>\n
select to_tsvector('Can a sheet slitter slit sheets?')\n <=> to_tsquery('slit');\n<\/code><\/pre>\n ?column?\n----------\n 16.4493\n(1 row)\n<\/code><\/pre>\nselect to_tsvector('Can a sheet slitter slit sheets?')\n <=> to_tsquery('sheet');\n<\/code><\/pre>\n ?column?\n----------\n 13.1595\n(1 row)\n<\/code><\/pre>\n\u8fd9\u4e2a\u6587\u6863\u770b\u8d77\u6765\u4e0e\u7b2c\u4e8c\u4e2a\u6587\u6863\u6bd4\u4e0e\u7b2c\u4e00\u4e2a\u6587\u6863\u66f4\u52a0\u76f8\u5173\uff1a\u4e00\u4e2a\u5355\u8bcd\u51fa\u73b0\u7684\u6b21\u6570\u8d8a\u591a\uff0c\u8fd9\u4e2a\u6587\u6863\u4ef7\u503c\u8d8a\u4f4e\u3002<\/p>\n
\u6211\u4eec\u518d\u4e00\u4e2a\u76f8\u5bf9\u5927\u4e00\u70b9\u7684\u6570\u636e\u6bd4\u8f83GIN\u548cRUM\uff1a\u627e\u51fa\u5305\u542bhello\u548chackers\u7684\u5341\u7bc7\u6700\u76f8\u5173\u7684\u6587\u6863\u3002<\/p>\n
explain (costs off, analyze)\nselect * from mail_messages\nwhere tsv @@ to_tsquery('hello & hackers')\norder by ts_rank(tsv,to_tsquery('hello & hackers'))\nlimit 10;\n<\/code><\/pre>\n QUERY PLAN\n---------------------------------------------------------------------------------------------\n Limit (actual time=27.076..27.078 rows=10 loops=1)\n -> Sort (actual time=27.075..27.076 rows=10 loops=1)\n Sort Key: (ts_rank(tsv, to_tsquery('hello & hackers'::text)))\n Sort Method: top-N heapsort Memory: 29kB\n -> Bitmap Heap Scan on mail_messages (actual ... rows=1776 loops=1)\n Recheck Cond: (tsv @@ to_tsquery('hello & hackers'::text))\n Heap Blocks: exact=1503\n -> Bitmap Index Scan on tsv_gin (actual ... rows=1776 loops=1)\n Index Cond: (tsv @@ to_tsquery('hello & hackers'::text))\n Planning time: 0.276 ms\n Execution time: 27.121 ms\n(11 rows)\n<\/code><\/pre>\nGIN\u7d22\u5f15\u8fd4\u56de\u4e861776\u6761\uff0c\u63a5\u7740\u4f7f\u7528\u4e00\u4e2a\u5355\u72ec\u7684\u6b65\u9aa4\u6392\u5e8f\uff0c\u9009\u51fa\u5341\u4e2a\u6700\u597d\u7684\u5339\u914d\u3002<\/p>\n
\u501f\u52a9RUM\u7d22\u5f15\uff0c\u67e5\u8be2\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e2a\u7b80\u5355\u7684\u7d22\u5f15\u626b\u63cf\u5b8c\u6210\uff1a\u65e0\u9700\u989d\u5916\u67e5\u770b\u6587\u6863\uff0c\u65e0\u9700\u989d\u5916\u7684\u6392\u5e8f\uff1a<\/p>\n
explain (costs off, analyze)\nselect * from mail_messages\nwhere tsv @@ to_tsquery('hello & hackers')\norder by tsv <=> to_tsquery('hello & hackers')\nlimit 10;\n<\/code><\/pre>\n QUERY PLAN\n--------------------------------------------------------------------------------------------\n Limit (actual time=5.083..5.171 rows=10 loops=1)\n -> Index Scan using tsv_rum on mail_messages (actual ... rows=10 loops=1)\n Index Cond: (tsv @@ to_tsquery('hello & hackers'::text))\n Order By: (tsv <=> to_tsquery('hello & hackers'::text))\n Planning time: 0.244 ms\n Execution time: 5.207 ms\n(6 rows)\n<\/code><\/pre>\n4. \u9644\u52a0\u5b57\u6bb5<\/h1>\n
RUM\u7d22\u5f15\uff0c\u548cGIN\u7d22\u5f15\u4e00\u6837\uff0c\u53ef\u4ee5\u5efa\u7acb\u5728\u591a\u4e2a\u5b57\u6bb5\u4e0a\u3002\u4f46\u662fGIN\u7d22\u5f15\u628a\u6bcf\u4e2a\u5217\u7684\u8bcd\u7d20\u5355\u72ec\u5b58\u50a8\u3002RUM\u53ef\u4ee5\u628a\u4e00\u4e2a\u9644\u52a0\u5c5e\u6027\u9644\u52a0\u5230\u4e00\u4e2a\u4e3b\u5c5e\u6027\u4e0a\u3002\u8fd9\u53ef\u4ee5\u501f\u52a9rum_tsvector_addon_ops\u64cd\u4f5c\u7b26\u7c7b\u5b8c\u6210\u3002<\/p>\n
create index on mail_messages\n using rum(tsv RUM_TSVECTOR_ADDON_OPS, sent)\n WITH (ATTACH='sent', TO='tsv');\n<\/code><\/pre>\n\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u7d22\u5f15\u5bf9\u7ed3\u679c\u6309\u7167\u9644\u52a0\u7684\u5c5e\u6027\u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n
select id, sent, sent <=> '2017-01-01 15:00:00'\nfrom mail_messages\nwhere tsv @@ to_tsquery('hello')\norder by sent <=> '2017-01-01 15:00:00'\nlimit 10;\n<\/code><\/pre>\n id | sent | ?column? \n---------+---------------------+----------\n 2298548 | 2017-01-01 15:03:22 | 202\n 2298547 | 2017-01-01 14:53:13 | 407\n 2298545 | 2017-01-01 13:28:12 | 5508\n 2298554 | 2017-01-01 18:30:45 | 12645\n 2298530 | 2016-12-31 20:28:48 | 66672\n 2298587 | 2017-01-02 12:39:26 | 77966\n 2298588 | 2017-01-02 12:43:22 | 78202\n 2298597 | 2017-01-02 13:48:02 | 82082\n 2298606 | 2017-01-02 15:50:50 | 89450\n 2298628 | 2017-01-02 18:55:49 | 100549\n(10 rows)\n<\/code><\/pre>\n\u6211\u4eec\u5728\u8fd9\u4e2a\u67e5\u8be2\u4e2d\uff0c\u67e5\u8be2\u4e86\u8ddd\u79bb\u6307\u5b9a\u65e5\u671f\u6700\u8fd1\u7684\u884c\uff0c\u65e0\u8bba\u65e9\u4e8e\u8fd8\u662f\u665a\u4e8e\u6307\u5b9a\u65e5\u671f\u3002\u5982\u679c\u60f3\u8981\u67e5\u627e\u4e25\u683c\u65e9\u4e8e\u6216\u665a\u4e8e\u6307\u5b9a\u65e5\u671f\u65f6\uff0c\u5e94\u8be5\u4f7f\u7528<=|(o\u6216|=>)\u64cd\u4f5c\u7b26\u3002\u6b63\u5982\u6240\u671f\u5f85\u7684\u90a3\u6837\uff0c\u67e5\u8be2\u53ea\u662f\u9700\u8981\u4e00\u4e2a\u7b80\u5355\u7684\u7d22\u5f15\u626b\u63cf\uff1a<\/p>\n
explain (costs off)\nselect id, sent, sent <=> '2017-01-01 15:00:00' \nfrom mail_messages\nwhere tsv @@ to_tsquery('hello')\norder by sent <=> '2017-01-01 15:00:00'\nlimit 10;\n<\/code><\/pre>\n QUERY PLAN\n---------------------------------------------------------------------------------\n Limit\n -> Index Scan using mail_messages_tsv_sent_idx on mail_messages\n Index Cond: (tsv @@ to_tsquery('hello'::text))\n Order By: (sent <=> '2017-01-01 15:00:00'::timestamp without time zone)\n(4 rows)\n<\/code><\/pre>\n\u5982\u679c\u6ca1\u6709\u8fd9\u4e2a\u9644\u52a0\u7684\u5c5e\u6027\uff0c\u6211\u4eec\u9700\u8981\u628a\u7d22\u5f15\u626b\u63cf\u7684\u7ed3\u679c\u4f7f\u7528Sort\u7b97\u5b50\u6392\u5e8f\u3002<\/p>\n
\u9664\u4e86\u65e5\u671f\u7c7b\u578b\uff0c\u6211\u4eec\u5f53\u7136\u53ef\u4ee5\u9644\u52a0\u5176\u5b83\u6570\u636e\u7c7b\u578b\u7684\u5b57\u6bb5\u3002\u51e0\u4e4e\u6240\u6709\u7684\u57fa\u672c\u7c7b\u578b\u90fd\u652f\u6301\u3002<\/p>\n
5. \u5176\u5b83\u64cd\u4f5c\u7b26\u7c7b<\/h1>\n
\u9996\u5148\u770brum_tsvector_hash_ops\u548crum_tsvector_hash_addon_ops\u3002\u5b83\u4eec\u4e0e\u5df2\u7ecf\u4ecb\u7ecd\u8fc7\u7684rum_tsvector_ops\u548crum_tsvector_addon_ops\u5f88\u76f8\u4f3c\uff0c\u53ea\u662f\u5b83\u4eec\u5b58\u50a8\u8bcd\u7d20\u7684Hash\u503c\uff0c\u800c\u4e0d\u662f\u8bcd\u7d20\u672c\u8eab\u3002\u8fd9\u53ef\u4ee5\u51cf\u5c0f\u7d22\u5f15\u7684\u4f53\u79ef\uff0c\u5f53\u7136\u67e5\u8be2\u53d8\u5f97\u4e0d\u7cbe\u786e\uff0c\u5e76\u4e14\u9700\u8981\u91cd\u65b0\u68c0\u67e5\u3002\u800c\u4e14\uff0c\u8fd9\u5bfc\u81f4\u65e0\u6cd5\u652f\u6301\u90e8\u5206\u5339\u914d\u3002<\/p>\n
rum_tsquery_ops\u975e\u5e38\u6709\u8da3\uff0c\u5b83\u4eec\u5e2e\u52a9\u6211\u4eec\u89e3\u51b3\u4e00\u4e2a\u76f8\u53cd\u7684\u95ee\u9898\uff1a\u627e\u51fa\u7b26\u5408\u6587\u6863\u7684\u67e5\u8be2\u3002\u4e3a\u4ec0\u4e48\u6709\u8fd9\u4e2a\u9700\u6c42\uff1f\u5047\u5982\u4e00\u4e2a\u7528\u6237\u8ba2\u9605\u4e86\u67d0\u79cd\u65b0\u7684\u5546\u54c1\u6216\u8005\u6bcf\u79cd\u7c7b\u578b\u7684\u6587\u6863\uff0c\u5f53\u65b0\u51fa\u73b0\u8fd9\u79cd\u6587\u6863\u65f6\uff0c\u5e94\u8be5\u63a8\u9001\u7ed9\u7528\u6237\u3002\u4f8b\u5982\uff1a<\/p>\n
create table categories(query tsquery, category text);\ninsert into categories values\n (to_tsquery('vacuum | autovacuum | freeze'), 'vacuum'),\n (to_tsquery('xmin | xmax | snapshot | isolation'), 'mvcc'),\n (to_tsquery('wal | (write & ahead & log) | durability'), 'wal');\ncreate index on categories using rum(query);\nselect array_agg(category)\nfrom categories\nwhere to_tsvector(\n 'Hello hackers, the attached patch greatly improves performance of tuple\n freezing and also reduces size of generated write-ahead logs.'\n) @@ query;\n<\/code><\/pre>\n array_agg \n--------------\n {vacuum,wal}\n(1 row)\n<\/code><\/pre>\nrum_anyarray_ops\u548crum_anyarray_addon_ops\u4e3a\u4e86\u6570\u7ec4\u800c\u8bbe\u8ba1\uff0c\u5df2\u7ecf\u5728GIN\u7d22\u5f15\u4e2d\u4ecb\u7ecd\u8fc7\uff0c\u6b64\u5904\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n
6. \u7d22\u5f15\u4f53\u79ef\u548cWAL\u65e5\u5fd7\u91cf<\/h1>\n
\u56e0\u4e3aRUM\u5b58\u50a8\u7684\u4fe1\u606f\u6bd4GIN\u66f4\u591a\uff0c\u5b83\u7684\u4f53\u79ef\u4e5f\u66f4\u5927\u3002\u4e0a\u4e00\u7bc7\u6587\u7ae0\u5df2\u7ecf\u6bd4\u8f83\u8fc7\u4f53\u79ef\uff0c\u73b0\u5728\u628a\u628aRUM\u52a0\u8fdb\u53bb\uff1a<\/p>\n
rum | gin | gist | btree\n--------+--------+--------+--------\n 457 MB | 179 MB | 125 MB | 546 MB\n<\/code><\/pre>\n\u53ef\u4ee5\u770b\u5230\uff0c\u4f53\u79ef\u589e\u5927\u4e86\u5f88\u591a\uff0c\u8fd9\u662f\u5feb\u901f\u67e5\u627e\u6240\u9700\u7684\u4ee3\u4ef7\u3002<\/p>\n
\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff1aRUM\u662f\u4e00\u4e2a\u63d2\u4ef6\uff0c\u56e0\u6b64\u5b89\u88c5\u5b83\u5e76\u4e0d\u9700\u8981\u5bf9\u5185\u6838\u8fdb\u884c\u4efb\u4f55\u4fee\u6539\u3002\u9700\u8981\u89e3\u51b3\u7684\u4e00\u4e2a\u95ee\u9898\u662f\u65e5\u5fd7\u8bb0\u5f55\u91cc\u7684\u751f\u6210\u95ee\u9898\u3002PG\u7684Xlog\u5b50\u7cfb\u7edf\u5fc5\u987b\u8981\u7edd\u5bf9\u5730\u53ef\u9760\uff0c\u56e0\u6b64\u4e0d\u5141\u8bb8\u63d2\u4ef6\u81ea\u5df1\u5199Xlog\u3002\u5199Xlog\u7684\u8fc7\u7a0b\u9700\u8981\u4ea4\u7ed9PG\u5185\u6838\u3002\u63d2\u4ef6\u9996\u5148\u901a\u77e5\u5185\u6838\u60f3\u8981\u4fee\u6539\u9875\u9762\uff0c\u7136\u540e\u4fee\u6539\u9875\u9762\uff0c\u6700\u540e\u901a\u77e5\u5185\u6838\u5df2\u7ecf\u4fee\u6539\u5b8c\u6bd5\u3002\u5185\u6838\u6839\u636e\u9875\u9762\u4fee\u6539\u524d\u540e\u7684\u7f16\u53f7\u751f\u6210Xlog\u3002<\/p>\n
\u73b0\u5728\u7684\u65e5\u5fd7\u751f\u6210\u7b97\u6cd5\u4f1a\u6309\u5b57\u8282\u6bd4\u8f83\u9875\u9762\uff0c\u68c0\u6d4b\u51fa\u9700\u8981\u66f4\u65b0\u7684\u6bb5\uff0c\u8bb0\u5f55\u6bcf\u4e2a\u6bb5\u3002\u5f53\u66f4\u65b0\u9875\u9762\u4e2d\u5c11\u91cf\u5b57\u8282\u65f6\uff0c\u6216\u6574\u4e2a\u9875\u9762\u65f6\u8fd9\u79cd\u65b9\u6cd5\u8fd8\u53ef\u4ee5\u3002\u4f46\u662f\u9700\u8981\u5bf9\u9875\u9762\u591a\u5904\u8fdb\u884c\u4fee\u6539\u65f6\uff0c\u5b9e\u9645\u8bb0\u5f55\u7684Xlog\u91cf\u6bd4\u5b9e\u9645\u4fee\u6539\u7684\u5b57\u8282\u6570\u8981\u591a\u5f88\u591a\u3002<\/p>\n
\u7531\u4e8e\u8fd9\u4e2a\u539f\u56e0\uff0c\u9891\u7e41\u66f4\u65b0RUM\u7d22\u5f15\u53ef\u80fd\u4f1a\u4ea7\u751f\u6bd4GIN\uff08\u4e0d\u662f\u63d2\u4ef6\uff0c\u800c\u662f\u5185\u6838\u7684\u4e00\u90e8\u5206\uff0c\u4ee5\u5b83\u81ea\u5df1\u7684\u65b9\u5f0f\u7ba1\u7406\u65e5\u5fd7\uff09\u7d22\u5f15\u591a\u7684\u591a\u7684\u65e5\u5fd7\u3002\u8fd9\u4e2a\u73b0\u8c61\u4e0e\u5177\u4f53\u7684\u8d1f\u8f7d\u6709\u5173\u3002\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u4e00\u4e9b\u64cd\u4f5c\uff0c\u8bb0\u5f55\u4e00\u4e0b\u65e5\u5fd7\u4ea7\u751f\u7684\u6570\u91cf\u3002\u5728\u5f00\u59cb\u548c\u7ed3\u675f\u4e4b\u524d\uff0c\u4f7f\u7528pg_current_wal_location\uff08PG 9.x\u7248\u672c\u4e2d\u4e3apg_current_xlog_location\uff09\u51fd\u6570\u83b7\u53d6\u5f53\u524dXlog\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u8ba1\u7b97\u65e5\u5fd7\u91cf\u3002<\/p>\n
\u5f53\u7136\uff0c\u6211\u4eec\u9700\u8981\u8003\u8651\u5f88\u591a\u65b9\u9762\u3002\u6211\u4eec\u9700\u8981\u4fdd\u8bc1\u53ea\u6709\u4e00\u4e2a\u7528\u6237\u5728\u4f7f\u7528\u8fd9\u4e2a\u7cfb\u7edf\uff0c\u5426\u5219\u4f1a\u4ea7\u751f\u989d\u5916\u7684\u65e5\u5fd7\u8bb0\u5f55\u3002\u5373\u4f7f\u8fd9\u6837\uff0c\u6211\u4eec\u4e5f\u9700\u8981\u8003\u8651\uff0c\u9664\u4e86RUM\uff0c\u66f4\u65b0\u8868\u672c\u8eab\u4e5f\u4f1a\u4ea7\u751f\u65e5\u5fd7\u3002\u4e00\u4e9b\u53c2\u6570\u4e5f\u4f1a\u5f71\u54cd\u65e5\u5fd7\u91cf\uff0c\u4e0b\u9762\u4f7f\u7528replica\u65e5\u5fd7\u7ea7\u522b\u3001\u6ca1\u6709\u538b\u7f29\u3002<\/p>\n
select pg_current_wal_location() as start_lsn \\gset\ninsert into mail_messages(parent_id, sent, subject, author, body_plain, tsv)\n select parent_id, sent, subject, author, body_plain, tsv\n from mail_messages where id % 100 = 0;\n<\/code><\/pre>\nINSERT 0 3576\n<\/code><\/pre>\ndelete from mail_messages where id % 100 = 99;\n<\/code><\/pre>\nDELETE 3590\n<\/code><\/pre>\nvacuum mail_messages;\n<\/code><\/pre>\ninsert into mail_messages(parent_id, sent, subject, author, body_plain, tsv)\n select parent_id, sent, subject, author, body_plain, tsv\n from mail_messages where id % 100 = 1;\n<\/code><\/pre>\nINSERT 0 3605\n<\/code><\/pre>\ndelete from mail_messages where id % 100 = 98;\n<\/code><\/pre>\nDELETE 3637\n<\/code><\/pre>\nvacuum mail_messages;\ninsert into mail_messages(parent_id, sent, subject, author, body_plain, tsv)\n select parent_id, sent, subject, author, body_plain, tsv from mail_messages\n where id % 100 = 2;\n<\/code><\/pre>\nINSERT 0 3625\n<\/code><\/pre>\ndelete from mail_messages where id % 100 = 97;\n<\/code><\/pre>\nDELETE 3668\n<\/code><\/pre>\nvacuum mail_messages;\nselect pg_current_wal_location() as end_lsn \\gset\nselect pg_size_pretty(:'end_lsn'::pg_lsn - :'start_lsn'::pg_lsn);\n<\/code><\/pre>\n pg_size_pretty\n----------------\n 3114 MB\n(1 row)\n<\/code><\/pre>\n\u65e5\u5fd7\u5927\u7ea6\u4e3a3GB\uff0c\u5982\u679c\u4f7f\u7528GIN\u7d22\u5f15\u91cd\u590d\u8bd5\u9a8c\uff0c\u53ea\u751f\u6210\u5927\u7ea6700MB\u3002<\/p>\n
\u56e0\u6b64\uff0c\u5f88\u6709\u5fc5\u8981\u7814\u53d1\u4e00\u79cd\u4e0d\u540c\u7684\u7b97\u6cd5\uff0c\u53ef\u4ee5\u7528\u6765\u627e\u51fa\u63d2\u5165\u548c\u5220\u9664\u6700\u5c0f\u7684\u5dee\u5f02\uff0c\u53ef\u4ee5\u628a\u9875\u9762\u7684\u72b6\u6001\u8f6c\u6362\u6210\u53e6\u5916\u4e00\u4e2a\u72b6\u6001\u3002diff\u4f7f\u7528\u7c7b\u4f3c\u7684\u5de5\u4f5c\u65b9\u5f0f\u3002Oleg Ivanov\u5b9e\u73b0\u4e86\u4e00\u4e2a\u8fd9\u79cd\u7b97\u6cd5\uff0c\u793e\u533a\u6b63\u5728\u8ba8\u8bba\uff0c\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u65e5\u5fd7\u91cc\u51cf\u5c0f\u52301900M\uff0c\u4ee3\u4ef7\u65f6\u6027\u80fd\u7a0d\u6162\u4e00\u4e9b\u3002<\/p>\n
\u4e0d\u5e78\u7684\u662f\uff0c\u8fd9\u4e2apatch\u505c\u6b62\u5f00\u53d1\u4e86\u3002<\/p>\n
7. \u5c5e\u6027<\/h1>\n
\u548c\u5f80\u5e38\u4e00\u6837\uff0c\u770b\u4e00\u4e0b\u5b83\u7684\u5c5e\u6027\u3002
\nAM\u7684\u5c5e\u6027\uff1a<\/p>\n
amname | name | pg_indexam_has_property\n--------+---------------+-------------------------\n rum | can_order | f\n rum | can_unique | f\n rum | can_multi_col | t\n rum | can_exclude | t -- f for gin\n<\/code><\/pre>\n\u7d22\u5f15\u5c42\u9762\u7684\u5c5e\u6027\uff1a<\/p>\n
name | pg_index_has_property\n---------------+-----------------------\n clusterable | f\n index_scan | t -- f for gin\n bitmap_scan | t\n backward_scan | f\n<\/code><\/pre>\n\u6ce8\u610f\uff0c\u4e0eGIN\u7d22\u5f15\u4e0d\u540c\u7684\u662f\uff0cRUM\u652f\u6301Index scan \u2014\u2014 \u5426\u5219\u5b83\u5c31\u4e0d\u53ef\u80fd\u8fd4\u56deLIMIT\u7b97\u5b50\u7684\u7ed3\u679c\u3002\u5b83\u4e0d\u9700\u8981\u4f7f\u7528gin_fuzzy_search_limit\u53c2\u6570\u3002\u5b83\u53ef\u4ee5\u652f\u6301\u6392\u5b83\u7ea6\u675f\u3002<\/p>\n
\u5217\u5c42\u9762\u7684\u7ea6\u675f\uff1a<\/p>\n
name | pg_index_column_has_property \n--------------------+------------------------------\n asc | f\n desc | f\n nulls_first | f\n nulls_last | f\n orderable | f\n distance_orderable | t -- f for gin\n returnable | f\n search_array | f\n search_nulls | f\n<\/code><\/pre>\nRUM\u652f\u6301\u6392\u5e8f\u64cd\u4f5c\u7b26\u3002\u4f46\u662f\uff0c\u8fd9\u4e0d\u662f\u5bf9\u6240\u6709\u64cd\u4f5c\u7b26\u90fd\u6210\u7acb\uff1a\u4f8b\u5982\uff0c\u5bf9tsquery_ops\u5c31\u4e0d\u6210\u7acb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u672c\u6587\u4ecb\u7ecdRUM\u7d22\u5f15\uff0c\u5b83\u6ca1\u6709\u88ab\u5305\u542b\u5728PG\u7684\u6807\u51c6\u53d1\u884c\u7248\u4e2d\u3002\u5b83\u662fGIN\u7d22\u5f15\u7684\u5347\u7ea7\u7248\uff0c\u4e0eGIN\u6700\u5927\u7684\u533a\u522b\u662f\uff0c\u5b83\u4e0d\u4f46\u7d22\u5f15\u8bcd\u7d20\uff0c\u628a\u628a\u8bcd\u7d20\u5728\u6587\u6863\u4e2d\u51fa\u73b0\u7684\u4f4d\u7f6e\u8bb0\u5f55\u5728\u7d22\u5f15\u4e2d\u3002\u5728\u9700\u8981\u8fd9\u4e9b\u4f4d\u7f6e\u4fe1\u606f\u65f6\uff0c\u5b83\u7684\u6027\u80fd\u6bd4GIN\u9ad8\u5f88\u591a\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/posts\/364"}],"collection":[{"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/comments?post=364"}],"version-history":[{"count":12,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/posts\/364\/revisions"}],"predecessor-version":[{"id":482,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/posts\/364\/revisions\/482"}],"wp:attachment":[{"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/media?parent=364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/categories?post=364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mengqingzhong.com\/wp-json\/wp\/v2\/tags?post=364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}