Packet Database Update

What is the difference between these three solutions in terms of definition and performance of a batch update:

1)

Insert into table1 values ('A','A1'),('B','B1'),('C','C1'), ....

2)

Transaction.begin();

insert into table1 values('A','A1'); insert into table1
values('B','B1'); insert into table1 values('C','C1'); ... ... ...

Transaction.commit();

3)

PreparedStatement.addBatch(...);
PreparedStatement.executeBatch();

OR Install Batch=truein MyBatis configuration

+3
source share
1 answer

Assuming your database accepts syntax 1 as valid (e.g. MS-SQL 2008) and assumes that # 1 and # 2 are executed as in the original SQL version of the database ...

Then to complete part of your question ...

# 1 is the fastest because it will be parsed / prepared once and executed once as one atomic transaction.

# 2 will be next in performance. There are two operators (txn begin) and (txn end), as well as one operator for each insert.

# 2a ( ) . , , , "" SQL () . , . .

  Transaction.begin();  
  Stmt.Prepare("insert into table1 values(:Var1, :Var2)");  
  Stmt.Execute('A','A1');  
  Stmt.Execute('B','B1');  
  Stmt.Execute('C','C1');  
  Transaction.commit();  

# 3 ORM, , # 1 # 2a. , # 2 , . # 3 , # 1, # 2a, "IF" . ORM , .

...

....
 #A .
 #B .

# 2a, , # 1, , , / .. , # 1 SQL .  # 3 ORM, , .

, . - , , .

+1

All Articles