ym0506 opened a new pull request, #38187:
URL: https://github.com/apache/shardingsphere/pull/38187
### Related
Fixes #37770
### Problem
For PostgreSQL, a query shaped like:
- `NOT ((outer_col) < (scalar subquery with sharding-table join))`
can fail with:
- `relation "t23" does not exist`
Although `t23` / `t22` are sharding tables, this shape may skip table
rewrite in the inner scalar subquery.
### Root Cause
In `PostgreSQLStatementVisitor#visitAExpr`, unary `NOT` was not explicitly
mapped to `NotExpression` for this form.
It could fall back to `CommonExpressionSegment`, which prevents downstream
recursive table extraction from seeing inner scalar-subquery tables (`t23`,
`t22`).
As a result, sharding table rewrite tokens are not generated.
### Fix
Add explicit unary `NOT` handling in PostgreSQL visitor:
- when `ctx.NOT() != null && ctx.aExpr().size() == 1`, return
`NotExpression`.
### Regression Test
Added:
- `PostgreSQLStatementVisitorTest.assertVisitUnaryNotWithScalarSubquery`
The test verifies:
1. `WHERE` is parsed as `NotExpression`.
2. `TableExtractor` can extract `t17`, `t23`, and `t22` from the reported
SQL shape.
### Verification
Executed:
```bash
./mvnw -pl parser/sql/engine/dialect/postgresql -am \
-DskipITs -Dsurefire.failIfNoSpecifiedTests=false \
-Dtest=org.apache.shardingsphere.sql.parser.engine.postgresql.visitor.statement.PostgreSQLStatementVisitorTest
test
```
Result:
- `BUILD SUCCESS`
### Scope
- Changes are limited to PostgreSQL parser visitor behavior.
- No direct route/rewrite engine logic changes.
--
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]