Repository navigation
fix(db): 清空表后自动刷新表数据页签(TRUNCATE 与全表 DELETE 的数据级失效通知) - #413
Merged
feigeCode merged 1 commit intoOct 16, 2026
Merged
Conversation
2 of 4 tasks
ekovovo
pushed a commit
to ekovovo/navop
that referenced
this pull request
Oct 19, 2026
- main/Cargo.toml、Cargo.lock:0.20.2 -> 0.20.3 - CHANGELOG.md:新增 v0.20.3 双语发布说明 本版自 v0.20.2 以来已合入 main 的变更: - 终端按行 / 按屏滚动回看历史输出(feigeCode#409) - Auto 模式 SQL 编辑器粘性会话,跨执行保留会话变量(feigeCode#312) - 笔记 Markdown 大纲面板与代码字体设置(feigeCode#406) - Redis:启用 TLS 修复、集群汇总全部 master、空库切换崩溃修复(feigeCode#414、feigeCode#416) - SFTP:上传可立即取消、同连接 3 条并发车道、目录符号链接处理(feigeCode#417、feigeCode#418) - 清空表刷新数据页签、结果集保存限定库名、剪贴板 JSON 原文复制(feigeCode#412、feigeCode#413)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题背景(Bug)
右键点击表选择「清空表」执行成功后,已打开的表数据页签中旧数据依然显示,用户误以为清空操作失败,只有手动刷新才能看到空表。
根因分析
排查定位到两个相互叠加的缺陷:
缺陷 1(主因):执行成功后无任何刷新通知 handle_truncate_table 执行成功后仅弹出 toast 提示,没有向 UI 层广播任何数据变更事件。表数据页签(DataGrid)不监听 ConnectionDataEvent::SchemaChanged ,其内部的查询结果缓存不会失效,旧数据一直渲染在界面上。
缺陷 2:SQLite/DuckDB 的清空语句绕过了失效管线 SQLite / DuckDB 不支持 TRUNCATE ,右键清空生成的 SQL 是 DELETE FROM
(无 WHERE 子句)。而 DdlInvalidator 的候选预筛只认 TRUNCATE 等 DDL 关键字, DELETE 属于 DML 被直接跳过——这类语句连「结构变更树刷新」都不会触发,彻底绕开了缓存失效管线。修复方案:数据级 / 结构级失效双通道
核心设计原则: 整表清空只影响数据,不影响表结构 。因此不滥用既有的 SchemaChanged (那会触发昂贵的元数据缓存失效与整树刷新),而是新增一条轻量的数据级通知通道:
SQL 执行成功
→ DdlInvalidator 识别 TRUNCATE / 无 WHERE 的 DELETE FROM
→ SchemaInvalidationScope { table, data_only: true } (数据级 scope)
→ ConnectionDataEvent::TableDataCleared(四元组精确标识)
→ DataGrid 精确匹配后仅重载自己的数据
1. SQL 识别层(ddl_invalidator.rs)
新增 DdlEvent::DeleteAllRows 事件,三层识别策略:
数据级事件不做元数据缓存失效(表结构未变),仅传递数据变更语义。
2. 失效计划层(cache_manager.rs)
SchemaInvalidationScope 新增 table: Option 与 data_only: bool 字段。 from_event 将 TruncateTable / DeleteAllRows 映射为 data_only: true 的 scope,其余事件保持结构级语义不变。
3. 事件广播层(manager.rs、sql_result_tab.rs、sql_editor_view.rs)
ConnectionDataEvent 新增 TableDataCleared { connection_id, database, schema, table } 变体。 三条执行链路全覆盖 ,统一按 scope 分流广播(数据级 → TableDataCleared ,结构级 → SchemaChanged ):
4. 消费端(data_grid.rs 及各监听点)
设计考量