2015-12-11 16 views
18

Tôi muốn chèn một số lượng lớn các thực thể vào bảng chéo. Để làm điều đó, tôi muốn kích hoạt tùy chọn chèn hàng loạt của hibernate, để mỗi chèn sẽ thêm không 1, nhưng 20 hoặc 50 hàng tại một thời điểm.Làm thế nào để cho phép chèn hàng loạt với Hibernate và Spring Boot

Tôi đang cố gắng tạo lại kết quả từ hibernate's tutorial. Tôi đã tạo một chức năng thử nghiệm sẽ cố gắng chèn 30 khách hàng, giống như trong ví dụ:

//Batch inserting test entities 
//This code is inside transaction already, so I'm not creating a new one 
entityManager.flush(); 
for (int i = 0; i < 30; ++i) { 
    Customer customer = new Customer("Customer" + i, (i + 5) * 1000, "Position " + i); 
    entityManager.persist(customer); 
    if (i % 20 == 0) { 
     entityManager.flush(); 
     entityManager.clear(); 
    } 
} 
entityManager.flush(); 
entityManager.clear(); 

Lớp khách hàng không có id được tạo.

@Entity 
public class Customer { 

    @Id 
    private String id; 
    @Column 
    private String name; 
    @Column 
    private long salary; 
    @Column 
    private String position; 

    public Customer() { 

    } 

    public Customer(String name, long salary, String position) { 
     this.id = UUID.randomUUID().toString(); 
     this.name = name; 
     this.salary = salary; 
     this.position = position; 
    } 

} 

Điều tôi mong đợi là 2 câu lệnh chèn, một cho 20 bản ghi và một cho 10 bản ghi. Tuy nhiên, khi tôi mở nhật ký postgres, tôi thấy 30 câu lệnh chèn, mỗi câu lệnh chỉ chèn 1 hàng. Tôi đã kiểm tra lại rằng có thể chèn nhiều hàng bằng cách sử dụng postgres.

Tôi tin rằng sự cố là do tham số hibernate.jdbc.batch_size 20, mà tôi phải chuyển sang chế độ ngủ đông. Tuy nhiên, vì tôi đang sử dụng khởi động mùa xuân, tệp cấu hình duy nhất tôi có là application.properties. Vì vậy, tôi đã cố gắng chèn vào đó:

hibernate.jdbc.batch_size=20 
hibernate.order_inserts=true 
hibernate.order_updates=true 
hibernate.jdbc.batch_versioned_data=true 
spring.jpa.hibernate.jdbc.batch_size=20 
spring.jpa.hibernate.order_inserts=true 
spring.jpa.hibernate.order_updates=true 
spring.jpa.hibernate.jdbc.batch_versioned_data=true 
spring.jpa.properties.hibernate.jdbc.batch_size=20 
spring.jpa.properties.hibernate.order_inserts=true 
spring.jpa.properties.hibernate.order_updates=true 
spring.jpa.properties.hibernate.jdbc.batch_versioned_data=true 

Theo answer này, điều này sẽ là đủ, nhưng Tôi cũng đã cố gắng sao chép các thông số cho hibernate.properties tập tin bên trong jar tôi và cung cấp các tham số thông qua dòng lệnh : -Dhibernate.jdbc.batch_size=20 như đã nêu trong documentation này.

Không điều nào trong số này hữu ích.
Tôi cũng không thể tìm cách đọc thuộc tính kích thước lô trong mã của mình. Dường như hầu hết các đối tượng được đề cập trong tài liệu hibernate không tồn tại trong ứng dụng khởi động mùa xuân.
Làm cách nào để kích hoạt chèn hàng loạt của hibernate trong ứng dụng khởi động mùa xuân?

tôi đã tạo ra một ví dụ làm việc tối thiểu mà tái tạo vấn đề: https://github.com/Alexey-/spring-boot-batch


Sau khi nhận được câu trả lời từ Vlad Mihalcea tôi nhận ra rằng có, trên thực tế báo cáo hàng loạt đang làm việc, ít nhất là trên mức hibernate và jdbc.

Tuy nhiên, nhật ký postgres tự thể hiện hành vi rất thú vị: chúng hầu như giống hệt nhau đối với trường hợp chèn hàng loạt và chèn thông thường.

gì ban đầu tôi đã mong đợi để xem là Hibernate sẽ sử dụng báo cáo như thế này:

test=# INSERT INTO customer (name, position, salary, id) values ('CustomerX', 'PositionX', '1000', 'idX'), ('CUSTOMERY', 'POSITIONY', '1000', 'idY'); 

nào sẽ tạo ra log hồ sơ tương tự như sau:

2015-12-15 11:43:33.238 MSK LOG: statement: INSERT INTO customer (name, position, salary, id) values ('CustomerX', 'PositionX', '1000', 'idX'), ('CUSTOMERY', 'POSITIONY', '1000', 'idY'); 

Tuy nhiên, đó không phải là trường hợp .
Khi chèn hàng loạt được kích hoạt (p6spy cho thấy báo cáo được, trên thực tế, batched), postgres sẽ sản xuất bản ghi tương tự như sau:

2015-12-15 12:07:00.638 MSK LOG: execute <unnamed>: BEGIN 
2015-12-15 12:07:00.638 MSK LOG: duration: 0.000 ms 
2015-12-15 12:07:00.638 MSK LOG: duration: 0.000 ms parse <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.638 MSK LOG: duration: 0.000 ms bind <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.638 MSK DETAIL: parameters: $1 = 'Customer0', $2 = 'Position 0', $3 = '0', $4 = '9c6a86fb-c991-4e98-aa65-fa736ef67dd7' 
2015-12-15 12:07:00.638 MSK LOG: execute <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.638 MSK DETAIL: parameters: $1 = 'Customer0', $2 = 'Position 0', $3 = '0', $4 = '9c6a86fb-c991-4e98-aa65-fa736ef67dd7' 
2015-12-15 12:07:00.639 MSK LOG: duration: 1.000 ms 
2015-12-15 12:07:00.648 MSK LOG: duration: 0.000 ms parse S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.648 MSK LOG: duration: 0.000 ms bind S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.648 MSK DETAIL: parameters: $1 = 'Customer1', $2 = 'Position 1', $3 = '10', $4 = 'c8b2669c-044a-4a4d-acbd-31c3bcd9a783' 
2015-12-15 12:07:00.648 MSK LOG: execute S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.648 MSK DETAIL: parameters: $1 = 'Customer1', $2 = 'Position 1', $3 = '10', $4 = 'c8b2669c-044a-4a4d-acbd-31c3bcd9a783' 
2015-12-15 12:07:00.648 MSK LOG: duration: 0.000 ms 
2015-12-15 12:07:00.648 MSK LOG: duration: 0.000 ms bind S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.648 MSK DETAIL: parameters: $1 = 'Customer2', $2 = 'Position 2', $3 = '20', $4 = '1c694f41-2ce7-4ee2-a0c0-f359690506f0' 
2015-12-15 12:07:00.649 MSK LOG: execute S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.649 MSK DETAIL: parameters: $1 = 'Customer2', $2 = 'Position 2', $3 = '20', $4 = '1c694f41-2ce7-4ee2-a0c0-f359690506f0' 
2015-12-15 12:07:00.649 MSK LOG: duration: 0.000 ms 
2015-12-15 12:07:00.649 MSK LOG: duration: 0.000 ms bind S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.649 MSK DETAIL: parameters: $1 = 'Customer3', $2 = 'Position 3', $3 = '30', $4 = '1815947d-2604-48d4-a6be-43f6905130cf' 
2015-12-15 12:07:00.649 MSK LOG: execute S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.649 MSK DETAIL: parameters: $1 = 'Customer3', $2 = 'Position 3', $3 = '30', $4 = '1815947d-2604-48d4-a6be-43f6905130cf' 
2015-12-15 12:07:00.649 MSK LOG: duration: 0.000 ms 
2015-12-15 12:07:00.649 MSK LOG: duration: 0.000 ms bind S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.649 MSK DETAIL: parameters: $1 = 'Customer4', $2 = 'Position 4', $3 = '40', $4 = 'cc521007-820f-4d58-8e1a-16a166aa91cf' 
2015-12-15 12:07:00.649 MSK LOG: execute S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:07:00.649 MSK DETAIL: parameters: $1 = 'Customer4', $2 = 'Position 4', $3 = '40', $4 = 'cc521007-820f-4d58-8e1a-16a166aa91cf' 
2015-12-15 12:07:00.649 MSK LOG: duration: 0.000 ms 
... the rest of the logs is identical and do not provide any valuable information... 

Và khi báo cáo hàng loạt bị vô hiệu hóa (p6spy cho thấy rằng không có trạm trộn được thực hiện) , nhật ký sẽ trông giống như sau:

