看来我的服务器不会使用gin index。
- 我创建了一个包含一张表的新数据库。
- 我插入了一行作为示例。
- 我已经加载了 trigram 扩展并使用 trigram 创建了 gin 索引
- 但是当我检查索引是否正常工作时,我发现它不正常
- 有什么想法吗?
SQL: http://pastebin.com/1yDQQA1Z
附言一天前,我学习了一个关于三元组的教程。基本上它和我上面的例子一样。该表有 2 列,numeric(5, 0) 和 character varying(具有 gin trgm 索引的列)。查询与使用“%”的类似运算符一起使用,并且索引正常工作(我可以在查询解释中看到使用位图),所以我知道,我的服务器可以使用索引(并且已正确安装)。
提前致谢。
最佳答案
不要在一行上测试,这是没有意义的。
这是解释原因的文档摘录,在 Examining Index Usage 中:
Use real data for experimentation. Using test data for setting up indexes will tell you what indexes you need for the test data, but that is all.
It is especially fatal to use very small test data sets. While selecting 1000 out of 100000 rows could be a candidate for an index, selecting 1 out of 100 rows will hardly be, because the 100 rows probably fit within a single disk page, and there is no plan that can beat sequentially fetching 1 disk page.
关于postgresql - Postgres - Gin 索引不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14547889/