【发布时间】:2021-10-13 03:12:08
【问题描述】:
我有以下查询来获取门票列表。
EXPLAIN select * from ticket_type
where ticket_type.event_id='89898'
and ticket_type.active=true
and (ticket_type.is_unlimited = true OR ticket_type.number_of_sold_tickets < ticket_type.number_of_tickets)
order by ticket_type.ticket_type_order
我在下面创建了索引但没有工作。
- 索引 (ticket_type_order,event_id,is_unlimited,active)
- 索引 (ticket_type_order,event_id,active,number_of_sold_tickets,number_of_tickets)。
【问题讨论】:
-
如果有的话,
ticket_type_order需要排在最后,以便 Postgres 可以遍历where条件上的索引,然后以正确的顺序获取行。number_of_sold_tickets < number_of_tickets不过会很困难,我怀疑那是可索引的
标签: postgresql indexing