feat(query): resume failed SQL batches safely
This commit is contained in:
16 files changed
+531
-33
No files matched your search
@@ -94,6 +94,19 @@ function structuredTimeoutError() {
|
||||
};
|
||||
}
|
||||
|
||||
function structuredSqlError(detail = "duplicate key") {
|
||||
return {
|
||||
version: 1 as const,
|
||||
code: "DBX-JDBC-4001",
|
||||
messageKey: "backendErrors.jdbc.sqlFailed",
|
||||
messageParams: { stage: "execute" },
|
||||
source: "jdbcAgent" as const,
|
||||
operationOutcome: "unknown" as const,
|
||||
detail,
|
||||
diagnostics: { category: "sql", stage: "execute" },
|
||||
};
|
||||
}
|
||||
|
||||
describe("queryStore multi-statement errors", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -204,6 +217,141 @@ describe("queryStore multi-statement errors", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("skips a failed statement and continues the original batch without replaying successful statements", async () => {
|
||||
const sqlError = structuredSqlError();
|
||||
const sql = "INSERT INTO t VALUES (1);\nINSERT INTO t VALUES (1);\nINSERT INTO t VALUES (2);\nINSERT INTO t VALUES (3)";
|
||||
mocks.executeMultiWithProgress
|
||||
.mockResolvedValueOnce([
|
||||
{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 2, statement_index: 0 },
|
||||
{ columns: ["Error"], rows: [["duplicate key"]], affected_rows: 0, execution_time_ms: 1, statement_index: 1, execution_error: true, error: sqlError },
|
||||
])
|
||||
.mockResolvedValueOnce([
|
||||
{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 2, statement_index: 0 },
|
||||
{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 2, statement_index: 1 },
|
||||
]);
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("mysql-1", "app", "Query", "query", undefined, sql);
|
||||
|
||||
await store.executeTabSql(tabId, sql);
|
||||
expect(store.tabs.find((item) => item.id === tabId)?.batchSqlExecution?.items).toMatchObject([{ status: "success" }, { status: "error" }, { status: "skipped" }, { status: "skipped" }]);
|
||||
|
||||
await expect(store.resumeBatchSql(tabId, "skip")).resolves.toBe(true);
|
||||
|
||||
expect(mocks.executeMultiWithProgress).toHaveBeenCalledTimes(2);
|
||||
expect(mocks.executeMultiWithProgress.mock.calls[1]?.[2]).toBe("INSERT INTO t VALUES (2);\nINSERT INTO t VALUES (3)");
|
||||
expect(mocks.executeMultiWithProgress.mock.calls[1]?.[5]).toMatchObject({ continueOnError: false });
|
||||
const tab = store.tabs.find((item) => item.id === tabId)!;
|
||||
expect(tab.batchSqlExecution?.items).toMatchObject([{ status: "success" }, { status: "error" }, { status: "success" }, { status: "success" }]);
|
||||
expect(tab.results?.map((result) => result.statement_index)).toEqual([0, 1, 2, 3]);
|
||||
expect(tab.results?.[1]?.execution_error).toBe(true);
|
||||
});
|
||||
|
||||
it("retries the failed statement and replaces its previous error result", async () => {
|
||||
const sqlError = structuredSqlError();
|
||||
const sql = "INSERT INTO t VALUES (1);\nINSERT INTO t VALUES (2);\nINSERT INTO t VALUES (3)";
|
||||
mocks.executeMultiWithProgress
|
||||
.mockResolvedValueOnce([
|
||||
{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 2, statement_index: 0 },
|
||||
{ columns: ["Error"], rows: [["duplicate key"]], affected_rows: 0, execution_time_ms: 1, statement_index: 1, execution_error: true, error: sqlError },
|
||||
])
|
||||
.mockResolvedValueOnce([
|
||||
{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 2, statement_index: 0 },
|
||||
{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 2, statement_index: 1 },
|
||||
]);
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("mysql-1", "app", "Query", "query", undefined, sql);
|
||||
|
||||
await store.executeTabSql(tabId, sql);
|
||||
await expect(store.resumeBatchSql(tabId, "retry")).resolves.toBe(true);
|
||||
|
||||
expect(mocks.executeMultiWithProgress.mock.calls[1]?.[2]).toBe("INSERT INTO t VALUES (2);\nINSERT INTO t VALUES (3)");
|
||||
const tab = store.tabs.find((item) => item.id === tabId)!;
|
||||
expect(tab.batchSqlExecution?.items).toMatchObject([{ status: "success" }, { status: "success" }, { status: "success" }]);
|
||||
expect(tab.results?.map((result) => ({ index: result.statement_index, error: result.execution_error }))).toEqual([
|
||||
{ index: 0, error: undefined },
|
||||
{ index: 1, error: undefined },
|
||||
{ index: 2, error: undefined },
|
||||
]);
|
||||
});
|
||||
|
||||
it("retries against the original execution target after the tab target changes", async () => {
|
||||
const sqlError = structuredSqlError();
|
||||
const sql = "INSERT INTO t VALUES (1);\nINSERT INTO t VALUES (2)";
|
||||
mocks.executeMultiWithProgress.mockResolvedValueOnce([{ columns: ["Error"], rows: [["duplicate key"]], affected_rows: 0, execution_time_ms: 1, statement_index: 0, execution_error: true, error: sqlError }]).mockResolvedValueOnce([
|
||||
{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 2, statement_index: 0 },
|
||||
{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 2, statement_index: 1 },
|
||||
]);
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("mysql-1", "app", "Query", "query", undefined, sql);
|
||||
|
||||
await store.executeTabSql(tabId, sql, {
|
||||
executionTarget: {
|
||||
connectionId: "mysql-original",
|
||||
catalog: "catalog-original",
|
||||
database: "database-original",
|
||||
schema: "schema-original",
|
||||
},
|
||||
});
|
||||
const tab = store.tabs.find((item) => item.id === tabId)!;
|
||||
tab.connectionId = "mysql-current";
|
||||
tab.catalog = "catalog-current";
|
||||
tab.database = "database-current";
|
||||
tab.schema = "schema-current";
|
||||
|
||||
await expect(store.resumeBatchSql(tabId, "retry")).resolves.toBe(true);
|
||||
|
||||
expect(mocks.executeMultiWithProgress.mock.calls[1]?.slice(0, 5)).toEqual(["mysql-original", "database-original", sql, expect.any(Function), "schema-original"]);
|
||||
expect(mocks.executeMultiWithProgress.mock.calls[1]?.[5]).toMatchObject({ catalog: "catalog-original" });
|
||||
});
|
||||
|
||||
it("continues past all later SQL errors only for the resumed batch", async () => {
|
||||
const sqlError = structuredSqlError();
|
||||
const sql = "INSERT INTO t VALUES (1);\nINSERT INTO t VALUES (2);\nINSERT INTO t VALUES (3)";
|
||||
mocks.executeMultiWithProgress.mockResolvedValueOnce([{ columns: ["Error"], rows: [["duplicate key"]], affected_rows: 0, execution_time_ms: 1, statement_index: 0, execution_error: true, error: sqlError }]).mockResolvedValueOnce([
|
||||
{ columns: ["Error"], rows: [["another duplicate"]], affected_rows: 0, execution_time_ms: 1, statement_index: 0, execution_error: true, error: sqlError },
|
||||
{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 2, statement_index: 1 },
|
||||
]);
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("mysql-1", "app", "Query", "query", undefined, sql);
|
||||
|
||||
await store.executeTabSql(tabId, sql);
|
||||
await expect(store.resumeBatchSql(tabId, "skip-all")).resolves.toBe(true);
|
||||
|
||||
expect(mocks.executeMultiWithProgress.mock.calls[1]?.[5]).toMatchObject({ continueOnError: true });
|
||||
expect(store.tabs.find((item) => item.id === tabId)?.batchSqlExecution?.items).toMatchObject([{ status: "error" }, { status: "error" }, { status: "success" }]);
|
||||
});
|
||||
|
||||
it("offers another recovery from the latest error after a resumed batch stops again", async () => {
|
||||
const sqlError = structuredSqlError();
|
||||
const sql = "INSERT INTO t VALUES (1);\nINSERT INTO t VALUES (2);\nINSERT INTO t VALUES (3);\nINSERT INTO t VALUES (4);\nINSERT INTO t VALUES (5)";
|
||||
mocks.executeMultiWithProgress
|
||||
.mockResolvedValueOnce([
|
||||
{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 1, statement_index: 0 },
|
||||
{ columns: ["Error"], rows: [["first error"]], affected_rows: 0, execution_time_ms: 1, statement_index: 1, execution_error: true, error: sqlError },
|
||||
])
|
||||
.mockResolvedValueOnce([
|
||||
{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 1, statement_index: 0 },
|
||||
{ columns: ["Error"], rows: [["second error"]], affected_rows: 0, execution_time_ms: 1, statement_index: 1, execution_error: true, error: sqlError },
|
||||
])
|
||||
.mockResolvedValueOnce([{ columns: [], rows: [], affected_rows: 1, execution_time_ms: 1, statement_index: 0 }]);
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("mysql-1", "app", "Query", "query", undefined, sql);
|
||||
|
||||
await store.executeTabSql(tabId, sql);
|
||||
await store.resumeBatchSql(tabId, "skip");
|
||||
expect(store.tabs.find((item) => item.id === tabId)?.batchSqlExecution?.items).toMatchObject([{ status: "success" }, { status: "error" }, { status: "success" }, { status: "error" }, { status: "skipped" }]);
|
||||
|
||||
await expect(store.resumeBatchSql(tabId, "skip")).resolves.toBe(true);
|
||||
expect(mocks.executeMultiWithProgress.mock.calls[2]?.[2]).toBe("INSERT INTO t VALUES (5)");
|
||||
expect(store.tabs.find((item) => item.id === tabId)?.batchSqlExecution?.items).toMatchObject([{ status: "success" }, { status: "error" }, { status: "success" }, { status: "error" }, { status: "success" }]);
|
||||
expect(store.tabs.find((item) => item.id === tabId)?.results?.map((result) => result.statement_index)).toEqual([0, 1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
it("marks every statement completed by a pipelined progress event", async () => {
|
||||
const pendingExecution = deferred<any[]>();
|
||||
let reportProgress!: (progress: any) => void;
|
||||
|
||||
@@ -60,6 +60,7 @@ import { buildTabResultSnapshot, deleteTabResultSnapshot, pruneTabResultSnapshot
|
||||
import { estimateQueryResultsBytes, selectInactiveResultEvictions } from "@/lib/tabs/queryResultSize";
|
||||
import { queryResultBaseSql, queryResultExecutionSql, resultGridInstanceKey } from "@/lib/tabs/tabPresentation";
|
||||
import { isQueryExecutionErrorResult } from "@/lib/query/queryResultError";
|
||||
import { batchSqlRecoverySql, batchSqlRecoveryState, mergeBatchQueryResults, offsetBatchQueryResultIndexes, prepareBatchSqlRecovery, type BatchSqlRecoveryAction } from "@/lib/query/batchSqlRecovery";
|
||||
import { decodeQueryResultArchive, encodeQueryResultArchive, type DecodedQueryResultArchive } from "@/lib/query/queryResultArchive";
|
||||
import * as api from "@/lib/backend/api";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
@@ -102,6 +103,13 @@ const CANCEL_ACK_SETTLE_TIMEOUT_MS = 2_000;
|
||||
const SAVED_SQL_EDITOR_POSITION_PERSIST_DELAY_MS = 500;
|
||||
type CloseConfirmContext = "tab" | "batch" | "app";
|
||||
|
||||
interface BatchSqlResumeOptions {
|
||||
batch: BatchSqlExecution;
|
||||
previousResults: QueryResult[];
|
||||
startStatementIndex: number;
|
||||
continueOnError: boolean;
|
||||
}
|
||||
|
||||
function hasHiddenPhysicalRowKey(databaseType: DatabaseType | undefined, hiddenPrimaryKeys: HiddenPrimaryKeyProjection[]): boolean {
|
||||
return hiddenPrimaryKeys.some((projection) => !usesSyntheticRowIdKey(databaseType, [projection.sourceName]));
|
||||
}
|
||||
@@ -273,7 +281,7 @@ const NON_STREAMING_BATCH_DATABASE_TYPES = new Set<DatabaseType>(["sqlserver", "
|
||||
const liveBatchSqlExecutions = new WeakMap<QueryTab, BatchSqlExecution>();
|
||||
|
||||
function cloneBatchSqlExecution(batch: BatchSqlExecution | undefined): BatchSqlExecution | undefined {
|
||||
return batch ? { ...batch, items: batch.items.map((item) => ({ ...item })) } : undefined;
|
||||
return batch ? { ...batch, executionTarget: batch.executionTarget ? { ...batch.executionTarget } : undefined, items: batch.items.map((item) => ({ ...item })) } : undefined;
|
||||
}
|
||||
|
||||
function batchSqlExecutionFor(tab: QueryTab, executionId: string): BatchSqlExecution | undefined {
|
||||
@@ -286,7 +294,7 @@ function clearLiveBatchSqlExecution(tab: QueryTab, executionId: string) {
|
||||
if (liveBatchSqlExecutions.get(tab)?.executionId === executionId) liveBatchSqlExecutions.delete(tab);
|
||||
}
|
||||
|
||||
function createBatchSqlExecution(executionId: string, editorSql: string, submittedSql: string, databaseType: DatabaseType | undefined, sourceOffset: number | undefined): BatchSqlExecution | undefined {
|
||||
function createBatchSqlExecution(executionId: string, editorSql: string, submittedSql: string, databaseType: DatabaseType | undefined, sourceOffset: number | undefined, executionTarget: MultiDbExecutionTarget): BatchSqlExecution | undefined {
|
||||
const statements = databaseType === "mongodb" ? splitMongoCommandRanges(submittedSql).map(({ from, to, text }) => ({ from, to, sql: text })) : splitSqlStatementRanges(submittedSql, databaseType);
|
||||
if (statements.length === 0) return undefined;
|
||||
if (statements.length > 1 && databaseType && NON_STREAMING_BATCH_DATABASE_TYPES.has(databaseType)) return undefined;
|
||||
@@ -299,6 +307,7 @@ function createBatchSqlExecution(executionId: string, editorSql: string, submitt
|
||||
completed: 0,
|
||||
total: statements.length,
|
||||
startedAt: Date.now(),
|
||||
executionTarget: { ...executionTarget },
|
||||
items: statements.map((statement, statementIndex) => ({
|
||||
statementIndex,
|
||||
sql: statement.sql,
|
||||
@@ -322,14 +331,15 @@ function applyBatchSqlProgress(
|
||||
error?: BackendError;
|
||||
},
|
||||
continueOnError: boolean,
|
||||
statementOffset = 0,
|
||||
) {
|
||||
const batch = batchSqlExecutionFor(tab, progress.executionId);
|
||||
if (!batch) return;
|
||||
const previousCompleted = batch.completed;
|
||||
const item = batch.items[progress.statementIndex];
|
||||
const statementIndex = statementOffset + progress.statementIndex;
|
||||
const item = batch.items[statementIndex];
|
||||
if (!item) return;
|
||||
if (progress.success && progress.completed > previousCompleted + 1) {
|
||||
for (let index = previousCompleted; index < progress.completed - 1; index += 1) {
|
||||
if (progress.completed > 1) {
|
||||
for (let index = statementOffset; index < statementOffset + progress.completed - 1; index += 1) {
|
||||
const completedItem = batch.items[index];
|
||||
if (completedItem && (completedItem.status === "pending" || completedItem.status === "running")) {
|
||||
completedItem.status = "success";
|
||||
@@ -341,9 +351,9 @@ function applyBatchSqlProgress(
|
||||
item.affectedRows = progress.affectedRows;
|
||||
item.errorDetails = progress.error;
|
||||
item.error = progress.error ? translateBackendError(i18n.global.t, progress.error) : undefined;
|
||||
batch.completed = Math.max(batch.completed, progress.completed);
|
||||
if ((progress.success || continueOnError) && progress.completed < batch.total) {
|
||||
const next = batch.items[progress.completed];
|
||||
batch.completed = batch.items.filter((candidate) => candidate.status === "success" || candidate.status === "error").length;
|
||||
if ((progress.success || continueOnError) && progress.completed < progress.total) {
|
||||
const next = batch.items[statementOffset + progress.completed];
|
||||
if (next?.status === "pending") next.status = "running";
|
||||
}
|
||||
}
|
||||
@@ -4225,6 +4235,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
targetContext?: SqlExecutionTargetContext;
|
||||
executionTarget?: MultiDbExecutionTarget;
|
||||
onExecutionStarted?: () => void;
|
||||
batchResume?: BatchSqlResumeOptions;
|
||||
},
|
||||
) {
|
||||
const tab = findExecutionTab(id);
|
||||
@@ -4262,9 +4273,16 @@ export const useQueryStore = defineStore("query", () => {
|
||||
if (captureResultRun && tab.activeResultRunId) {
|
||||
pendingResultRunRestores.set(executionId, tab.activeResultRunId);
|
||||
}
|
||||
tab.batchSqlExecution = undefined;
|
||||
liveBatchSqlExecutions.delete(tab);
|
||||
const preserveResultDuringExecution = options?.preserveResultDuringExecution === true || (tab.mode === "query" && !!tab.activeResultRunId && !tab.resultAutoSave && !captureResultRun);
|
||||
const batchResume = options?.batchResume;
|
||||
const continueOnBatchError = batchResume?.continueOnError ?? settingsStore.editorSettings.continueOnErrorOnBatch;
|
||||
if (batchResume) {
|
||||
tab.batchSqlExecution = prepareBatchSqlRecovery(batchResume.batch, executionId, batchResume.startStatementIndex);
|
||||
liveBatchSqlExecutions.set(tab, tab.batchSqlExecution);
|
||||
} else {
|
||||
tab.batchSqlExecution = undefined;
|
||||
liveBatchSqlExecutions.delete(tab);
|
||||
}
|
||||
const preserveResultDuringExecution = batchResume !== undefined || options?.preserveResultDuringExecution === true || (tab.mode === "query" && !!tab.activeResultRunId && !tab.resultAutoSave && !captureResultRun);
|
||||
const updateActiveResultRun = !!tab.activeResultRunId && preserveResultDuringExecution;
|
||||
if (!updateActiveResultRun) {
|
||||
tab.activeResultRunId = undefined;
|
||||
@@ -4299,11 +4317,12 @@ export const useQueryStore = defineStore("query", () => {
|
||||
let useAgentResultSession = false;
|
||||
let executionDispatched = false;
|
||||
let producedResult = false;
|
||||
const executionConnectionId = options?.executionTarget?.connectionId ?? tab.connectionId;
|
||||
const resumedExecutionTarget = batchResume?.batch.executionTarget;
|
||||
const executionConnectionId = resumedExecutionTarget?.connectionId ?? options?.executionTarget?.connectionId ?? tab.connectionId;
|
||||
try {
|
||||
await waitForTabSessionReset(id);
|
||||
const connStore = useConnectionStore();
|
||||
const executionTarget = options?.executionTarget;
|
||||
const executionTarget = resumedExecutionTarget ?? options?.executionTarget;
|
||||
const usesExternalExecutionTarget = !!executionTarget;
|
||||
let conn = connStore.getConfig(executionConnectionId);
|
||||
const parsedMongoCommands = conn?.db_type === "mongodb" ? splitMongoCommandRanges(sql) : undefined;
|
||||
@@ -4329,15 +4348,26 @@ export const useQueryStore = defineStore("query", () => {
|
||||
throw new Error("Namespace execution targets require a registered execution adapter.");
|
||||
}
|
||||
const databaseTargetContext = targetContext?.scope === "catalog" || targetContext?.scope === "database" ? targetContext : undefined;
|
||||
const executionCatalog = targetContext ? (targetContext.scope === "catalog" ? targetContext.catalog : undefined) : (executionTarget?.catalog ?? (tab.mode === "data" ? tab.tableMeta?.catalog : tab.catalog));
|
||||
const executionCatalog = resumedExecutionTarget ? resumedExecutionTarget.catalog : targetContext ? (targetContext.scope === "catalog" ? targetContext.catalog : undefined) : (executionTarget?.catalog ?? (tab.mode === "data" ? tab.tableMeta?.catalog : tab.catalog));
|
||||
const contextDatabase = databaseTargetContext?.database;
|
||||
const targetDatabase = targetContext?.scope === "connection" ? "" : (contextDatabase ?? executionTarget?.database ?? tab.database);
|
||||
const targetDatabase = resumedExecutionTarget ? resumedExecutionTarget.database : targetContext?.scope === "connection" ? "" : (contextDatabase ?? executionTarget?.database ?? tab.database);
|
||||
const targetSchema = resumedExecutionTarget ? resumedExecutionTarget.schema : targetContext?.scope === "connection" ? undefined : (databaseTargetContext?.schema ?? executionTarget?.schema ?? tab.schema);
|
||||
const executionDatabase = dataTabExecutionDatabase(conn, targetDatabase, executionCatalog);
|
||||
const useAgentCursor = usesAgentCursorForQuery(conn?.db_type);
|
||||
const queryTimeoutSecs = queryTimeoutSecsForConnection(conn, settingsStore.editorSettings.globalQueryTimeoutSecs);
|
||||
const statementExecution = tab.mode === "query" ? createBatchSqlExecution(executionId, tab.sql, sql, effectiveDbType, options?.sourceOffset) : undefined;
|
||||
tab.batchSqlExecution = statementExecution && (tab.autoCommit !== false || statementExecution.total === 1) ? statementExecution : undefined;
|
||||
if (tab.batchSqlExecution) liveBatchSqlExecutions.set(tab, tab.batchSqlExecution);
|
||||
if (!batchResume) {
|
||||
const statementExecution =
|
||||
tab.mode === "query"
|
||||
? createBatchSqlExecution(executionId, tab.sql, sql, effectiveDbType, options?.sourceOffset, {
|
||||
connectionId: executionConnectionId,
|
||||
catalog: executionCatalog,
|
||||
database: targetDatabase,
|
||||
schema: targetSchema,
|
||||
})
|
||||
: undefined;
|
||||
tab.batchSqlExecution = statementExecution && (tab.autoCommit !== false || statementExecution.total === 1) ? statementExecution : undefined;
|
||||
if (tab.batchSqlExecution) liveBatchSqlExecutions.set(tab, tab.batchSqlExecution);
|
||||
}
|
||||
queryExecutionLog("info", "previous-session-close:start", { traceId, elapsed: elapsed() });
|
||||
await previousResultSessionClose;
|
||||
queryExecutionLog("info", "previous-session-close:done", { traceId, elapsed: elapsed() });
|
||||
@@ -4808,7 +4838,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
sql,
|
||||
});
|
||||
const allResults: QueryResult[] = [];
|
||||
const continueOnError = settingsStore.editorSettings.continueOnErrorOnBatch;
|
||||
const continueOnError = continueOnBatchError;
|
||||
for (const request of elasticsearchRequests) {
|
||||
const current = findExecutionTab(id);
|
||||
if (current?.executionId !== executionId) break;
|
||||
@@ -4926,7 +4956,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
pageOffset = pagination.offset;
|
||||
}
|
||||
|
||||
const executionSchema = targetContext?.scope === "connection" ? undefined : connectionQueryExecutionSchema(conn, databaseTargetContext?.database ?? executionTarget?.database ?? tab.database, databaseTargetContext?.schema ?? executionTarget?.schema ?? tab.schema, tab.mode === "data");
|
||||
const executionSchema = connectionQueryExecutionSchema(conn, targetDatabase, targetSchema, tab.mode === "data");
|
||||
const frontendTimeoutSecs = frontendQueryTimeoutSecsForSql(sqlToExecute, effectiveDbType, queryTimeoutSecs);
|
||||
const sourceLabelDatabase = targetDatabase || conn?.database;
|
||||
const executionClientSessionId = options?.pagination?.clientSessionId ?? (tab.mode === "query" || tab.mode === "data" ? tabClientSessionId(tab) : undefined);
|
||||
@@ -4977,7 +5007,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
...(useOracleLobPreview ? { tableDataPreview: true } : {}),
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
catalog: executionCatalog,
|
||||
continueOnError: settingsStore.editorSettings.continueOnErrorOnBatch,
|
||||
continueOnError: continueOnBatchError,
|
||||
};
|
||||
queryExecutionLog("info", "execute-multi:invoke", {
|
||||
traceId,
|
||||
@@ -4996,7 +5026,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
(progress) => {
|
||||
const current = findExecutionTab(id);
|
||||
if (current?.executionId === executionId) {
|
||||
applyBatchSqlProgress(current, progress, settingsStore.editorSettings.continueOnErrorOnBatch);
|
||||
applyBatchSqlProgress(current, progress, continueOnBatchError, batchResume?.startStatementIndex ?? 0);
|
||||
}
|
||||
},
|
||||
executionSchema,
|
||||
@@ -5004,7 +5034,10 @@ export const useQueryStore = defineStore("query", () => {
|
||||
)
|
||||
: api.executeMulti(executionConnectionId, executionDatabase, sqlToExecute, executionSchema, executionId, executionOptions);
|
||||
}
|
||||
const results = annotateQueryResultSources(markQueryResultsRowsRaw(await withFrontendQueryTimeout(executionPromise, frontendTimeoutSecs, t("editor.queryTimeoutError", { seconds: frontendTimeoutSecs }))), queryBaseSql, sourceLabelDatabase, effectiveDbType, options?.sourceOffset);
|
||||
const results = offsetBatchQueryResultIndexes(
|
||||
annotateQueryResultSources(markQueryResultsRowsRaw(await withFrontendQueryTimeout(executionPromise, frontendTimeoutSecs, t("editor.queryTimeoutError", { seconds: frontendTimeoutSecs }))), queryBaseSql, sourceLabelDatabase, effectiveDbType, options?.sourceOffset),
|
||||
batchResume?.startStatementIndex ?? 0,
|
||||
);
|
||||
reconcileBatchSqlResults(tab, executionId, results);
|
||||
const successfulOracleSchemaChanges = effectiveDbType === "oracle" ? results.filter((result) => result.execution_error !== true && isOracleCurrentSchemaStatement(result.sourceStatement)).length : 0;
|
||||
const successfulSapHanaSchemaChanges = effectiveDbType === "saphana" ? results.filter((result) => result.execution_error !== true && isSapHanaSetSchemaStatement(result.sourceStatement)).length : 0;
|
||||
@@ -5055,7 +5088,14 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const activeGroupResults = current.results;
|
||||
const shouldAppendResult = !!options?.appendResult && !!current.result;
|
||||
const shouldReplaceActiveResultInGroup = options?.replaceActiveResultInGroup === true && results.length === 1 && Array.isArray(activeGroupResults) && typeof activeGroupIndex === "number" && activeGroupIndex >= 0 && activeGroupIndex < activeGroupResults.length;
|
||||
if (shouldAppendResult) {
|
||||
if (batchResume) {
|
||||
const mergedResults = mergeBatchQueryResults(batchResume.previousResults, results);
|
||||
const preferredResult = results.find((result) => isQueryExecutionErrorResult(result)) ?? results[results.length - 1] ?? mergedResults[mergedResults.length - 1];
|
||||
const resultIndex = preferredResult ? mergedResults.indexOf(preferredResult) : 0;
|
||||
current.results = mergedResults.length > 1 ? mergedResults : undefined;
|
||||
current.activeResultIndex = mergedResults.length > 1 ? Math.max(0, resultIndex) : undefined;
|
||||
current.result = mergedResults[Math.max(0, resultIndex)];
|
||||
} else if (shouldAppendResult) {
|
||||
if (results.length !== 1) throw new Error("Expected one result while loading the next segment");
|
||||
if (options.pagination?.offset !== current.result!.rows.length) {
|
||||
throw new Error("Ignoring a stale result segment whose offset no longer matches the loaded rows");
|
||||
@@ -5083,8 +5123,8 @@ export const useQueryStore = defineStore("query", () => {
|
||||
current.result = results[0];
|
||||
}
|
||||
producedResult = current.result !== undefined;
|
||||
current.resultBaseSql = shouldReplaceActiveResultInGroup ? (current.resultBaseSql ?? queryBaseSql) : queryBaseSql;
|
||||
current.resultEditorFingerprint = shouldReplaceActiveResultInGroup ? (current.resultEditorFingerprint ?? executionEditorFingerprint) : executionEditorFingerprint;
|
||||
current.resultBaseSql = batchResume ? batchResume.batch.submittedSql : shouldReplaceActiveResultInGroup ? (current.resultBaseSql ?? queryBaseSql) : queryBaseSql;
|
||||
current.resultEditorFingerprint = batchResume ? batchResume.batch.editorFingerprint : shouldReplaceActiveResultInGroup ? (current.resultEditorFingerprint ?? executionEditorFingerprint) : executionEditorFingerprint;
|
||||
current.resultSortedSql = resultSortedSql;
|
||||
// Appended rows form one logical result starting at the original page.
|
||||
// Keep the base page state so later table refresh/cache recovery does
|
||||
@@ -5293,6 +5333,36 @@ export const useQueryStore = defineStore("query", () => {
|
||||
return producedResult;
|
||||
}
|
||||
|
||||
function dismissBatchSqlRecovery(id: string) {
|
||||
const tab = findExecutionTab(id);
|
||||
if (!tab?.batchSqlExecution || !batchSqlRecoveryState(tab)) return false;
|
||||
tab.batchSqlExecution.recoveryDismissed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
async function resumeBatchSql(id: string, action: BatchSqlRecoveryAction) {
|
||||
const tab = findExecutionTab(id);
|
||||
const recovery = tab ? batchSqlRecoveryState(tab) : undefined;
|
||||
const batch = tab?.batchSqlExecution;
|
||||
if (!tab || !batch || !recovery) return false;
|
||||
|
||||
const startStatementIndex = action === "retry" ? recovery.failedStatementIndex : recovery.failedStatementIndex + 1;
|
||||
const resumed = batchSqlRecoverySql(batch, startStatementIndex);
|
||||
if (!resumed) return false;
|
||||
|
||||
const previousResults = tab.results?.slice() ?? (tab.result ? [tab.result] : []);
|
||||
return await executeTabSql(id, resumed.sql, {
|
||||
sourceOffset: resumed.sourceOffset,
|
||||
preserveResultDuringExecution: true,
|
||||
batchResume: {
|
||||
batch: cloneBatchSqlExecution(batch)!,
|
||||
previousResults,
|
||||
startStatementIndex,
|
||||
continueOnError: action === "skip-all",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function explainTabSql(id: string, sql: string, databaseType?: DatabaseType, explainMode?: string) {
|
||||
const tab = tabs.value.find((t) => t.id === id);
|
||||
if (!tab) return { ok: false as const, reason: "empty" as const };
|
||||
@@ -6405,6 +6475,8 @@ export const useQueryStore = defineStore("query", () => {
|
||||
executeCurrentTab,
|
||||
executeCurrentSql,
|
||||
executeTabSql,
|
||||
dismissBatchSqlRecovery,
|
||||
resumeBatchSql,
|
||||
activeResultExecutionTarget,
|
||||
getExecutionTab,
|
||||
createMultiDbExecutionWorker,
|
||||
|
||||
Reference in new issue
Block a user