Skip to content

[Bug]: IVFFLAT l2_distance with lower and upper bounds returns an empty Top-K #29037

Closed as not planned

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

01d60e1

Other Environment Information

  • Local multi-CN launch (etc/launch-multi-cn/launch.toml), SQL ports 16001 and 16002
  • One IVFFLAT list so the result does not depend on approximate-list recall
  • Reproduces with both vector_l2_ops and vector_l2sq_ops

Actual Behavior

An IVFFLAT query using l2_distance with both a lower and an upper range predicate returns an empty result even though matching vectors exist:

where l2_distance(v, '[0,0]') > 150
  and l2_distance(v, '[0,0]') < 250
order by l2_distance(v, '[0,0]')
limit 10 by rank

The IVFFLAT plan returns 0 rows. The exact mode=force path returns 10 rows, all with distance 200.

The problem is specific to the pushed two-sided l2_distance range:

  • lower-only l2_distance > 150: correct;
  • upper-only l2_distance < 250: correct;
  • equivalent squared range 22500 < l2_distance_sq(...) < 62500: correct;
  • BETWEEN 150 AND 250, which is not folded into the same pushed range path: correct;
  • separate > and < predicates: empty result.

It also occurs through the binary protocol with prepared bounds. Reusing the same prepared statement with (150,250), an empty interval, and (150,250) again returns 0 for both valid executions, so this is not a stale parameter value.

The matrix reproduced on both CNs, both equivalent L2 op types, and each of mode=post, mode=include, and mode=pre, three consecutive executions per combination.

Expected Behavior

The IVFFLAT path must apply both bounds in the same l2_distance unit as SQL and return the 10 vectors whose distance is 200, matching the exact path and the equivalent squared-distance query.

Steps to Reproduce

set experimental_ivf_index = 1;
drop database if exists ivf_l2_range_repro;
create database ivf_l2_range_repro;
use ivf_l2_range_repro;

create table t(id int primary key, grp int, v vecf32(2));
insert into t
select result,
       floor((result - 1) / 40),
       cast(concat('[', floor((result - 1) / 40) * 200, ',0]') as vecf32(2))
from generate_series(1, 120) g;

create index idx using ivfflat on t(v)
lists = 1 op_type 'vector_l2_ops';

-- Returns 10 rows at distance 200.
select id, grp, l2_distance(v, '[0,0]') d
from t
where l2_distance(v, '[0,0]') > 150
  and l2_distance(v, '[0,0]') < 250
order by l2_distance(v, '[0,0]')
limit 10 by rank with option 'mode=force';

-- Uses Vector Index Scan but returns 0 rows.
select id, grp, l2_distance(v, '[0,0]') d
from t
where l2_distance(v, '[0,0]') > 150
  and l2_distance(v, '[0,0]') < 250
order by l2_distance(v, '[0,0]')
limit 10 by rank with option 'mode=post';

Additional information

The range is removed from the base-table filter and stored in the vector scan's DistRange. The IVFFLAT relation reader deliberately disables storage Top-K when a lower bound exists and is expected to compute exact entry distances, filter the interval, and only then compact the final Top-K. The result indicates that the two bounds are not being evaluated in a consistent distance domain on the l2_distance path.

Discovered while expanding IVFFLAT correctness coverage related to #28943; this is an independent single-list range-pushdown defect rather than the unordered multi-CN merge described there.

Activity

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

    @Ariznawlll
    CollaboratorAuthor

    Correction after an additional name-lifecycle control: the two-sided l2_distance range itself is correct on a database/table/index name that has never been used. The same 120-row, lists=1, two-CN matrix returns 10 rows in post, include, and pre, matching force.

    The earlier empty result depended on repeatedly dropping and recreating the same database, table, and IVFFLAT index names. mo_catalog.mo_indexes then exposed two generations of metadata for the same database and index name (six rows instead of the current three hidden-table roles), and the query reached stale hidden-index state.

    Therefore the title and diagnosis of this issue are not accurate. I am closing it rather than leaving a misleading distance-range report. The DDL/name-reuse lifecycle behavior is being minimized and will be reported separately only after fresh-name controls and repeated generation tests confirm it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions