gpt4 book ai didi

sql - 为什么创建表比更新字段快?

转载 作者:行者123 更新时间:2023-11-29 13:19:01 26 4
gpt4 key购买 nike

如果我创建一个包含一周数据的新表快 30 秒:

-- Executing query:
CREATE TABLE avl_tracker.avl2 as
SELECT * -- here can change the has_link to false
FROM avl_tracker.avl
Query returned successfully: 6998969 rows affected, 52587 ms execution time.

比只更新一天,即使 event_time 有一个索引:

-- Executing query:
UPDATE avl_tracker.avl
SET has_link = false
WHERE event_time >= '2017-06-16 00:00:00'::timestamp without time zone
AND event_time < '2017-06-17 00:00:00'::timestamp without time zone
Query returned successfully: 1646479 rows affected, 84109 ms execution time.

并且在新表上重新创建索引不需要 30 秒

有什么我应该检查的吗?我做错了什么?

最佳答案

可以预料,在没有索引的表上插入数据然后创建索引比在有索引的表上更新相同数量的数据更快。

索引维护很昂贵。

关于sql - 为什么创建表比更新字段快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44972167/

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