Skip to content

Add explain-plan FFI for query and vector query - #70

Merged
yuvalif merged 3 commits into
lancedb:mainfrom
galsalomon66:explainplan-ffi
Sep 24, 2026
Merged

yuvalif merged 3 commits into
lancedb:mainfrom
galsalomon66:explainplan-ffi

Conversation

@galsalomon66

Copy link
Copy Markdown
Contributor

Expose LanceDB's query plan through the C ABI so callers can inspect the execution plan without running the query. Adds two functions:

  • lancedb_query_explain_plan(query, verbose, out_plan, out_error)
  • lancedb_vector_query_explain_plan(query, verbose, out_plan, out_error)

Both return LanceDBError and write the plan text to an out-param. Used by RGW S3 Vectors' explainPlan / explainOnly QueryVectors feature.

Expose LanceDB's query plan through the C ABI so callers can inspect the
execution plan without running the query. Adds two functions:

  - lancedb_query_explain_plan(query, verbose, out_plan, out_error)
  - lancedb_vector_query_explain_plan(query, verbose, out_plan, out_error)

Both return LanceDBError and write the plan text to an out-param. Used by
RGW S3 Vectors' explainPlan / explainOnly QueryVectors feature.

Signed-off-by: gal salomon <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread src/query.rs Outdated
if let Some(ref df_filter) = query_ref.df_filter {
rust_query.mut_query().filter =
Some(QueryFilter::Datafusion(df_filter.clone()));
} else if let Some(ref filter) = query_ref.filter {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we allow for both sql filter and datafusion filter to exist in the query?
if we don't, we should probably treat that as an error here as well (instead of one taking precendence ocer the other)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you remove the sql filter?
our API here support both. just not together - it should be considered as an error

Comment thread src/query.rs
if let Some(ref select) = query_ref.select {
rust_query = rust_query.select(select.clone());
}
if let Some(ref df_filter) = query_ref.df_filter {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as line 599

@yuvalif

yuvalif commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator
  • please run cargo fmt --check && cargo clippy on the code - these tests are failing.
  • please add test coverage for the new APIs

… case we will use the SQL ..., it should be back

Signed-off-by: Gal Salomon <[email protected]>
@galsalomon66

galsalomon66 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

@yuvalif
i did the fixes.
there are tests (s3vector_test) for the explain-plan

@yuvalif

yuvalif commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

@yuvalif i did the fixes. there are tests (s3vector_test) for the explain-plan

but we also need to add unit tests here: https://github.com/lancedb/lancedb-c/tree/main/tests
(lets try to keep the code coverage check passing)

Add Catch2 cases exercising lancedb_query_explain_plan and
lancedb_vector_query_explain_plan: basic (verbose/non-verbose) plans,
the DataFusion-filter branch, tuning options (distance/nprobes/
refine_factor/ef), the non-consume contract (query still executable
after explain), and null-argument guards.

Restores coverage lost by the explain-plan functions added in this PR.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@yuvalif
yuvalif self-requested a review September 24, 2026 14:35
@yuvalif
yuvalif merged commit b817cb3 into lancedb:main Sep 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants