makssent opened a new pull request, #40210:
URL: https://github.com/apache/shardingsphere/pull/40210
Changes proposed in this pull request:
- `FirebirdPrepareStatementCommandExecutor` now describes `+` and `-` of
integers (integer literals, `SMALLINT`, `INTEGER` and `BIGINT` columns, such
arithmetic) and `*` and `/` of `SMALLINT` and `INTEGER` values in the select
list as `BIGINT`.
- The type of `+` and `-` is produced by
[Firebird](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/dsql/ExprNodes.cpp#L1210-L1224),
the type of `*` and `/` by
[Firebird](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/common/dsc.cpp#L832-L850),
and both are read by
[Jaybird](https://github.com/FirebirdSQL/jaybird/blob/v6.0.6/src/main/org/firebirdsql/gds/ng/StatementInfoProcessor.java#L161-L175).
- `+`, `-`, `*` and `/` in the select list are now named `ADD`,
`SUBTRACT`, `MULTIPLY` and `DIVIDE`.
- The name is produced by
[Firebird](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/dsql/ExprNodes.h#L59-L79)
and read by
[Jaybird](https://github.com/FirebirdSQL/jaybird/blob/v6.0.6/src/main/org/firebirdsql/gds/ng/StatementInfoProcessor.java#L177-L183).
- Previously, when the select list had arithmetic of integers (for
example, `SELECT ID + 1 FROM T_PLAIN`), the proxy described the column as
`INTEGER` (4 bytes) named `+` but sent the 8-byte `BIGINT` value of the backend
in the row. The client read the rest of the value as the next operation code
and failed with `jb_unexpectedOperationCode`, and every later statement on the
connection failed with `jb_connectionClosed`. Now the proxy describes the
column as the Firebird server does (`BIGINT` named `ADD`).
<details>
<summary>Verification</summary>
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
Rows `(5101, 'a')` and `(5102, 'b')` are inserted into `T_PLAIN (ID
INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(20))`, then the statements below run
on the same connection. A select list alone reads row 5101, `ID, ID + 10` reads
both rows `ORDER BY ID`, and `RDB$FIELD_POSITION + 1` reads the `NAME` column
of `T_PLAIN`. A cell shows the name/label and type of each column (scale 0 in
all of them), then the rows.
The tables are from Jaybird 6; Jaybird 5 gets the same first error, then
reports the closed connection as `This connection is closed and cannot be used
now.`
Before the fix:
| Query | Proxy | Server | Match |
|---|---|---|---|
| `ID + 1` | error `jb_unexpectedOperationCode` `Unsupported or unexpected
operation code 5102 in processOperation` | ADD/ADD BIGINT; 5102 | no |
| `ID - 1, ID * 2, ID / 2` | error `jb_connectionClosed` `The connection
is closed` | SUBTRACT/SUBTRACT BIGINT, MULTIPLY/MULTIPLY BIGINT, DIVIDE/DIVIDE
BIGINT; 5100, 10202, 2550 | no |
| `ID + 1 - 2 AS SHIFTED, 3 * ID` | the same error | SUBTRACT/SHIFTED
BIGINT, MULTIPLY/MULTIPLY BIGINT; 5100, 15303 | no |
| `RDB$FIELD_POSITION + 1` from `RDB$RELATION_FIELDS` | the same error |
ADD/ADD BIGINT; 2 | no |
| `ID, ID + 10` for both rows | the same error | ID/ID INTEGER, ADD/ADD
BIGINT; (5101, 5111), (5102, 5112) | no |
| `DELETE` of both rows | the same error | 2 | no |
After the fix:
| Query | Proxy | Server | Match |
|---|---|---|---|
| `ID + 1` | ADD/ADD BIGINT; 5102 | ADD/ADD BIGINT; 5102 | yes |
| `ID - 1, ID * 2, ID / 2` | SUBTRACT/SUBTRACT BIGINT, MULTIPLY/MULTIPLY
BIGINT, DIVIDE/DIVIDE BIGINT; 5100, 10202, 2550 | SUBTRACT/SUBTRACT BIGINT,
MULTIPLY/MULTIPLY BIGINT, DIVIDE/DIVIDE BIGINT; 5100, 10202, 2550 | yes |
| `ID + 1 - 2 AS SHIFTED, 3 * ID` | SUBTRACT/SHIFTED BIGINT,
MULTIPLY/MULTIPLY BIGINT; 5100, 15303 | SUBTRACT/SHIFTED BIGINT,
MULTIPLY/MULTIPLY BIGINT; 5100, 15303 | yes |
| `RDB$FIELD_POSITION + 1` from `RDB$RELATION_FIELDS` | ADD/ADD BIGINT; 2
| ADD/ADD BIGINT; 2 | yes |
| `ID, ID + 10` for both rows | ID/ID INTEGER, ADD/ADD BIGINT; (5101,
5111), (5102, 5112) | ID/ID INTEGER, ADD/ADD BIGINT; (5101, 5111), (5102, 5112)
| yes |
| `DELETE` of both rows | 2 | 2 | yes |
</details>
---
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]