Skip to content

Find/Explain support and other improvements to sqlite driver#1165

Merged
flimzy merged 21 commits into
mainfrom
sqlite55
Mar 4, 2026
Merged

Find/Explain support and other improvements to sqlite driver#1165
flimzy merged 21 commits into
mainfrom
sqlite55

Conversation

@flimzy
Copy link
Copy Markdown
Member

@flimzy flimzy commented Mar 4, 2026

No description provided.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.79%. Comparing base (817f44d) to head (a921e50).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1165      +/-   ##
==========================================
- Coverage   61.80%   61.79%   -0.01%     
==========================================
  Files         293      293              
  Lines       19362    19362              
==========================================
- Hits        11966    11965       -1     
- Misses       6825     6826       +1     
  Partials      571      571              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

flimzy added 4 commits March 4, 2026 15:46
Replaces the "not implemented" stub with a working implementation that
parses the query, extracts the selector, and returns a QueryPlan with
the _all_docs fallback index and CouchDB's default limit of 25.
Explain now queries mango indexes and selects the best match by
checking selector field coverage and sort field coverage, falling
back to _all_docs when no index matches.
Explain now respects the use_index query parameter by looking up the
specified index directly, falling back to auto-selection if not found
(matching CouchDB's hint semantics). Extracted buildMangoIndexMap to
share index result construction between lookupMangoIndex and
selectMangoIndex.
An empty sortFields slice caused the loop to not execute, falling
through to return true. This made selectMangoIndex incorrectly
match any index even when no sort was requested.
@flimzy flimzy force-pushed the sqlite55 branch 2 times, most recently from 3b5a4d5 to ecfb3c9 Compare March 4, 2026 21:15
flimzy added 16 commits March 4, 2026 16:20
…nd's behavior

Unskip SQLite integration test for Explain and configure expected plan.
…CouchDB behavior

Validate field directions in ExtractIndexFields and return HTTP 400 when
an index definition mixes ascending and descending sort directions.
…uery

CouchDB selects the index with the least fields when multiple candidates
cover the selector, indicated by the too_many_fields reason code.
When multiple indexes match with the same field count, CouchDB picks
the one whose ddoc name comes first alphabetically.
…ed candidates

coversSelector now matches indexes covering at least one selector field,
matching CouchDB behavior. selectMangoIndex collects candidates into a
slice and sorts by (fewest fields, alphabetical ddoc) for clarity.
…erion

coversSelector now returns the overlap count instead of a boolean, and
indexCandidate.cmp sorts by most overlap first, then fewest fields, then
alphabetical ddoc name, matching CouchDB's less_overlap behavior.
Move the default find limit from the SQLite driver into x/options so
FindLimit() never returns a negative value, matching CouchDB behavior.
…he index is not found

CouchDB treats use_index as advisory — if the specified index doesn't exist,
it falls back to the best available index and returns a warning. This matches
that behavior by implementing driver.RowsWarner on the rows struct.
CouchDB returns "no matching index found, create an index to optimize
query time" when _find falls back to _all_docs. Add the same warning
via the RowsWarner interface. Also document that Find currently ignores
mango indexes entirely and should be fixed to use them.
$in can't use SQLite indexes and its SQL IN doesn't match CouchDB's
deep equality for non-scalar or mixed-type values. Let the in-memory
fallback handle it correctly instead.
@flimzy flimzy merged commit 4a034a4 into main Mar 4, 2026
17 of 18 checks passed
@flimzy flimzy deleted the sqlite55 branch March 4, 2026 21:46
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.

1 participant