Files
openclaw/scripts/lib/sqlite-query-plan-evidence.ts
Vincent Koc 608e365ce4 improve(sqlite): report production workloads independently (#130994)
* perf(scripts): report SQLite scenarios independently

* perf(sqlite): benchmark production state workloads

* test(sqlite): use tracked benchmark temp dirs

* perf(sqlite): harden workload evidence

* fix(perf): require matching SQLite workloads
2026-08-28 01:02:42 +08:00

32 lines
916 B
TypeScript

export type SqliteQueryPlanEvidence = {
fullTableScans: string[];
indexes: string[];
raw: string[];
tempSorts: string[];
};
const INDEX_PATTERN = /\bUSING ((?:(?:AUTOMATIC|PARTIAL|COVERING)\s+)*INDEX)(?:\s+([^\s(]+))?/iu;
const NON_TABLE_SCAN_PATTERN = /\b(?:CONSTANT ROW|SUBQUERY|VALUES CLAUSE|VIRTUAL TABLE INDEX)\b/iu;
export function collectSqliteQueryPlanEvidence(raw: string[]): SqliteQueryPlanEvidence {
const indexes = [
...new Set(
raw.flatMap((detail) => {
const match = INDEX_PATTERN.exec(detail);
return match?.[1] ? [match[2] ?? match[1]] : [];
}),
),
];
return {
fullTableScans: raw.filter(
(detail) =>
/^\s*SCAN \S+/iu.test(detail) &&
!/\bUSING\b/iu.test(detail) &&
!NON_TABLE_SCAN_PATTERN.test(detail),
),
indexes,
raw,
tempSorts: raw.filter((detail) => detail.includes("USE TEMP B-TREE")),
};
}