gpt4 book ai didi

sql - 优化 postgresql 更新

转载 作者:行者123 更新时间:2023-11-29 14:12:03 30 4
gpt4 key购买 nike

我在 postgresql 中有一个表包含超过 10 百万行,我想更新一个字段:

update annonce set confirmed = true;

但是查询需要很长时间才能执行,我该如何优化这个查询?

最佳答案

update annonce set confirmed = true
where not confirmed

部分索引可以帮助:

create index index_name on annonce (confirmed)
where not confirmed

与全索引相比,部分索引将大大减小索引大小并使所有更新、删除和插入操作更快。

关于sql - 优化 postgresql 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15621114/

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