postgresql文档指定一个 GiST 索引可以有多个列,但没有提供这可能是什么样子的示例。
我有一张表格,可以跟踪不同客户拥有的资产。
CREATE TABLE asset (
id serial PRIMARY KEY,
description text NOT NULL,
customer_id uuid NOT NULL
);
我正在编写一个查询,允许客户根据描述中的单词搜索资产。
SELECT *
FROM asset
WHERE to_tsvector('english', asset.description) @@ plainto_tsvector('english', ?)
AND asset.customer_id = ?;
如果这是一个非 tsvector 查询,我会建立一个简单的多列索引
CREATE INDEX idx_name ON asset(customer_id, description);
我只能在 tsvector 上创建索引:
CREATE INDEX idx_name ON asset USING gist(to_tsvector('english', asset.description));
但是,查询优化器不使用 gist 索引,因为它似乎想先进行customer_id
过滤。有没有办法可以将非 tsvector 字段包含customer_id
在 gist 索引中,或者我不走运?