Skip to content

Commit f60a25a

Browse files
committed
test
1 parent 8fd9f79 commit f60a25a

File tree

10 files changed

+1115
-51
lines changed

10 files changed

+1115
-51
lines changed

pkg/sql/plan/apply_indices_hnsw.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func (builder *QueryBuilder) prepareHnswIndexContext(vecCtx *vectorSortContext,
4646
if vecCtx.distFnExpr == nil {
4747
return nil, nil
4848
}
49+
50+
// RankOption.Mode controls vector index behavior:
51+
// - "force": Disable vector index, force full table scan (for debugging/comparison)
52+
// - nil/other: Enable vector index with default behavior
4953
if vecCtx.rankOption != nil && vecCtx.rankOption.Mode == "force" {
5054
return nil, nil
5155
}

pkg/sql/plan/apply_indices_ivfflat.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func (builder *QueryBuilder) prepareIvfIndexContext(vecCtx *vectorSortContext, m
4949
if vecCtx.distFnExpr == nil {
5050
return nil, nil
5151
}
52+
53+
// RankOption.Mode controls vector index behavior:
54+
// - "pre": Enable vector index with BloomFilter pushdown for better filtering
55+
// - "force": Disable vector index, force full table scan (for debugging/comparison)
56+
// - nil/other: Enable vector index with default behavior
5257
if vecCtx.rankOption != nil && vecCtx.rankOption.Mode == "force" {
5358
return nil, nil
5459
}
@@ -579,6 +584,11 @@ func (builder *QueryBuilder) rebindScanNode(scanNode *plan.Node) {
579584
for _, expr := range scanNode.FilterList {
580585
replaceColRefTag(expr, oldTag, newTag)
581586
}
587+
// Also update BlockFilterList, which was copied from the original scanNode
588+
// and still contains references to the old binding tag
589+
for _, expr := range scanNode.BlockFilterList {
590+
replaceColRefTag(expr, oldTag, newTag)
591+
}
582592
}
583593

584594
func replaceColRefTag(expr *plan.Expr, oldTag, newTag int32) {

pkg/sql/plan/query_builder.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5222,7 +5222,7 @@ func (builder *QueryBuilder) GetContext() context.Context {
52225222
// parseRankOption parses rank options from a map of option key-value pairs.
52235223
// It extracts the "mode" option case-insensitively and validates it.
52245224
// Returns a RankOption with the parsed mode if valid, or nil if no mode is specified.
5225-
// Returns an error if the mode value is invalid (must be "pre" or "post").
5225+
// Returns an error if the mode value is invalid (must be "pre", "post", or "force").
52265226
func parseRankOption(options map[string]string, ctx context.Context) (*plan.RankOption, error) {
52275227
if len(options) == 0 {
52285228
return nil, nil
@@ -5243,8 +5243,12 @@ func parseRankOption(options map[string]string, ctx context.Context) (*plan.Rank
52435243

52445244
if mode, ok := getOptionValue("mode"); ok {
52455245
modeLower := strings.ToLower(strings.TrimSpace(mode))
5246-
if modeLower != "pre" && modeLower != "post" {
5247-
return nil, moerr.NewInvalidInputf(ctx, "mode must be 'pre' or 'post', got '%s'", mode)
5246+
// Mode options:
5247+
// - "pre": Enable vector index with BloomFilter pushdown
5248+
// - "post": Enable vector index with standard behavior (post-filtering)
5249+
// - "force": Force disable vector index, use full table scan
5250+
if modeLower != "pre" && modeLower != "post" && modeLower != "force" {
5251+
return nil, moerr.NewInvalidInputf(ctx, "mode must be 'pre', 'post', or 'force', got '%s'", mode)
52485252
}
52495253
rankOption.Mode = modeLower
52505254
}

pkg/sql/plan/query_builder_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func TestQueryBuilder_bindLimit(t *testing.T) {
380380
stmts, _ := parsers.Parse(context.TODO(), dialect.MYSQL, "select a from select_test.bind_select limit 1, 5", 1)
381381
astLimit := stmts[0].(*tree.Select).Limit
382382

383-
boundOffsetExpr, boundCountExpr, _, err := builder.bindLimit(bindCtx, astLimit)
383+
boundOffsetExpr, boundCountExpr, _, err := builder.bindLimit(bindCtx, astLimit, nil)
384384
require.NoError(t, err)
385385
require.Equal(t, int32(types.T_uint64), boundOffsetExpr.Typ.Id)
386386
offsetExpr, ok := boundOffsetExpr.Expr.(*plan.Expr_Lit)
@@ -858,10 +858,20 @@ func TestParseRankOption(t *testing.T) {
858858
rankOption, err := parseRankOption(options, ctx)
859859
require.Error(t, err)
860860
require.Nil(t, rankOption)
861-
require.Contains(t, err.Error(), "mode must be 'pre' or 'post'")
861+
require.Contains(t, err.Error(), "mode must be 'pre', 'post', or 'force'")
862862
require.Contains(t, err.Error(), "invalid")
863863
})
864864

865+
t.Run("valid mode force", func(t *testing.T) {
866+
options := map[string]string{
867+
"mode": "force",
868+
}
869+
rankOption, err := parseRankOption(options, ctx)
870+
require.NoError(t, err)
871+
require.NotNil(t, rankOption)
872+
require.Equal(t, "force", rankOption.Mode)
873+
})
874+
865875
t.Run("empty options map", func(t *testing.T) {
866876
options := map[string]string{}
867877
rankOption, err := parseRankOption(options, ctx)

test/distributed/cases/ivf/pre.result

Lines changed: 0 additions & 29 deletions
This file was deleted.

test/distributed/cases/ivf/pre.sql

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)