gpt4 book ai didi

postgresql - 如何使用索引有效地找到空字段

转载 作者:行者123 更新时间:2023-11-29 13:18:30 25 4
gpt4 key购买 nike

我有一个查询,我试图从数百万条记录中找到一个空字段。只有一两个。

查询看起来像这样:

SELECT  * 
FROM “table”
WHERE “id” = $1
AND “end_time” IS NULL
ORDER BY “start_time” DESC LIMIT 1

我怎样才能让这个查询更高效,例如使用数据库中的索引。

最佳答案

尝试部分索引,像这样:

create index iname on "table" (id, start_time) where end_time is null;

关于postgresql - 如何使用索引有效地找到空字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45694529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com