Skip to content

fix(model): 修复 SQL 审计计划关联查询 #3031

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

Merged
merged 1 commit into from
Apr 29, 2025

Conversation

littleniannian
Copy link
Collaborator

@littleniannian littleniannian commented Apr 29, 2025

User description

关联的 issue

描述你的变更

  • 使用 CONCAT 函数将 instance_audit_plan_id 转换为字符串,以确保类型匹配正确
  • 这个修改解决了 SQL 审计计划的正确关联问题,提高了查询的准确性和性能

确认项(pr提交后操作)

Tip

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


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


Description

  • 使用 CONCAT 函数将 instance_audit_plan_id 转换为字符串

  • 修正 JOIN 条件中类型不匹配问题

  • 提升 SQL 审计计划关联查询的准确性与性能


Changes walkthrough 📝

Relevant files
Bug fix
instance_audit_plan.go
更新 JOIN 条件以确保数据类型匹配                                                                           

sqle/model/instance_audit_plan.go

  • 修改 JOIN 语句,增加 CONCAT 函数
  • 将 apv.instance_audit_plan_id 转换为字符串
  • 确保连接条件中类型匹配正确
  • +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.
  • - 使用 CONCAT 函数将 instance_audit_plan_id 转换为字符串,以确保类型匹配正确
    - 这个修改解决了 SQL 审计计划的正确关联问题,提高了查询的准确性和性能
    @actiontech-bot actiontech-bot requested a review from iwanghc April 29, 2025 08:16
    Copy link

    PR Reviewer Guide 🔍

    🎫 Ticket compliance analysis 🔶

    2318 - Partially compliant

    Compliant requirements:

    • 使用 CONCAT 函数将 instance_audit_plan_id 转为字符串以确保类型匹配
    • 修正 JOIN 条件中的类型不匹配问题
    • 提升 SQL 审计计划关联查询的准确性和性能

    Non-compliant requirements:

    |

    Requires further human verification:

    |

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    SQL 类型转换

    请确认使用 CONCAT 函数进行类型转换不会导致查询性能下降,尤其是在大数据量情况下需要进一步验证转换后索引能否正常利用。

    Joins("JOIN audit_plans_v2 apv ON sql_manage_records.source_id = CONCAT(apv.instance_audit_plan_id, '') AND sql_manage_records.source = apv.type AND apv.deleted_at IS NULL").

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    使用 CAST 进行转换

    建议使用 CAST() 替换 CONCAT() 以进行显式的数据类型转换。使用函数包装字段可能导致索引失效,从而影响 SQL 查询性能。

    sqle/model/instance_audit_plan.go [795]

    -Joins("JOIN audit_plans_v2 apv ON sql_manage_records.source_id = CONCAT(apv.instance_audit_plan_id, '') AND sql_manage_records.source = apv.type AND apv.deleted_at IS NULL")
    +Joins("JOIN audit_plans_v2 apv ON sql_manage_records.source_id = CAST(apv.instance_audit_plan_id AS CHAR) AND sql_manage_records.source = apv.type AND apv.deleted_at IS NULL")
    Suggestion importance[1-10]: 6

    __

    Why: The suggestion correctly identifies a potential performance issue with using CONCAT for type conversion and proposes a CAST alternative. However, the actual performance improvement may be minor and the change is more of an optimization rather than addressing a critical bug.

    Low

    @iwanghc iwanghc merged commit b501d29 into main Apr 29, 2025
    4 checks passed
    @littleniannian littleniannian deleted the fix_instance_audit_plan_sql branch April 30, 2025 01:55
    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