lance-format / lance-format/lance

explain_plan does not accurately represent projection of nested subfields

Open
#3,793 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Rust
Stars
7.1k
Forks
852
Avg merge
3d 18h
Merged PRs (30d)
272

Description

Using this script

import lancedb
import random
from pydantic import BaseModel
from lancedb.pydantic import LanceModel

class Document(BaseModel):
    content: str
    source: str

class NestedSchema(LanceModel):
    id: str
    doc: Document

# this works
db = lancedb.connect(
        "my-db",
)

data = [{
    "id": "foo",
    "doc": {
        "content": "foo",
        "source": "foobar",
    },
}]

key = random.randint(1, 1000000)
table = db.create_table(f"test{key}", schema=NestedSchema, data=data)
print(table.search().where("`doc`.`source` = 'foobar' and id <> ''").explain_plan())

I get this plan:

ProjectionExec: expr=[id@0 as id, doc@1 as doc]
  Take: columns="id, (doc), _rowid"
    CoalesceBatchesExec: target_batch_size=1024
      FilterExec: get_field(doc@1, source) = foobar AND id@0 != 
        LanceScan: uri=my-db/test919631.lance/data, projection=[id, doc], row_id=true, row_addr=false, ordered=true

From the plan, it's unclear why "Take" is required at all, because [id, doc] are projected from the LanceScan. The reason is that only the "source" subfield of doc is really getting projected. We should update the explain_plan representation to indicate [id, doc@1] instead of what it's currently doing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the explain_plan entry point and reproduce the nested-field query from the issue using the provided LanceDB and Pydantic script. Trace how the projection is represented in the plan, then verify that the output distinguishes the projected nested subfield from the full doc field, such as showing id and doc@1 rather than only id and doc.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.