fix(facet): prevent int32 -1 facet_id sentinel collision with 1 - #3075
Open
Tyagiquamar wants to merge 1 commit into
Open
Tyagiquamar wants to merge 1 commit into
Tyagiquamar wants to merge 1 commit into
Conversation
When int32 facet value -1 is indexed, its bitwise uint32 representation is 0xFFFFFFFF (UINT32_MAX). Previously, facet_index_t::insert treated fvalue.facet_id == UINT32_MAX as an indicator that no explicit facet ID was provided, allocating ++next_facet_id (1). When a document with int32 value 1 was subsequently indexed, both values mapped to facet ID 1 in fid_fvalues, causing value 1 to be mislabeled as -1 and merging their counts into a single bucket. Decouple explicit facet IDs from UINT32_MAX by introducing a has_explicit_facet_id flag on facet_value_id_t, and check !fvalue.has_explicit_facet_id in facet_index_t::insert. Add a regression test in test/facet_index_test.cpp. Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
Author
|
Hi, just following up on this when you get a chance. The PR is ready from my side. Happy to make any changes if needed. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Summary
When an
int32facet value of-1is indexed, its raw bitwise representation is0xFFFFFFFF(UINT32_MAX).In
src/facet_index.cpp,facet_index_t::insertcheckedif(fvalue.facet_id == UINT32_MAX)to determine if a facet value omitted an explicit numerical facet ID (the pattern used by strings and int64). Because-1matchedUINT32_MAX, the facet index assignedfacet_id = ++next_facet_id, assigning ID1to-1when-1was the first facet value indexed.When a document with
int32value1was subsequently indexed, its facet ID was1, causingfid_fvalues[1]to collide and label value1as"-1", merging both documents into a single facet bucket.This change:
has_explicit_facet_idboolean member tostruct facet_value_id_t, initialized totruewhen constructed with a numerical ID (fid) andfalsewhen constructed with only a string value.facet_index_t::insertto checkif(!fvalue.has_explicit_facet_id)instead of comparing against the in-band sentinelUINT32_MAX.test/facet_index_test.cppverifying that sequential insertion ofint32-1and1preserves distinct facet IDs and labels.fixes #3069
PR Checklist