fix(mysql): infer LIMIT placeholders in prepare#8149
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements type inference for placeholders in LIMIT and OFFSET clauses, defaulting them to Int64, and ensures the MySQL handler correctly advertises all parameters to clients by using a null data type for unknown parameters. Review feedback identified a critical SQL injection vulnerability in the fallback execution path for unknown parameters, requiring string escaping. Additionally, the reviewer suggested improving error handling in the expression traversal logic to prevent swallowing potential errors.
6141346 to
2d8e86d
Compare
Signed-off-by: discord9 <discord9@163.com>
2d8e86d to
3e4fff4
Compare
|
Updated the PR to narrow the fix to the actual #8142 path: LIMIT/OFFSET placeholders are now inferred as Int64, and the MySQL handler/fallback string replacement changes were removed. The previous bot comments about unknown-placeholder fallback string substitution are therefore obsolete for the current diff. |
I hereby agree to the terms of the GreptimeDB CLA.
Refer to a related PR or issue link (optional)
Closes #8142
What's changed and what's your intention?
This PR fixes MySQL prepared statements with placeholders in
LIMIT/OFFSET, e.g.:Before this change, DataFusion kept the placeholder in the logical plan but could not infer its type. GreptimeDB's existing MySQL prepare path only advertises placeholders with inferred concrete types, so the client saw the prepared statement as requiring 0 parameters and failed before execution with an argument count mismatch.
The changes are:
LogicalPlan::Limit(LIMIT/OFFSET) asInt64inDfLogicalPlanner::get_inferred_parameter_types().LIMIT/OFFSETplaceholders typed.LIMIT ?and mixedWHERE ? LIMIT ?prepared statements.This does not change public APIs, schemas, or persisted data.
PR Checklist
Please convert it to a draft if some of the following conditions are not met.
Tests:
cargo fmt --checkcargo test -p query -- test_get_inferred_parameter_types_limit_offsetcargo test -p servers --features testing -- test_query_prepared