perf(oracle): stop slow index metadata from blocking first query
This commit is contained in:
2 files changed
+92
-4
No files matched your search
@@ -104,6 +104,8 @@ const QUERY_RESULT_EXPORT_UNSUPPORTED_ERROR = "Streaming export is unsupported f
|
||||
const BACKGROUND_CLIENT_SESSION_SUFFIXES = ["count", "explain", "export"] as const;
|
||||
const CANCEL_QUERY_TIMEOUT_MS = 10_000;
|
||||
const CANCEL_ACK_SETTLE_TIMEOUT_MS = 2_000;
|
||||
const ORACLE_QUERY_METADATA_PREFLIGHT_BUDGET_MS = 1_000;
|
||||
const ORACLE_QUERY_METADATA_PREFLIGHT_TIMEOUT = Symbol("oracle-query-metadata-preflight-timeout");
|
||||
const SAVED_SQL_EDITOR_POSITION_PERSIST_DELAY_MS = 500;
|
||||
type CloseConfirmContext = "tab" | "batch" | "app";
|
||||
|
||||
@@ -529,6 +531,20 @@ async function withCancelQueryTimeout<T>(promise: Promise<T>): Promise<T> {
|
||||
}
|
||||
}
|
||||
|
||||
async function waitForOracleQueryMetadataPreflight<T>(promise: Promise<T>): Promise<T | typeof ORACLE_QUERY_METADATA_PREFLIGHT_TIMEOUT> {
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
try {
|
||||
return await Promise.race([
|
||||
promise,
|
||||
new Promise<typeof ORACLE_QUERY_METADATA_PREFLIGHT_TIMEOUT>((resolve) => {
|
||||
timer = setTimeout(() => resolve(ORACLE_QUERY_METADATA_PREFLIGHT_TIMEOUT), ORACLE_QUERY_METADATA_PREFLIGHT_BUDGET_MS);
|
||||
}),
|
||||
]);
|
||||
} finally {
|
||||
if (timer) clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeUppercaseFoldedMetadataIdentifier(dbType: string, identifier: string | undefined, quoted?: boolean) {
|
||||
if (!identifier || quoted || !UPPERCASE_FOLDED_METADATA_TYPES.has(dbType)) return identifier;
|
||||
return identifier.toUpperCase();
|
||||
@@ -4051,9 +4067,19 @@ export const useQueryStore = defineStore("query", () => {
|
||||
traceLogger: (event) => queryExecutionLog("debug", "metadata:table-trace", { sourceTraceId: traceId, ...event }),
|
||||
});
|
||||
void fullMetadataPromise.catch((error) => queryExecutionLog("warn", "metadata:table-prefetch:failed", { traceId, error, elapsed: elapsed() }));
|
||||
const indexes = await loadTableIndexes(target.request);
|
||||
if (primaryKeyIndex(indexes) && projectsAllColumnsForSource(target.analysis, target.source.key) && tab.autoCommit !== false) {
|
||||
return unchanged;
|
||||
const wholeSourceAutoCommit = projectsAllColumnsForSource(target.analysis, target.source.key) && tab.autoCommit !== false;
|
||||
if (wholeSourceAutoCommit) {
|
||||
const indexes = await waitForOracleQueryMetadataPreflight(loadTableIndexes(target.request));
|
||||
if (indexes === ORACLE_QUERY_METADATA_PREFLIGHT_TIMEOUT) {
|
||||
queryExecutionLog("info", "metadata:preflight:timeout", {
|
||||
traceId,
|
||||
table: target.request.tableName,
|
||||
budgetMs: ORACLE_QUERY_METADATA_PREFLIGHT_BUDGET_MS,
|
||||
elapsed: elapsed(),
|
||||
});
|
||||
return unchanged;
|
||||
}
|
||||
if (primaryKeyIndex(indexes)) return unchanged;
|
||||
}
|
||||
loaded = loadedEditableSourceFromMetadata(target, (await fullMetadataPromise).metadata);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user