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): 避免 Oracle 慢字段元数据阻塞自动提交查询
zipg9bdf6fb0a02b
diff --git a/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.ts b/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.tsindex d906c4c7d9..e8cdd45fa7 100644--- a/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.ts+++ b/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.ts@@ -959,6 +959,94 @@ describe("queryStore hidden primary key editing", () => {await execution;});+ it.each([+ ["oracle", true],+ ["oracle", false],+ ["xugu", true],+ ["xugu", false],+ ] as const)("starts a %s query (star=%s) when synonym columns are slow and indexes return no key", async (databaseType, selectStar) => {+ const columnsGate = deferred<Awaited<ReturnType<typeof getColumns>>>();+ getConnectionConfig.mockReturnValue({ id: "synonym-1", name: "Synonym", db_type: databaseType, database: "APP", query_timeout_secs: 30 });+ getColumns.mockReturnValue(columnsGate.promise);+ listIndexes.mockResolvedValue([]);+ analyzeEditableQueryEditability.mockImplementation(async () => ({+ editable: true,+ analysis: {+ schema: "APP",+ tableName: "ORDERS_ALIAS",+ selectStar,+ columns: selectStar ? [] : [{ sourceName: "NAME", resultName: "NAME" }],+ },+ }));+ executeMulti.mockResolvedValue([+ {+ columns: selectStar ? ["ID", "NAME"] : ["NAME"],+ rows: selectStar ? [[1, "Alice"]] : [["Alice"]],+ affected_rows: 0,+ execution_time_ms: 18,+ },+ ]);+ const { useQueryStore } = await import("@/stores/queryStore");+ const store = useQueryStore();+ const tabId = store.createTab("synonym-1", "APP", "Query");+ store.setAutoCommit(tabId, true);+ vi.useFakeTimers();+ const sql = `SELECT ${selectStar ? "*" : "NAME"} FROM APP.ORDERS_ALIAS`;+ const execution = store.executeTabSql(tabId, sql);+ try {+ await vi.waitFor(() => expect(getColumns).toHaveBeenCalledOnce());+ expect(executeMulti).not.toHaveBeenCalled();+ await vi.advanceTimersByTimeAsync(1_000);+ expect(executeMulti).toHaveBeenCalledOnce();+ expect(executeMulti.mock.calls[0]?.[2]).toBe(sql);+ await execution;+ expect(store.tabs.find((tab) => tab.id === tabId)?.result?.rows).toEqual(selectStar ? [[1, "Alice"]] : [["Alice"]]);++ columnsGate.resolve([+ { name: "ID", data_type: "NUMBER", is_nullable: false, column_default: null, is_primary_key: true, extra: null },+ { name: "NAME", data_type: "VARCHAR2(100)", is_nullable: true, column_default: null, is_primary_key: false, extra: null },+ ]);+ const { getCachedTableMetadata } = await import("@/lib/metadata/tableMetadataCache");+ await vi.waitFor(() => expect(getCachedTableMetadata({ connectionId: "synonym-1", database: "APP", schema: "APP", tableName: "ORDERS_ALIAS", databaseType })?.metadata.columns).toHaveLength(2));+ expect(getColumns).toHaveBeenCalledOnce();+ expect(listIndexes).toHaveBeenCalledOnce();+ } finally {+ columnsGate.resolve([]);+ await execution;+ await vi.runAllTimersAsync();+ vi.useRealTimers();+ }+ });++ it("shares one Oracle preflight deadline between slow indexes and pending columns", async () => {+ const columnsGate = deferred<Awaited<ReturnType<typeof getColumns>>>();+ const indexesGate = deferred<Awaited<ReturnType<typeof listIndexes>>>();+ getConnectionConfig.mockReturnValue({ id: "oracle-1", name: "Oracle", db_type: "oracle", database: "APP", query_timeout_secs: 30 });+ getColumns.mockReturnValue(columnsGate.promise);+ listIndexes.mockReturnValue(indexesGate.promise);+ analyzeEditableQueryEditability.mockImplementation(async () => ({ editable: true, analysis: { schema: "APP", tableName: "ORDERS_ALIAS", selectStar: true, columns: [] } }));+ const { useQueryStore } = await import("@/stores/queryStore");+ const store = useQueryStore();+ const tabId = store.createTab("oracle-1", "APP", "Query");+ store.setAutoCommit(tabId, true);+ vi.useFakeTimers();+ const execution = store.executeTabSql(tabId, "SELECT * FROM APP.ORDERS_ALIAS");+ try {+ await vi.waitFor(() => expect(listIndexes).toHaveBeenCalledOnce());+ await vi.advanceTimersByTimeAsync(500);+ indexesGate.resolve([]);+ await vi.advanceTimersByTimeAsync(500);+ expect(executeMulti).toHaveBeenCalledOnce();+ await execution;+ } finally {+ indexesGate.resolve([]);+ columnsGate.resolve([]);+ await execution;+ await vi.runAllTimersAsync();+ vi.useRealTimers();+ }+ });+it("starts an Oracle star query when index metadata exceeds the preflight budget", async () => {vi.useFakeTimers();const columnsGate = deferred<Awaited<ReturnType<typeof getColumns>>>();diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.tsindex 8d01f6991d..1148460baa 100644--- a/apps/desktop/src/stores/queryStore.ts+++ b/apps/desktop/src/stores/queryStore.ts@@ -6445,6 +6445,14 @@ 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() }));+ // Synonyms and views often have no directly reported primary index.+ // Bound the full metadata wait as well, including named projections,+ // and start its deadline before waiting for indexes so both share it.+ // Manual transactions still need their first-run type/LOB metadata.+ const preparedMetadata = tab.autoCommit !== false ? waitForQueryMetadataPreflight(fullMetadataPromise) : fullMetadataPromise;+ // The primary-index shortcut can return before this promise is awaited;+ // the original prefetch already records errors in that background path.+ void preparedMetadata.catch(() => undefined);const wholeSourceAutoCommit = projectsAllColumnsForSource(target.analysis, target.source.key) && tab.autoCommit !== false;if (wholeSourceAutoCommit) {const indexes = await waitForQueryMetadataPreflight(loadTableIndexes(target.request));@@ -6459,7 +6467,17 @@ export const useQueryStore = defineStore("query", () => {}if (primaryKeyIndex(indexes)) return unchanged;}- loaded = loadedEditableSourceFromMetadata(target, (await fullMetadataPromise).metadata);+ const metadata = await preparedMetadata;+ if (metadata === 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 = loadedEditableSourceFromMetadata(target, metadata.metadata);}if (!loaded) {