LLLLLL302311 opened a new pull request, #71262:
URL: https://github.com/apache/doris/pull/71262
### Background
The FE sql cache is keyed by statement text. `ConnectProcessor.executeQuery`
first converts the
client SQL with the session `sql_dialect` converter
(`SqlDialectHelper.convertSqlByDialect`), then
parses the converted text. When a cached plan exists, the FE replays it and
the query is not sent to
the BE; when it does not, the statement is parsed, planned and executed, and
the result and physical
plan are added to the cache under the statement's origin text.
### What problem does this PR solve?
Issue Number: None
Related PR: #46308 (introduced the dialect conversion that made the lookup
key diverge from the write key)
PR Type: Bugfix
Problem Summary:
When `sql_dialect` is not `doris` and the dialect converter rewrites the SQL
(for example spark or
presto), the cache entry is written under the converted statement text while
the lookup uses the raw
client SQL. The keys never match, so the cache is filled on every execution
but never hit, and the
FE parses and plans the query again each time. Example: with
`sql_dialect=spark`, a statement the
spark converter rewrites executes and is cached under the rewritten text,
and the next identical
client statement misses because the lookup uses the original text. The fix
makes the lookup pass the
same converted text that the write path uses.
### Details
- **Frequency:** Always when `sql_dialect` is not `doris` and the converter
changes the statement
text. Not observed with `sql_dialect=doris`, where the converter returns
the input unchanged.
- **Root cause:** In `ConnectProcessor.executeQuery`, `convertedStmt` is
computed and parsed, so
`parsedStmt.getOrigStmt().originStmt` - the key used by
`StmtExecutor.tryAddBeCache` and
`NereidsPlanner.tryAddFeSqlCache` - is the converted text. The lookup
called
`parseFromSqlCache(originStmt)` with the raw client text, so lookup and
write disagreed whenever
the conversion changed the text.
- **Why existing tests missed it:**
`fe/fe-core/src/test/java/org/apache/doris/qe/SqlCacheTest.java`
and
`regression-test/suites/query_p0/cache/parse_sql_from_sql_cache.groovy`
exercise the cache
lookup and hit path only with the default doris dialect, where
`convertedStmt` is identical to
`originStmt`. No test sets a non-doris dialect whose converter rewrites
the text, and none
observes the text passed to the cache lookup.
- **Fix:** Pass `convertedStmt` to `parseFromSqlCache` so lookup and write
use the same key. The
method is widened to package-private so the new test can observe the text
passed by
`executeQuery`. The write side is left unchanged because the converted
text is also the statement
text used for audit and execution.
- **Other paths and branches:** The FE cache write
(`NereidsPlanner.tryAddFeSqlCache`) and the BE
cache write (`StmtExecutor.tryAddBeCache`) already use the converted
statement text; only the
lookup was wrong. The code exists on `branch-3.1`, `branch-4.0`,
`branch-4.1`, `branch-4.2` and
`master`; all of them contain the dialect conversion added by #46308.
### Testing
Added `ConnectProcessorSqlCacheTest`, which registers a test PRESTO dialect
converter, calls
`executeQuery`, and asserts that the lookup receives the converted statement
(the first test fails
before the fix because the captured text equals the raw `ORIGIN_SQL`), that
the text is unchanged
for doris, and that no lookup is attempted when the sql cache is disabled.
The test was not executed locally. This machine has no JDK 17, Maven, or the
thirdparty/protoc
needed to build FE; the result is expected from CI.
### Notes for Reviewers
The write key is `convertedStmt` only for single-statement queries; for
multi-statement queries the
cache is not populated per statement, so passing `convertedStmt` does not
introduce a new hit path.
### Release note
Queries whose `sql_dialect` is not `doris` and whose dialect converter
rewrites the SQL now hit the
sql cache instead of being re-parsed and re-planned on every execution.
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Partially verified: FE unit test added but not run
locally (no JDK
17/Maven/thirdparty build environment); CI is expected to run it.
### AI Disclosure
- Tool: Claude Code (DeepSeek V4.1 Flash)
- Generated: code change, unit test, this description
- Human review: Author reviewed the final diff and test logic.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]