Skip to content

SQLite improvements#1166

Merged
flimzy merged 26 commits into
mainfrom
sqlite08
Mar 10, 2026
Merged

SQLite improvements#1166
flimzy merged 26 commits into
mainfrom
sqlite08

Conversation

@flimzy
Copy link
Copy Markdown
Member

@flimzy flimzy commented Mar 10, 2026

No description provided.

flimzy added 26 commits March 5, 2026 16:09
Reorganize x/sqlite/TODO.md into Correctness, Functionality, Test Gaps,
and Performance sections based on a full driver audit against CouchDB
behavior. Add Flusher fallback no-op item to V5.md.
Operator-based selectors ($gt, $lt, etc.) set selectorComplete=true,
bypassing the in-memory mango filter. SQLite's type guards don't
implement CouchDB's cross-type ordering, so queries on mixed-type
fields returned incorrect results (e.g. nulls and booleans included
by $gt on a number). Change else-if to independent if so complete=false
whenever a field value contains operators, ensuring the safety net runs.
Add PurgeSeq to driver.DBStats and kivik.DBStats, with CouchDB version-
aware deserialization (number in 1.x, string in 2.x+). Implement purge_seq
in the SQLite driver, incrementing on every Purge() call to match CouchDB
behavior. Consolidate the single-purpose Security table into a generic
Metadata key-value table. Combine Stats() into a single query for atomicity.
When a Find query includes use_index with a valid ddoc and index name,
resolve the corresponding SQLite index name and inject INDEXED BY into
the leaves CTE, forcing SQLite to use the specified index rather than
relying on its automatic index selection.
Previously, updating a design document created new map tables for the
new revision but never dropped the old ones, leaking orphaned tables.
Now dropOldMapTables runs before inserting new Design rows, cleaning up
stale map tables. Note: in conflict scenarios this drops too aggressively
(all revisions, not just the parent); tracked in TODO for a follow-up fix.
Previously dropOldMapTables dropped map tables for all revisions of a
design doc, which would incorrectly destroy other branches' tables in a
conflict scenario. Now filters by the specific parent revision being
superseded, and also calls updateDesignDoc in the new_edits=false path
so replicated design docs get their entries and map tables created.
Offset() was hardcoded to 0. CouchDB returns the skip value as offset,
so expose PaginationOptions.Skip() and wire it through to the rows struct.
CouchDB's _sum supports element-wise summing of arrays, with bare
numbers treated as single-element arrays and shorter arrays zero-padded.
CouchDB's _sum supports recursive field-wise summing of objects.
Objects with overlapping keys have their numeric values summed;
nested objects are merged recursively.
Dispatch to object or numeric path based on the first non-nil value
encountered in the main loop, avoiding a separate pre-scan. Also
flag null handling as incorrect per CouchDB (errors, not skips).
Callers now control cancellation policy by passing a context to MapFunc
and ReduceFunc, rather than relying on a hardcoded timeout in the js
package. Threads real request contexts from query.go and changes.go
through the reduce pipeline to JavaScript execution.
Extends the context-based cancellation pattern to Filter, matching Map
and Reduce. The changes.go caller now passes its request context through
to the filter JS execution.
Extends context-based cancellation to Validate, completing the pattern
for Filter/Validate. The validate.go caller now passes its request
context through to JavaScript execution.
Completes context-based cancellation across all JS functions (Map,
Reduce, Filter, Validate, Update). The update.go caller now passes
its request context through to JavaScript execution.
Adds a Runtime struct with a configurable timeout and converts Map to
a method on *Runtime. The Runtime enforces its timeout on every
invocation, independent of the caller's context deadline. Package-level
Map() remains as a convenience wrapper with no timeout.
…support

Completes the Runtime conversion for all JS functions. Each method
enforces the configured timeout independently of the caller's context.
Package-level functions remain as zero-timeout convenience wrappers.
…timeouts

Add a *js.Runtime field to client and db structs, initialized with a 5s
default timeout matching CouchDB's os_process_timeout. All JS compilation
calls now go through d.js instead of package-level functions. Fix a race
condition in watchContext by using context.AfterFunc instead of a manual
goroutine, ensuring VM interrupt cleanup is properly synchronized.
@flimzy flimzy merged commit c5e56b1 into main Mar 10, 2026
16 checks passed
@flimzy flimzy deleted the sqlite08 branch March 10, 2026 20:49
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 10, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 61.79%. Comparing base (4a034a4) to head (3460c3a).
⚠️ Report is 31 commits behind head on main.

Files with missing lines Patch % Lines
x/options/pagination.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1166   +/-   ##
=======================================
  Coverage   61.79%   61.79%           
=======================================
  Files         293      293           
  Lines       19362    19365    +3     
=======================================
+ Hits        11964    11966    +2     
- Misses       6826     6827    +1     
  Partials      572      572           

☔ 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.

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