Skip to content

Commit 2a79660

Browse files
committed
fix: index tests
1 parent 07c423e commit 2a79660

2 files changed

Lines changed: 55 additions & 34 deletions

File tree

src/remote/gin-indexes.test.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ test("GIN: basic @> containment recommends GIN with jsonb_path_ops", async () =>
8686
reltuples: 100_000,
8787
relallvisible: 1,
8888
columns: [
89-
{ columnName: "id", stats: null },
90-
{ columnName: "data", stats: null },
89+
{ columnName: "id", stats: null, attlen: 8 },
90+
{ columnName: "data", stats: null, attlen: null },
9191
],
9292
indexes: [],
9393
}],
@@ -171,8 +171,8 @@ test("GIN: key existence (?) recommends GIN with default jsonb_ops", async () =>
171171
reltuples: 100_000,
172172
relallvisible: 1,
173173
columns: [
174-
{ columnName: "id", stats: null },
175-
{ columnName: "payload", stats: null },
174+
{ columnName: "id", stats: null, attlen: 8 },
175+
{ columnName: "payload", stats: null, attlen: null },
176176
],
177177
indexes: [],
178178
}],
@@ -258,8 +258,8 @@ test("GIN: any-key existence (?|) recommends GIN with default jsonb_ops", async
258258
reltuples: 100_000,
259259
relallvisible: 1,
260260
columns: [
261-
{ columnName: "id", stats: null },
262-
{ columnName: "payload", stats: null },
261+
{ columnName: "id", stats: null, attlen: 8 },
262+
{ columnName: "payload", stats: null, attlen: null },
263263
],
264264
indexes: [],
265265
}],
@@ -342,8 +342,8 @@ test("GIN: all-keys existence (?&) recommends GIN with default jsonb_ops", async
342342
reltuples: 100_000,
343343
relallvisible: 1,
344344
columns: [
345-
{ columnName: "id", stats: null },
346-
{ columnName: "payload", stats: null },
345+
{ columnName: "id", stats: null, attlen: 8 },
346+
{ columnName: "payload", stats: null, attlen: null },
347347
],
348348
indexes: [],
349349
}],
@@ -428,9 +428,9 @@ test("GIN: mixed JSONB and regular column produces both GIN and B-tree", async (
428428
reltuples: 100_000,
429429
relallvisible: 1,
430430
columns: [
431-
{ columnName: "id", stats: null },
432-
{ columnName: "data", stats: null },
433-
{ columnName: "price", stats: null },
431+
{ columnName: "id", stats: null, attlen: 8 },
432+
{ columnName: "data", stats: null, attlen: null },
433+
{ columnName: "price", stats: null, attlen: 8 },
434434
],
435435
indexes: [],
436436
}],
@@ -536,8 +536,8 @@ test("GIN: mixed @> and ? on same column escalates to jsonb_ops", async () => {
536536
reltuples: 100_000,
537537
relallvisible: 1,
538538
columns: [
539-
{ columnName: "id", stats: null },
540-
{ columnName: "data", stats: null },
539+
{ columnName: "id", stats: null, attlen: 8 },
540+
{ columnName: "data", stats: null, attlen: null },
541541
],
542542
indexes: [],
543543
}],
@@ -626,8 +626,8 @@ test("GIN: table alias resolves to correct table for GIN recommendation", async
626626
reltuples: 100_000,
627627
relallvisible: 1,
628628
columns: [
629-
{ columnName: "id", stats: null },
630-
{ columnName: "data", stats: null },
629+
{ columnName: "id", stats: null, attlen: 8 },
630+
{ columnName: "data", stats: null, attlen: null },
631631
],
632632
indexes: [],
633633
}],
@@ -710,8 +710,8 @@ test("GIN: non-JSONB query produces B-tree only, no GIN", async () => {
710710
reltuples: 100_000,
711711
relallvisible: 1,
712712
columns: [
713-
{ columnName: "id", stats: null },
714-
{ columnName: "name", stats: null },
713+
{ columnName: "id", stats: null, attlen: 8 },
714+
{ columnName: "name", stats: null, attlen: 20 },
715715
],
716716
indexes: [],
717717
}],
@@ -802,14 +802,17 @@ test("GIN: existing GIN index prevents duplicate recommendation", async () => {
802802
reltuples: 100_000,
803803
relallvisible: 1,
804804
columns: [
805-
{ columnName: "id", stats: null },
806-
{ columnName: "data", stats: null },
805+
{ columnName: "id", stats: null, attlen: 8 },
806+
{ columnName: "data", stats: null, attlen: null },
807807
],
808808
indexes: [{
809809
indexName: "idx_products_data",
810810
relpages: 50,
811811
reltuples: 100_000,
812812
relallvisible: 1,
813+
amname: "gin",
814+
columns: [{ attlen: null }],
815+
fillfactor: 0.9
813816
}],
814817
}],
815818
});

src/remote/query-optimizer.test.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,22 @@ test("controller syncs correctly", async () => {
8484
columns: [{
8585
columnName: "a",
8686
stats: null,
87+
attlen: null,
8788
}, {
8889
columnName: "b",
8990
stats: null,
91+
attlen: null,
9092
}],
9193
indexes: [{
9294
indexName: "testing_index",
9395
relpages: 2,
9496
reltuples: 10000,
9597
relallvisible: 1,
98+
amname: "btree",
99+
columns: [{
100+
attlen: 8
101+
}],
102+
fillfactor: 0.9,
96103
}],
97104
}],
98105
});
@@ -157,15 +164,20 @@ test("controller syncs correctly", async () => {
157164
columns: [{
158165
columnName: "a",
159166
stats: null,
167+
attlen: 8,
160168
}, {
161169
columnName: "b",
162170
stats: null,
171+
attlen: 8,
163172
}],
164173
indexes: [{
165174
indexName: "testing_index",
166175
relpages: 2,
167176
reltuples: 10000,
168177
relallvisible: 1,
178+
amname: "btree",
179+
columns: [{ attlen: 8 }],
180+
fillfactor: 0.9,
169181
}],
170182
}],
171183
});
@@ -223,14 +235,17 @@ test("disabling an index removes it from indexesUsed and recommends it", async (
223235
reltuples: 10_000_000,
224236
relallvisible: 1,
225237
columns: [
226-
{ columnName: "id", stats: null },
227-
{ columnName: "email", stats: null },
238+
{ columnName: "id", stats: null, attlen: null },
239+
{ columnName: "email", stats: null, attlen: null },
228240
],
229241
indexes: [{
230242
indexName: "users_email_idx",
231243
relpages: 100,
232244
reltuples: 10_000_000,
233245
relallvisible: 1,
246+
amname: "btree",
247+
fillfactor: 0.9,
248+
columns: [{ attlen: null }],
234249
}],
235250
}],
236251
};
@@ -392,11 +407,11 @@ test("hypertable optimization includes index recommendations", async () => {
392407
reltuples: 100_000,
393408
relallvisible: 1,
394409
columns: [
395-
{ columnName: "time", stats: null },
396-
{ columnName: "sensor_id", stats: null },
397-
{ columnName: "aqi", stats: null },
398-
{ columnName: "pm25_ugm3", stats: null },
399-
{ columnName: "pm10_ugm3", stats: null },
410+
{ columnName: "time", stats: null, attlen: null },
411+
{ columnName: "sensor_id", stats: null, attlen: null },
412+
{ columnName: "aqi", stats: null, attlen: null },
413+
{ columnName: "pm25_ugm3", stats: null, attlen: null },
414+
{ columnName: "pm10_ugm3", stats: null, attlen: null },
400415
],
401416
indexes: [],
402417
},
@@ -407,9 +422,9 @@ test("hypertable optimization includes index recommendations", async () => {
407422
reltuples: 100,
408423
relallvisible: 1,
409424
columns: [
410-
{ columnName: "id", stats: null },
411-
{ columnName: "name", stats: null },
412-
{ columnName: "location_type", stats: null },
425+
{ columnName: "id", stats: null, attlen: null },
426+
{ columnName: "name", stats: null, attlen: null },
427+
{ columnName: "location_type", stats: null, attlen: null },
413428
],
414429
indexes: [],
415430
},
@@ -490,8 +505,8 @@ test("timed out queries are retried with exponential backoff up to maxRetries",
490505
reltuples: 1_000_000,
491506
relallvisible: 1,
492507
columns: [
493-
{ columnName: "id", stats: null },
494-
{ columnName: "data", stats: null },
508+
{ columnName: "id", stats: null, attlen: null },
509+
{ columnName: "data", stats: null, attlen: null },
495510
],
496511
indexes: [],
497512
}],
@@ -577,15 +592,18 @@ test("optimizer does not treat ASC index as duplicate of DESC candidate", async
577592
reltuples: 100_000,
578593
relallvisible: 1,
579594
columns: [
580-
{ columnName: "id", stats: null },
581-
{ columnName: "created_at", stats: null },
582-
{ columnName: "status", stats: null },
595+
{ columnName: "id", stats: null, attlen: null },
596+
{ columnName: "created_at", stats: null, attlen: null },
597+
{ columnName: "status", stats: null, attlen: null },
583598
],
584599
indexes: [{
585600
indexName: "orders_multi_asc",
586601
relpages: 50,
587602
reltuples: 100_000,
588603
relallvisible: 1,
604+
amname: "btree",
605+
fillfactor: 0.9,
606+
columns: [{ attlen: null }, { attlen: null }],
589607
}],
590608
}],
591609
});

0 commit comments

Comments
 (0)