Revert "enhance: change default index of hybrid at high cardinality to stl_so…"

This reverts commit 72f8866dd6.
This commit is contained in:
Buqian Zheng
2026-01-19 16:08:04 +08:00
committed by GitHub
parent ff4c066f43
commit 9e8d805171
5 changed files with 26 additions and 23 deletions
+16 -12
View File
@@ -21,7 +21,6 @@
#include "common/Common.h"
#include "index/Meta.h"
#include "index/ScalarIndex.h"
#include "index/StringIndexSort.h"
#include "index/Utils.h"
#include "storage/Util.h"
@@ -55,9 +54,13 @@ HybridScalarIndex<T>::SelectIndexBuildType(size_t n, const T* values) {
distinct_vals.insert(values[i]);
}
// Decide whether to select bitmap index or stlsort
// Decide whether to select bitmap index or inverted sort
if (distinct_vals.size() >= bitmap_index_cardinality_limit_) {
internal_index_type_ = ScalarIndexType::STLSORT;
if constexpr (std::is_integral_v<T>) {
internal_index_type_ = ScalarIndexType::STLSORT;
} else {
internal_index_type_ = ScalarIndexType::INVERTED;
}
} else {
internal_index_type_ = ScalarIndexType::BITMAP;
}
@@ -76,9 +79,9 @@ HybridScalarIndex<std::string>::SelectIndexBuildType(
}
}
// Decide whether to select bitmap index or stlsort
// Decide whether to select bitmap index or inverted index
if (distinct_vals.size() >= bitmap_index_cardinality_limit_) {
internal_index_type_ = ScalarIndexType::STLSORT;
internal_index_type_ = ScalarIndexType::INVERTED;
} else {
internal_index_type_ = ScalarIndexType::BITMAP;
}
@@ -101,9 +104,13 @@ HybridScalarIndex<T>::SelectBuildTypeForPrimitiveType(
}
}
// Decide whether to select bitmap index or stlsort
// Decide whether to select bitmap index or inverted sort
if (distinct_vals.size() >= bitmap_index_cardinality_limit_) {
internal_index_type_ = ScalarIndexType::STLSORT;
if constexpr (std::is_integral_v<T>) {
internal_index_type_ = ScalarIndexType::STLSORT;
} else {
internal_index_type_ = ScalarIndexType::INVERTED;
}
} else {
internal_index_type_ = ScalarIndexType::BITMAP;
}
@@ -126,9 +133,9 @@ HybridScalarIndex<std::string>::SelectBuildTypeForPrimitiveType(
}
}
// Decide whether to select bitmap index or stlsort
// Decide whether to select bitmap index or inverted sort
if (distinct_vals.size() >= bitmap_index_cardinality_limit_) {
internal_index_type_ = ScalarIndexType::STLSORT;
internal_index_type_ = ScalarIndexType::INVERTED;
} else {
internal_index_type_ = ScalarIndexType::BITMAP;
}
@@ -216,9 +223,6 @@ HybridScalarIndex<std::string>::GetInternalIndex() {
} else if (internal_index_type_ == ScalarIndexType::MARISA) {
internal_index_ =
std::make_shared<StringIndexMarisa>(file_manager_context_);
} else if (internal_index_type_ == ScalarIndexType::STLSORT) {
internal_index_ =
std::make_shared<StringIndexSort>(file_manager_context_);
} else if (internal_index_type_ == ScalarIndexType::INVERTED) {
internal_index_ = std::make_shared<InvertedIndexTantivy<std::string>>(
tantivy_index_version_, file_manager_context_);
@@ -27,10 +27,10 @@ func Test_HybridIndexChecker(t *testing.T) {
assert.NoError(t, c.CheckValidDataType(IndexHybrid, &schemapb.FieldSchema{DataType: schemapb.DataType_Array, ElementType: schemapb.DataType_String}))
assert.Error(t, c.CheckValidDataType(IndexHybrid, &schemapb.FieldSchema{DataType: schemapb.DataType_JSON}))
assert.NoError(t, c.CheckValidDataType(IndexHybrid, &schemapb.FieldSchema{DataType: schemapb.DataType_Float}))
assert.NoError(t, c.CheckValidDataType(IndexHybrid, &schemapb.FieldSchema{DataType: schemapb.DataType_Double}))
assert.NoError(t, c.CheckValidDataType(IndexHybrid, &schemapb.FieldSchema{DataType: schemapb.DataType_Array, ElementType: schemapb.DataType_Float}))
assert.NoError(t, c.CheckValidDataType(IndexHybrid, &schemapb.FieldSchema{DataType: schemapb.DataType_Array, ElementType: schemapb.DataType_Double}))
assert.Error(t, c.CheckValidDataType(IndexHybrid, &schemapb.FieldSchema{DataType: schemapb.DataType_Float}))
assert.Error(t, c.CheckValidDataType(IndexHybrid, &schemapb.FieldSchema{DataType: schemapb.DataType_Double}))
assert.Error(t, c.CheckValidDataType(IndexHybrid, &schemapb.FieldSchema{DataType: schemapb.DataType_Array, ElementType: schemapb.DataType_Float}))
assert.Error(t, c.CheckValidDataType(IndexHybrid, &schemapb.FieldSchema{DataType: schemapb.DataType_Array, ElementType: schemapb.DataType_Double}))
assert.Error(t, c.CheckTrain(schemapb.DataType_JSON, schemapb.DataType_None, map[string]string{}))
assert.Error(t, c.CheckTrain(schemapb.DataType_Float, schemapb.DataType_None, map[string]string{"bitmap_cardinality_limit": "0"}))
assert.Error(t, c.CheckTrain(schemapb.DataType_Double, schemapb.DataType_None, map[string]string{"bitmap_cardinality_limit": "2000"}))
@@ -26,14 +26,13 @@ func (c *HYBRIDChecker) CheckValidDataType(indexType IndexType, field *schemapb.
mainType := field.GetDataType()
elemType := field.GetElementType()
if !typeutil.IsBoolType(mainType) && !typeutil.IsIntegerType(mainType) &&
!typeutil.IsStringType(mainType) && !typeutil.IsArrayType(mainType) &&
!typeutil.IsFloatingType(mainType) {
return errors.New("hybrid index are only supported on bool, int, float, string and array field")
!typeutil.IsStringType(mainType) && !typeutil.IsArrayType(mainType) {
return errors.New("hybrid index are only supported on bool, int, string and array field")
}
if typeutil.IsArrayType(mainType) {
if !typeutil.IsBoolType(elemType) && !typeutil.IsIntegerType(elemType) &&
!typeutil.IsStringType(elemType) && !typeutil.IsFloatingType(elemType) {
return errors.New("hybrid index are only supported on bool, int, float, string for array field")
!typeutil.IsStringType(elemType) {
return errors.New("hybrid index are only supported on bool, int, string for array field")
}
}
return nil
+1 -1
View File
@@ -198,7 +198,7 @@ func (p *AutoIndexConfig) init(base *BaseTable) {
p.ScalarAutoIndexParams = ParamItem{
Key: "scalarAutoIndex.params.build",
Version: "2.4.0",
DefaultValue: `{"int": "HYBRID","varchar": "HYBRID","bool": "BITMAP", "float": "HYBRID", "json": "INVERTED", "geometry": "RTREE", "timestamptz": "STL_SORT"}`,
DefaultValue: `{"int": "HYBRID","varchar": "HYBRID","bool": "BITMAP", "float": "INVERTED", "json": "INVERTED", "geometry": "RTREE", "timestamptz": "STL_SORT"}`,
}
p.ScalarAutoIndexParams.Init(base.mgr)
+1 -1
View File
@@ -22,7 +22,7 @@ TRIE: only support varchar
STL_SORT: only support numeric (not include Array field)
INVERTED: all supported except Json
Bitmap: all supported except Json, float, double. (If Array field, according to its ElementType)
ScalarAutoIndex: {"int_*": "HYBRID","varchar": "HYBRID","bool": "BITMAP", "float/double": "HYBRID"}
ScalarAutoIndex: {"int_*": "HYBRID","varchar": "HYBRID","bool": "BITMAP", "float/double": "INVERTED"}
- except Json
- if Array field, according to its ElementType
*/