Skip to content

Addressed performance issue on Bulk Copy API with batch insert - #2735

Merged
Mahendra Chavan (machavan) merged 5 commits into
mainfrom
users/muskgupta/bulkcopyapi_perf
Aug 14, 2025
Merged

Mahendra Chavan (machavan) merged 5 commits into
mainfrom
users/muskgupta/bulkcopyapi_perf

Conversation

@muskan124947

@muskan124947 Muskan Gupta (muskan124947) commented Aug 11, 2025 •

Copy link
Copy Markdown
Contributor

Description

A GitHub issue was raised highlighting a performance degradation in the Bulk Copy API when using batch inserts
Pre-release 13.1 is slower #2732

The original issue reported was Bulk copy for batch insert destroys data without error #2669
This occurred when inserting string data using the following settings:

- useBulkCopyForBatchInsert=true
- sendStringParametersAsUnicode=false

Under these conditions, data was inserted in byte array format rather than as readable strings.

Expected behavior
Select StateCode from states -> "OH"

Actual behavior
Select StateCode from states; -> "[B@4b01d9e4"

On top of this a new issue was reported Accented characters saved incorrectly in database when using useBulkCopyForBatchInsert=true and sendStringParametersAsUnicode=false #2721.
When inserting data using useBulkCopyForBatchInsert=true and sendStringParametersAsUnicode=false, names with accented characters were saved incorrectly in the database.

Root Cause

When inserting string data using batch insert for bulk copy with below combinations:

- useBulkCopyForBatchInsert=true
- sendStringParametersAsUnicode=false

Fix#2704 and Fix#2727 introduced a performance slowdown because of unnecessary conversion from byte array back to string during the bulk copy batch insert operation.

Fix

Modified the logic to avoid sending data as a byte array in the first place when useBulkCopyForBatchInsert=true. As data inserted to destination table is being taken from dtv.value which is byte array.
Post this fix performance has improved significantly.

Testing

  • Added test cases for all combinations of useBulkCopyForBatchInsert and sendStringParametersAsUnicode to validate data insertion (including Unicode and accented characters) without performance degradation.
  • Added a test case to simulate an unsupported INSERT-SELECT batch insert with useBulkCopyForBatchInsert=true and sendStringParametersAsUnicode=false, verifying that the fallback to normal execution occurs and the data is inserted correctly.
@codecov

codecov Bot commented Aug 11, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 51.70%. Comparing base (44d6010) to head (3fc45fc).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...rc/main/java/com/microsoft/sqlserver/jdbc/dtv.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2735      +/-   ##
============================================
+ Coverage     51.60%   51.70%   +0.09%     
- Complexity     4083     4106      +23     
============================================
  Files           149      149              
  Lines         34242    34239       -3     
  Branches       5719     5718       -1     
============================================
+ Hits          17672    17702      +30     
+ Misses        14104    14092      -12     
+ Partials       2466     2445      -21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants