Skip to main content
Glama

get_queries_not_using_covering_index

Identify queries that perform index scans but require additional fetches, indicating they're not using covering indexes. Helps optimize database performance by finding inefficient queries.

Instructions

Get queries that don't use a covering index from the system:completed_requests catalog.

Args:
    limit: Number of queries to return (default: 10)

Returns:
    List of queries that perform index scans but also require fetches (not covering)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'get_queries_not_using_covering_index' tool. It executes a SQL++ query on system:completed_requests to find queries that perform index scans (phaseCounts.indexScan present) but also require document fetches (phaseCounts.fetch present), indicating non-covering indexes. Results are ordered by resultCount DESC, limited by the input limit, and handled with a custom empty message via the helper function.
    def get_queries_not_using_covering_index(
        ctx: Context, limit: int = 10
    ) -> list[dict[str, Any]]:
        """Get queries that don't use a covering index from the system:completed_requests catalog.
    
        Args:
            limit: Number of queries to return (default: 10)
    
        Returns:
            List of queries that perform index scans but also require fetches (not covering)
        """
        query = """
        SELECT *
        FROM system:completed_requests
        WHERE phaseCounts.`indexScan` IS NOT MISSING
            AND phaseCounts.`fetch` IS NOT MISSING
            AND UPPER(statement) NOT LIKE '% SYSTEM:%'
        ORDER BY resultCount DESC
        LIMIT $limit
        """
    
        return _run_query_tool_with_empty_message(
            ctx,
            query,
            limit=limit,
            empty_message=(
                "No queries that require fetches after index scans were found "
                "in system:completed_requests."
            ),
        )
  • The tool is registered by being imported from src/tools/query.py and included in the ALL_TOOLS list, which is used for MCP tool registration.
    ALL_TOOLS = [
        get_buckets_in_cluster,
        get_server_configuration_status,
        test_cluster_connection,
        get_scopes_and_collections_in_bucket,
        get_collections_in_scope,
        get_scopes_in_bucket,
        get_document_by_id,
        upsert_document_by_id,
        delete_document_by_id,
        get_schema_for_collection,
        run_sql_plus_plus_query,
        get_index_advisor_recommendations,
        list_indexes,
        get_cluster_health_and_services,
        get_queries_not_selective,
        get_queries_not_using_covering_index,
        get_queries_using_primary_index,
        get_queries_with_large_result_count,
        get_queries_with_largest_response_sizes,
        get_longest_running_queries,
        get_most_frequent_queries,
    ]
  • Helper function used by get_queries_not_using_covering_index (and other query tools) to execute cluster queries and return a standardized empty result payload if no results are found.
    def _run_query_tool_with_empty_message(
        ctx: Context,
        query: str,
        *,
        limit: int,
        empty_message: str,
        extra_payload: dict[str, Any] | None = None,
        **query_kwargs: Any,
    ) -> list[dict[str, Any]]:
        """Execute a cluster query with a consistent empty-result response."""
        results = run_cluster_query(ctx, query, limit=limit, **query_kwargs)
    
        if results:
            return results
    
        payload: dict[str, Any] = {"message": empty_message, "results": []}
        if extra_payload:
            payload.update(extra_payload)
        return [payload]
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While it describes what the tool returns, it doesn't mention important behavioral aspects like whether this is a read-only operation, if it requires specific permissions, potential performance impact, or how results are formatted/paginated beyond the limit parameter.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with a clear purpose statement followed by separate Args and Returns sections. Every sentence serves a distinct purpose: the first states what the tool does, the second explains the parameter, and the third clarifies the return value. No wasted words or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema and only one parameter with good description coverage, the description provides adequate context. It explains both what the tool does and what it returns, though it could benefit from more behavioral context (especially with no annotations) and clearer differentiation from sibling tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage and only one parameter, the description adds meaningful context by explaining the 'limit' parameter's purpose ('Number of queries to return') and default value. This compensates well for the lack of schema descriptions, though it doesn't provide additional details like valid ranges or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get queries that don't use a covering index') and identifies the exact resource ('from the system:completed_requests catalog'). It distinguishes this tool from siblings like 'get_queries_using_primary_index' or 'get_queries_not_selective' by focusing specifically on covering index usage issues.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying the source catalog and the type of queries returned, but doesn't explicitly state when to use this tool versus alternatives like 'get_index_advisor_recommendations' or 'get_longest_running_queries'. It provides some guidance through the return value description but lacks explicit when/when-not instructions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Couchbase-Ecosystem/mcp-server-couchbase'

If you have feedback or need assistance with the MCP directory API, please join our Discord server