@minnowdb/core 0.6.9 → 0.7.1
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.d.ts +5 -0
- package/dist/date-value.js +71 -41
- 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 +15952 -18465
- 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 +2642 -2515
- package/dist/engine/point-read.d.ts +4 -2
- package/dist/engine/point-read.js +121 -171
- package/dist/engine/query-api.js +12 -3
- package/dist/engine/query-cache.js +61 -69
- package/dist/engine/query.d.ts +45 -0
- package/dist/engine/query.js +8506 -9375
- 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.d.ts +7 -1
- package/dist/engine/sql-domains.js +648 -734
- package/dist/engine/sql-driver.js +0 -1
- package/dist/engine/sql-functions.d.ts +11 -0
- package/dist/engine/sql-functions.js +1092 -0
- package/dist/engine/sql-json.js +199 -218
- package/dist/engine/sql-semantics.d.ts +25 -4
- package/dist/engine/sql-semantics.js +579 -513
- package/dist/engine/typed-live.js +271 -293
- package/dist/engine/vector.d.ts +7 -1
- package/dist/engine/vector.js +4513 -4580
- 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 +9 -1
- package/dist/plan/model.js +20 -27
- package/dist/storage/index.js +0 -12
- package/dist/storage/indexeddb.js +11776 -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 +5792 -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 +2952 -3228
- 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/postgres-feature-profile.json +15 -5
- package/sql-feature-matrix.json +252 -2
package/dist/engine/index.js
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The everyday in-thread API. Larger optional surfaces have their own entry points so exporting
|
|
3
|
-
* one helper cannot make an application download the worker client or typed live-query layer.
|
|
4
|
-
*/
|
|
5
1
|
export * from "./catalog.js";
|
|
6
2
|
export * from "./database.js";
|
|
7
3
|
export * from "./errors.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
import { QueryMemoryBudgetError } from "./memory.js";
|
|
5
|
+
import { MAX_SQL_NESTING_DEPTH, MAX_SQL_NUMERIC_DIGITS, MAX_SQL_PARAMETERS, MAX_SQL_PATTERN_CHARACTERS, MAX_SQL_PATTERN_MATCH_STEPS, MAX_SQL_SCALAR_RESULT_CHARACTERS, MAX_SQL_STRUCTURED_VALUE_DEPTH, MAX_SQL_STRUCTURED_VALUE_ITEMS, MAX_SQL_TEXT_CHARACTERS, MAX_SQL_TOKENS } from "./cache-limits.js";
|
|
6
|
+
import { column, foreignKeyName, isDestructiveStep, planMigration, schema, table, view } from "./schema.js";
|
|
7
|
+
export {
|
|
8
|
+
MAX_SQL_NESTING_DEPTH,
|
|
9
|
+
MAX_SQL_NUMERIC_DIGITS,
|
|
10
|
+
MAX_SQL_PARAMETERS,
|
|
11
|
+
MAX_SQL_PATTERN_CHARACTERS,
|
|
12
|
+
MAX_SQL_PATTERN_MATCH_STEPS,
|
|
13
|
+
MAX_SQL_SCALAR_RESULT_CHARACTERS,
|
|
14
|
+
MAX_SQL_STRUCTURED_VALUE_DEPTH,
|
|
15
|
+
MAX_SQL_STRUCTURED_VALUE_ITEMS,
|
|
16
|
+
MAX_SQL_TEXT_CHARACTERS,
|
|
17
|
+
MAX_SQL_TOKENS,
|
|
18
|
+
QueryMemoryBudgetError,
|
|
19
|
+
column,
|
|
20
|
+
foreignKeyName,
|
|
21
|
+
isDestructiveStep,
|
|
22
|
+
planMigration,
|
|
23
|
+
schema,
|
|
24
|
+
table,
|
|
25
|
+
view
|
|
26
|
+
};
|
|
@@ -1,203 +1,194 @@
|
|
|
1
1
|
import { dateMilliseconds } from "../date-value.js";
|
|
2
|
-
import { copyScratchKey, encodeSingleScalarKey, equalsScratch, hashScratch, safeDouble, safeProduct
|
|
2
|
+
import { copyScratchKey, encodeSingleScalarKey, equalsScratch, hashScratch, safeDouble, safeProduct } from "./group-index.js";
|
|
3
3
|
const INITIAL_ENTRY_CAPACITY = 4;
|
|
4
4
|
const INITIAL_BUCKET_CAPACITY = 8;
|
|
5
5
|
const INITIAL_KEY_CAPACITY = 32;
|
|
6
6
|
const ENTRY_FIELDS = 6;
|
|
7
7
|
const UINT32_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
throw new RangeError("Join index row capacity must be a non-negative safe integer");
|
|
29
|
-
}
|
|
30
|
-
this.#memory = memory;
|
|
31
|
-
memory.reserve(safeProduct(rowCapacity, Int32Array.BYTES_PER_ELEMENT, "Join duplicate row chains"), "Join duplicate row chains");
|
|
32
|
-
this.#rowNext = new Int32Array(rowCapacity);
|
|
33
|
-
this.#rowNext.fill(-1);
|
|
8
|
+
class ByteJoinIndex {
|
|
9
|
+
#memory;
|
|
10
|
+
#rowNext;
|
|
11
|
+
#buckets = new Int32Array(0);
|
|
12
|
+
#hashes = new Uint32Array(0);
|
|
13
|
+
#offsets = new Uint32Array(0);
|
|
14
|
+
#lengths = new Uint32Array(0);
|
|
15
|
+
#bucketNext = new Int32Array(0);
|
|
16
|
+
#rowHeads = new Int32Array(0);
|
|
17
|
+
#rowTails = new Int32Array(0);
|
|
18
|
+
#keys = new Uint8Array(0);
|
|
19
|
+
#keyLength = 0;
|
|
20
|
+
#entryCount = 0;
|
|
21
|
+
#unique = true;
|
|
22
|
+
#entryReservation;
|
|
23
|
+
#bucketReservation;
|
|
24
|
+
#keyReservation;
|
|
25
|
+
constructor(memory, rowCapacity) {
|
|
26
|
+
if (!Number.isSafeInteger(rowCapacity) || rowCapacity < 0) {
|
|
27
|
+
throw new RangeError("Join index row capacity must be a non-negative safe integer");
|
|
34
28
|
}
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
this.#memory = memory;
|
|
30
|
+
memory.reserve(safeProduct(rowCapacity, Int32Array.BYTES_PER_ELEMENT, "Join duplicate row chains"), "Join duplicate row chains");
|
|
31
|
+
this.#rowNext = new Int32Array(rowCapacity);
|
|
32
|
+
this.#rowNext.fill(-1);
|
|
33
|
+
}
|
|
34
|
+
get unique() {
|
|
35
|
+
return this.#unique;
|
|
36
|
+
}
|
|
37
|
+
add(value, row) {
|
|
38
|
+
if (!Number.isSafeInteger(row) || row < 0 || row >= this.#rowNext.length) {
|
|
39
|
+
throw new RangeError("Join index row is outside its declared capacity");
|
|
37
40
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.#rowNext[tail] = row;
|
|
52
|
-
this.#rowTails[existing] = row;
|
|
53
|
-
this.#unique = false;
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const encoded = copyScratchKey(length);
|
|
57
|
-
const index = this.#entryCount;
|
|
58
|
-
this.#ensureEntryCapacity(index + 1);
|
|
59
|
-
this.#ensureBucketCapacity(index + 1);
|
|
60
|
-
this.#ensureKeyCapacity(encoded.byteLength);
|
|
61
|
-
const offset = this.#keyLength;
|
|
62
|
-
this.#keys.set(encoded, offset);
|
|
63
|
-
this.#keyLength += encoded.byteLength;
|
|
64
|
-
this.#hashes[index] = hash;
|
|
65
|
-
this.#offsets[index] = offset;
|
|
66
|
-
this.#lengths[index] = encoded.byteLength;
|
|
67
|
-
this.#rowHeads[index] = row;
|
|
68
|
-
this.#rowTails[index] = row;
|
|
69
|
-
const bucket = hash & (this.#buckets.length - 1);
|
|
70
|
-
this.#bucketNext[index] = this.#buckets[bucket] ?? -1;
|
|
71
|
-
this.#buckets[bucket] = index;
|
|
72
|
-
this.#entryCount += 1;
|
|
41
|
+
const length = encodeJoinKey(value);
|
|
42
|
+
if (length < 0)
|
|
43
|
+
return;
|
|
44
|
+
const hash = hashScratch(length);
|
|
45
|
+
const existing = this.#find(length, hash);
|
|
46
|
+
if (existing >= 0) {
|
|
47
|
+
const tail = this.#rowTails[existing] ?? -1;
|
|
48
|
+
if (tail < 0)
|
|
49
|
+
throw new Error("Join index row chain is corrupt");
|
|
50
|
+
this.#rowNext[tail] = row;
|
|
51
|
+
this.#rowTails[existing] = row;
|
|
52
|
+
this.#unique = false;
|
|
53
|
+
return;
|
|
73
54
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
55
|
+
const encoded = copyScratchKey(length);
|
|
56
|
+
const index = this.#entryCount;
|
|
57
|
+
this.#ensureEntryCapacity(index + 1);
|
|
58
|
+
this.#ensureBucketCapacity(index + 1);
|
|
59
|
+
this.#ensureKeyCapacity(encoded.byteLength);
|
|
60
|
+
const offset = this.#keyLength;
|
|
61
|
+
this.#keys.set(encoded, offset);
|
|
62
|
+
this.#keyLength += encoded.byteLength;
|
|
63
|
+
this.#hashes[index] = hash;
|
|
64
|
+
this.#offsets[index] = offset;
|
|
65
|
+
this.#lengths[index] = encoded.byteLength;
|
|
66
|
+
this.#rowHeads[index] = row;
|
|
67
|
+
this.#rowTails[index] = row;
|
|
68
|
+
const bucket = hash & this.#buckets.length - 1;
|
|
69
|
+
this.#bucketNext[index] = this.#buckets[bucket] ?? -1;
|
|
70
|
+
this.#buckets[bucket] = index;
|
|
71
|
+
this.#entryCount += 1;
|
|
72
|
+
}
|
|
73
|
+
firstRow(value) {
|
|
74
|
+
const length = encodeJoinKey(value);
|
|
75
|
+
if (length < 0)
|
|
76
|
+
return -1;
|
|
77
|
+
const index = this.#find(length, hashScratch(length));
|
|
78
|
+
return index < 0 ? -1 : this.#rowHeads[index] ?? -1;
|
|
79
|
+
}
|
|
80
|
+
nextRow(row) {
|
|
81
|
+
return row < 0 || row >= this.#rowNext.length ? -1 : this.#rowNext[row] ?? -1;
|
|
82
|
+
}
|
|
83
|
+
#find(length, hash) {
|
|
84
|
+
if (this.#buckets.length === 0)
|
|
85
|
+
return -1;
|
|
86
|
+
let index = this.#buckets[hash & this.#buckets.length - 1] ?? -1;
|
|
87
|
+
while (index >= 0) {
|
|
88
|
+
if (this.#hashes[index] === hash && this.#lengths[index] === length && equalsScratch(this.#keys, this.#offsets[index] ?? 0, length)) {
|
|
89
|
+
return index;
|
|
90
|
+
}
|
|
91
|
+
index = this.#bucketNext[index] ?? -1;
|
|
80
92
|
}
|
|
81
|
-
|
|
82
|
-
|
|
93
|
+
return -1;
|
|
94
|
+
}
|
|
95
|
+
#ensureEntryCapacity(required) {
|
|
96
|
+
if (required <= this.#hashes.length)
|
|
97
|
+
return;
|
|
98
|
+
let capacity = Math.max(INITIAL_ENTRY_CAPACITY, this.#hashes.length * 2);
|
|
99
|
+
while (capacity < required)
|
|
100
|
+
capacity = safeDouble(capacity, "Join index entries");
|
|
101
|
+
const reservation = this.#memory.reserve(safeProduct(capacity, ENTRY_FIELDS * UINT32_BYTES, "Join index entry storage"), "Join index entry storage");
|
|
102
|
+
try {
|
|
103
|
+
const hashes = new Uint32Array(capacity);
|
|
104
|
+
const offsets = new Uint32Array(capacity);
|
|
105
|
+
const lengths = new Uint32Array(capacity);
|
|
106
|
+
const bucketNext = new Int32Array(capacity);
|
|
107
|
+
const rowHeads = new Int32Array(capacity);
|
|
108
|
+
const rowTails = new Int32Array(capacity);
|
|
109
|
+
bucketNext.fill(-1);
|
|
110
|
+
rowHeads.fill(-1);
|
|
111
|
+
rowTails.fill(-1);
|
|
112
|
+
hashes.set(this.#hashes);
|
|
113
|
+
offsets.set(this.#offsets);
|
|
114
|
+
lengths.set(this.#lengths);
|
|
115
|
+
bucketNext.set(this.#bucketNext);
|
|
116
|
+
rowHeads.set(this.#rowHeads);
|
|
117
|
+
rowTails.set(this.#rowTails);
|
|
118
|
+
this.#hashes = hashes;
|
|
119
|
+
this.#offsets = offsets;
|
|
120
|
+
this.#lengths = lengths;
|
|
121
|
+
this.#bucketNext = bucketNext;
|
|
122
|
+
this.#rowHeads = rowHeads;
|
|
123
|
+
this.#rowTails = rowTails;
|
|
124
|
+
this.#entryReservation?.release();
|
|
125
|
+
this.#entryReservation = reservation;
|
|
126
|
+
} catch (error) {
|
|
127
|
+
reservation.release();
|
|
128
|
+
throw error;
|
|
83
129
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.#lengths[index] === length &&
|
|
92
|
-
equalsScratch(this.#keys, this.#offsets[index] ?? 0, length)) {
|
|
93
|
-
return index;
|
|
94
|
-
}
|
|
95
|
-
index = this.#bucketNext[index] ?? -1;
|
|
96
|
-
}
|
|
97
|
-
return -1;
|
|
130
|
+
}
|
|
131
|
+
#ensureBucketCapacity(requiredEntries) {
|
|
132
|
+
let capacity = this.#buckets.length;
|
|
133
|
+
if (capacity === 0)
|
|
134
|
+
capacity = INITIAL_BUCKET_CAPACITY;
|
|
135
|
+
while (requiredEntries * 4 > capacity * 3) {
|
|
136
|
+
capacity = safeDouble(capacity, "Join index buckets");
|
|
98
137
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
hashes.set(this.#hashes);
|
|
117
|
-
offsets.set(this.#offsets);
|
|
118
|
-
lengths.set(this.#lengths);
|
|
119
|
-
bucketNext.set(this.#bucketNext);
|
|
120
|
-
rowHeads.set(this.#rowHeads);
|
|
121
|
-
rowTails.set(this.#rowTails);
|
|
122
|
-
this.#hashes = hashes;
|
|
123
|
-
this.#offsets = offsets;
|
|
124
|
-
this.#lengths = lengths;
|
|
125
|
-
this.#bucketNext = bucketNext;
|
|
126
|
-
this.#rowHeads = rowHeads;
|
|
127
|
-
this.#rowTails = rowTails;
|
|
128
|
-
this.#entryReservation?.release();
|
|
129
|
-
this.#entryReservation = reservation;
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
reservation.release();
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
138
|
+
if (capacity === this.#buckets.length)
|
|
139
|
+
return;
|
|
140
|
+
const reservation = this.#memory.reserve(safeProduct(capacity, Int32Array.BYTES_PER_ELEMENT, "Join index bucket storage"), "Join index bucket storage");
|
|
141
|
+
try {
|
|
142
|
+
const buckets = new Int32Array(capacity);
|
|
143
|
+
buckets.fill(-1);
|
|
144
|
+
for (let index = 0; index < this.#entryCount; index += 1) {
|
|
145
|
+
const bucket = (this.#hashes[index] ?? 0) & capacity - 1;
|
|
146
|
+
this.#bucketNext[index] = buckets[bucket] ?? -1;
|
|
147
|
+
buckets[bucket] = index;
|
|
148
|
+
}
|
|
149
|
+
this.#buckets = buckets;
|
|
150
|
+
this.#bucketReservation?.release();
|
|
151
|
+
this.#bucketReservation = reservation;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
reservation.release();
|
|
154
|
+
throw error;
|
|
135
155
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
catch (error) {
|
|
159
|
-
reservation.release();
|
|
160
|
-
throw error;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
#ensureKeyCapacity(additionalBytes) {
|
|
164
|
-
const required = this.#keyLength + additionalBytes;
|
|
165
|
-
if (!Number.isSafeInteger(required))
|
|
166
|
-
throw new RangeError("Join key arena is too large");
|
|
167
|
-
if (required > 0xffff_ffff)
|
|
168
|
-
throw new RangeError("Join key arena exceeds uint32 offsets");
|
|
169
|
-
if (required <= this.#keys.byteLength)
|
|
170
|
-
return;
|
|
171
|
-
let capacity = Math.max(INITIAL_KEY_CAPACITY, this.#keys.byteLength * 2);
|
|
172
|
-
while (capacity < required)
|
|
173
|
-
capacity = safeDouble(capacity, "Join key arena");
|
|
174
|
-
const reservation = this.#memory.reserve(capacity, "Join key arena");
|
|
175
|
-
try {
|
|
176
|
-
const keys = new Uint8Array(capacity);
|
|
177
|
-
keys.set(this.#keys.subarray(0, this.#keyLength));
|
|
178
|
-
this.#keys = keys;
|
|
179
|
-
this.#keyReservation?.release();
|
|
180
|
-
this.#keyReservation = reservation;
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
reservation.release();
|
|
184
|
-
throw error;
|
|
185
|
-
}
|
|
156
|
+
}
|
|
157
|
+
#ensureKeyCapacity(additionalBytes) {
|
|
158
|
+
const required = this.#keyLength + additionalBytes;
|
|
159
|
+
if (!Number.isSafeInteger(required))
|
|
160
|
+
throw new RangeError("Join key arena is too large");
|
|
161
|
+
if (required > 4294967295)
|
|
162
|
+
throw new RangeError("Join key arena exceeds uint32 offsets");
|
|
163
|
+
if (required <= this.#keys.byteLength)
|
|
164
|
+
return;
|
|
165
|
+
let capacity = Math.max(INITIAL_KEY_CAPACITY, this.#keys.byteLength * 2);
|
|
166
|
+
while (capacity < required)
|
|
167
|
+
capacity = safeDouble(capacity, "Join key arena");
|
|
168
|
+
const reservation = this.#memory.reserve(capacity, "Join key arena");
|
|
169
|
+
try {
|
|
170
|
+
const keys = new Uint8Array(capacity);
|
|
171
|
+
keys.set(this.#keys.subarray(0, this.#keyLength));
|
|
172
|
+
this.#keys = keys;
|
|
173
|
+
this.#keyReservation?.release();
|
|
174
|
+
this.#keyReservation = reservation;
|
|
175
|
+
} catch (error) {
|
|
176
|
+
reservation.release();
|
|
177
|
+
throw error;
|
|
186
178
|
}
|
|
179
|
+
}
|
|
187
180
|
}
|
|
188
|
-
/**
|
|
189
|
-
* Encodes one join key into the shared scratch arena and returns its byte length, or -1 for keys
|
|
190
|
-
* SQL equality can never match (null, undefined, NaN). Dates coerce to their epoch milliseconds,
|
|
191
|
-
* so a Date and its number representation join as the same key.
|
|
192
|
-
*/
|
|
193
181
|
function encodeJoinKey(value) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
182
|
+
const key = value instanceof Date ? dateMilliseconds(value) : value;
|
|
183
|
+
if (key === null || key === void 0)
|
|
184
|
+
return -1;
|
|
185
|
+
if (typeof key === "number" && Number.isNaN(key))
|
|
186
|
+
return -1;
|
|
187
|
+
if (typeof key === "boolean" || typeof key === "number" || typeof key === "string") {
|
|
188
|
+
return encodeSingleScalarKey(key);
|
|
189
|
+
}
|
|
190
|
+
throw new TypeError("Join keys must be SQL scalar values");
|
|
203
191
|
}
|
|
192
|
+
export {
|
|
193
|
+
ByteJoinIndex
|
|
194
|
+
};
|