我想在 postgrest 中创建多列。我想过滤多列

问题描述 投票:0回答:1

如果客户在目前的查询结果中放置过滤器,则非常慢。 我是否需要在单个索引或单个列中的所有过滤器列上创建索引。最大的问题是排序。

以下是查询

select it.conversation_id, it.conversation_source, it.full_name,
    it.last_message_timestamp, it.conversation_read,
    it.id as ticket_id, it.owner_id, it.status, it.priority,
    it.tags, it.last_msg_content, it.last_msg_attachment,
    it.last_msg_actor, it.last_msg_delivered, it.last_msg_read,
    it.last_message_timestamp as message_created_at, it.subject,
    it.closed_at, it.last_message_received_at
from inbox_ticket it
where
    it.merchant_id = 115 and it.status <> 'assigned_to_bot' 
    and it.owner_id in (3486070,60,-1)  
    and it.last_message_timestamp >= '2023-07-01 00:00:00+05:30' 
    and it.last_message_timestamp <= '2023-07-31 00:00:00+05:30'
    and it.last_message_timestamp < '2023-07-31 18:40:00+05:30' 
order by it.last_message_timestamp desc, it.id desc 
limit 25

排序包括两列。我是否必须单独创建索引,例如 (last_message_timestamp desc, id desc) 上的索引。 或者所有过滤器 + (last_message_timestamp desc, id desc)

我没有尝试任何东西,因为数据很大。目前是640万

目前,如果我解释一下,我会得到以下结果。

限制(成本=4.18..4.19行=1宽度=218) ->排序(成本=4.18..4.19行=1宽度=218) 排序键:last_message_timestamp DESC、id DESC -> 在 inbox_ticket 上使用 inbox_ticket_merchant_id_67656847 进行索引扫描(成本=0.14..4.17 行=1 宽度=218) 索引条件:(merchant_id = 115) 过滤器: (((status)::text <> 'assigned_to_bot'::text) AND (last_message_timestamp >= '2023-07-01 00:00:00+05:30'::timestamp with time zone) AND (last_message_timestamp <= '2023-07-31 00:00:00+05:30'::timestamp with time zone) AND (last_message_timestamp < '2023-07-31 18:40:00+05:30'::timestamp with time zone) AND (owner_id = ANY ('{3486070,60,-1}'::integer[])))

postgresql indexing z-index multi-index postgresql-13
1个回答
0
投票

LAG(标量表达式 [,偏移量] [,默认值])[ 忽略 NULL |尊重空值] 结束([partition_by_clause]order_by_clause)

© www.soinside.com 2019 - 2024. All rights reserved.