Skip to content

Conversation

@Song-Quan
Copy link
Collaborator

  • 缓存 infoschema 来加速 select、create view 之类语句

@Song-Quan Song-Quan requested a review from Copilot January 4, 2026 03:38
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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) 缓存机制来显著提升数据库操作的性能,特别是针对 SELECTCREATE VIEW 等语句。通过缓存常用的信息模式数据并确保在 DDL 操作后及时更新缓存,系统可以减少对底层数据库的频繁查询,从而提高响应速度和整体效率。

Highlights

  • 引入信息模式缓存: 在 pkg/scdb/storage/storage.go 中引入了一个 sync.Map (infoSchemaCache) 来缓存数据库的信息模式 (infoschema),并添加了缓存命中/未命中统计。
  • 实现缓存失效机制: 新增 InvalidateInfoSchemaCache 函数,用于根据数据库名称清除特定缓存或清空所有缓存。
  • 集成缓存到查询逻辑: 修改 QueryDBInfoSchema 函数,使其在查询信息模式时首先检查缓存,如果未命中则从数据库查询并存入缓存。
  • DDL操作后缓存失效: 在 pkg/scdb/executor/ddl.gopkg/scdb/storage/schema_tables.go 中,为 CREATE DATABASE, CREATE TABLE, CREATE VIEW, DROP DATABASE, DROP TABLE 等 DDL 操作成功后添加了调用 InvalidateInfoSchemaCache 的逻辑,确保缓存数据的一致性。

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 缓存机制,旨在提升 selectcreate view 等语句的执行效率,这是一个很好的优化。代码整体实现不错,但在并发安全、代码冗余和性能方面还有一些可以改进的地方。我主要提出了以下几点建议:

  1. 修复了 InvalidateInfoSchemaCache 中一个严重的竞态条件问题。
  2. 指出了 ddl.go 中存在的多余的缓存失效调用,并建议移除。
  3. 建议使用 sync/atomic 来优化缓存命中/未命中计数器的性能,以减少锁竞争。

Copy link

Copilot AI left a 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.Map with 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.

@Song-Quan Song-Quan marked this pull request as ready for review January 5, 2026 03:03
@Song-Quan Song-Quan requested a review from a team January 5, 2026 03:10
}
}

storage.InvalidateInfoSchemaCache(dbName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid的操作直接在调用 executeCreateView 的层级上统一做应该会更简洁。

Copy link
Collaborator Author

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个func只是为了测试用吗?可以看看是否适合加到metrics里面

@Song-Quan Song-Quan added the run-ci-full run ci on multiple platforms label Jan 5, 2026
@github-actions github-actions bot removed the run-ci-full run ci on multiple platforms label Jan 5, 2026
@Song-Quan Song-Quan requested a review from a team January 6, 2026 07:47
@Song-Quan Song-Quan mentioned this pull request Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants