-
Notifications
You must be signed in to change notification settings - Fork 74
Feat: cache infoschema #772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Song-Quan
commented
Jan 4, 2026
- 缓存 infoschema 来加速 select、create view 之类语句
Summary of ChangesHello @Song-Quan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在通过引入信息模式 (infoschema) 缓存机制来显著提升数据库操作的性能,特别是针对 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
本次 PR 引入了 infoschema 缓存机制,旨在提升 select、create view 等语句的执行效率,这是一个很好的优化。代码整体实现不错,但在并发安全、代码冗余和性能方面还有一些可以改进的地方。我主要提出了以下几点建议:
- 修复了
InvalidateInfoSchemaCache中一个严重的竞态条件问题。 - 指出了
ddl.go中存在的多余的缓存失效调用,并建议移除。 - 建议使用
sync/atomic来优化缓存命中/未命中计数器的性能,以减少锁竞争。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces an InfoSchema caching mechanism to improve query performance for operations like SELECT and CREATE VIEW by reducing database queries. The implementation adds a cache layer with automatic invalidation on schema-modifying DDL operations.
Key Changes:
- Implements InfoSchema caching using
sync.Mapwith cache hit/miss statistics tracking - Adds cache invalidation hooks to all DDL operations (CREATE/DROP database, table, and view)
- Provides utility functions for cache management and statistics retrieval
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| pkg/scdb/storage/storage.go | Adds cache infrastructure with sync.Map, statistics tracking, and cache invalidation/query functions |
| pkg/scdb/storage/schema_tables.go | Adds cache invalidation calls to DropSchema and DropTable operations |
| pkg/scdb/executor/ddl.go | Adds cache invalidation calls to all DDL executor methods (create/drop database, table, view) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pkg/scdb/executor/ddl.go
Outdated
| } | ||
| } | ||
|
|
||
| storage.InvalidateInfoSchemaCache(dbName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
invalid的操作直接在调用 executeCreateView 的层级上统一做应该会更简洁。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| } | ||
|
|
||
| // GetInfoSchemaCacheStats returns cache hit and miss statistics | ||
| func GetInfoSchemaCacheStats() (hits, misses int64) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这两个func只是为了测试用吗?可以看看是否适合加到metrics里面