Skip to content

Commit 4a034a4

Browse files
authored
Merge pull request #1165 from go-kivik/sqlite55
Find/Explain support and other improvements to sqlite driver
2 parents 817f44d + a921e50 commit 4a034a4

File tree

10 files changed

+917
-59
lines changed

10 files changed

+917
-59
lines changed

x/sqlite/TODO.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# SQLite Driver TODO
22

3-
## Missing Implementations
4-
5-
- [ ] **Explain** (`db.go`) — Currently returns "not implemented"; useful for
6-
Mango query debugging.
7-
- [ ] **Missing options**:
8-
- `att_encoding_info` (Get/Changes/Views)
9-
- `batch` (Put)
10-
- `heartbeat` (Changes)
11-
- `execution_stats` (Find)
12-
133
## Low Priority (polyfilled by kivik)
144

155
- [ ] **BulkDocs** (`db.go`) — kivik emulates via individual Put/CreateDoc.
166
- [ ] **Copy** (`db.go`) — kivik emulates via Get+Put.
177

188
## Performance / Code Quality
199

10+
- [ ] **Find cross-type comparison correctness** (`find.go`) —
11+
`selectorToSQL` translates comparison operators (`$lt`, `$lte`, `$gt`,
12+
`$gte`, `$eq`) to SQL, but SQLite doesn't support CouchDB's cross-type
13+
ordering (null < bool < number < string < array < object). When
14+
`selectorComplete=true`, the in-memory filter is skipped, producing
15+
incorrect results for cross-type queries.
16+
- [ ] **`use_index` doesn't influence query execution** (`find.go`) — The hint
17+
is validated and triggers a warning if missing, but doesn't guide the
18+
query plan.
2019
- [ ] **Reduce caching** (`README.md`) — Reduce functions run on-demand with no
2120
intermediate result caching.
22-
- [ ] **Mango SQL optimization** (`find.go`) — These selectors work via
23-
in-memory fallback but aren't translated to SQL: `$not`, `$nor`, `$nin`,
24-
`$regex`, `$mod`, `$all`, `$elemMatch`, `$type`, `$size`, `$allMatch`,
25-
`$keyMapMatch`.
21+
- [ ] **Mango SQL optimization** (`find.go`) — These selectors could be
22+
translated to SQL for index support but aren't yet: `$size`, `$type`.
23+
The remaining operators (`$nin`, `$mod`, `$all`, `$elemMatch`,
24+
`$allMatch`, `$keyMapMatch`) aren't indexable in SQLite and are handled
25+
adequately by the in-memory fallback.
2626
- [ ] **Filter in Go instead of SQL** (`query.go:569`) — Local and design
2727
document filtering during view updates is done in Go after fetching rows,
2828
rather than in the SQL query.

x/sqlite/createindex_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ func TestCreateIndex(t *testing.T) {
4343
name: "my-index",
4444
index: json.RawMessage(`{"fields":["name"]}`),
4545
})
46+
tests.Add("mixed sort directions", test{
47+
ddoc: "_design/mixed",
48+
name: "mixed",
49+
index: json.RawMessage(`{"fields":[{"name":"asc"},{"age":"desc"}]}`),
50+
wantErr: "Sorts currently only support a single direction for all fields",
51+
})
4652
tests.Add("creates a real SQLite index", func(t *testing.T) any {
4753
db := newDB(t)
4854
return test{

x/sqlite/db.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ func (db) Copy(context.Context, string, string, driver.Options) (string, error)
116116
return "", errors.New("not implemented")
117117
}
118118

119-
func (db) Explain(context.Context, any, driver.Options) (*driver.QueryPlan, error) {
120-
return nil, errors.New("not implemented")
121-
}
122-
123119
// errDatabaseNotFound converts a sqlite "no such table" error into a kivik
124120
// database not found error
125121
func (d *db) errDatabaseNotFound(err error) error {

0 commit comments

Comments
 (0)