为什么批量插入/更新更快?批量更新如何工作?

编程入门 行业动态 更新时间:2024-10-14 06:17:50
本文介绍了为什么批量插入/更新更快?批量更新如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为什么批量插入速度更快?是否因为插入单行的连接和设置开销对于一组行是相同的?还有哪些因素可以加快批量插入的速度?

Why are batch inserts faster? Is it because the connection and setup overhead for inserting a single row is the same for a set of rows? What other factors make batch inserts faster?

批量更新如何工作?假设表没有唯一性约束,insert 语句实际上对批处理中的其他 insert 语句没有任何影响.但是,在批量更新期间,更新可能会改变表的状态,因此会影响批处理中其他更新查询的结果.

How do batch updates work? Assuming the table has no uniqueness constraints, insert statements don't really have any effect on other insert statements in the batch. However, during batch updates, an update can alter the state of the table and hence can affect the outcome of other update queries in the batch.

我知道批量插入查询的语法是在一个大查询中包含所有插入值.批量更新查询是什么样的?例如如果我有表单的单个更新查询:

I know that batch insert queries have a syntax where you have all the insert values in one big query. How do batch update queries look like? For e.g. if i have single update queries of the form:

update <table> set <column>=<expression> where <condition1> update <table> set <column>=<expression> where <condition2> update <table> set <column>=<expression> where <condition3> update <table> set <column>=<expression> where <condition4>

当它们成批使用时会发生什么.单个查询会是什么样子?

What happens when they are used in a batch. What will the single query look like ?

并且是批量插入 &更新部分 SQL 标准?

And are batch inserts & updates part of the SQL standard?

推荐答案

我正在寻找关于同一主题的答案,关于批量/批量"更新.人们通常通过将问题与具有多个值集(批量"部分)的插入子句进行比较来描述问题.

I was looking for an answer on the same subject, about "bulk/batch" update. People often describe the problem by comparing it with insert clause with multiple value sets (the "bulk" part).

INSERT INTO mytable (mykey, mytext, myint) VALUES (1, 'text1', 11), (2, 'text2', 22), ...

明确的答案仍然避开我,但我在这里找到了解决方案:www.postgresql/docs/9.1/static/sql-values.html

Clear answer was still avoiding me, but I found the solution here: www.postgresql/docs/9.1/static/sql-values.html

说清楚:

UPDATE mytable SET mytext = myvalues.mytext, myint = myvalues.myint FROM ( VALUES (1, 'textA', 99), (2, 'textB', 88), ... ) AS myvalues (mykey, mytext, myint) WHERE mytable.mykey = myvalues.mykey

它具有相同的特性,即批量",也就是在一个语句中包含大量数据.

It has the same property of being "bulk" aka containing alot of data with one statement.

更多推荐

为什么批量插入/更新更快?批量更新如何工作?

本文发布于:2023-10-27 10:35:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533115.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:批量   更快   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!