gpt4 book ai didi

mysql - 按主键顺序插入行更快吗?

转载 作者:行者123 更新时间:2023-11-29 01:44:37 24 4
gpt4 key购买 nike

我有一张这样的 table :

create table stream_last
(
symbol_id integer,
high decimal(8,2),
low decimal(8,2),
last decimal(8,2),
volume integer,
last_updated datetime,
INDEX USING BTREE(symbol_id)
) ENGINE=MEMORY;

我需要每 5 秒执行大约 4,000 次插入(由 C 程序读取流并在 symbol_id 上聚合)。但是,我可以先对数据进行排序,然后按 symbol_id 升序插入。这会让这个批量插入更快吗?

第二个问题是,BTREE 是索引的最佳选择吗?从文档中,我可以使用 HASH 但不确定哪个最好...

最佳答案

不要认为你可能会从你提出的优化中获得任何显着差异,但这里列出了建议

http://dev.mysql.com/doc/refman/5.0/en/insert-speed.html

当然可以帮助您更好地了解您的需求。

这句话可能有道理

The size of the table slows down the insertion of indexes by log N, assuming B-tree indexes.

You can use the following methods to speed up inserts:

If you are inserting many rows from the same client at the same time, use INSERT statements with multiple VALUES lists to insert several rows at a time. This is considerably faster (many times faster in some cases) than using separate single-row INSERT statements. If you are adding data to a nonempty table, you can tune the bulk_insert_buffer_size variable to make data insertion even faster. See Section 5.1.3, “Server System Variables”.

关于mysql - 按主键顺序插入行更快吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10219980/

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