apache / apache/shardingsphere

Why are methods not replayed on the PreparedStatement object in batch executor scenarios?

Open
#32,468 3 comments 0 reactions 0 assignees View on GitHub
in: JDBC
Dominant language
Java
Stars
20.8k
Forks
6.9k
Avg merge
11h 35m
Merged PRs (30d)
326

Description

## Bug Report
In ShardingSpherePreparedStatement,settings of Statements will be recorded first and will be replayed on actual JDBC PreparedStatement after it is acquired. For exeample, in cacheStatements(...) method, replay() method will be called for method replay. As a result, in PreparedStatement scenarios, when executing executeQuery()、executeUpdate()、execute() methods, replay action will take effect.

But in batch executor scenarios, methods on statement object are not replyed. Related code is at initBatchPreparedStatementExecutor(...) method.
[Why+are+methods+not+replayed+on+the+PreparedStatement+object+in+batch+executor+scenarios_.pdf](https://github.com/user-attachments/files/16576836/Why%2Bare%2Bmethods%2Bnot%2Breplayed%2Bon%2Bthe%2BPreparedStatement%2Bobject%2Bin%2Bbatch%2Bexecutor%2Bscenarios_.pdf)

If there is no ShardingSphere-JDBC, such as MyBatis only, when executing executeBatch() method, settings of PreparedStatement object will take effect, involving setMaxFieldSize、setQueryTimeout, etc.

I would like to confirm whether this is by design or a flaw.

### Which version of ShardingSphere did you use?
Shardingsphere 5.1.0 and 5.5.0

### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-JDBC

### Expected behavior
Settings of PreparedStatement object is valid in batch executor scenarios.

### Actual behavior
Settings of PreparedStatement object is not valid in batch executor scenarios.

### Reason analyze (If you can)
As above.

Contributor guide

Open the contributing guide

Research direction

Start by comparing initBatchPreparedStatementExecutor(...) with cacheStatements(...) and its replay() call in ShardingSpherePreparedStatement. Reproduce a JDBC batch execution using settings such as setMaxFieldSize or setQueryTimeout, then verify whether those settings reach the actual PreparedStatement. Done means the expected settings are effective in batch executor scenarios, with tests covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.