functions: save FieldType as value instead of ptr in json function#10846
functions: save FieldType as value instead of ptr in json function#10846yongman wants to merge 1 commit into
Conversation
Signed-off-by: yongman <yming0221@gmail.com>
|
@yongman I've received your pull request and will start the review. I'll conduct a thorough review covering code quality, potential issues, and implementation details. ⏳ This process typically takes 10-30 minutes depending on the complexity of the changes. ℹ️ Learn more details on Pantheon AI. |
📝 WalkthroughWalkthroughRefactored JSON casting functions to use ChangesJSON FieldType Optional Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
dbms/src/Functions/FunctionsJson.h (1)
439-439: 💤 Low valueRefactoring from pointer to value changes ownership semantics.
The change from
const tipb::FieldType*tostd::optional<tipb::FieldType>is semantically significant: the function now owns a copy of the FieldType rather than holding a reference to external data. This eliminates potential lifetime issues (dangling pointers), which likely addresses the consistency bug mentioned in issue#10845.The setter copies
tipb::FieldTypeon each call. Iftipb::FieldType(a protobuf message) is large, consider adding a move-enabled overload:void setOutputTiDBFieldType(tipb::FieldType tidb_tp_) { tidb_tp = std::move(tidb_tp_); }However, the current implementation is correct, and the copy overhead may be acceptable.
Also applies to: 467-467, 530-530
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@dbms/src/Functions/FunctionsJson.h` at line 439, The setter currently copies a potentially large protobuf (setOutputTiDBFieldType) which can be expensive; add a move-enabled overload that takes tipb::FieldType by value (or an rvalue ref) and moves it into the std::optional member (tidb_tp) to avoid the extra copy, and apply the same change to the other setters flagged in this file (the other setOutputTiDBFieldType occurrences referenced in the comment).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@dbms/src/Functions/FunctionsJson.h`:
- Line 439: The setter currently copies a potentially large protobuf
(setOutputTiDBFieldType) which can be expensive; add a move-enabled overload
that takes tipb::FieldType by value (or an rvalue ref) and moves it into the
std::optional member (tidb_tp) to avoid the extra copy, and apply the same
change to the other setters flagged in this file (the other
setOutputTiDBFieldType occurrences referenced in the comment).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: aa141322-ab1a-4623-ab1a-810339dd1046
📒 Files selected for processing (1)
dbms/src/Functions/FunctionsJson.h
|
@yongman: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
JaySon-Huang
left a comment
There was a problem hiding this comment.
Verified the fixed in the tiflash-cse columnar branch.
LGTM
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JaySon-Huang The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
/cc @windtalker @gengliqi |
What problem does this PR solve?
Issue Number: close #10845
Problem Summary:
When TiFlash nextgen evaluates
JSON_EXTRACTon aTEXTcolumn withIS NULL/IS NOT NULLfilters, the result can be inconsistent withJSONcolumns.For example,
JSON_EXTRACT(action_params, '$.popup_id') IS NULLmay return rows whose extracted value is actually non-null, whileIS NOT NULLreturns no rows.The root cause is that the disaggregated columnar path builds temporary
FilterConditions, and JSON cast functions keep raw pointers totipb::FieldType. After the temporary object is destroyed, those pointers can become dangling, soFunctionCastStringAsJsonmay read invalid FieldType metadata.What is changed and how it works?
Check List
Tests
Manual test:
Use the SQL in #10845 to create
event_log1withaction_params TEXTandevent_log2withaction_params JSON, then run with:Verify that both TEXT and JSON columns return consistent results:
Side effects
Documentation
Release note