如何在Postgres中制作多列JSON索引?
我有一个查询,可以通过普通文本列查询,而在JSON列中进行了值。我想知道如何为查询创建最佳索引?
这是查询:
explain select * from "tags" where "slug"->>'en' = 'slugName'
and "type" in ('someType1','someType1');
-------
Seq Scan on tags (cost=0.00..1.47 rows=1 width=888)
" Filter: (((type)::text = ANY ('{dsfdsf,fgsdf}'::text[])) AND ((slug ->> 'en'::text) = 'dsfdsf'::text))"
“ slug”列是类型JSON,“类型”列是类型Varchar(191)。我很熟悉我可以在JSON列中添加索引:
CREATE INDEX tag_slug_index ON tags USING btree ((slug ->> 'en'));
但是我想知道,如何在slug名称上与类型列相结合?
I have a query where I query by a normal text column and a value in a JSON column. What I'm wondering is how to create the best index for the query?
This is the query:
explain select * from "tags" where "slug"->>'en' = 'slugName'
and "type" in ('someType1','someType1');
-------
Seq Scan on tags (cost=0.00..1.47 rows=1 width=888)
" Filter: (((type)::text = ANY ('{dsfdsf,fgsdf}'::text[])) AND ((slug ->> 'en'::text) = 'dsfdsf'::text))"
The "slug" column is type JSON and the "type" column is type varchar(191). I'm familiar that I can add an index to the JSON column like:
CREATE INDEX tag_slug_index ON tags USING btree ((slug ->> 'en'));
But I'm wondering, how do I create a multi-column index on the slug name combined with the type column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有什么特别的,您只需通过逗号将它们分开来以正常方式进行:
表达式仍然需要额外的括号中,同样是索引中唯一的“列”。
There is nothing special about it, you just do it the normal way, by separating them with a comma:
The expression does still need to be in an extra set of parentheses, same is if it were the only 'column' in the index.