postgresql - BIGINT 列的 PostgreSQL GIN 索引
问题描述
我有tbl
带有列的表 - 数据 TEXT - fk_id BIGINT - 文本 TEXT
有超过 1 亿条记录,fk_id 有大约 1K 不同的值。我需要像这样运行查询
SELECT * FROM tbl WHERE fk_id=12345 AND text LIKE '%abcdef%
我尝试使用扩展GIN
索引btree_gin
和gin_trgm_ops
CREATE EXTENSION pg_trgm;
CREATE EXTENSION btree_gin;
CREATE INDEX on tbl USING GIN (fk_id, text gin_trgm_ops)
但查询分析器忽略fk_id
查询列
explain select * from tbl where fk_id = 12345 and text like '%abcdef%' limit 10;
Limit (cost=28.00..32.02 rows=1 width=90)
-> Bitmap Heap Scan on tbl (cost=28.00..32.02 rows=1 width=90)
Recheck Cond: (text ~~ '%abcdef%'::text)
Filter: (fk_id = 12345)
-> Bitmap Index Scan on table_fk_id_text_idx (cost=0.00..28.00 rows=1 width=0)
Index Cond: (text ~~ '%abcdef%'::text)
但是,如果我对列 fk_id 使用 INT 类型而不是 BIGINT,则索引将按预期工作
tbl
- 数据 TEXT - fk_id INT - 文本 TEXT
explain select * from tbl where fk_id = 12345 and text like '%abcdef%' limit 10;
Limit (cost=36.00..40.02 rows=1 width=90)
-> Bitmap Heap Scan on tbl (cost=36.00..40.02 rows=1 width=90)
Recheck Cond: ((fk_id = 12345) AND (text ~~ '%abcdef%'::text))
-> Bitmap Index Scan on tbl_fk_id_text_idx (cost=0.00..36.00 rows=1 width=0)
Index Cond: ((fk_id = 12345) AND (text ~~ '%abcdef%'::text))
所以,我可以将 GIN 与 INT 一起使用,但不能将 GIN 与 BIGINT 一起使用。为什么我不能将 BIGINT 列用于 GIN 索引? 文档说,btree_gin 与 int4(INT) 和 int8(BIGINT) 一起使用。也许还有另一种方法可以解决这个问题?
解决方案
推荐阅读
- memory - CubeMX stm32 FreeRTOS + USB 主机 MSC 用于 USB 闪存
- c# - C# DLLImport“内联”
- java - 如何在 IST 从星期六早上 6 点到星期一下午 6 点每 5 分钟运行一次 cron 作业?
- http - 使用 GoDaddy UCC 证书将 https www 重定向到非 www 问题
- spring-mvc - Spring MVC WebSocket:意外的响应代码:302
- react-native - 如何在 React Native 中隐藏 Picker 的第一个 Picker 项?
- php - 如何获取动态更新的网站的表格行(简单的 html DOM 解析器)?
- java - 将 5,00,000 条记录插入我的 SQL 服务器需要多长时间?
- php - 美化 Google App Engine PHP 静态网站上的 URL
- instagram - Instagram 提要令牌不断过期