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(structure): speed up index editor rendering and column lookups
lxk955f85fe496e6ab
diff --git a/apps/desktop/src/components/structure/TableStructureEditor.vue b/apps/desktop/src/components/structure/TableStructureEditor.vueindex efe9bef10f..c6b068d3b1 100644--- a/apps/desktop/src/components/structure/TableStructureEditor.vue+++ b/apps/desktop/src/components/structure/TableStructureEditor.vue@@ -132,6 +132,7 @@ import {generateUniqueIndexName,generateUniqueShortIndexName,structureIndexKind,+ canIndexTypeHaveSpecialIssue,specialIndexColumnIssue,type StructureIndexKind,getColumnEditorControls,@@ -1622,6 +1623,38 @@ function structureColumnComparisonKey(name: string): string {return tableStructureIdentifierComparisonKey(name, databaseType.value, connection.value?.database_info);}+const activeColumnByName = computed(() => {+ const map = new Map<string, EditableStructureColumn>();+ for (const item of columns.value) {+ if (!item.markedForDrop) map.set(item.name, item);+ }+ return map;+});++const activeColumnByComparisonKey = computed(() => {+ const map = new Map<string, EditableStructureColumn>();+ for (const item of columns.value) {+ if (item.markedForDrop) continue;+ if (item.name) map.set(structureColumnComparisonKey(item.name), item);+ if (item.original?.name) map.set(structureColumnComparisonKey(item.original.name), item);+ }+ return map;+});++const indexesByColumnComparisonKey = computed(() => {+ const map = new Map<string, EditableStructureIndex[]>();+ for (const index of indexes.value) {+ if (index.markedForDrop || index.isPrimary) continue;+ for (const name of index.columns) {+ const key = structureColumnComparisonKey(name);+ const list = map.get(key);+ if (list) list.push(index);+ else map.set(key, [index]);+ }+ }+ return map;+});+function indexContainsColumn(index: EditableStructureIndex, column: EditableStructureColumn): boolean {const names = [column.name, column.original?.name].filter((name): name is string => !!name).map(structureColumnComparisonKey);return index.columns.some((name) => names.includes(structureColumnComparisonKey(name)));@@ -1629,7 +1662,21 @@ function indexContainsColumn(index: EditableStructureIndex, column: EditableStrufunction columnIndexes(column: EditableStructureColumn): EditableStructureIndex[] {if (!column.name.trim() || column.markedForDrop) return [];- return indexes.value.filter((index) => !index.markedForDrop && !index.isPrimary && indexContainsColumn(index, column));+ const key1 = structureColumnComparisonKey(column.name);+ const key2 = column.original?.name ? structureColumnComparisonKey(column.original.name) : null;+ const list1 = indexesByColumnComparisonKey.value.get(key1) ?? [];+ if (!key2 || key1 === key2) return list1;+ const list2 = indexesByColumnComparisonKey.value.get(key2) ?? [];+ if (!list2.length) return list1;+ const set = new Set(list1);+ const result = [...list1];+ for (const idx of list2) {+ if (!set.has(idx)) {+ set.add(idx);+ result.push(idx);+ }+ }+ return result;}const indexKindOrder: StructureIndexKind[] = ["primary", "unique", "index", "fulltext", "spatial"];@@ -4084,13 +4131,14 @@ function columnRowClass(column: EditableStructureColumn, index: number) {const dragState = columnDragState.value;const isSearchMatch = filteredColumnRowIds.value.has(column.id);const isSelected = selectedColumnIds.value.has(column.id) && !column.markedForDrop;+ const kind = columnIndexKind(column);return {"bg-destructive/5 opacity-60": column.markedForDrop,- "structure-column-primary-key": columnIndexKind(column) === "primary",- "structure-column-unique-key": columnIndexKind(column) === "unique",- "structure-column-index-key": columnIndexKind(column) === "index",- "structure-column-fulltext-key": columnIndexKind(column) === "fulltext",- "structure-column-spatial-key": columnIndexKind(column) === "spatial",+ "structure-column-primary-key": kind === "primary",+ "structure-column-unique-key": kind === "unique",+ "structure-column-index-key": kind === "index",+ "structure-column-fulltext-key": kind === "fulltext",+ "structure-column-spatial-key": kind === "spatial","structure-column-search-match": isSearchMatch,// Reuse the existing search-current highlight for the active/selected row."structure-column-search-current": highlightedColumnId.value === column.id || isSelected,@@ -4629,10 +4677,25 @@ const availableColumnNames = computed(() =>.filter(Boolean),);+const defaultIndexColumnOptions = computed(() => {+ return availableColumnNames.value.map((name) => {+ const column = activeColumnByName.value.get(name);+ return { name, dataType: column?.dataType ?? "", disabled: false };+ });+});+function indexColumnPickerOptions(index: EditableStructureIndex, included = false) {const selected = included ? index.includedColumns : index.columns;+ const isSpecial = !included && canIndexTypeHaveSpecialIssue(structureDialect.value, index.indexType);+ const availableSet = new Set(availableColumnNames.value);+ const hasUnavailableSelected = selected.some((name) => name.trim() && !availableSet.has(name));++ if (!isSpecial && !hasUnavailableSelected) {+ return defaultIndexColumnOptions.value;+ }+return filterStructureIndexColumnOptions(availableColumnNames.value, selected).map((name) => {- const column = columns.value.find((item) => item.name === name && !item.markedForDrop);+ const column = activeColumnByName.value.get(name);return { name, dataType: column?.dataType ?? "", disabled: !included && !canToggleIndexColumn(index, name) };});}@@ -4652,8 +4715,9 @@ function toggleIndexColumn(index: EditableStructureIndex, col: string) {}function indexColumnsIssue(index: EditableStructureIndex, names = index.columns, indexType = index.indexType, isUnique = index.isUnique) {+ if (!canIndexTypeHaveSpecialIssue(structureDialect.value, indexType)) return null;const fields = names.flatMap((name) => {- const column = columns.value.find((item) => !item.markedForDrop && [item.name, item.original?.name].some((value) => value && structureColumnComparisonKey(value) === structureColumnComparisonKey(name)));+ const column = activeColumnByComparisonKey.value.get(structureColumnComparisonKey(name));return column ? [column] : [];});return specialIndexColumnIssue(structureDialect.value, indexType, fields, isUnique);@@ -4666,6 +4730,7 @@ function needsIndexColumnValidation(index: EditableStructureIndex): boolean {}function canToggleIndexColumn(index: EditableStructureIndex, name: string): boolean {+ if (!canIndexTypeHaveSpecialIssue(structureDialect.value, index.indexType)) return true;return index.columns.includes(name) || !indexColumnsIssue(index, [...index.columns, name]);}diff --git a/apps/desktop/src/components/structure/__tests__/TableStructureEditor.selectedRowStyle.spec.ts b/apps/desktop/src/components/structure/__tests__/TableStructureEditor.selectedRowStyle.spec.tsindex 795398a17c..d0c5bfe80a 100644--- a/apps/desktop/src/components/structure/__tests__/TableStructureEditor.selectedRowStyle.spec.ts+++ b/apps/desktop/src/components/structure/__tests__/TableStructureEditor.selectedRowStyle.spec.ts@@ -31,4 +31,13 @@ describe("TableStructureEditor selected-row styles", () => {expect(scopedStyle).toContain(className);}});++ it("guards index column options and column issues against hot-path recalculations (#11637)", () => {+ expect(source).toContain("canIndexTypeHaveSpecialIssue(structureDialect.value, indexType)");+ expect(source).toContain("canIndexTypeHaveSpecialIssue(structureDialect.value, index.indexType)");+ expect(source).toContain("defaultIndexColumnOptions = computed");+ expect(source).toContain("activeColumnByName = computed");+ expect(source).toContain("activeColumnByComparisonKey = computed");+ expect(source).toContain("indexesByColumnComparisonKey = computed");+ });});diff --git a/apps/desktop/src/lib/table/__tests__/structureIndexColumnOptions.spec.ts b/apps/desktop/src/lib/table/__tests__/structureIndexColumnOptions.spec.tsindex b196606708..5dc3754bdf 100644--- a/apps/desktop/src/lib/table/__tests__/structureIndexColumnOptions.spec.ts+++ b/apps/desktop/src/lib/table/__tests__/structureIndexColumnOptions.spec.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { sortStructureIndexColumnOptions } from "../tableStructureEditorState";+import { canIndexTypeHaveSpecialIssue, sortStructureIndexColumnOptions } from "../tableStructureEditorState";describe("sortStructureIndexColumnOptions", () => {const options = [{ name: "order_total" }, { name: "ID" }, { name: "amount2" }, { name: "amount10" }, { name: "customer" }];@@ -21,4 +21,33 @@ describe("sortStructureIndexColumnOptions", () => {const [first] = sortStructureIndexColumnOptions(options, picked);expect(first).toEqual({ name: "ID" });});++ it("returns a copy intact for empty or single element lists", () => {+ expect(sortStructureIndexColumnOptions([], new Map())).toEqual([]);+ const single = [{ name: "col_a" }];+ expect(sortStructureIndexColumnOptions(single, new Map([["col_a", 1]]))).toEqual([{ name: "col_a" }]);+ });+});++describe("canIndexTypeHaveSpecialIssue", () => {+ it("returns true only for MySQL FULLTEXT/SPATIAL and SQL Server SPATIAL", () => {+ expect(canIndexTypeHaveSpecialIssue("mysql", "FULLTEXT")).toBe(true);+ expect(canIndexTypeHaveSpecialIssue("mysql", "SPATIAL")).toBe(true);+ expect(canIndexTypeHaveSpecialIssue("mysql", "BTREE")).toBe(false);+ expect(canIndexTypeHaveSpecialIssue("mysql", "HASH")).toBe(false);++ expect(canIndexTypeHaveSpecialIssue("sqlserver", "SPATIAL")).toBe(true);+ expect(canIndexTypeHaveSpecialIssue("sqlserver", "CLUSTERED")).toBe(false);+ expect(canIndexTypeHaveSpecialIssue("sqlserver", "NONCLUSTERED")).toBe(false);+ expect(canIndexTypeHaveSpecialIssue("sqlserver", "COLUMNSTORE")).toBe(false);++ expect(canIndexTypeHaveSpecialIssue("postgres", "BTREE")).toBe(false);+ expect(canIndexTypeHaveSpecialIssue("postgres", "GIN")).toBe(false);+ expect(canIndexTypeHaveSpecialIssue("postgres", "GIST")).toBe(false);+ expect(canIndexTypeHaveSpecialIssue("oracle", "NORMAL")).toBe(false);+ expect(canIndexTypeHaveSpecialIssue("sqlite", "BTREE")).toBe(false);++ expect(canIndexTypeHaveSpecialIssue("sqlserver", null)).toBe(false);+ expect(canIndexTypeHaveSpecialIssue("sqlserver", "")).toBe(false);+ });});diff --git a/apps/desktop/src/lib/table/tableStructureEditorState.ts b/apps/desktop/src/lib/table/tableStructureEditorState.tsindex 2877fe8969..15d996da2d 100644--- a/apps/desktop/src/lib/table/tableStructureEditorState.ts+++ b/apps/desktop/src/lib/table/tableStructureEditorState.ts@@ -1217,20 +1217,27 @@ export function filterStructureIndexColumnOptions(availableColumns: readonly strreturn query ? options.filter((column) => column.toLowerCase().includes(query)) : options;}+const indexColumnNameCollator = typeof Intl !== "undefined" && typeof Intl.Collator === "function" ? new Intl.Collator(undefined, { sensitivity: "base", numeric: true }) : null;+/*** Order index-column picker rows: picked columns first in their index order,* then unpicked columns alphabetically (case-insensitive, numeric-aware) so a* long field list is scannable (#11747).*/export function sortStructureIndexColumnOptions<T extends { name: string }>(options: readonly T[], selectedPositions: ReadonlyMap<string, number>): T[] {- return [...options].sort((left, right) => {- const leftPicked = selectedPositions.get(left.name);- const rightPicked = selectedPositions.get(right.name);- if (leftPicked !== undefined || rightPicked !== undefined) {- return (leftPicked ?? Number.MAX_SAFE_INTEGER) - (rightPicked ?? Number.MAX_SAFE_INTEGER);+ if (options.length <= 1) return [...options];+ const picked: T[] = [];+ const unpicked: T[] = [];+ for (const option of options) {+ if (selectedPositions.has(option.name)) {+ picked.push(option);+ } else {+ unpicked.push(option);}- return left.name.localeCompare(right.name, undefined, { sensitivity: "base", numeric: true });- });+ }+ picked.sort((left, right) => (selectedPositions.get(left.name) ?? 0) - (selectedPositions.get(right.name) ?? 0));+ unpicked.sort((left, right) => (indexColumnNameCollator ? indexColumnNameCollator.compare(left.name, right.name) : left.name.localeCompare(right.name, undefined, { sensitivity: "base", numeric: true })));+ return [...picked, ...unpicked];}export function createIndexDrafts(indexes: IndexInfo[]): EditableStructureIndex[] {@@ -1315,6 +1322,12 @@ export function structureIndexKind(index: IndexNamingOptions): StructureIndexKinexport type SpecialIndexColumnIssue = "specialIndexUnique" | "fulltextIndexColumns" | "spatialIndexColumn" | "spatialIndexNullable";+export function canIndexTypeHaveSpecialIssue(dialect: string, indexType?: string | null): boolean {+ if (!indexType) return false;+ const type = indexType.trim().toUpperCase();+ return (dialect === "mysql" && type === "FULLTEXT") || ((dialect === "mysql" || dialect === "sqlserver") && type === "SPATIAL");+}+export function specialIndexColumnIssue(dialect: string, indexType: string, columns: readonly Pick<EditableStructureColumn, "dataType" | "isNullable">[], isUnique = false): SpecialIndexColumnIssue | null {const type = indexType.trim().toUpperCase();const fulltext = dialect === "mysql" && type === "FULLTEXT";