makssent opened a new pull request, #40176:
URL: https://github.com/apache/shardingsphere/pull/40176
Changes proposed in this pull request:
- `FirebirdStatementVisitor.visitPredicate` builds a
`BinaryOperationExpression` for `[NOT] STARTING WITH`, `IS [NOT] DISTINCT FROM`
and `[NOT] SIMILAR TO` and visits the right operand (with `ESCAPE`, a
`ListExpression` of the pattern and the escape, as for `LIKE`), so its `?` is
registered as a parameter marker. Before, the predicate was replaced by its
left operand and its `?` was lost.
- The left operand is visited first, so the markers keep the order of the
text, and the operator is named in full (`IS NOT DISTINCT FROM`, not `IS`).
- The prepare response describes the `?` of these predicates, typed by the
column on the other side, so the client can set their values.
Verification:
The same queries were executed directly against a real database and through
the proxy, and the results were compared.
* Server: Firebird 5.0
* Clients: Jaybird 5.0.13 and 6.0.6
Table `T_PLAIN (ID INTEGER PRIMARY KEY, NAME VARCHAR(20))` with rows
(3001, 'alpha'), (3002, 'alpine'), (3003, NULL), (3004, 'beta_1'), inserted
with the same results directly and through the proxy. Each `SELECT` is `SELECT
ID FROM T_PLAIN WHERE NAME <predicate> ? AND ID >= ? ORDER BY ID`. Each answer
is the parameter count of the prepared statement and the result; at the end the
rows are read directly from the server. Errors with code 0 come from Jaybird,
which checks the values against the parameter description before sending the
query.
Before the fix:
| Query | Proxy | Server | Match |
|---|---|---|---|
| `SELECT` with `STARTING WITH`, 'alp', 3001 | error 0 "Unsupported set
conversion requested for field null at index 1 (JDBC type INTEGER), source
type: java.lang.String, reason: alp" | 2 parameters, rows 3001, 3002 | no |
| `SELECT` with `NOT STARTING WITH`, 'alp', 3001 | the same error | 2
parameters, rows 3004 | no |
| `SELECT` with `IS NOT DISTINCT FROM`, NULL, 3001 | error 0 "Invalid
column index: 2" | 2 parameters, rows 3003 | no |
| `SELECT` with `IS DISTINCT FROM`, 'alpha', 3001 | the same error as in
the first row, reason: alpha | 2 parameters, rows 3002, 3003, 3004 | no |
| `SELECT` with `SIMILAR TO`, 'al(pha\|pine)', 3001 | the same error as in
the first row, reason: al(pha\|pine) | 2 parameters, rows 3001, 3002 | no |
| `UPDATE T_PLAIN SET NAME = ? WHERE NAME IS NOT DISTINCT FROM ? AND ID >=
?`, 'was null', NULL, 3001 | error 0 "Invalid column index: 3" | 3 parameters,
updated 1 | no |
| `DELETE FROM T_PLAIN WHERE NAME STARTING WITH ? AND ID >= ?`, 'alpi',
3001 | the same error as in the first row, reason: alpi | 2 parameters, updated
1 | no |
| Rows read directly from the server | 3001 'alpha', 3002 'alpine', 3003
NULL, 3004 'beta_1' | 3001 'alpha', 3003 'was null', 3004 'beta_1' | no |
After the fix:
| Query | Proxy | Server | Match |
|---|---|---|---|
| `SELECT` with `STARTING WITH`, 'alp', 3001 | 2 parameters, rows 3001,
3002 | 2 parameters, rows 3001, 3002 | yes |
| `SELECT` with `NOT STARTING WITH`, 'alp', 3001 | 2 parameters, rows 3004
| 2 parameters, rows 3004 | yes |
| `SELECT` with `IS NOT DISTINCT FROM`, NULL, 3001 | 2 parameters, rows
3003 | 2 parameters, rows 3003 | yes |
| `SELECT` with `IS DISTINCT FROM`, 'alpha', 3001 | 2 parameters, rows
3002, 3003, 3004 | 2 parameters, rows 3002, 3003, 3004 | yes |
| `SELECT` with `SIMILAR TO`, 'al(pha\|pine)', 3001 | 2 parameters, rows
3001, 3002 | 2 parameters, rows 3001, 3002 | yes |
| `UPDATE T_PLAIN SET NAME = ? WHERE NAME IS NOT DISTINCT FROM ? AND ID >=
?`, 'was null', NULL, 3001 | 3 parameters, updated 1 | 3 parameters, updated 1
| yes |
| `DELETE FROM T_PLAIN WHERE NAME STARTING WITH ? AND ID >= ?`, 'alpi',
3001 | 2 parameters, updated 1 | 2 parameters, updated 1 | yes |
| Rows read directly from the server | 3001 'alpha', 3003 'was null', 3004
'beta_1' | 3001 'alpha', 3003 'was null', 3004 'beta_1' | yes |
---
Before committing this PR, I'm sure that I have checked the following
options:
- [x] My code follows the [code of
conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/)
of this project.
- [x] I have self-reviewed the commit code.
- [ ] I have (or in comment I request) added corresponding labels for the
pull request.
- [ ] I have passed maven check locally : `./mvnw clean install -B -T1C
-Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
- [ ] I have made corresponding changes to the documentation.
- [x] I have added corresponding unit tests for my changes.
- [ ] I have updated the Release Notes of the current development version.
For more details, see [Update Release
Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
- [ ] I have specified the tool and the affected files or area for
substantial AI assistance, as required by the [AI-assisted contribution policy].
[AI-assisted contribution policy]:
https://github.com/apache/shardingsphere/blob/master/AI_POLICY.md
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]