Skip to content

[Bug]: LIMIT BY RANK silently ignores query-level nprobe and fudge_factor options #28996

Closed

Description

@Ariznawlll

MatrixOne version

01d60e1c4ded1b0f3fc1a4ecd75ce54e95e23b90 (current main under validation)

Environment

Local distributed deployment with 2 CN, 1 TN, and 1 log service.

Problem

LIMIT ... BY RANK WITH OPTION accepts the documented/proposed query-level nprobe and fudge_factor options, but the planner silently discards both. Only mode is copied into plan.RankOption.

Consequently, users cannot tune IVF probe count per query even though the SQL is accepted. The actual NProbe always comes from the session variable probe_limit.

Reproduction

set experimental_ivf_index = 1;
create database rank_option_repro;
use rank_option_repro;

create table t(id bigint primary key, v vecf32(2));
insert into t select result, concat('[', result, ',', result, ']')
from generate_series(1, 1000) g;
create index ix using ivfflat on t(v)
  op_type 'vector_l2_ops' lists=20;

set probe_limit = 5;

explain verbose
select id from t
order by l2_distance(v, '[0,0]')
limit 5 by rank with option 'mode=post', 'nprobe=1';

explain verbose
select id from t
order by l2_distance(v, '[0,0]')
limit 5 by rank with option 'mode=post', 'nprobe=99';

explain verbose
select id from t
order by l2_distance(v, '[0,0]')
limit 5 by rank with option 'mode=post', 'fudge_factor=100';

All three plans report:

Vector Index: ix, Metric: l2_distance, Candidate Limit: 5, NProbe: 5

Changing only the session variable proves which value is used:

set probe_limit = 1;
explain verbose
select id from t
order by l2_distance(v, '[0,0]')
limit 5 by rank with option 'mode=post', 'nprobe=99';
-- NProbe: 1

set probe_limit = 17;
explain verbose
select id from t
order by l2_distance(v, '[0,0]')
limit 5 by rank with option 'mode=post', 'nprobe=1';
-- NProbe: 17

The behavior is identical on both CNs and is deterministic across repeated planning.

Code path

The parser stores every option in tree.RankOption.Option, but parseRankOption in pkg/sql/plan/query_builder.go extracts only mode and returns a protobuf RankOption containing only that field. prepareIvfIndexContext then resolves NProbe exclusively from probe_limit.

The original LIMIT BY RANK request (#22919) explicitly proposed fudge_factor and nprobe as query-level controls and was closed as supported. Current parser tests also accept these option names, so silently ignoring them is misleading.

Expected behavior

Either:

  1. apply supported query-level nprobe / fudge_factor values to the vector search plan with validation and documented precedence over session defaults; or
  2. reject unsupported rank options explicitly instead of accepting and discarding them.

Unknown option names should likewise not be silently treated as effective settings.

Impact

Per-query IVF recall/latency tuning does not work. Operators may believe a query uses a larger probe budget while it continues to run with the session default, which can produce unexpected recall and latency characteristics.

Activity

  1. added this to the MO-202609 milestone on Sep 16, 2026
  2. added
    kind/bug
    on Sep 16, 2026
  3. added theissue type on Sep 16, 2026
  4. Ariznawlll commented on Sep 16, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充 unhappy-case 证据:option 不仅不生效,也完全不校验。以下三条都被接受并生成相同计划(session probe_limit=5,计划均为 NProbe: 5):

    ... LIMIT 3 BY RANK WITH OPTION 'mode=post', 'nprobe=not-a-number';
    ... LIMIT 3 BY RANK WITH OPTION 'mode=post', 'fudge_factor=-999';
    ... LIMIT 3 BY RANK WITH OPTION 'mode=post', 'nproeb=99'; -- typo

    因此用户写错 key、写入非法值或以为在逐查询调参时都得不到任何提示。建议支持的 option 做类型/范围校验,未知 key 直接报错;不要继续静默回落到 session 默认。

  5. Ariznawlll commented on Sep 16, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充算法范围:该问题不只影响 CPU IVFFLAT,同一条 query-level nprobe 选项在 GPU IVF-PQ 规划路径中也不会生效。

    代码路径如下:

    • 公共 parseRankOption 仍只把 mode 写入 plan.RankOption,nprobe 在这里已丢失;
    • prepareIvfpqIndexContext 随后只通过 ResolveVariable("probe_limit", ...) 获取 nProbe;
    • 生成的 ivfpq_search 配置中的 "nprobe" 直接使用这个 session 值,不存在 query option 覆盖路径。

    因此 #28996 的修复范围需要同时包含 IVFFLAT 和 IVF-PQ。CAGRA 本身没有 nprobe 参数,不属于这部分。

    本次在 commit 01d60e1c4ded1b0f3fc1a4ecd75ce54e95e23b90 上完成规划器代码核查,并运行 pkg/sql/plan 中 IVF-PQ/CAGRA 的 force、success、rich-pushdown 针对性 UT;本地 CPU 部署不具备 GPU IVF-PQ 执行条件,因此这里没有把白盒结论写成 GPU 运行结果。

  6. added
    ai-easy
    on Oct 14, 2026
  7. Ariznawlll commented on Oct 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。本次按已确认的单 CN 验收范围,查询级 nprobe 生效,非法或不支持的选项被拒绝。

    关键证据

    • 2026-10-29 使用 main@1cea057047b7485736421842612c38d5667152ef 的 GPU 镜像,单 CN、单 NVIDIA RTX 4090;镜像 digest 为 sha256:5e83d01ed5605d6a0ef369bcc3a79344ebce40e42d616930fa87ce699f159dcc。该版本不是本评论发布时最新 main。
    • 原 1000 行 IVFFLAT 场景和 GPU IVFPQ 均执行 3/3:session probe_limit=5 时,查询选项 nprobe=1、99 的 EXPLAIN 分别显示 1、99,而非静默回落 5;正常查询结果正确。切换 session 值、prepared 重用、非法范围、非数字、未知 key 和不支持的 fudge_factor 进行校验,拒绝后源行和元数据保持不变。
    • GPU 补充回归 MOTR #292,测试代码定向运行 3 轮通过,清理测试库和租户;普通环境未启用时跳过。

    待解决点

    • 原报告为双 CN;本次未复验双 CN。GPU 回归尚未接入或运行 TKE GPU 线路,MOTR CI 因 Actions 预算未启动,完整 suite 未运行。上述范围与版本限制按测试侧确认记录。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions