fix(mysql): stop multi-statement execution after first error
This commit is contained in:
1 parent
6368c49c16
commit
7a42b1e96b
12 files changed
+523
-47
No files matched your search
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { QueryResult } from "@/types/database";
|
||||
|
||||
import { isNoSnapshotErrorResult } from "@/lib/query/queryResultError";
|
||||
import { isMysqlExecutionErrorResult, isNoSnapshotErrorResult } from "@/lib/query/queryResultError";
|
||||
|
||||
function errorResult(message: string): QueryResult {
|
||||
return { columns: ["Error"], rows: [[message]], affected_rows: 0, execution_time_ms: 0 };
|
||||
@@ -39,3 +39,23 @@ describe("isNoSnapshotErrorResult", () => {
|
||||
expect(isNoSnapshotErrorResult({ ...errorResult("There is currently no snapshot."), rows: [] })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isMysqlExecutionErrorResult", () => {
|
||||
it("recognizes an explicitly marked MySQL batch execution error", () => {
|
||||
expect(isMysqlExecutionErrorResult({ ...errorResult("Duplicate entry '1'"), execution_error: true }, "mysql")).toBe(true);
|
||||
});
|
||||
|
||||
it("does not mistake an unmarked Error alias without type metadata for an execution error", () => {
|
||||
const result: QueryResult = {
|
||||
columns: ["Error"],
|
||||
rows: [["2"]],
|
||||
affected_rows: 0,
|
||||
execution_time_ms: 1,
|
||||
};
|
||||
expect(isMysqlExecutionErrorResult(result, "mysql")).toBe(false);
|
||||
});
|
||||
|
||||
it("does not apply the native MySQL heuristic to JDBC connections", () => {
|
||||
expect(isMysqlExecutionErrorResult({ ...errorResult("Duplicate entry '1'"), execution_error: true }, "jdbc")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { QueryResult } from "@/types/database";
|
||||
import type { DatabaseType, QueryResult } from "@/types/database";
|
||||
|
||||
// Lake/external tables (e.g. Paimon in StarRocks) return this error on a data
|
||||
// read when no snapshot exists yet, while metadata reads (DESC/SHOW CREATE)
|
||||
@@ -6,6 +6,17 @@ import type { QueryResult } from "@/types/database";
|
||||
// callers can detect this case and fall back to a structure-only (LIMIT 0)
|
||||
// preview instead of showing a cryptic server error.
|
||||
const NO_SNAPSHOT_ERROR_PATTERN = /there is currently no snapshot/i;
|
||||
const MYSQL_PROTOCOL_DATABASE_TYPES = new Set<DatabaseType>(["mysql", "doris", "starrocks", "manticoresearch"]);
|
||||
|
||||
export function usesMysqlProtocolDatabaseType(databaseType: DatabaseType | undefined): boolean {
|
||||
return databaseType !== undefined && MYSQL_PROTOCOL_DATABASE_TYPES.has(databaseType);
|
||||
}
|
||||
|
||||
// The batch executor marks synthesized MySQL-protocol errors explicitly so a
|
||||
// successful result column named Error is never mistaken for a failure.
|
||||
export function isMysqlExecutionErrorResult(result: QueryResult, databaseType: DatabaseType | undefined): boolean {
|
||||
return usesMysqlProtocolDatabaseType(databaseType) && result.execution_error === true;
|
||||
}
|
||||
|
||||
export function isNoSnapshotErrorResult(result: QueryResult | undefined | null): boolean {
|
||||
if (!result || !result.columns.includes("Error") || result.rows.length === 0) return false;
|
||||
|
||||
@@ -40,6 +40,7 @@ export interface TabResultSnapshot {
|
||||
|
||||
interface ColumnarQueryResult {
|
||||
columns: string[];
|
||||
execution_error?: true;
|
||||
column_types?: string[];
|
||||
columnValues: CellValue[][];
|
||||
rowCount: number;
|
||||
@@ -134,6 +135,7 @@ function stripSessionIds(result: QueryResult | undefined): QueryResult | undefin
|
||||
if (!result) return undefined;
|
||||
return {
|
||||
columns: [...result.columns],
|
||||
execution_error: result.execution_error,
|
||||
column_types: result.column_types ? [...result.column_types] : undefined,
|
||||
rows: result.rows.map((row) => [...row]),
|
||||
mongo_documents: result.mongo_documents ? clonePlain(result.mongo_documents) : undefined,
|
||||
@@ -167,6 +169,7 @@ function toColumnarResult(result: QueryResult | undefined): ColumnarQueryResult
|
||||
const columnValues = result.columns.map((_, colIndex) => result.rows.map((row) => row[colIndex] ?? null));
|
||||
return removeUndefinedFields({
|
||||
columns: [...result.columns],
|
||||
execution_error: result.execution_error,
|
||||
column_types: result.column_types ? [...result.column_types] : undefined,
|
||||
columnValues,
|
||||
rowCount: result.rows.length,
|
||||
@@ -185,6 +188,7 @@ function fromColumnarResult(result: ColumnarQueryResult | undefined): QueryResul
|
||||
const rows = Array.from({ length: result.rowCount }, (_, rowIndex) => result.columnValues.map((values) => values[rowIndex] ?? null));
|
||||
return {
|
||||
columns: [...result.columns],
|
||||
execution_error: result.execution_error,
|
||||
column_types: result.column_types ? [...result.column_types] : undefined,
|
||||
rows,
|
||||
mongo_documents: result.mongo_documents ? clonePlain(result.mongo_documents) : undefined,
|
||||
|
||||
Reference in new issue
Block a user