jooqbatch-updates

Why JOOQ executes batch insert like twice?


Here is my upsert method:

public void update(long objectId, Map<Long, String> props) {
    if (props != null && !props.isEmpty()) {
        var inserts = props.entrySet().stream()
                .map(p -> dsl.insertInto(OBJECT_PROPERTIES_VALUES)
                        .set(new ObjectPropertiesValuesRecord(objectId, p.getKey(), p.getValue()))
                        .onDuplicateKeyUpdate()
                        .set(OBJECT_PROPERTIES_VALUES.PROPERTY_VALUE, p.getValue()))
                .collect(Collectors.toList());
        dsl.batch(inserts).execute();
    }
}

Here is the console log, all rows appear when the last line of the method is executed:

Executing batch query    : insert into "warehouse"."object_properties_values" ("object_id", "property_id", "property_value") values (3, 9, '2008') on conflict ("object_id", "property_id") do update set "property_value" = '2008'
Executing batch query    : insert into "warehouse"."object_properties_values" ("object_id", "property_id", "property_value") values (3, 10, 'Зеленый в бурую крапинку') on conflict ("object_id", "property_id") do update set "property_value" = 'Зеленый в бурую крапинку'
Executing batch query    : insert into "warehouse"."object_properties_values" ("object_id", "property_id", "property_value") values (3, 2, '170') on conflict ("object_id", "property_id") do update set "property_value" = '170'
Executing batch query    : insert into "warehouse"."object_properties_values" ("object_id", "property_id", "property_value") values (3, 4, '400') on conflict ("object_id", "property_id") do update set "property_value" = '400'
Executing batch query    : insert into "warehouse"."object_properties_values" ("object_id", "property_id", "property_value") values (3, 9, '2008') on conflict ("object_id", "property_id") do update set "property_value" = '2008'
Executing batch query    : insert into "warehouse"."object_properties_values" ("object_id", "property_id", "property_value") values (3, 10, 'Зеленый в бурую крапинку') on conflict ("object_id", "property_id") do update set "property_value" = 'Зеленый в бурую крапинку'
Executing batch query    : insert into "warehouse"."object_properties_values" ("object_id", "property_id", "property_value") values (3, 2, '170') on conflict ("object_id", "property_id") do update set "property_value" = '170'
Executing batch query    : insert into "warehouse"."object_properties_values" ("object_id", "property_id", "property_value") values (3, 4, '400') on conflict ("object_id", "property_id") do update set "property_value" = '400'
Executing batch query    : insert into "warehouse"."object_properties_values" ("object_id", "property_id", "property_value") values (3, 5, '140') on conflict ("object_id", "property_id") do update set "property_value" = '140'
Batch size               : 5

Actually, 5 rows are being inserted, so the last log row is correct. But why 9 inserts are executed?
The target table was 100% empty, so no conflicts or something else.

enter image description here Actual data: enter image description here


Solution

  • There was a (cosmetic) logging bug in recent jOOQ versions. Only the logs are affected, you shouldn't actually have duplicate inserts being executed. The bug has been fixed as:

    The fix was implemented in versions:

    The problem should go away once you upgrade