Skip to content

Commit 0d2d8fd

Browse files
authored
Version of the sqlite index using a single table (electric-sql#4)
* Version of the sqlite index using a single table * Cache the compaction frontear * Simplify sql for join, do combining of values in JS * use temp tables for the delta in an index join
1 parent 583b0f8 commit 0d2d8fd

File tree

5 files changed

+141
-234
lines changed

5 files changed

+141
-234
lines changed

packages/d2ts/src/multiset.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DefaultMap } from './utils.js'
1+
import { DefaultMap, chunkedArrayPush } from './utils.js'
22

33
export type MultiSetArray<T> = [T, number][]
44
export type KeyedData<T> = [key: string, value: T]
@@ -55,8 +55,8 @@ export class MultiSet<T> {
5555
*/
5656
concat(other: MultiSet<T>): MultiSet<T> {
5757
const out: MultiSetArray<T> = []
58-
out.push(...this.#inner)
59-
out.push(...other.#inner)
58+
chunkedArrayPush(out, this.#inner)
59+
chunkedArrayPush(out, other.getInner())
6060
return new MultiSet(out)
6161
}
6262

@@ -93,7 +93,7 @@ export class MultiSet<T> {
9393
const out: MultiSetArray<KeyedData<[T, U]>> = []
9494

9595
for (const [[k1, v1], d1] of this.#inner as MultiSetArray<KeyedData<T>>) {
96-
for (const [[k2, v2], d2] of other.#inner) {
96+
for (const [[k2, v2], d2] of other.getInner()) {
9797
if (k1 === k2) {
9898
out.push([[k1, [v1, v2]], d1 * d2])
9999
}
@@ -283,11 +283,8 @@ export class MultiSet<T> {
283283
}
284284

285285
extend(other: MultiSet<T> | MultiSetArray<T>): void {
286-
if (other instanceof MultiSet) {
287-
this.#inner.push(...other.getInner())
288-
} else {
289-
this.#inner.push(...other)
290-
}
286+
const otherArray = other instanceof MultiSet ? other.getInner() : other
287+
chunkedArrayPush(this.#inner, otherArray)
291288
}
292289

293290
getInner(): MultiSetArray<T> {

packages/d2ts/src/sqlite/operators/join.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export class JoinOperatorSQLite<K, V1, V2> extends BinaryOperator<
3434
super(id, inputA, inputB, output, initialFrontier)
3535
this.#indexA = new SQLIndex<K, V1>(db, `join_a_${id}`)
3636
this.#indexB = new SQLIndex<K, V2>(db, `join_b_${id}`)
37-
this.#deltaA = new SQLIndex<K, V1>(db, `join_delta_a_${id}`)
38-
this.#deltaB = new SQLIndex<K, V2>(db, `join_delta_b_${id}`)
37+
this.#deltaA = new SQLIndex<K, V1>(db, `join_delta_a_${id}`, true)
38+
this.#deltaB = new SQLIndex<K, V2>(db, `join_delta_b_${id}`, true)
3939
}
4040

4141
run(): void {

0 commit comments

Comments
 (0)