mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
Add partial index on material(is_active) for the catalogue read
The modelling_e2e Lambda reads the active catalogue once per invocation (SELECT * FROM material WHERE is_active ORDER BY id). Without an index this was a full seq scan every time (~23ms), paid by all 32 concurrent Lambdas at startup. Partial index on id WHERE is_active returns the active rows already id-ordered — no sort, no filter. Verified on dev: seq scan 23.2ms -> index scan 4.2ms. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4ae4487055
commit
f51fdca3d8
4 changed files with 11671 additions and 2 deletions
1
src/app/db/migrations/0247_glorious_darkhawk.sql
Normal file
1
src/app/db/migrations/0247_glorious_darkhawk.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
CREATE INDEX "idx_material_active" ON "material" USING btree ("id") WHERE "material"."is_active";
|
||||
11654
src/app/db/migrations/meta/0247_snapshot.json
Normal file
11654
src/app/db/migrations/meta/0247_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1723,6 +1723,13 @@
|
|||
"when": 1782498864047,
|
||||
"tag": "0246_minor_lady_bullseye",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 247,
|
||||
"version": "7",
|
||||
"when": 1782730761916,
|
||||
"tag": "0247_glorious_darkhawk",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { InferModel } from "drizzle-orm";
|
||||
import { InferModel, sql } from "drizzle-orm";
|
||||
import {
|
||||
bigserial,
|
||||
text,
|
||||
|
|
@ -8,6 +8,7 @@ import {
|
|||
pgEnum,
|
||||
json,
|
||||
boolean,
|
||||
index,
|
||||
} from "drizzle-orm/pg-core";
|
||||
|
||||
export const MaterialType: [string, ...string[]] = [
|
||||
|
|
@ -125,6 +126,12 @@ export const material = pgTable("material", {
|
|||
includesScaffolding: boolean("includes_scaffolding").default(false),
|
||||
includesBattery: boolean("includes_battery").default(false),
|
||||
batterySize: real("battery_size"),
|
||||
});
|
||||
}, (table) => [
|
||||
// The modelling_e2e Lambda reads the active catalogue once per invocation
|
||||
// (WHERE is_active ORDER BY id). Without this index that is a full seq scan
|
||||
// every time (~23ms, ×32 concurrent at startup). Partial on id so the active
|
||||
// rows come back already id-ordered — no sort, no filter.
|
||||
index("idx_material_active").on(table.id).where(sql`${table.isActive}`),
|
||||
]);
|
||||
|
||||
export type Material = InferModel<typeof material, "select">;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue