Skip to content

fix(mysql): cancel where condition for querying schema tables#3076

Closed
BugsGuru wants to merge 1 commit intomainfrom
fix-show-schema-tables
Closed

fix(mysql): cancel where condition for querying schema tables#3076
BugsGuru wants to merge 1 commit intomainfrom
fix-show-schema-tables

Conversation

@BugsGuru
Copy link
Copy Markdown
Collaborator

@BugsGuru BugsGuru commented Jul 2, 2025

User description

关联的 issue

https://github.com/actiontech/sqle-ee/issues/2419

描述你的变更

  • Remove TABLE_TYPE condition from the query to information_schema.tables

确认项(pr提交后操作)

Tip

请在指定复审人之前,确认并完成以下事项,完成后✅


  • 我已完成自测
  • 我已记录完整日志方便进行诊断
  • 我已在关联的issue里补充了实现方案
  • 我已在关联的issue里补充了测试影响面
  • 我已确认了变更的兼容性,如果不兼容则在issue里标记 not_compatible
  • 我已确认了是否要更新文档,如果要更新则在issue里标记 need_update_doc


Description

  • 新增 showSchemaObjects API

  • 新增 ShowAllSchemaObjects 方法

  • 更新 ShowSchemaTables 与 Context 调用

  • 统一 schema 对象查询逻辑


Changes diagram

flowchart LR
  A["\"ShowSchemaTables\""] --> B["\"showSchemaObjects\""]
  C["\"ShowAllSchemaObjects\""] --> B
  D["\"Context:IsTableExist\""] --> C
Loading

Changes walkthrough 📝

Relevant files
Bug fix
executor.go
executor 查询逻辑变更                                                                                   

sqle/driver/mysql/executor/executor.go

  • 新增 showSchemaObjects 方法
  • 新增 ShowAllSchemaObjects 方法
  • 更新 ShowSchemaTables 调用
  • +19/-5   
    context.go
    context 表检测更新                                                                                       

    sqle/driver/mysql/session/context.go

    • 修改表存在检测方法
    • 替换为调用 ShowAllSchemaObjects
    +1/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @BugsGuru BugsGuru self-assigned this Jul 2, 2025
    Comment thread sqle/driver/mysql/executor/executor.go Outdated
    Comment on lines 383 to 391
    func (c *Executor) ShowSchemaTables(schema string) ([]string, error) {
    query := fmt.Sprintf(
    "select TABLE_NAME from information_schema.tables where table_schema='%s' and TABLE_TYPE in ('BASE TABLE','SYSTEM VIEW')", schema)
    "select TABLE_NAME from information_schema.tables where table_schema='%s'", schema)

    if c.IsLowerCaseTableNames() {
    schema = strings.ToLower(schema)
    query = fmt.Sprintf(
    "select TABLE_NAME from information_schema.tables where lower(table_schema)='%s' and TABLE_TYPE in ('BASE TABLE','SYSTEM VIEW')", schema)
    "select TABLE_NAME from information_schema.tables where lower(table_schema)='%s'", schema)

    Copy link
    Copy Markdown
    Collaborator

    Choose a reason for hiding this comment

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

    这样做视图可以显示了,那会影响其他不需要视图的方法

    Copy link
    Copy Markdown
    Collaborator

    Choose a reason for hiding this comment

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

    能确定所有引用来源都不需要视图吗?包括基于mysql开发的mysql系插件

    @github-actions
    Copy link
    Copy Markdown

    github-actions Bot commented Jul 2, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    参数校验增强

    建议在函数开头对传入的 schema 参数进行非空检查,避免传入空字符串时查询条件失效可能导致返回过多或非预期的数据。添加简单的检查逻辑,可防止运行时出错或资源滥用。

    sqle/driver/mysql/executor/executor.go [391-406]

     func (c *Executor) showSchemaObjects(schema string, objects ...string) ([]string, error) {
    +	if schema == "" {
    +		return nil, fmt.Errorf("schema 参数不能为空")
    +	}
     	var query string
     	if c.IsLowerCaseTableNames() {
     		schema = strings.ToLower(schema)
     		if len(objects) == 0 {
     			query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where lower(table_schema)='%s'", schema)
     		} else {
     			query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where lower(table_schema)='%s' and TABLE_TYPE in (%s)", schema, strings.Join(objects, ","))
     		}
     	} else {
     		if len(objects) == 0 {
     			query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where table_schema='%s'", schema)
     		} else {
     			query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where table_schema='%s' and TABLE_TYPE in (%s)", schema, strings.Join(objects, ","))
     		}
     	}
    Suggestion importance[1-10]: 6

    __

    Why: Adding a non-empty check for schema improves robustness by preventing unintended queries, though it is a minor validation improvement.

    Low

    - Introduce `ShowAllSchemaObjects` method to retrieve all table types
    - Implement `showSchemaObjects` helper method for flexible queries
    - Update `ShowSchemaTables` to use `showSchemaObjects` with specific parameters
    - Modify `context.go` to use `ShowAllSchemaObjects` for schema checks
    @BugsGuru BugsGuru force-pushed the fix-show-schema-tables branch from 85b66bd to 5d7420f Compare July 2, 2025 10:11
    @github-actions
    Copy link
    Copy Markdown

    github-actions Bot commented Jul 2, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    参数校验增强

    建议在函数开头对传入的 schema 参数进行非空检查,避免传入空字符串时查询条件失效可能导致返回过多或非预期的数据。添加简单的检查逻辑,可防止运行时出错或资源滥用。

    sqle/driver/mysql/executor/executor.go [391-406]

     func (c *Executor) showSchemaObjects(schema string, objects ...string) ([]string, error) {
    +	if schema == "" {
    +		return nil, fmt.Errorf("schema 参数不能为空")
    +	}
     	var query string
     	if c.IsLowerCaseTableNames() {
     		schema = strings.ToLower(schema)
     		if len(objects) == 0 {
     			query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where lower(table_schema)='%s'", schema)
     		} else {
     			query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where lower(table_schema)='%s' and TABLE_TYPE in (%s)", schema, strings.Join(objects, ","))
     		}
     	} else {
     		if len(objects) == 0 {
     			query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where table_schema='%s'", schema)
     		} else {
     			query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where table_schema='%s' and TABLE_TYPE in (%s)", schema, strings.Join(objects, ","))
     		}
     	}
    Suggestion importance[1-10]: 6

    __

    Why: Adding a non-empty check for schema improves robustness by preventing unintended queries, though it is a minor validation improvement.

    Low

    @BugsGuru BugsGuru closed this Jul 2, 2025
    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.

    2 participants