database - 使用加权 tsvector 进行 PostgreSQL 全文搜索的最佳索引

标签 database postgresql indexing full-text-search

我是数据库的新手,对索引的工作原理不是很清楚。

我正在研究索引我的列,其中包含加权的 tsvector(标题被赋予最大权重,然后是副标题,然后是段落内容)。根据 Postgres 文档,GIN 是用于全文搜索的最佳选择,其次是 GiST。但是在第 12.9 章中有一条注释:

GIN indexes are the preferred text search index type. As inverted indexes, they contain an index entry for each word (lexeme), with a compressed list of matching locations. Multi-word searches can find the first match, then use the index to remove rows that are lacking additional words. GIN indexes store only the words (lexemes) of tsvector values, and not their weight labels. Thus a table row recheck is needed when using a query that involves weights.

这是否意味着 GIN 在我的用例中效率低下并且我应该使用 GiST,或者它仍然是最好用的吗?我使用的是最新的 Postgres 版本 (12)。

最佳答案

不,您应该坚持使用 GIN 索引。

索引扫描充当过滤器,并有望消除大部分行,因此只有少数行需要重新检查。

您可能无论如何都必须获取表行,因此除非在索引扫描期间发现许多误报,否则不会有很多额外的工作。

最好的办法是对你的数据集运行一些基准测试,这会给你一个权威的答案,哪个索引在你的情况下更好。

要找出在位图堆扫描期间消除了多少误报,您可以检查查询的 EXPLAIN (ANALYZE, BUFFERS) 输出。

关于database - 使用加权 tsvector 进行 PostgreSQL 全文搜索的最佳索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60198680/

相关文章:

mysql - 如何有效地存储这种语言设置数据?

PostgreSQL:VACUUM FULL 还是 CLUSTER?

hadoop - Hadoop大数据文件文本搜索

java - GWT 中的 hibernate 错误

sql - 删除索引并重新创建索引后是否需要收集统计信息?

python - 使用 numpy 查找每列的最大值及其索引(+ 当最大值在同一列中重复时)

arrays - Presto SQL - 如何获得数组的所有可能组合?

php - 有没有办法使用更少的 "mysql_num_rows"函数并达到相同的结果?

python - 如何在 html 表中编辑从数据库中获取的数据? flask ,Jinja2

postgresql - Spark Dataframe 到 Postgres 使用复制命令 -pyspark