get_queries_not_selective
Identify queries with poor selectivity by analyzing Couchbase system data to find index scans returning many more documents than final results.
Instructions
Get queries that are not very selective from the system:completed_requests catalog.
Args:
limit: Number of queries to return (default: 10)
Returns:
List of queries where index scans return significantly more documents than the final result
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No |
Implementation Reference
- src/tools/query.py:334-360 (handler)Core implementation of the get_queries_not_selective tool handler. It executes a query on system:completed_requests to find non-selective queries where index scans return more documents than the final result set, using a helper function for execution.def get_queries_not_selective(ctx: Context, limit: int = 10) -> list[dict[str, Any]]: """Get queries that are not very selective from the system:completed_requests catalog. Args: limit: Number of queries to return (default: 10) Returns: List of queries where index scans return significantly more documents than the final result """ query = """ SELECT statement, AVG(phaseCounts.`indexScan` - resultCount) AS diff FROM system:completed_requests WHERE phaseCounts.`indexScan` > resultCount GROUP BY statement ORDER BY diff DESC LIMIT $limit """ return _run_query_tool_with_empty_message( ctx, query, limit=limit, empty_message=( "No non-selective queries were found in system:completed_requests." ), )
- src/tools/__init__.py:17-28 (registration)Registration of the get_queries_not_selective tool via import into the main tools __init__.py module, making it available for MCP tool registration.# Query tools from .query import ( get_longest_running_queries, get_most_frequent_queries, 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_schema_for_collection, run_sql_plus_plus_query, )
- src/tools/__init__.py:42-64 (registration)Inclusion of get_queries_not_selective in the ALL_TOOLS list for convenient bulk registration of all MCP tools.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, ]