[MDEV-30366] Permit bulk implementation to return ALL individual results Created: 2023-01-09 Updated: 2024-01-15 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Protocol |
| Fix Version/s: | 11.5 |
| Type: | New Feature | Priority: | Critical |
| Reporter: | Diego Dupin | Assignee: | Oleksandr Byelkin |
| Resolution: | Unresolved | Votes: | 3 |
| Labels: | None | ||
| Attachments: |
|
||||||||||||||||
| Issue Links: |
|
||||||||||||||||
| Description |
|
The bulk command COM_STMT_BULK_STMT actually returns one OK_Packet that contains the first insert ID and the total of affected rows. Using java there is 2 behaviors that are not compatible :
Explaination of those use cases : insert ids neededPrepared statement can be created with explicit indicator that auto increment ids are needed : https://docs.oracle.com/en/java/javase/18/docs/api/java.sql/java/sql/Connection.html#prepareStatement(java.lang.String,int) example :
Actual java connector implementation is to just loop with COM_STMT_EXECUTE, since driver is aware that generated id's are needed. Second case is more problematic. optimistic locking.In java, when using multiple client servers, a stragegy named "Optimistic locking" to have faster result is to cache some data client side. "Optimistic locking" doesn't shared cache information between client servers: This is more complex than that, but to simplify, all tables have an additional 'version' column that is incremented at any changes. All operations on data will check primary AND that version equality, then increment version. Table basket_item DDL :
When updating some Entity, update command will use primary key + version like, incrementing version :
Application check that affected rows is exactly 1 to ensure value has not changed by another client during the time this data has been in client cache. If Affected row is 0, then application knows changes has occurs, then will handle that. the problem is when using BULK, actual server implementation only returns the total number of changes, not unitary change. Java connector then returns an array of Statement.SUCCESS_NO_INFO, indicating that command has succedded,not knowing exact affected rows. This isn't compatible with Optimistic locking. SolutionThere is a flag STMT_BULK_FLAG_SEND_UNIT_RESULTS for bulk that has not been implemented. Link is a proposed implementation (based on 11.0). |
| Comments |
| Comment by Sergei Golubchik [ 2023-12-04 ] |
|
pushed into bb-11.4-MDEV-30366-bulk-results |