postgresql - postgres:全文搜索:查找重复文本行的最快方法?
问题描述
:-)
在表格中查找重复文本的最快方法是什么,即表格中的行在一列中的文本在整个表格中至少出现两次?该表包含超过 1.6 亿行。
我有一个包含以下列的表:id
、maintext
和maintext_token
,后者是用to_tsvector(maintext);
. 此外,我在 上创建了一个 GIN 索引maintext_token
,即create index idx_maintext_tokens on tablename using gin(maintext_token);
目前,我正在使用以下内容,但这需要相当长的时间:我有一个包含以下列的表:id
、maintext
和maintext_token
,后者是用to_tsvector(maintext);
. 此外,我在 上创建了一个 GIN 索引maintext_token
,即create index idx_maintext_tokens on tablename using gin(maintext_token);
select maintext, count(maintext)
from ccnc
group by maintext
having count(maintext)>1
order by maintext;
我也尝试执行相同的操作,但maintext
我没有使用该maintext_token
列进行比较:
select maintext_token, count(maintext_token)
from ccnc
group by maintext_token
having count(maintext_token)>1
order by maintext_token;
这两个查询似乎都运行了很长时间,尽管我预计至少第二个查询会快得多,因为 postgres 可以使用索引进行比较。
提前感谢您的任何见解!干杯:)
解决方案
你说你想测试是否相等,所以你可能想对文本进行散列,然后搜索散列。您可以使用散列索引来执行此操作,也可以索引文本的散列。我最近在一个相关问题上得到了一些帮助,您可以在此处找到详细信息和比较:
推荐阅读
- oracle - Oracle SQL 排除约束
- java - 如何将意图传递给广播接收器并启动服务Android
- reactjs - 加载时如何为 Nextjs/Image 添加淡入动画?
- javascript - 尝试在我的用户脚本中使用 'const' 和 Opera 时出现错误
- node.js - 节点 Sass 设置
- c - 如何将字符串输入一分为二,并使用第二个打开/创建文件,读取和写入
- c - scanf 没有读取整个字符串
- python - 在重复行之前包含额外行
- oracle - 如何编写适用于具有时差的 DATE 字段的 SELECT DISTINCT
- linux-from-scratch - 鼠标和键盘在 XWindows 中不起作用