Skip to main content
Glama
Teradata

Teradata MCP Server

Official
by Teradata

Sql Retrieve Cluster Queries

sql_Retrieve_Cluster_Queries
Idempotent

Retrieve actual SQL queries from Teradata clusters to analyze patterns, identify performance issues, and guide query optimization.

Instructions

RETRIEVE ACTUAL SQL QUERIES FROM SPECIFIC CLUSTERS FOR PATTERN ANALYSIS

This tool extracts the actual SQL query text and performance metrics from selected clusters, enabling detailed pattern analysis and specific optimization recommendations. Essential for moving from cluster-level analysis to actual query optimization.

DETAILED ANALYSIS CAPABILITIES:

  • SQL Pattern Recognition: Analyze actual query structures, joins, predicates, and functions

  • Performance Correlation: Connect query patterns to specific performance characteristics

  • Optimization Identification: Identify common anti-patterns, missing indexes, inefficient joins

  • Code Quality Assessment: Evaluate query construction, complexity, and best practices

  • Workload Understanding: See actual business logic and data access patterns

QUERY SELECTION STRATEGIES:

  • By CPU Impact: Sort by 'ampcputime' to focus on highest CPU consumers

  • By I/O Volume: Sort by 'logicalio' to find scan-intensive queries

  • By Skew Problems: Sort by 'cpuskw' or 'ioskw' for distribution issues

  • By Complexity: Sort by 'numsteps' for complex execution plans

  • By Response Time: Sort by 'response_secs' for user experience impact

AVAILABLE METRICS FOR SORTING:

  • ampcputime: Total CPU seconds (primary optimization target)

  • logicalio: Total logical I/O operations (scan indicator)

  • cpuskw: CPU skew ratio (distribution problems)

  • ioskw: I/O skew ratio (hot spot indicators)

  • pji: Physical-to-Logical I/O ratio (compute intensity)

  • uii: Unit I/O Intensity (I/O efficiency)

  • numsteps: Query execution plan steps (complexity)

  • response_secs: Wall-clock execution time (user impact)

  • delaytime: Time spent in queue (concurrency issues)

AUTOMATIC PERFORMANCE CATEGORIZATION: Each query is categorized using configurable thresholds (from sql_opt_config.yml):

  • CPU Categories: VERY_HIGH_CPU (>config.very_high), HIGH_CPU (>config.high), MEDIUM_CPU (>10s), LOW_CPU

  • CPU Skew: SEVERE_CPU_SKEW (>config.severe), HIGH_CPU_SKEW (>config.high), MODERATE_CPU_SKEW (>config.moderate), NORMAL

  • I/O Skew: SEVERE_IO_SKEW (>config.severe), HIGH_IO_SKEW (>config.high), MODERATE_IO_SKEW (>config.moderate), NORMAL

Use thresholds set in config file for, CPU - high, very_high, Skew moderate, high, severe

TYPICAL OPTIMIZATION WORKFLOW:

  1. Start with clusters identified from sql_Analyze_Cluster_Stats

  2. Retrieve top queries by impact metric (usually 'ampcputime')

  3. Analyze SQL patterns for common issues:

    • Missing WHERE clauses or inefficient predicates

    • Cartesian products or missing JOIN conditions

    • Inefficient GROUP BY or ORDER BY operations

    • Suboptimal table access patterns

    • Missing or outdated statistics

  4. Develop specific optimization recommendations

QUERY LIMIT STRATEGY:

  • Use the query limit set in config file for pattern recognition and analysis, unless user specifies a different limit

OUTPUT INCLUDES:

  • Complete SQL query text for each query

  • All performance metrics, user, application, and workload context, cluster membership and rankings

  • Performance categories for quick filtering

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
metricNoampcputime
cluster_idsYes
limit_per_clusterNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv0.2.1
    • addedInput schema / additionalProperties
      Added value: +false
    • removedInput schema / properties / cluster_ids / title
      Removed value: -"Cluster Ids"
    • removedInput schema / properties / limit_per_cluster / title
      Removed value: -"Limit Per Cluster"
    • removedInput schema / properties / metric / title
      Removed value: -"Metric"
  2. Addedv1.0.0

TDQS

A4.7/5.0
Behavior5/5

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

Annotations provide idempotentHint=true and readOnlyHint=false, but the description adds substantial behavioral detail: available sort metrics, automatic performance categorization with configurable thresholds, query selection strategies, and expected output contents. It does not contradict the annotations, and it goes far beyond what the structured fields reveal.

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 long but exceptionally well-structured with headers, bold terms, and bullet lists. The core purpose is front-loaded, and every section—metrics, categories, workflow, output—earns its place given the 0% schema coverage and absence of an output schema.

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

Completeness5/5

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

For a tool with no output schema, the description is remarkably complete. It explains what the output includes (SQL text, metrics, context, categories), how to sort queries, how categories are derived, and the recommended workflow. An agent has enough information to invoke it correctly and interpret results.

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?

Schema description coverage is 0%, so the description must compensate. It thoroughly explains the 'metric' parameter with a full list of options and their meanings, and it addresses 'limit_per_cluster' via the query limit strategy. The required 'cluster_ids' parameter is only indirectly explained through the workflow reference to clusters from sql_Analyze_Cluster_Stats, but the context is sufficient.

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 opens with a clear verb+resource statement: 'RETRIEVE ACTUAL SQL QUERIES FROM SPECIFIC CLUSTERS FOR PATTERN ANALYSIS'. It then details capabilities and explicitly references the sibling sql_Analyze_Cluster_Stats as the upstream step, making it easy to distinguish from cluster-level statistics tools.

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

Usage Guidelines4/5

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

The description provides a 'TYPICAL OPTIMIZATION WORKFLOW' and explains when to use this tool: after cluster identification, to move from cluster-level analysis to query-level optimization. It also gives a query limit strategy and mentions sql_Analyze_Cluster_Stats as the source of clusters. However, it does not explicitly state when not to use this tool or name other alternatives.

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