25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(query): bound editable metadata preflight across all databases
t8y281850df0d11b
diff --git a/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.ts b/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.tsindex 7925142ba7..00474b4a7d 100644--- a/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.ts+++ b/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.ts@@ -159,6 +159,22 @@ describe("queryStore hidden primary key editing", () => {expect(tab.queryEditabilityReason).toBeUndefined();}, 10_000);+ it("falls back to the original SQL for non-Oracle databases when editability metadata exceeds the preflight budget", async () => {+ // 慢元数据:列/索引加载永不在预算内返回,触发对所有数据库统一施加的 1s preflight 预算超时。+ // 泛化前仅 Oracle/Xugu 有此预算,MySQL 等会被慢元数据阻塞到结果显示。+ getColumns.mockReturnValue(deferred<never[]>().promise);+ listIndexes.mockReturnValue(deferred<never[]>().promise);++ const { useQueryStore } = await import("@/stores/queryStore");+ const store = useQueryStore();+ const tabId = store.createTab("mysql-1", "app", "Query");++ await store.executeTabSql(tabId, "SELECT name FROM users");++ // 预算超时后先出结果:执行原始 SQL、未注入隐藏主键(可编辑能力随后台加载补齐)。+ expect(executeMulti).toHaveBeenCalledWith("mysql-1", "app", "SELECT name FROM users", undefined, expect.any(String), expect.objectContaining({ timeoutSecs: 30 }));+ }, 10_000);+it("appends the hidden primary key for Dameng tables whose columns keep the created case", async () => {// #10233: Dameng keeps the case an unquoted identifier was created with, so the// server reports `name` while the Oracle-family dialect handling folds the SQLdiff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.tsindex 206150f531..a52ad3fd74 100644--- a/apps/desktop/src/stores/queryStore.ts+++ b/apps/desktop/src/stores/queryStore.ts@@ -168,8 +168,8 @@ const QUERY_RESULT_EXPORT_UNSUPPORTED_ERROR = "Streaming export is unsupported fconst 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 QUERY_METADATA_PREFLIGHT_BUDGET_MS = 1_000;+const QUERY_METADATA_PREFLIGHT_TIMEOUT = Symbol("query-metadata-preflight-timeout");const SAVED_SQL_EDITOR_POSITION_PERSIST_DELAY_MS = 500;type CloseConfirmContext = "tab" | "batch" | "app";@@ -780,13 +780,13 @@ async function withCancelQueryTimeout<T>(promise: Promise<T>): Promise<T> {}}-async function waitForOracleQueryMetadataPreflight<T>(promise: Promise<T>): Promise<T | typeof ORACLE_QUERY_METADATA_PREFLIGHT_TIMEOUT> {+async function waitForQueryMetadataPreflight<T>(promise: Promise<T>): Promise<T | typeof 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);+ new Promise<typeof QUERY_METADATA_PREFLIGHT_TIMEOUT>((resolve) => {+ timer = setTimeout(() => resolve(QUERY_METADATA_PREFLIGHT_TIMEOUT), QUERY_METADATA_PREFLIGHT_BUDGET_MS);}),]);} finally {@@ -6276,12 +6276,12 @@ export const useQueryStore = defineStore("query", () => {void fullMetadataPromise.catch((error) => queryExecutionLog("warn", "metadata:table-prefetch:failed", { traceId, error, elapsed: elapsed() }));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) {+ const indexes = await waitForQueryMetadataPreflight(loadTableIndexes(target.request));+ if (indexes === QUERY_METADATA_PREFLIGHT_TIMEOUT) {queryExecutionLog("info", "metadata:preflight:timeout", {traceId,table: target.request.tableName,- budgetMs: ORACLE_QUERY_METADATA_PREFLIGHT_BUDGET_MS,+ budgetMs: QUERY_METADATA_PREFLIGHT_BUDGET_MS,elapsed: elapsed(),});return unchanged;@@ -6291,7 +6291,23 @@ export const useQueryStore = defineStore("query", () => {loaded = loadedEditableSourceFromMetadata(target, (await fullMetadataPromise).metadata);}- loaded ??= await loadEditableQuerySource(tab, analysis, source, conn, databaseType, executionDatabase, traceId, elapsed);+ if (!loaded) {+ // 可编辑性所需的源表元数据加载,对所有数据库统一施加预算上限:慢元数据+ // (如 SQLServer 只读账号、宽表、跨 schema 同义词)超时则先显示查询结果、+ // 放弃本次结果可编辑;loadEditableQuerySource 仍在后台完成加载并写入缓存,+ // 下次打开同一查询即可编辑(原先仅 Oracle/Xugu 有预算,其它库会被慢元数据阻塞)。+ const loadedOrTimeout = await waitForQueryMetadataPreflight(loadEditableQuerySource(tab, analysis, source, conn, databaseType, executionDatabase, traceId, elapsed));+ if (loadedOrTimeout === QUERY_METADATA_PREFLIGHT_TIMEOUT) {+ queryExecutionLog("info", "metadata:preflight:timeout", {+ traceId,+ table: target.request.tableName,+ budgetMs: QUERY_METADATA_PREFLIGHT_BUDGET_MS,+ elapsed: elapsed(),+ });+ return unchanged;+ }+ loaded = loadedOrTimeout;+ }if (loaded.tableMeta.columns.length === 0) return unchanged;if (loaded.tableMeta.tableType?.toUpperCase().includes("VIEW")) return unchanged;const columnPrimaryKeys = loaded.tableMeta.columns.filter((column) => column.is_primary_key).map((column) => column.name);