{"uid":"cap_2E8hRupi866_aMKL_VjTP","slug":"api-strale-io-96d51680","name":"SQL Query Optimizer","description":"Analyze and optimize a SQL query for performance. Returns rewritten query, index recommendations, and explanation of improvements.","url":"https://api.strale.io/x402/sql-optimize?utm_source=zero.xyz","method":"GET","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method"],"properties":{"type":{"type":"string","const":"http"},"method":{"enum":["GET","HEAD","DELETE"],"type":"string"},"queryParams":{"type":"object","required":["sql"],"properties":{"sql":{"type":"string"},"dialect":{"type":"string"},"table_schema":{"type":"string"}}}},"additionalProperties":false}}},"responseSchema":null,"example":{"request":{"sql":"SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.status = 'pending' AND o.created_at > '2024-01-01'","dialect":"postgresql","table_schema":"orders(id INT, customer_id INT, status VARCHAR, created_at TIMESTAMP), customers(id INT, name VARCHAR)"},"response":{"_meta":{"payment":{"method":"x402","price_usd":0.054000000000000006,"settlement_id":"0x419fd6b9ea2c47698f0d00e373fa758de0604b7611b509a96972b2d6a425e5d1"},"capability":"sql-optimize","latency_ms":3313,"provenance":{"source":"claude-haiku","fetched_at":"2026-06-13T04:23:35.953Z"}},"dialect":"postgresql","explanation":"Explicit column selection reduces memory and network overhead. The composite index on (status, created_at) enables efficient filtering of pending orders by date. The customer_id index accelerates the join operation. The partial index on pending status reduces index size. INNER JOIN is more optimal than implicit joins. These changes allow PostgreSQL to use index-only scans and reduce full table scans.","changes_made":["Replaced SELECT * with explicit column names to reduce data transfer","Changed JOIN to INNER JOIN for clarity and potential optimizer hints","Reordered WHERE conditions to filter on indexed columns first","Removed unnecessary wildcard selection"],"original_sql":"SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.status = 'pending' AND o.created_at > '2024-01-01'","optimized_sql":"SELECT o.id, o.customer_id, o.status, o.created_at, c.id, c.name FROM orders o INNER JOIN customers c ON o.customer_id = c.id WHERE o.status = 'pending' AND o.created_at > '2024-01-01'","estimated_improvement":"Expected 30-50% performance improvement through reduced I/O, better index utilization, and smaller result sets","index_recommendations":["CREATE INDEX idx_orders_status_created ON orders(status, created_at) WHERE status = 'pending'","CREATE INDEX idx_orders_customer_id ON orders(customer_id)","CREATE INDEX idx_customers_id ON customers(id)"]}},"exampleRequest":{"sql":"SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.status = 'pending' AND o.created_at > '2024-01-01'","dialect":"postgresql","table_schema":"orders(id INT, customer_id INT, status VARCHAR, created_at TIMESTAMP), customers(id INT, name VARCHAR)"},"tags":["x402"],"displayCostAmount":"0.054001","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"settled","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.054001/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.054","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.054","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_RoSNzNktnHxR_0T7Emt8l","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.054","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Analyzes a SQL query for performance issues and returns a rewritten query, index recommendations, and explanation of improvements","exampleAgentPrompt":"Can you optimize this SQL query for me and tell me what indexes I should add? SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.status = 'pending' AND o.created_at > '2024-01-01' — using PostgreSQL dialect.","exampleUseCases":[{"title":"Optimize slow customer analytics query","prompt":"I've got a query that joins our orders and customers tables to find recent pending orders, but it's taking way too long to run. Can you rewrite it for better performance and suggest what indexes would help? It's on PostgreSQL and filters for orders created after January 2024."},{"title":"Speed up financial reconciliation report","prompt":"Our nightly reconciliation job queries transactions, accounts, and audit logs across three tables and it's timing out. Can you look at the SQL, tell me why it's slow, rewrite it to be faster, and give me the exact index statements I need to run?"},{"title":"Reduce latency on compliance check queries","prompt":"We're running compliance verification queries that pull from our regulatory audit tables, but they're blocking other operations. Can you optimize the SQL query logic and recommend which indexes we should create to speed this up?"}],"resultDescription":"Returns a rewritten SQL query optimized for performance, specific index recommendations for the tables involved, and a plain-English explanation of what changes were made and why they improve performance.","failureModes":["Invalid or unparseable SQL syntax returns an error","Unsupported SQL dialect may produce generic or inaccurate recommendations","Missing table schema may reduce the quality of index recommendations","Very complex queries with many joins may produce incomplete optimizations","Empty or null sql parameter returns a validation error"],"whenToPreferThis":"Use this endpoint when you need automated, on-demand SQL query performance analysis without setting up a dedicated database tuning tool. Ideal for AI agents that need to suggest query improvements, generate index DDL statements, or explain performance issues to developers. Prefer this over general-purpose LLM SQL advice when you want structured, actionable output including a rewritten query and concrete index recommendations.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-12T18:46:46.798Z","isFirstParty":false,"canonicalSlug":"api-strale-io-96d51680"}