Skip to content

Conversation

@AayushTyagi1
Copy link
Contributor

@AayushTyagi1 AayushTyagi1 commented Nov 11, 2025

Screen.Recording.2025-11-11.at.2.02.48.PM.mov

@AayushTyagi1 AayushTyagi1 requested a review from Copilot November 11, 2025 08:21
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @AayushTyagi1, 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!

This pull request introduces a comprehensive set of new query analysis tools designed to help identify and diagnose performance issues within the system. By leveraging the system:completed_requests catalog, these tools provide detailed insights into query behavior, including execution times, frequency, result sizes, and index usage patterns. This enhancement aims to empower developers and administrators with better capabilities for optimizing database performance and pinpointing inefficient queries.

Highlights

  • New Query Analysis Tools: A comprehensive suite of new functions has been added to identify and analyze various aspects of query performance and efficiency.
  • Performance Insight: These tools provide detailed insights into longest-running queries, most frequent queries, queries with large result sets, and different types of index utilization (primary, covering, selectivity).
  • Expanded Toolset: The src/tools module now exposes these new query analysis capabilities, making them accessible for broader use within the system.
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

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 adds multiple query analysis tools to diagnose slow-running and inefficient queries by leveraging the system:completed_requests catalog. The change also removes a comment that was preventing the exposure of run_cluster_query to the MCP server.

Key changes:

  • Exposed run_cluster_query function by removing restriction comment
  • Added seven new query analysis functions for performance diagnostics
  • Updated exports in __init__.py to include all new query analysis tools

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/tools/query.py Removed comment blocking run_cluster_query exposure; added seven query analysis functions for identifying slow, frequent, large-response, primary-index-using, non-covering-index, and non-selective queries
src/tools/init.py Added imports and exports for all seven new query analysis functions to make them available as tools

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"""
query = f"""
SELECT statement,
AVG(phaseCounts.`indexScan` - resultCount) AS diff
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

The subtraction phaseCounts.indexScan - resultCount could produce negative values if resultCount exceeds phaseCounts.indexScan. While the WHERE clause filters for phaseCounts.indexScan > resultCount, aggregating across multiple query executions with AVG could still yield unexpected results. Consider using AVG(GREATEST(phaseCounts.indexScan - resultCount, 0)) or adding AND phaseCounts.indexScan > resultCount to the GROUP BY filter to ensure all records in each group satisfy the condition.

Suggested change
AVG(phaseCounts.`indexScan` - resultCount) AS diff
AVG(GREATEST(phaseCounts.`indexScan` - resultCount, 0)) AS diff

Copilot uses AI. Check for mistakes.
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

This pull request introduces a suite of new tools for analyzing query performance by querying the system:completed_requests catalog. The changes are well-structured, adding new functions in src/tools/query.py and exposing them through src/tools/__init__.py.

My review focuses on several key areas:

  1. Security: I've identified multiple instances of potential SQL injection vulnerabilities due to the use of f-strings for constructing queries with user-provided parameters. I've provided suggestions to use parameterized queries, which is a critical security best practice.
  2. Correctness & Consistency: Some of the new query functions have inconsistent filtering logic compared to others. I've suggested changes to align them, ensuring they all exclude system-level queries for more focused and relevant results.
  3. Maintainability: I've also pointed out a minor style issue in __init__.py regarding the sorting of tool lists, which will improve code readability and long-term maintenance.

Overall, these are valuable additions for monitoring database performance. Addressing the feedback will make the new tools more secure, robust, and maintainable.

Comment on lines +227 to +228
WHERE phaseCounts.`primaryScan` IS NOT MISSING
AND UPPER(statement) NOT LIKE '% SYSTEM:%'
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For consistency with other query-analyzing tools in this file, consider filtering out INFER and CREATE INDEX statements. This will help focus the results on application-level queries.

Suggested change
WHERE phaseCounts.`primaryScan` IS NOT MISSING
AND UPPER(statement) NOT LIKE '% SYSTEM:%'
WHERE phaseCounts.`primaryScan` IS NOT MISSING
AND UPPER(statement) NOT LIKE 'INFER %'
AND UPPER(statement) NOT LIKE 'CREATE INDEX%'
AND UPPER(statement) NOT LIKE '% SYSTEM:%'

Comment on lines +250 to +252
WHERE phaseCounts.`indexScan` IS NOT MISSING
AND phaseCounts.`fetch` IS NOT MISSING
AND UPPER(statement) NOT LIKE '% SYSTEM:%'
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This query is missing filters for INFER and CREATE INDEX statements, which are present in other similar functions. Adding them would provide more consistent and focused results on application queries.

Suggested change
WHERE phaseCounts.`indexScan` IS NOT MISSING
AND phaseCounts.`fetch` IS NOT MISSING
AND UPPER(statement) NOT LIKE '% SYSTEM:%'
WHERE phaseCounts.`indexScan` IS NOT MISSING
AND phaseCounts.`fetch` IS NOT MISSING
AND UPPER(statement) NOT LIKE 'INFER %'
AND UPPER(statement) NOT LIKE 'CREATE INDEX%'
AND UPPER(statement) NOT LIKE '% SYSTEM:%'

SELECT statement,
AVG(phaseCounts.`indexScan` - resultCount) AS diff
FROM system:completed_requests
WHERE phaseCounts.`indexScan` > resultCount
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This query is missing filters to exclude system-level statements (like INFER, CREATE INDEX, and queries on SYSTEM: keyspaces). Including these filters, as done in other functions in this file, will help to focus on application performance issues.

Suggested change
WHERE phaseCounts.`indexScan` > resultCount
WHERE phaseCounts.`indexScan` > resultCount
AND UPPER(statement) NOT LIKE 'INFER %'
AND UPPER(statement) NOT LIKE 'CREATE INDEX%'
AND UPPER(statement) NOT LIKE '% SYSTEM:%'

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