Skip to content

[refactor](inverted-index) replace void* query_value with typed paraminterface#62960

Open
csun5285 wants to merge 1 commit intoapache:masterfrom
csun5285:fix/inverted-index-query-void-ptr
Open

[refactor](inverted-index) replace void* query_value with typed paraminterface#62960
csun5285 wants to merge 1 commit intoapache:masterfrom
csun5285:fix/inverted-index-query-void-ptr

Conversation

@csun5285
Copy link
Copy Markdown
Contributor

@csun5285 csun5285 commented Apr 30, 2026

What problem does this PR solve?

A typed query-param interface replaces the void*:

  • InvertedIndexQueryParam (root) → StringQueryParam / NumericQueryParam (intermediates) → TypedInvertedIndexQueryParam (concrete, picks base via PT).
  • Readers dynamic_cast to the appropriate intermediate at entry; mismatch fail-fast with Status::InternalError.
  • Sentinels move into TypedInvertedIndexQueryParam::encode_min/max_ascending using type_limit<storage_val> directly — no scratch buffer, no TypeInfo callback.
  • TypeInfo::set_to_min/max and all its overrides are removed.
  • DATETIME signedness fix: storage_val = std::conditional_t<PT == TYPE_DATETIME, int64_t, ...> aligns the typed param with KeyCoder's signed view, so type_limit<int64_t>::max() = INT64_MAX
    produces the correct +inf byte string.

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@csun5285 csun5285 requested a review from airborne12 as a code owner April 30, 2026 02:51
@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@csun5285 csun5285 force-pushed the fix/inverted-index-query-void-ptr branch from 6839dd5 to a842dba Compare April 30, 2026 02:57
… interface

Production query path no longer carries a const void* + reinterpret_cast
through InvertedIndexReader::query / try_query. Three classes with
distinct responsibilities replace the old conflated InvertedIndexQueryParamFactory:

  * InvertedIndexQueryParam            — abstract value interface; readers
                                          pull the value via typed virtuals
                                          (get_string / encode_ascending /
                                          encode_min_ascending /
                                          encode_max_ascending).
  * TypedInvertedIndexQueryParam<PT>   — concrete typed value; numeric/
                                          date/decimal/IP specialisation
                                          implements the encode_* virtuals
                                          using type_limit<>; string
                                          specialisation implements
                                          get_string only.
  * InvertedIndexQueryParamFactory     — static-only namespace class that
                                          maps FE values onto the correct
                                          TypedInvertedIndexQueryParam<PT>;
                                          no instances, no inheritance.

BkdIndexReader::construct_bkd_query_value drops the std::vector<char>
tmp scratch buffer and the _type_info->set_to_min/max calls used to
synthesize +/-infinity sentinels for half-bounded range queries. The
sentinel is now produced directly by the typed query value
(encode_min_ascending / encode_max_ascending), so only inverted-index
supported types ever need to know how to emit a min/max.

With BKD no longer the only consumer, the entire TypeInfo::set_to_min/max
API surface is removed: TypeInfo virtuals, ScalarTypeInfo storage,
List/Map/Struct DCHECK-fail overrides, every FieldTypeTraits<...>
specialization, the OLAP_FIELD_TYPE_CHAR static function pointer in
types.cpp, Field::set_to_min/max wrappers, and the CharField/VarcharField
/StringField overrides. Corresponding storage_types_test cases are removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@csun5285 csun5285 force-pushed the fix/inverted-index-query-void-ptr branch from a842dba to 5fee30d Compare April 30, 2026 03:11
@csun5285
Copy link
Copy Markdown
Contributor Author

run buildall

Comment thread be/src/core/type_limit.h

// DATE storage. Packed as `year<<9 | month<<5 | day`: 33=0001-01-01, 5119903=9999-12-31.
template <>
struct type_limit<uint24_t> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

我们这个typelimit 的参数为什么不是datev1 这种类型,而是Uint24?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

别的类型也是这样,这里是特化的模板

// TYPE_DATETIME: PrimitiveTypeTraits=uint64_t but KeyCoder=int64_t. With
// uint64_t, type_limit::max() = UINT64_MAX is read as -1 and encodes
// smaller than any real datetime — broken +inf.
using storage_val = std::conditional_t<PT == TYPE_DATETIME, int64_t,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这个你讲清楚来龙去卖,就说之前有一个地方用的,现在改不了了

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

这个地方就是KeyCoder=int64_t

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

哦对,这里得索引用了keycoder

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.

3 participants