2015-12-15 12:09:00.246 MSK LOG: execute <unnamed>: BEGIN 
2015-12-15 12:09:00.246 MSK LOG: duration: 0.000 ms 
2015-12-15 12:09:00.246 MSK LOG: duration: 0.000 ms parse <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.246 MSK LOG: duration: 0.000 ms bind <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.246 MSK DETAIL: parameters: $1 = 'Customer0', $2 = 'Position 0', $3 = '0', $4 = '9e085ad0-437f-4d7d-afaa-e342e031cbee' 
2015-12-15 12:09:00.246 MSK LOG: execute <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.246 MSK DETAIL: parameters: $1 = 'Customer0', $2 = 'Position 0', $3 = '0', $4 = '9e085ad0-437f-4d7d-afaa-e342e031cbee' 
2015-12-15 12:09:00.246 MSK LOG: duration: 0.000 ms 
2015-12-15 12:09:00.248 MSK LOG: duration: 0.000 ms parse <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.248 MSK LOG: duration: 0.000 ms bind <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.248 MSK DETAIL: parameters: $1 = 'Customer1', $2 = 'Position 1', $3 = '10', $4 = 'f29cfa40-7d24-49a6-ae5d-2a2021932d80' 
2015-12-15 12:09:00.248 MSK LOG: execute <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.248 MSK DETAIL: parameters: $1 = 'Customer1', $2 = 'Position 1', $3 = '10', $4 = 'f29cfa40-7d24-49a6-ae5d-2a2021932d80' 
2015-12-15 12:09:00.249 MSK LOG: duration: 1.000 ms 
2015-12-15 12:09:00.250 MSK LOG: duration: 0.000 ms parse <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.250 MSK LOG: duration: 0.000 ms bind <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.250 MSK DETAIL: parameters: $1 = 'Customer2', $2 = 'Position 2', $3 = '20', $4 = '067dd6d4-5060-467f-b533-75994ecbaedc' 
2015-12-15 12:09:00.250 MSK LOG: execute <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.250 MSK DETAIL: parameters: $1 = 'Customer2', $2 = 'Position 2', $3 = '20', $4 = '067dd6d4-5060-467f-b533-75994ecbaedc' 
2015-12-15 12:09:00.250 MSK LOG: duration: 0.000 ms 
2015-12-15 12:09:00.250 MSK LOG: duration: 0.000 ms parse <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.250 MSK LOG: duration: 0.000 ms bind <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.251 MSK DETAIL: parameters: $1 = 'Customer3', $2 = 'Position 3', $3 = '30', $4 = '7df32327-f2f5-4011-848d-55aafb3f09fa' 
2015-12-15 12:09:00.251 MSK LOG: execute <unnamed>: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.251 MSK DETAIL: parameters: $1 = 'Customer3', $2 = 'Position 3', $3 = '30', $4 = '7df32327-f2f5-4011-848d-55aafb3f09fa' 
2015-12-15 12:09:00.251 MSK LOG: duration: 0.000 ms 
2015-12-15 12:09:00.251 MSK LOG: duration: 0.000 ms parse S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.251 MSK LOG: duration: 0.000 ms bind S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.251 MSK DETAIL: parameters: $1 = 'Customer4', $2 = 'Position 4', $3 = '40', $4 = '1e55ab6a-8780-4c8f-8af2-2886d954f819' 
2015-12-15 12:09:00.251 MSK LOG: execute S_1: insert into customer (name, position, salary, id) values ($1, $2, $3, $4) 
2015-12-15 12:09:00.251 MSK DETAIL: parameters: $1 = 'Customer4', $2 = 'Position 4', $3 = '40', $4 = '1e55ab6a-8780-4c8f-8af2-2886d954f819' 
2015-12-15 12:09:00.251 MSK LOG: duration: 0.000 ms 
... the rest of the logs is identical and do not provide any valuable information... 

Vì vậy, sự khác biệt duy nhất giữa hai lô là khi lô bị vô hiệu, postgres sẽ mất nhiều thời gian hơn để nhận ra rằng nên sử dụng lại câu lệnh đã chuẩn bị.

Vì vậy, tôi quyết định chạy thử nghiệm hiệu suất để xác nhận điều này.
Tôi đã thử chèn 30.000 bản ghi vào cơ sở dữ liệu trống.
Với chức năng xử lý hàng loạt bị vô hiệu hóa, phải mất 334ms.
Với chức năng nhóm được kích hoạt, nó mất 4650ms!

Vì vậy, sau đó tôi đã xóa tất cả các cuộc gọi đến entityManager.flush (chỉ để lại entityManager.clear) và thời gian giảm xuống 320ms. Tôi không biết tại sao hướng dẫn của hibernate khuyên dùng flush. Tôi đoán đó chỉ là một sai lầm.

Vì vậy, tôi đoán điểm mấu chốt là: việc xử lý theo lô đang hoạt động, nhưng nó không cung cấp bất kỳ lợi ích thực sự nào (ít nhất là cho bưu phí). Hơn nữa, sử dụng nó không đúng (như trong hướng dẫn) có thể dẫn đến một kết quả khủng khiếp, khủng khiếp. Sử dụng rủi ro của riêng bạn và luôn đo lường sự tăng hiệu suất thực tế.

+2

Bạn đã xác nhận rằng trình điều khiển JDBC của bạn hỗ trợ các hoạt động DDL hàng loạt?Trong khi cơ sở dữ liệu có thể hỗ trợ nó, nếu phiên bản của trình điều khiển của bạn không, nó sẽ không có bất kỳ ảnh hưởng nào. – Naros

+0

Có, trình điều khiển jdbc hỗ trợ hàng loạt. – Alexey

+0

Thêm lớp 'Customer' của bạn. Bạn đang sử dụng Spring boot để 'spring.jpa.properties' của bạn là cái bạn nên sử dụng, những cái khác thì khá vô dụng. –

Trả lời

10

Không có gì sai với mã của bạn và mã hoạt động bình thường.

Tôi đã sửa lỗi và sau đó tôi đã cài đặt p6spy và nó hoạt động. Đây là cách bạn có thể tets nó quá:

  1. Trong build.gradle thêm sự phụ thuộc này:

    compile 'p6spy:p6spy:2.1.4' 
    
  2. Sửa đổi các thuộc tính kết nối như thế này:

    database.driver=com.p6spy.engine.spy.P6SpyDriver 
    database.url=jdbc:p6spy:postgresql://localhost:5432/ 
    
  3. Thêm spy.properties trong resources . Bạn có thể tải về nó from here.

Và sau đó bạn sẽ thấy những điều khoản đồng loạt:

2015-12-14 19:38:03.655 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114683655|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer0', 'Position 0', 5000, '9f92ac01-8156-41f1-9bdb-36ff622a99cc') 
2015-12-14 19:38:03.658 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114683658|2|statement|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer0', 'Position 0', 5000, '9f92ac01-8156-41f1-9bdb-36ff622a99cc') 
2015-12-14 19:38:04.212 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684212|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer1', 'Position 1', 6000, 'e3a1dc5a-2183-4fb0-aa9a-4fb8cace23a3') 
2015-12-14 19:38:04.213 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684213|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer2', 'Position 2', 7000, '8824f5be-afe5-4a6a-ab8a-8f266db5973f') 
2015-12-14 19:38:04.213 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684213|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer3', 'Position 3', 8000, '249304b3-19c5-4376-b5dc-2da685c1db64') 
2015-12-14 19:38:04.213 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684213|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer4', 'Position 4', 9000, '2bf15945-94c3-45f8-b0d1-e2fedbdcbaca') 
2015-12-14 19:38:04.214 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684214|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer5', 'Position 5', 10000, '85b2b999-5d84-4181-9c71-1a83b4d20b86') 
2015-12-14 19:38:04.214 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684214|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer6', 'Position 6', 11000, '8ed6289e-3d04-4ba5-9285-9bce202c8dae') 
2015-12-14 19:38:04.215 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684215|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer7', 'Position 7', 12000, '2fc489a8-c6c4-4984-808d-2da9a2e8ad4a') 
2015-12-14 19:38:04.215 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684215|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer8', 'Position 8', 13000, '897cd341-b65b-4521-87e6-f4fb78b09bfd') 
2015-12-14 19:38:04.215 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684215|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer9', 'Position 9', 14000, 'fa59d5a7-2570-43f9-ba46-595b8fcefa35') 
2015-12-14 19:38:04.216 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684216|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer10', 'Position 10', 15000, '0b5b38d1-d644-4ea0-a3f0-9aa025463b8a') 
2015-12-14 19:38:04.216 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684216|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer11', 'Position 11', 16000, 'afbb349f-cf28-4cfb-b5b8-73b4df6fa4b1') 
2015-12-14 19:38:04.216 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684216|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer12', 'Position 12', 17000, 'd6719dc4-1dfd-433f-a8ae-4c931f461e78') 
2015-12-14 19:38:04.216 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684216|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer13', 'Position 13', 18000, 'ca277f3c-d51e-493d-a4f7-a945879bd7d0') 
2015-12-14 19:38:04.217 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684217|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer14', 'Position 14', 19000, '07014145-332b-4b4c-b320-9412443c45b6') 
2015-12-14 19:38:04.217 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684217|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer15', 'Position 15', 20000, '8ffde083-420f-418d-b624-b059b9e28f3b') 
2015-12-14 19:38:04.217 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684217|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer16', 'Position 16', 21000, '6ac39900-69db-408a-bda1-4d2706da49ba') 
2015-12-14 19:38:04.217 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684217|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer17', 'Position 17', 22000, '45f6db1b-18cd-4986-8f46-ce8f02d9588d') 
2015-12-14 19:38:04.217 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684217|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer18', 'Position 18', 23000, 'b4312298-a818-4b7a-9cff-7923328de4dc') 
2015-12-14 19:38:04.218 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684218|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer19', 'Position 19', 24000, 'efe7e3d2-da11-40ce-9fee-6f77726499db') 
2015-12-14 19:38:04.218 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684218|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer20', 'Position 20', 25000, 'd51484c3-36e2-4737-b5c9-135709ad1d30') 
2015-12-14 19:38:04.808 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684808|2|statement|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer20', 'Position 20', 25000, 'd51484c3-36e2-4737-b5c9-135709ad1d30') 
2015-12-14 19:38:04.811 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684811|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer21', 'Position 21', 26000, '8c7e0e43-f89f-4000-8367-3406974102f4') 
2015-12-14 19:38:04.811 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684811|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer22', 'Position 22', 27000, 'ab757793-1c45-4861-aff8-aa5cea3c8bd5') 
2015-12-14 19:38:04.812 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684812|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer23', 'Position 23', 28000, 'edf18735-cc27-437b-9a28-156f57b51343') 
2015-12-14 19:38:04.812 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684812|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer24', 'Position 24', 29000, 'c882f053-2e9a-405f-bb94-3ba83303aefe') 
2015-12-14 19:38:04.812 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684812|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer25', 'Position 25', 30000, 'd6af1feb-5842-4b40-816d-8e2aaa2ce9b3') 
2015-12-14 19:38:04.812 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684812|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer26', 'Position 26', 31000, '48f6a4cb-5671-4b73-bb51-3e37964fa136') 
2015-12-14 19:38:04.813 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684812|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer27', 'Position 27', 32000, '6ac59ed6-2a0f-4dbb-a6d7-7231a9c9d2cc') 
2015-12-14 19:38:04.813 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684813|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer28', 'Position 28', 33000, '57565a6a-4e44-4fe0-86bd-837a9687487d') 
2015-12-14 19:38:04.813 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684813|0|batch|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer29', 'Position 29', 34000, 'f3c2dbdd-5d54-4bf3-86d2-327c60ee5cc0') 
2015-12-14 19:38:04.814 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684814|1|statement|connection 7|insert into customer (name, position, salary, id) values (?, ?, ?, ?)|insert into customer (name, position, salary, id) values ('Customer29', 'Position 29', 34000, 'f3c2dbdd-5d54-4bf3-86d2-327c60ee5cc0') 
2015-12-14 19:38:04.817 INFO 14116 --- [io-18080-exec-3] p6spy : 1450114684817|2|commit|connection 7|| 

Cột thứ ba là batch chỉ ra rằng các tuyên bố được thực hiện trong một lô JDBC.

Cột ngay trước cột đề cập đến batch cho biết số lượng mili giây cần thiết để thực hiện tuyên bố. Những cái có 0 là khi câu lệnh được thêm vào lô.

Những cái có chứa statement trong cột thứ 3 (do đó có 1 hoặc 2 trong cột thứ 2) là khi lô được thực thi, tương ứng với lần lặp thứ 20 và thứ 30.

+0

Dự án tuyệt vời bạn có ở đó bằng cách này! – Jagger

+0

Cảm ơn bạn, có vẻ như mã thực sự hoạt động mọi lúc. Có vẻ như đó là postgres đã tối ưu hóa tối ưu hóa hàng loạt, do đó, để nói. Tôi đã cập nhật câu hỏi của mình với chi tiết. – Alexey

+0

Thông thường, bạn không nên viết một mục 30k trong một giao dịch đơn lẻ và không phải là một ý tưởng tồi để chia tải trên nhiều giao dịch nhỏ hơn. Ngay cả khi bạn tăng các cửa sổ tuôn ra, việc trộn vẫn sẽ xảy ra. Hãy chắc chắn rằng bạn sử dụng kết nối tổng hợp vì điều đó thực sự có thể gây ra rất nhiều chi phí. –

Các vấn đề liên quan