postgresql 我想在postgrest中创建多个列,有多个要筛选的列

9avjhtql  于 2023-08-04  发布在  PostgreSQL
关注(0)|答案(1)|浏览(133)

如果客户把过滤器在截至目前的查询结果是非常缓慢的。我是否需要在单个索引或单个列中的所有过滤器列上创建索引。最大的问题是分类。
下面是查询

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

字符串
排序包括两列。我必须单独创建索引,如index on(last_message_timestamp desc,id desc)。或者所有过滤器+(last_message_timestamp desc,id desc)
我什么都没做,因为数据太大了。目前为640万

ukdjmx9f

ukdjmx9f1#

LAG(scalar_expression [,offset ] [,default ])[ IGNORE NULL| RESPECT NULLS ] OVER([ partition_by_clause ] order_by_clause)

相关问题