Skip to content

[Bug]: AND/OR seekOp always returns 0 due to min() with zero-initialized accumulator #24305

Closed

Description

@aunjgr

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

Present since at least b1e35e0

Actual Behavior

In pkg/vm/engine/readutil/expr_filter.go, both the "and" and "or" compound cases define a seekOp that combines child seek positions:

seekOp = func(meta objectio.ObjectDataMeta) int {
    var pos int  // zero-initialized
    for idx := range seekOps {
        if seekOps[idx] == nil {
            continue
        }
        pp := seekOps[idx](meta)
        pos = min(pos, pp)
    }
    return pos
}

Two problems:

  1. pos starts at 0 (the minimum possible block index). Since all seek positions are >= 0, min(0, pp) always returns 0. The seekOp is effectively dead code.

  2. The AND case uses min but should use max. For AND semantics, ALL conditions must be satisfied, so we can safely skip to the furthest (maximum) seek position. For OR, min is correct since any single condition might match.

Expected Behavior

AND case — use max, seed with 0:

seekOp = func(meta objectio.ObjectDataMeta) int {
    var pos int
    for idx := range seekOps {
        if seekOps[idx] == nil {
            continue
        }
        pp := seekOps[idx](meta)
        pos = max(pos, pp)
    }
    return pos
}

OR case — use min, seed with blockCnt (so any real seek position wins):

seekOp = func(meta objectio.ObjectDataMeta) int {
    pos := int(meta.BlockCount())
    for idx := range seekOps {
        if seekOps[idx] == nil {
            continue
        }
        pp := seekOps[idx](meta)
        pos = min(pos, pp)
    }
    return pos
}

Steps to Reproduce

  1. Create a table with a composite filter that compiles to AND or OR of two seekable sub-expressions (e.g., WHERE pk > 500 AND pk < 900)
  2. The reader will always start scanning from block 0 regardless of the seek positions computed by the child expressions

Additional information

This is an optimization-only bug — correctness is preserved because blockFilterOp still validates each block. The impact is unnecessary block scans on sorted objects when compound filters are used.

Activity

  1. added
    kind/bug
    on May 7, 2026
  2. added a commit that references this issue on May 7, 2026
    535a2b3
  3. added a commit that references this issue on May 8, 2026
    4d31cb7
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

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions