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
feat(opengauss): support the explain button with plain-text EXPLAIN
弈秋3c4075a87cdd
diff --git a/apps/desktop/src/lib/__tests__/query/opengaussExplainPlan.spec.ts b/apps/desktop/src/lib/__tests__/query/opengaussExplainPlan.spec.tsnew file mode 100644index 0000000000..80a953a657--- /dev/null+++ b/apps/desktop/src/lib/__tests__/query/opengaussExplainPlan.spec.ts@@ -0,0 +1,46 @@+import { describe, expect, it } from "vitest";+import { parseExplainResult, supportsExplainPlan } from "@/lib/diagram/explainPlan";+import type { QueryResult } from "@/types/database";++function textPlanResult(lines: string[]): QueryResult {+ return { columns: ["QUERY PLAN"], rows: lines.map((line) => [line]), affected_rows: 0, execution_time_ms: 1 };+}++describe("openGauss explain plan (#13055)", () => {+ it("supports the opengauss database type", () => {+ expect(supportsExplainPlan("opengauss")).toBe(true);+ });++ it("builds a tree from indented text plan rows", () => {+ const result = parseExplainResult("opengauss", textPlanResult(["Data Node Scan (cost=0.00..0.00 rows=10 width=4)", " Node/s: All datanodes", " -> Seq Scan on t (cost=0.00..14.10 rows=410 width=4)"]));++ expect(result.databaseType).toBe("opengauss");+ expect(result.nodes).toHaveLength(1);+ const root = result.nodes[0]!;+ expect(root.title).toContain("Data Node Scan");+ expect(root.children).toHaveLength(2);+ expect(root.children[0]!.title).toBe("Node/s: All datanodes");+ expect(root.children[0]!.children).toHaveLength(0);+ expect(root.children[1]!.title).toContain("Seq Scan on t");+ });++ it("keeps consecutive same-indent detail lines as siblings under their node", () => {+ // PG-style plans put a node's detail lines several levels under the `->` row;+ // consecutive same-indent lines must stay siblings, not chain parent→child.+ const result = parseExplainResult("opengauss", textPlanResult(["Nested Loop (cost=0.00..1.00 rows=1 width=4)", " -> Seq Scan on a (cost=0.00..1.00 rows=1 width=4)", " Filter: (id = 1)", " Rows Removed by Filter: 3"]));++ const seqScan = result.nodes[0]!.children[0]!;+ expect(seqScan.title).toContain("Seq Scan on a");+ expect(seqScan.children).toHaveLength(2);+ expect(seqScan.children[0]!.title).toBe("Filter: (id = 1)");+ expect(seqScan.children[1]!.title).toBe("Rows Removed by Filter: 3");+ expect(seqScan.children[0]!.children).toHaveLength(0);+ });++ it("keeps top-level rows as siblings", () => {+ const result = parseExplainResult("opengauss", textPlanResult(["Seq Scan on a (cost=0.00..1.00 rows=1 width=4)", "Seq Scan on b (cost=0.00..2.00 rows=2 width=4)"]));+ expect(result.nodes).toHaveLength(2);+ expect(result.nodes[0]!.children).toHaveLength(0);+ expect(result.nodes[1]!.children).toHaveLength(0);+ });+});diff --git a/apps/desktop/src/lib/diagram/explainPlan.ts b/apps/desktop/src/lib/diagram/explainPlan.tsindex 803eb19978..ef7cba9759 100644--- a/apps/desktop/src/lib/diagram/explainPlan.ts+++ b/apps/desktop/src/lib/diagram/explainPlan.ts@@ -24,7 +24,7 @@ export interface ExplainPlanNode {children: ExplainPlanNode[];}-export type ExplainPlanDatabaseType = "mysql" | "postgres" | "dameng" | "questdb" | "doris" | "oracle" | "oceanbase-oracle" | "sqlserver" | "xugu" | "db2";+export type ExplainPlanDatabaseType = "mysql" | "postgres" | "opengauss" | "dameng" | "questdb" | "doris" | "oracle" | "oceanbase-oracle" | "sqlserver" | "xugu" | "db2";export interface ParsedExplainPlan {databaseType: ExplainPlanDatabaseType;@@ -39,7 +39,7 @@ export function formatExplainPlanDetails(node: ExplainPlanNode | undefined, estireturn node.estimatedTimeUs === undefined ? node.details : [`${estimatedTimeLabel}: ${node.estimatedTimeUs} µs`, ...node.details];}-const SUPPORTED_EXPLAIN_TYPES = new Set<DatabaseType>(["mysql", "postgres", "dameng", "questdb", "doris", "oracle", "oceanbase-oracle", "sqlserver", "xugu", "db2"]);+const SUPPORTED_EXPLAIN_TYPES = new Set<DatabaseType>(["mysql", "postgres", "opengauss", "dameng", "questdb", "doris", "oracle", "oceanbase-oracle", "sqlserver", "xugu", "db2"]);export function supportsExplainPlan(databaseType?: DatabaseType): databaseType is ExplainPlanDatabaseType {return !!databaseType && supportsDatabaseFeature(databaseType, "sqlExplain") && SUPPORTED_EXPLAIN_TYPES.has(databaseType);}@@ -57,6 +57,8 @@ export function parseExplainResult(databaseType: ExplainPlanDatabaseType, resultreturn parseXuguExplainResult(result);} else if (databaseType === "dameng") {return parseDamengExplain(result);+ } else if (databaseType === "opengauss") {+ return parseOpenGaussExplain(result);} else if (databaseType === "questdb") {return parseQuestdbExplain(result);} else if (databaseType === "doris") {@@ -929,6 +931,43 @@ function parseMysqlTable(table: Record<string, unknown>, id: string): ExplainPla}// ── QuestDB explain parser ─────────────────────────────────────────+// ── openGauss explain parser ────────────────────────────────────────+// openGauss (PostgreSQL 9.2 lineage) returns the plan as indented text rows+// with no FORMAT JSON output, so the tree comes from the leading-space depth.+function parseOpenGaussExplain(result: QueryResult): ParsedExplainPlan {+ const rows = (result.rows ?? []).map((row: unknown[]) => String(row[0] ?? ""));+ const nodes: ExplainPlanNode[] = [];+ // Stack of (depth, node); each row nests under the shallowest deeper predecessor.+ const stack: { depth: number; node: ExplainPlanNode }[] = [];+ rows.forEach((text, index) => {+ if (!text.trim()) return;+ const leading = text.length - text.trimStart().length;+ const depth = Math.floor(leading / 2);+ const node: ExplainPlanNode = {+ id: `plan_${index}`,+ title: text.trim(),+ nodeType: "Plan",+ relation: "",+ index: String(index),+ cost: undefined,+ rows: undefined,+ details: [text.trim()],+ children: [],+ };+ // Compare stored depths, not stack length: a row may jump more than one+ // level past its parent (detail lines under a `->` node), which desyncs+ // length from depth and chains same-indent siblings as parent-child.+ while (stack.length > 0 && stack[stack.length - 1]!.depth >= depth) stack.pop();+ if (stack.length === 0) {+ nodes.push(node);+ } else {+ stack[stack.length - 1]!.node.children.push(node);+ }+ stack.push({ depth, node });+ });+ return { databaseType: "opengauss", raw: result, nodes };+}+function parseQuestdbExplain(result: QueryResult): ParsedExplainPlan {let nodes: ExplainPlanNode[] = result.rows.map((row: unknown[], index: number) => {const text = String(row[0] ?? "");diff --git a/crates/dbx-core/assets/database-drivers.manifest.json b/crates/dbx-core/assets/database-drivers.manifest.jsonindex 805c60bb3b..7e47bc6a21 100644--- a/crates/dbx-core/assets/database-drivers.manifest.json+++ b/crates/dbx-core/assets/database-drivers.manifest.json@@ -1679,7 +1679,7 @@"sqlFileExecution": true,"databaseCreate": true,"fieldLineage": true,- "sqlExplain": false,+ "sqlExplain": true,"userAdmin": true,"driverManagement": false}diff --git a/crates/dbx-core/src/query/plugin_plan.rs b/crates/dbx-core/src/query/plugin_plan.rsindex 20028dd2c2..131c463c35 100644--- a/crates/dbx-core/src/query/plugin_plan.rs+++ b/crates/dbx-core/src/query/plugin_plan.rs@@ -845,6 +845,7 @@ mod tests {(DatabaseType::Mysql, GeneratedSql),(DatabaseType::Doris, GeneratedSql),(DatabaseType::Postgres, GeneratedSql),+ (DatabaseType::OpenGauss, GeneratedSql),(DatabaseType::Questdb, GeneratedSql),(DatabaseType::Dameng, DriverNative),(DatabaseType::Oracle, DriverNative),diff --git a/crates/dbx-sql-core/src/query_execution_sql.rs b/crates/dbx-sql-core/src/query_execution_sql.rsindex 8058c84d7b..fff9d58f4c 100644--- a/crates/dbx-sql-core/src/query_execution_sql.rs+++ b/crates/dbx-sql-core/src/query_execution_sql.rs@@ -234,6 +234,13 @@ pub fn estimated_plan_strategy(database_type: Option<DatabaseType>) -> Option<EsDatabaseType::Postgres => {EstimatedPlanStrategy { sql_generation: Postgres, acquisition: GeneratedSql, format: Json }}+ // openGauss documents EXPLAIN (FORMAT TEXT|XML|JSON|YAML) but JSON output+ // additionally depends on the session's explain_perf_mode; plain text avoids+ // assuming that GUC, so the plan is generated as plain `EXPLAIN <statement>`+ // text (#13055).+ DatabaseType::OpenGauss => {+ EstimatedPlanStrategy { sql_generation: Plain, acquisition: GeneratedSql, format: Text }+ }DatabaseType::Questdb => {EstimatedPlanStrategy { sql_generation: Plain, acquisition: GeneratedSql, format: Text }}@@ -2226,6 +2233,7 @@ mod tests {(DatabaseType::Doris, "EXPLAIN SELECT 1", Text, GeneratedSql),(DatabaseType::Xugu, "EXPLAIN VERBOSE SELECT 1", Text, GeneratedSql),(DatabaseType::Postgres, "EXPLAIN (FORMAT JSON) SELECT 1", Json, GeneratedSql),+ (DatabaseType::OpenGauss, "EXPLAIN SELECT 1", Text, GeneratedSql),(DatabaseType::Questdb, "EXPLAIN SELECT 1", Text, GeneratedSql),(DatabaseType::Dameng, "EXPLAIN SELECT 1", Text, DriverNative),(DatabaseType::Oracle, "EXPLAIN PLAN FOR SELECT 1", Text, DriverNative),diff --git a/plugins/connection-types/opengauss.yaml b/plugins/connection-types/opengauss.yamlindex 731bba6fdc..f356b41802 100644--- a/plugins/connection-types/opengauss.yaml+++ b/plugins/connection-types/opengauss.yaml@@ -34,6 +34,6 @@ capabilities:sqlFileExecution: truedatabaseCreate: truefieldLineage: true- sqlExplain: false+ sqlExplain: trueuserAdmin: truedriverManagement: false