@minnowdb/core 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/block-format/block.js +254 -325
- package/dist/block-format/checksum.js +30 -52
- package/dist/block-format/codecs.js +112 -125
- package/dist/block-format/column.js +187 -205
- package/dist/block-format/index.js +5 -1
- package/dist/block-format/physical.js +371 -387
- package/dist/block-format/types.js +4 -1
- package/dist/block-format/unicode.js +30 -39
- package/dist/date-value.js +67 -78
- package/dist/engine/artifact-cache.js +106 -116
- package/dist/engine/batch.js +36 -44
- package/dist/engine/buffered-writer.js +156 -158
- package/dist/engine/byte-estimates.js +20 -22
- package/dist/engine/cache-limits.js +24 -25
- package/dist/engine/cancellation.js +5 -3
- package/dist/engine/catalog.js +64 -73
- package/dist/engine/client.js +715 -780
- package/dist/engine/database.js +15942 -19313
- package/dist/engine/defaults.js +104 -111
- package/dist/engine/errors.js +113 -128
- package/dist/engine/fts.js +233 -280
- package/dist/engine/group-index.js +287 -321
- package/dist/engine/index.js +23 -12
- package/dist/engine/join-index.js +177 -186
- package/dist/engine/keyed-live.js +168 -173
- package/dist/engine/live-api.js +0 -1
- package/dist/engine/live-equal.js +32 -37
- package/dist/engine/live.js +603 -647
- package/dist/engine/memory.js +109 -111
- package/dist/engine/optimizer.d.ts +19 -1
- package/dist/engine/optimizer.js +2691 -2933
- package/dist/engine/point-read.js +122 -182
- package/dist/engine/query-api.js +12 -3
- package/dist/engine/query-cache.js +61 -69
- package/dist/engine/query.d.ts +6 -0
- package/dist/engine/query.js +8511 -9980
- package/dist/engine/result-wire.js +221 -252
- package/dist/engine/schema-wire.js +97 -112
- package/dist/engine/schema.js +1099 -1254
- package/dist/engine/sort-keys.js +315 -389
- package/dist/engine/sql-domains.js +646 -769
- package/dist/engine/sql-driver.js +0 -1
- package/dist/engine/sql-functions.js +1031 -1125
- package/dist/engine/sql-json.js +199 -218
- package/dist/engine/sql-semantics.js +572 -639
- package/dist/engine/typed-live.js +271 -293
- package/dist/engine/vector.js +4484 -5145
- package/dist/engine/worker-host.d.ts +8 -63
- package/dist/engine/worker-host.js +28 -1130
- package/dist/engine/worker-indexeddb.d.ts +1 -0
- package/dist/engine/worker-indexeddb.js +3 -0
- package/dist/engine/worker-memory.d.ts +1 -0
- package/dist/engine/worker-memory.js +3 -0
- package/dist/engine/worker-opfs.d.ts +1 -0
- package/dist/engine/worker-opfs.js +3 -0
- package/dist/engine/worker-server.d.ts +93 -0
- package/dist/engine/worker-server.js +999 -0
- package/dist/engine/worker-store-indexeddb.d.ts +2 -0
- package/dist/engine/worker-store-indexeddb.js +11 -0
- package/dist/engine/worker-store-memory.d.ts +2 -0
- package/dist/engine/worker-store-memory.js +6 -0
- package/dist/engine/worker-store-opfs.d.ts +2 -0
- package/dist/engine/worker-store-opfs.js +9 -0
- package/dist/engine/worker.js +0 -12
- package/dist/engine/write-block-planner.js +93 -100
- package/dist/plan/index.js +15 -16
- package/dist/plan/model.d.ts +6 -0
- package/dist/plan/model.js +20 -27
- package/dist/storage/index.js +0 -12
- package/dist/storage/indexeddb.js +11784 -13171
- package/dist/storage/memory.js +1198 -1241
- package/dist/storage/opfs/files.js +238 -295
- package/dist/storage/opfs/index.js +9 -3
- package/dist/storage/opfs/leader.js +4386 -4856
- package/dist/storage/opfs/rpc.js +223 -259
- package/dist/storage/opfs/snapshot-ledger.js +219 -260
- package/dist/storage/opfs/store.js +884 -1003
- package/dist/storage/persistence.js +59 -74
- package/dist/storage/snapshot-stream.js +788 -826
- package/dist/storage/snapshot.js +36 -37
- package/dist/storage/toolkit/extents.js +444 -520
- package/dist/storage/toolkit/index.js +28 -29
- package/dist/storage/toolkit/record-core.js +5804 -6377
- package/dist/storage/toolkit/sync-file.js +34 -42
- package/dist/storage/toolkit/wal.js +92 -127
- package/dist/storage/toolkit/wire.js +232 -256
- package/dist/storage/types.js +2948 -3250
- package/dist/testing/block-store-conformance.js +1556 -1629
- package/dist/testing/index.js +310 -291
- package/dist/testing/opfs-shim.js +280 -312
- package/dist/testing/simulator.js +496 -534
- package/dist/testing/sqllogictest.js +425 -365
- package/dist/transactions/index.js +1464 -1712
- package/dist/worker-protocol/index.js +70 -69
- package/package.json +20 -2
- package/sql-feature-matrix.json +2 -2
package/dist/engine/memory.js
CHANGED
|
@@ -1,120 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
1
|
+
const DEFAULT_QUERY_MEMORY_BUDGET_BYTES = 64 * 1024 * 1024;
|
|
2
|
+
class QueryMemoryBudgetError extends Error {
|
|
3
|
+
label;
|
|
4
|
+
requestedBytes;
|
|
5
|
+
usedBytes;
|
|
6
|
+
budgetBytes;
|
|
7
|
+
name = "QueryMemoryBudgetError";
|
|
8
|
+
constructor(label, requestedBytes, usedBytes, budgetBytes) {
|
|
9
|
+
super(`${label} requested ${String(requestedBytes)} accounted bytes with ${String(usedBytes)} of ${String(budgetBytes)} bytes already reserved`);
|
|
10
|
+
this.label = label;
|
|
11
|
+
this.requestedBytes = requestedBytes;
|
|
12
|
+
this.usedBytes = usedBytes;
|
|
13
|
+
this.budgetBytes = budgetBytes;
|
|
14
|
+
}
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
this.#parent = parent;
|
|
29
|
-
if (parent === undefined)
|
|
30
|
-
this.#state = { budgetBytes, usedBytes: 0, peakBytes: 0 };
|
|
31
|
-
else {
|
|
32
|
-
this.#state = parent.#state;
|
|
33
|
-
parent.#children.add(this);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
get usage() {
|
|
37
|
-
return { ...this.#state };
|
|
38
|
-
}
|
|
39
|
-
createChild() {
|
|
40
|
-
this.#assertOpen();
|
|
41
|
-
return new QueryMemoryContext(this.#state.budgetBytes, this);
|
|
42
|
-
}
|
|
43
|
-
reserve(bytes, label) {
|
|
44
|
-
this.#assertOpen();
|
|
45
|
-
validateMemoryBytes(bytes, "Query memory reservation");
|
|
46
|
-
const nextUsed = this.#state.usedBytes + bytes;
|
|
47
|
-
if (!Number.isSafeInteger(nextUsed) || nextUsed > this.#state.budgetBytes) {
|
|
48
|
-
throw new QueryMemoryBudgetError(label, bytes, this.#state.usedBytes, this.#state.budgetBytes);
|
|
49
|
-
}
|
|
50
|
-
this.#state.usedBytes = nextUsed;
|
|
51
|
-
this.#state.peakBytes = Math.max(this.#state.peakBytes, nextUsed);
|
|
52
|
-
const reservation = new QueryMemoryReservation(this, bytes);
|
|
53
|
-
this.#reservations.add(reservation);
|
|
54
|
-
return reservation;
|
|
16
|
+
class QueryMemoryContext {
|
|
17
|
+
#state;
|
|
18
|
+
#parent;
|
|
19
|
+
#children = /* @__PURE__ */ new Set();
|
|
20
|
+
#reservations = /* @__PURE__ */ new Set();
|
|
21
|
+
#talliedBytes = 0;
|
|
22
|
+
#closed = false;
|
|
23
|
+
constructor(budgetBytes = DEFAULT_QUERY_MEMORY_BUDGET_BYTES, parent) {
|
|
24
|
+
if (!Number.isSafeInteger(budgetBytes) || budgetBytes < 0) {
|
|
25
|
+
throw new RangeError("Query memory budget must be a non-negative safe integer");
|
|
55
26
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*/
|
|
63
|
-
tally(bytes, label) {
|
|
64
|
-
this.#assertOpen();
|
|
65
|
-
validateMemoryBytes(bytes, "Query memory reservation");
|
|
66
|
-
const nextUsed = this.#state.usedBytes + bytes;
|
|
67
|
-
if (!Number.isSafeInteger(nextUsed) || nextUsed > this.#state.budgetBytes) {
|
|
68
|
-
throw new QueryMemoryBudgetError(label, bytes, this.#state.usedBytes, this.#state.budgetBytes);
|
|
69
|
-
}
|
|
70
|
-
this.#state.usedBytes = nextUsed;
|
|
71
|
-
this.#state.peakBytes = Math.max(this.#state.peakBytes, nextUsed);
|
|
72
|
-
this.#talliedBytes += bytes;
|
|
27
|
+
this.#parent = parent;
|
|
28
|
+
if (parent === void 0)
|
|
29
|
+
this.#state = { budgetBytes, usedBytes: 0, peakBytes: 0 };
|
|
30
|
+
else {
|
|
31
|
+
this.#state = parent.#state;
|
|
32
|
+
parent.#children.add(this);
|
|
73
33
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
34
|
+
}
|
|
35
|
+
get usage() {
|
|
36
|
+
return { ...this.#state };
|
|
37
|
+
}
|
|
38
|
+
createChild() {
|
|
39
|
+
this.#assertOpen();
|
|
40
|
+
return new QueryMemoryContext(this.#state.budgetBytes, this);
|
|
41
|
+
}
|
|
42
|
+
reserve(bytes, label) {
|
|
43
|
+
this.#assertOpen();
|
|
44
|
+
validateMemoryBytes(bytes, "Query memory reservation");
|
|
45
|
+
const nextUsed = this.#state.usedBytes + bytes;
|
|
46
|
+
if (!Number.isSafeInteger(nextUsed) || nextUsed > this.#state.budgetBytes) {
|
|
47
|
+
throw new QueryMemoryBudgetError(label, bytes, this.#state.usedBytes, this.#state.budgetBytes);
|
|
88
48
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
49
|
+
this.#state.usedBytes = nextUsed;
|
|
50
|
+
this.#state.peakBytes = Math.max(this.#state.peakBytes, nextUsed);
|
|
51
|
+
const reservation = new QueryMemoryReservation(this, bytes);
|
|
52
|
+
this.#reservations.add(reservation);
|
|
53
|
+
return reservation;
|
|
54
|
+
}
|
|
55
|
+
tally(bytes, label) {
|
|
56
|
+
this.#assertOpen();
|
|
57
|
+
validateMemoryBytes(bytes, "Query memory reservation");
|
|
58
|
+
const nextUsed = this.#state.usedBytes + bytes;
|
|
59
|
+
if (!Number.isSafeInteger(nextUsed) || nextUsed > this.#state.budgetBytes) {
|
|
60
|
+
throw new QueryMemoryBudgetError(label, bytes, this.#state.usedBytes, this.#state.budgetBytes);
|
|
99
61
|
}
|
|
62
|
+
this.#state.usedBytes = nextUsed;
|
|
63
|
+
this.#state.peakBytes = Math.max(this.#state.peakBytes, nextUsed);
|
|
64
|
+
this.#talliedBytes += bytes;
|
|
65
|
+
}
|
|
66
|
+
close() {
|
|
67
|
+
if (this.#closed)
|
|
68
|
+
return;
|
|
69
|
+
this.#closed = true;
|
|
70
|
+
for (const child of [...this.#children])
|
|
71
|
+
child.close();
|
|
72
|
+
for (const reservation of [...this.#reservations])
|
|
73
|
+
reservation.release();
|
|
74
|
+
this.#state.usedBytes -= this.#talliedBytes;
|
|
75
|
+
this.#talliedBytes = 0;
|
|
76
|
+
if (this.#state.usedBytes < 0)
|
|
77
|
+
throw new Error("Query memory accounting underflow");
|
|
78
|
+
if (this.#parent !== void 0)
|
|
79
|
+
this.#parent.#children.delete(this);
|
|
80
|
+
}
|
|
81
|
+
release(reservation, bytes) {
|
|
82
|
+
if (!this.#reservations.delete(reservation))
|
|
83
|
+
return;
|
|
84
|
+
this.#state.usedBytes -= bytes;
|
|
85
|
+
if (this.#state.usedBytes < 0)
|
|
86
|
+
throw new Error("Query memory accounting underflow");
|
|
87
|
+
}
|
|
88
|
+
#assertOpen() {
|
|
89
|
+
if (this.#closed)
|
|
90
|
+
throw new Error("Query memory context is closed");
|
|
91
|
+
}
|
|
100
92
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
93
|
+
class QueryMemoryReservation {
|
|
94
|
+
#context;
|
|
95
|
+
bytes;
|
|
96
|
+
#released = false;
|
|
97
|
+
constructor(context, bytes) {
|
|
98
|
+
this.#context = context;
|
|
99
|
+
this.bytes = bytes;
|
|
100
|
+
}
|
|
101
|
+
release() {
|
|
102
|
+
if (this.#released)
|
|
103
|
+
return;
|
|
104
|
+
this.#released = true;
|
|
105
|
+
this.#context.release(this, this.bytes);
|
|
106
|
+
}
|
|
115
107
|
}
|
|
116
108
|
function validateMemoryBytes(bytes, label) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
if (!Number.isSafeInteger(bytes) || bytes < 0) {
|
|
110
|
+
throw new RangeError(`${label} must be a non-negative safe integer`);
|
|
111
|
+
}
|
|
120
112
|
}
|
|
113
|
+
export {
|
|
114
|
+
DEFAULT_QUERY_MEMORY_BUDGET_BYTES,
|
|
115
|
+
QueryMemoryBudgetError,
|
|
116
|
+
QueryMemoryContext,
|
|
117
|
+
QueryMemoryReservation
|
|
118
|
+
};
|
|
@@ -5,7 +5,25 @@ import { type CompiledQuery } from "./query.js";
|
|
|
5
5
|
* The optimizer runs before subquery resolution, so subquery blocks optimize recursively and
|
|
6
6
|
* predicates containing subqueries stay self-contained when they move.
|
|
7
7
|
*/
|
|
8
|
-
export declare function optimizePlan(plan: CompiledQuery): CompiledQuery;
|
|
8
|
+
export declare function optimizePlan(plan: CompiledQuery, options?: OptimizeOptions): CompiledQuery;
|
|
9
|
+
export interface OptimizeOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Every unqualified column name in every subquery has been resolved against its scopes, so
|
|
12
|
+
* one that remains is local to its block. Compilation has no catalog and cannot know whether
|
|
13
|
+
* `WHERE region = home_region` inside a subquery reads the subquery's table or the enclosing
|
|
14
|
+
* query's, so it holds back the rewrites that would move such a name into a derived block —
|
|
15
|
+
* an uncorrelated `IN (SELECT …)` becoming a join, an unqualified outer predicate entering a
|
|
16
|
+
* correlation probe. The database applies them after `qualifyCorrelatedReferences`.
|
|
17
|
+
*/
|
|
18
|
+
readonly resolvedNames?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The bind-time half of the calendar rewrite. Compilation runs before parameters exist, so
|
|
22
|
+
* `DATE_TRUNC('day', col) = ?` reaches execution as a per-row call over the whole scan; once
|
|
23
|
+
* the placeholder is a Date literal the same range rewrite applies. Walks every block the
|
|
24
|
+
* optimizer would have — nested sources and subquery blocks included.
|
|
25
|
+
*/
|
|
26
|
+
export declare function rewriteBoundCalendarEqualities(plan: CompiledQuery): void;
|
|
9
27
|
/**
|
|
10
28
|
* Resolves an unqualified column in a nested block against the nearest enclosing query scope
|
|
11
29
|
* when that name does not exist in the nested block itself. Compilation has no catalog, so this
|