简体   繁体   English

SQL性能:UPDATE是否比INSERT更快

[英]SQL performance: Is UPDATE faster than INSERT

I must do 10,000 INSERTs, then 10,000 UPDATEs on the inserted rows. 我必须执行10,000次INSERT,然后对插入的行执行10,000次UPDATE。 I am wondering whether UPDATE in SQL is faster than INSERT or not. 我想知道SQL中的UPDATE是否比INSERT快。 Normal simple table with 30 to 50 columns. 普通的简单表格有30到50列。 I am using JDBC. 我正在使用JDBC。

Forget IDBC - the difference is neglegible. 忘记IDBC-区别可忽略不计。

Theoretically updates CAN be faster, especially if the columns updated are not indexed. 从理论上讲,更新可以更快,特别是如果未索引更新的列。 Simple reason is that an insert requires the reallocation of space and possibly split / rebalance of indices, while an update that does not contain an index at most requires a reallocation of space (varchar), possibly not even that (fields with fixed length). 原因很简单,一个插入操作需要重新分配空间,并可能需要拆分/重新分配索引,而最多不包含索引的更新需要重新分配空间(varchar),甚至可能不需要重新分配空间(具有固定长度的字段)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM