Skip to content

Conversation

@dirtysalt
Copy link
Contributor

@dirtysalt dirtysalt commented Dec 28, 2025

Why I'm doing:

What I'm doing:

These optimizations reduce overhead by:

  • Avoiding allocations in common status cases
  • Inlining hot methods to eliminate function call overhead
  • Returning null instead of errors for expected cases (missing keys, out-of-bounds) - since these are often normal control flow in variant path operations

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.0
    • 3.5
    • 3.4
    • 3.3

Note

Improves Variant path/object/array navigation performance and semantics, plus a small Status optimization.

  • Use hinted dictionary search in VariantMetadata::_get_index to minimize scans for non-unique dicts; refactor get_object_by_key to leverage hints and return null when key not found instead of errors
  • get_element_at_index now returns null for out-of-bounds indices (was error); VariantPath::seek short-circuits when current segment resolves to null
  • Inline VariantValue::type() into variant.h and add is_null() for fast checks
  • Optimize Status state assembly for empty message/context path
  • Update unit tests to expect NULL_TYPE instead of errors for missing keys/OOB, and adjust SQL golden results to show Null where appropriate

Written by Cursor Bugbot for commit f345716. This will update automatically on new commits. Configure here.

@dirtysalt dirtysalt requested review from a team as code owners December 28, 2025 04:27
return Status::OK();
},
segment));
if (current.is_null()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast break if it's null value.

}
} else {
// non-unique dictionary, find all matching indexes
} else if (hint == 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint = 0 means just return the first index
otherwise it means to search from this index.

RETURN_IF_ERROR(search(0));

// don't find key in the dict, then return null value.
if (dict_indexes.empty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is no dict index found, we don't return error, but return null value.
remember this case is not a abnormal case.

std::string_view raw() const { return _value; }
VariantType type() const;
VariantType type() const {
switch (basic_type()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline this method.

inline const char* assemble_state(TStatusCode::type code, std::string_view msg, std::string_view ctx) {
DCHECK(code != TStatusCode::OK);

if (msg.empty() && ctx.empty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast initialization

Signed-off-by: yan zhang <[email protected]>
@dirtysalt dirtysalt force-pushed the optimize-variant-path branch from 9ce2a4c to f345716 Compare December 28, 2025 06:48
@github-actions
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions
Copy link

[FE Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions
Copy link

[BE Incremental Coverage Report]

pass : 3 / 3 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/common/status.cpp 3 3 100.00% []

@dirtysalt dirtysalt enabled auto-merge (squash) December 28, 2025 10:19
@dirtysalt dirtysalt disabled auto-merge December 28, 2025 10:19
@dirtysalt dirtysalt enabled auto-merge (squash) December 28, 2025 10:19
@dirtysalt dirtysalt disabled auto-merge December 28, 2025 10:19
@dirtysalt dirtysalt enabled auto-merge (squash) December 28, 2025 10:19
@alvin-celerdata
Copy link
Contributor

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no bugs!

@alvin-celerdata alvin-celerdata merged commit ae46e78 into StarRocks:main Dec 28, 2025
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants