@secondlayer/shared 6.14.0 → 6.14.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.
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
|
|
3
|
+
// Composite index backing /v1/index/events keyset pagination for a bare
|
|
4
|
+
// event-type source (no contract/sender/recipient filter). The reader paginates
|
|
5
|
+
// with `event_type = ? AND (block_height, event_index) > (?, ?)
|
|
6
|
+
// ORDER BY block_height, event_index`. Without a leading-event_type composite,
|
|
7
|
+
// Postgres bitmap-ANDs the single-column event_type index — re-scanning the
|
|
8
|
+
// ENTIRE event-type partition (e.g. ~4.2M `print` rows) on every cursor page,
|
|
9
|
+
// turning a backfill into O(n²) (measured ~6.8s/page vs ~50ms for page one).
|
|
10
|
+
// With this index each page is an index range scan. Mirrors the existing
|
|
11
|
+
// (contract_id|sender|recipient, block_height, event_index) composites that
|
|
12
|
+
// already make filtered queries fast.
|
|
13
|
+
//
|
|
14
|
+
// Already created CONCURRENTLY on prod; IF NOT EXISTS makes this a no-op there
|
|
15
|
+
// and a cheap build on fresh/dev databases (small data).
|
|
16
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
17
|
+
await sql`CREATE INDEX IF NOT EXISTS decoded_events_type_height_event_idx ON decoded_events (event_type, block_height, event_index) WHERE canonical`.execute(
|
|
18
|
+
db,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
23
|
+
await sql`DROP INDEX IF EXISTS decoded_events_type_height_event_idx`.execute(
|
|
24
|
+
db,
|
|
25
|
+
);
|
|
26
|
+
}
|