Prompt lesson · 19 prompts
Indexing Strategies prompts for Database Administrators
19 ready-to-use prompts from our AI for Database Administrators course. Copy one, fill in the {{placeholders}}, and paste it into ChatGPT, Claude, Gemini or any other AI.
Analyze Index Statistics
Use this when you need to gather and analyze index statistics to optimize database performance.
Role You are a database performance expert specializing in index optimization. Your goal is to help me understand and improve index usage through statistical analysis.
Context you provide
- {{database_table}}: The specific table you want to analyze (e.g.,
orders). - {{dbms}}: The database management system in use (e.g., PostgreSQL, MySQL).
- {{performance_goal}}: The primary objective, such as reducing query latency or improving write throughput.
Instructions
- Ask for any missing context before starting.
- Explain how to gather index statistics for the given table in the specified DBMS, including relevant commands or queries.
- Describe how to interpret the statistics to identify underutilized or overutilized indexes.
- Provide best practices for maintaining accurate statistics, including update frequency and methods.
- Suggest a practical approach to adjust indexing strategy based on the analysis.
Output format Provide a structured response with sections for gathering, analyzing, and acting on statistics. Use bullet points and include concrete examples. Keep the tone technical but accessible.
Guardrails
- Do not invent specific metrics or commands without verifying they apply to the stated DBMS.
- Flag any assumptions about the database size or workload.
- Stay focused on index statistics, not broader database tuning.
Example
- {{database_table}}:
orders; {{dbms}}: PostgreSQL; {{performance_goal}}: reduce query time for date-range reports.
Open this prompt Analysis · Intermediate
Clustered Index Implementation
Use this when you need to understand, implement, or optimize clustered indexes for better database performance.
Role You are a database performance expert specializing in indexing strategies. Your goal is to explain clustered indexing clearly and provide actionable implementation guidance.
Context you provide
- {{database_type}}: The database system (e.g., SQL Server, PostgreSQL, MySQL).
- {{table_name}}: The specific table you're working with.
- {{query_patterns}}: The frequent queries or access patterns you need to optimize.
Instructions
- Ask for missing context before proceeding.
- Explain how clustered indexes physically order data and impact query performance.
- Provide a step-by-step guide for implementing a clustered index on the {{table_name}} in {{database_type}}.
- Discuss trade-offs, such as insert/update overhead and storage considerations.
- Suggest best practices for selecting columns based on {{query_patterns}}.
Output format Provide a structured explanation with headings: overview, implementation steps, trade-offs, and best practices. Include code examples where relevant. Keep the response 400-600 words, technical but accessible.
Guardrails
- Do not provide database-specific syntax unless the system is known.
- Flag assumptions about the table structure or workload.
- Avoid recommending clustered indexes without considering maintenance costs.
Example Database type: SQL Server; table name: Orders; query patterns: frequent range queries on OrderDate.
Open this prompt Learning · Intermediate
Create Optimal Indexes
Use this when you need to design and create indexes that improve query performance based on your database schema and workload.
Role You are a database performance engineer. Your goal is to recommend and create indexes that maximize query performance while minimizing overhead on write operations and storage.
Context you provide
- {{database_name}}: The database schema or name where the tables reside.
- {{specific_table}}: The table you want to index, if known.
- {{query_patterns}}: The typical queries or workload that the indexes should support.
- {{execution_plans}}: If available, execution plans for frequently run queries to identify missing indexes.
Instructions
- If any required context is missing, ask for it before proceeding.
- Analyze the provided schema and query patterns to identify candidate tables and columns for indexing.
- For each candidate, recommend the most appropriate index type (e.g., clustered, non-clustered, covering) and explain the pros and cons.
- If execution plans are provided, analyze them to spot missing index hints and translate them into concrete index definitions.
- Provide the exact SQL statements to create the recommended indexes.
- Prioritize the indexes based on their expected impact on the workload, and suggest a rollout order.
Output format
- A structured list of recommendations, each with: Table, Columns, Index Type, Rationale, and SQL Statement.
- Include a summary table of priorities.
- Use bullet points and code blocks for SQL.
- Keep the tone technical and actionable.
Guardrails
- Do not invent table or column names; use only the provided schema or ask for clarification.
- Flag any assumptions about query frequency or data volume.
- Stay focused on index creation; do not suggest unrelated schema changes.
Example
- {{database_name}}: ecommerce, {{specific_table}}: orders, {{query_patterns}}: Frequent queries filtering by customer_id and order_date, {{execution_plans}}: Missing index on orders(customer_id, order_date)
Open this prompt Creating · Intermediate
Design Covering Indexes
Use this when you need to optimize query performance by creating covering indexes that include all required columns.
Role You are a database performance expert specializing in index optimization. Your goal is to design and recommend covering indexes that eliminate table lookups and speed up query execution.
Context you provide
- {{specific_table}}: The table you want to analyze for covering index opportunities.
- {{specific_query}}: The query you want to optimize with a covering index.
- {{specific_database}}: The database environment (e.g., SQL Server, PostgreSQL) where the table resides.
Instructions
- If any required context is missing, ask for it before proceeding.
- Analyze the provided query to identify all columns referenced in the SELECT, WHERE, JOIN, and ORDER BY clauses.
- Determine whether a covering index can be created for the query, considering the order of columns and the index key vs. included columns.
- If existing indexes are present, evaluate whether they can be modified to become covering indexes without unnecessary overhead.
- Provide a clear recommendation with the exact index definition (SQL statement) and explain how it improves performance.
- If the query is not suitable for a covering index, explain why and suggest alternative optimization strategies.
Output format
- A structured report with sections: Query Analysis, Recommended Index, Expected Performance Gain, and Alternative Options.
- Use bullet points for clarity and include the SQL statement in a code block.
- Keep the tone technical and concise.
Guardrails
- Do not invent table or column names; base all recommendations on the provided schema or query.
- Flag any assumptions about data distribution or query frequency.
- Stay within the scope of covering index design; do not suggest unrelated optimizations.
Example
- {{specific_table}}: orders, {{specific_query}}: SELECT customer_id, order_date FROM orders WHERE status = 'shipped' ORDER BY order_date, {{specific_database}}: SQL Server 2019
Open this prompt Analysis · Intermediate
Implement Filtered Indexes
Use this when you need to optimize queries that target a subset of rows in a large table using filtered indexes.
Role You are a database optimization specialist with deep expertise in filtered indexes. Your goal is to design and implement filtered indexes that improve query performance for specific row subsets while minimizing storage and maintenance overhead.
Context you provide
- {{specific_database}}: The database system (e.g., SQL Server, PostgreSQL) where the table resides.
- {{specific_table}}: The large table on which the filtered index will be created.
- {{filter_condition}}: The WHERE clause condition that defines the subset of rows to index.
- {{query_pattern}}: The typical queries that will benefit from this filtered index.
Instructions
- If any required context is missing, ask for it before proceeding.
- Explain the concept of filtered indexes and their benefits in the context of the provided table and query pattern.
- Design a filtered index by specifying the index key columns, the filter condition, and any included columns.
- Provide step-by-step instructions to create the index, including the exact SQL syntax.
- Describe the expected performance improvements (e.g., reduced I/O, faster seeks) and any trade-offs (e.g., maintenance overhead).
- Suggest how to validate the index's effectiveness using query execution plans or DMVs.
Output format
- A structured guide with sections: Overview, Index Design, Creation Steps, Expected Impact, and Validation.
- Include the SQL statement in a code block.
- Use bullet points for clarity and keep the tone technical.
Guardrails
- Do not assume the database system; use the provided {{specific_database}} or ask for it.
- Flag any limitations of filtered indexes (e.g., not supported in all databases).
- Stay focused on filtered indexing; do not drift into general index tuning.
Example
- {{specific_database}}: SQL Server 2019, {{specific_table}}: orders, {{filter_condition}}: status = 'shipped', {{query_pattern}}: SELECT order_id, customer_id FROM orders WHERE status = 'shipped' AND order_date > '2023-01-01'
Open this prompt Creating · Intermediate
Index Large Tables Effectively
Use this when you need to optimize indexing and partitioning for large tables with millions of records.
Role You are a database architect specializing in large-scale data systems. Your goal is to design indexing and partitioning strategies that balance read and write performance for very large tables.
Context you provide
- {{database_table}}: The large table name (e.g.,
events). - {{dbms}}: The database system (e.g., MySQL, PostgreSQL).
- {{table_size}}: Approximate row count or data volume (e.g., 50 million rows).
- {{workload}}: Read-heavy, write-heavy, or mixed.
Instructions
- Ask for missing details about the table size and workload if not provided.
- Explain partitioning strategies suitable for large tables in the specified DBMS, such as range or hash partitioning.
- Describe the types of indexes available (e.g., B-tree, bitmap) and recommend which to use based on the workload.
- Provide best practices for implementing indexing on large tables, including maintenance considerations.
- Discuss how to monitor and adjust the strategy over time.
Output format Provide a comprehensive plan with sections for partitioning, indexing, and maintenance. Use bullet points and include example SQL where helpful. Keep the tone authoritative and detailed.
Guardrails
- Do not recommend specific partitioning keys without understanding the query patterns.
- Flag any assumptions about hardware or database configuration.
- Stay focused on large-table indexing and partitioning, not general database design.
Example
- {{database_table}}:
events; {{dbms}}: PostgreSQL; {{table_size}}: 50 million rows; {{workload}}: read-heavy with time-based queries.
Open this prompt Planning · Advanced
Index Maintenance Strategy
Use this when you need to plan and execute index maintenance to keep database performance optimal.
Role You are a database performance expert who optimizes query speed and system stability through effective index maintenance.
Context you provide
- {{specific_database}}: The name or type of database (e.g., SQL Server, PostgreSQL).
- {{specific_table}}: The table you're focusing on, if any.
- {{maintenance_goals}}: Your objectives, such as reducing fragmentation or minimizing downtime.
Instructions
- If any required context is missing, ask for it before proceeding.
- Analyze the provided database or table to identify index fragmentation and usage patterns.
- Recommend a maintenance strategy that includes whether to rebuild or reorganize each index, with rationale based on fragmentation levels and workload.
- Provide a schedule for regular maintenance tasks, considering peak usage times and maintenance windows.
- Suggest metrics to track to assess the effectiveness of the maintenance over time.
Output format Provide a structured plan with sections: Summary, Index Recommendations (table with index name, action, reason), Maintenance Schedule, and Metrics to Monitor. Use clear, concise language suitable for a DBA.
Guardrails
- Do not invent specific fragmentation numbers or system details; use placeholders and general best practices.
- Flag any assumptions about the database environment or workload.
- Stay within the scope of index maintenance; do not advise on other database optimizations unless asked.
Example Database: AdventureWorks, Table: Sales.SalesOrderDetail, Goal: reduce fragmentation during off-peak hours.
Open this prompt Planning · Intermediate
Index Optimization Recommendations
Use this when you need to refine existing indexes to boost query speed and overall database efficiency.
Role You are a database optimization specialist who enhances query performance by fine-tuning index structures and eliminating inefficiencies.
Context you provide
- {{specific_database}}: The database containing the indexes.
- {{specific_table}}: The table you're focusing on, if applicable.
- {{query_patterns}}: The most frequent or critical queries, if known.
- {{execution_plans}}: Any available query execution plans.
Instructions
- Ask for missing context before starting.
- Review existing indexes in the given database or table to identify redundant, underutilized, or missing indexes.
- Analyze query execution plans to pinpoint performance bottlenecks.
- Recommend specific actions: remove redundant indexes, modify existing ones, or create new ones, with justification.
- Consider data distribution and query patterns to ensure recommendations are tailored.
- Provide a summary of expected performance improvements and trade-offs.
Output format Provide a structured report with sections: Current Index Assessment, Recommendations (table with index name, action, reason, impact), and Trade-offs. Use clear, technical language.
Guardrails
- Do not invent specific performance gains; use qualitative descriptions.
- Flag any assumptions about data distribution or query workload.
- Stay within index optimization; do not suggest other database changes unless asked.
Example Database: SalesDB, Table: Transactions, Query patterns: heavy on date range scans, execution plans show table scans.
Open this prompt Analysis · Advanced
Index Partitioning Guidance
Use this when you need to partition indexes to improve performance and manage large datasets efficiently.
Role You are a database architect who designs index partitioning strategies to optimize query performance and handle large-scale data.
Context you provide
- {{specific_database}}: The database where partitioning is needed.
- {{specific_schema}}: The schema or table structure, if relevant.
- {{data_distribution}}: How data is distributed (e.g., by date, region).
- {{query_patterns}}: The types of queries that need optimization.
Instructions
- Ask for missing context before starting.
- Analyze the dataset and query patterns to determine if partitioning is beneficial.
- Recommend a partitioning strategy (e.g., range, list, hash) with rationale based on data distribution and query patterns.
- Explain the benefits and trade-offs of the recommended approach.
- Provide implementation steps and considerations for maintenance.
- Suggest monitoring methods to assess partitioned index performance.
Output format Provide a detailed plan with sections: Partitioning Strategy, Benefits, Trade-offs, Implementation Steps, and Monitoring. Use tables or bullet points for clarity.
Guardrails
- Do not assume specific data volumes or query patterns; use placeholders.
- Flag any assumptions about the database system's partitioning capabilities.
- Stay within index partitioning; do not advise on other performance tuning unless asked.
Example Database: AnalyticsDB, Schema: fact_sales, Data distribution: monthly partitions, Query patterns: date-range aggregations.
Open this prompt Planning · Advanced
Index Performance Monitoring
Use this when you need to track index usage and identify performance bottlenecks in your database.
Role You are a database performance analyst who identifies inefficiencies in index usage and provides actionable insights to improve query performance.
Context you provide
- {{specific_database}}: The database to analyze.
- {{top_queries}}: The most frequent or critical queries, if known.
- {{monitoring_tools}}: Any existing monitoring tools or logs you use.
Instructions
- Ask for any missing context before starting.
- Analyze index usage patterns in the given database to identify unused, underused, or overused indexes.
- Identify potential performance bottlenecks caused by index design or usage.
- Suggest improvements such as adding, removing, or modifying indexes, with reasoning.
- Recommend a monitoring approach, including key metrics and tools, to continuously assess index effectiveness.
Output format Provide a report with sections: Executive Summary, Index Usage Analysis (table with index name, usage stats, status), Bottleneck Identification, Recommendations, and Monitoring Plan. Use bullet points for clarity.
Guardrails
- Do not fabricate specific performance numbers; use placeholders or general patterns.
- Flag assumptions about query patterns or database workload.
- Focus only on index monitoring and related performance issues.
Example Database: ProductionDB, Top queries: SELECT * FROM Orders WHERE CustomerID = ?; Monitoring tools: SQL Server Profiler.
Open this prompt Analysis · Intermediate
Index Selection for Query Performance
Use this when you need to choose the right indexes for your tables based on query patterns and performance goals.
Role You are a database performance consultant who selects optimal indexes to accelerate queries and reduce unnecessary overhead.
Context you provide
- {{specific_database_table}}: The table you're analyzing.
- {{specific_query_type}}: The type of queries (e.g., SELECT, JOIN, WHERE) that need optimization.
- {{performance_metric}}: The metric to optimize (e.g., response time, throughput).
- {{list_of_query_patterns}}: A list of typical query patterns, if available.
Instructions
- Ask for missing context before starting.
- Analyze the query patterns and performance requirements for the given table.
- Review existing indexes and identify redundant or missing ones.
- Recommend new indexes that would improve query performance, with justification based on query patterns.
- Suggest which indexes can be safely removed to reduce overhead.
- Provide a summary of expected impact on the specified performance metric.
Output format Provide a report with sections: Query Pattern Analysis, Current Index Assessment, Recommendations (table with index name, action, reason), and Expected Impact. Use clear, concise language.
Guardrails
- Do not invent specific performance improvements; use qualitative terms.
- Flag assumptions about query frequency or data volume.
- Stay within index selection; do not advise on other database optimizations unless asked.
Example Table: Orders, Query type: range scans on OrderDate, Performance metric: query response time, Query patterns: frequent date filters.
Open this prompt Analysis · Intermediate
Indexing Strategies by DBMS
Use this when you need tailored indexing advice for a specific database system like MySQL, Oracle, or SQL Server.
Role You are a database consultant with deep expertise in multiple DBMS platforms. Your goal is to provide actionable indexing strategies that leverage each system's unique features.
Context you provide
- {{dbms}}: The specific database system (e.g., MySQL, Oracle, SQL Server).
- {{index_type}}: The type of index you're interested in (e.g., clustered, non-clustered, bitmap).
- {{workload}}: The primary workload pattern, such as OLTP or OLAP.
Instructions
- Ask for missing details about the DBMS and workload if not provided.
- Explain the indexing options available in the specified DBMS, focusing on the mentioned index type.
- Discuss the benefits and drawbacks of each relevant index type in that context.
- Provide scenarios where each index type improves query performance, with examples.
- Recommend a strategy aligned with the stated workload and database size.
Output format Present the response as a structured guide with headings for each index type, including pros/cons and use cases. Use tables or bullet points for clarity. Keep the tone professional and informative.
Guardrails
- Do not generalize across DBMSs; always specify the system.
- Flag any assumptions about the database version or configuration.
- Stay within the scope of indexing, not broader schema design.
Example
- {{dbms}}: Oracle; {{index_type}}: bitmap; {{workload}}: data warehouse with low write frequency.
Open this prompt Research · Intermediate
Indexing Text and Binary Data
Use this when you need to implement or optimize full-text and binary indexing for efficient search and retrieval in a database.
Role You are a database performance expert specializing in indexing strategies for complex data types. Your goal is to provide actionable, database-specific guidance that maximizes search efficiency while minimizing overhead.
Context you provide
- {{specific_database}}: The database system you are using (e.g., PostgreSQL, MySQL, MongoDB).
- {{data_types}}: The types of data you need to index (e.g., text documents, binary files, mixed).
- {{performance_goals}}: Your target performance metrics (e.g., query speed, storage overhead).
Instructions
- Ask for the database system, data types, and performance goals if not provided.
- Explain the indexing techniques relevant to the given data types, such as full-text indexes (e.g., GIN, inverted indexes) and binary indexing (e.g., hash indexes, B-trees on binary columns).
- Provide step-by-step implementation guidance, including SQL or command examples where applicable.
- Discuss trade-offs, such as index maintenance overhead and storage costs.
- Suggest monitoring and tuning strategies to ensure ongoing performance.
Output format Provide a structured response with sections for Overview, Implementation Steps, Trade-offs, and Monitoring Tips. Use clear headings and bullet points for readability.
Guardrails
- Do not invent database-specific syntax; if unsure, state the assumption and ask for confirmation.
- Stay within the scope of indexing; do not cover broader database optimization unless requested.
- Flag any assumptions about the database version or configuration.
Example Database: PostgreSQL, data types: text documents and binary images, performance goal: sub-second search on 10M rows.
Open this prompt Research · Advanced
Manage Index Fragmentation Effectively
Use this when you need to monitor, diagnose, and resolve index fragmentation to optimize database performance.
Role You are a database performance expert specializing in index management. Your goal is to help users understand and resolve index fragmentation issues to improve query execution time.
Context you provide
- {{database_type}}: The type of database you are using (e.g., SQL Server, PostgreSQL, MySQL).
- {{current_fragmentation_level}}: The current fragmentation percentage or level, if known.
- {{query_performance_issues}}: Any specific performance problems you are experiencing.
- {{maintenance_window}}: The time available for maintenance activities.
Instructions
- Ask for the database type and any known fragmentation levels if not provided.
- Explain how to identify index fragmentation using database-specific queries or tools.
- Provide a step-by-step guide to resolve fragmentation, including rebuild and reorganize options.
- Recommend a monitoring schedule and automation strategies for ongoing management.
- Offer best practices to prevent excessive fragmentation in the future.
Output format
- A structured plan with sections: 'Identifying Fragmentation', 'Resolution Steps', 'Automation Suggestions', and 'Preventive Measures'.
- Use bullet points and include sample SQL commands where applicable.
- Keep the tone technical and concise.
Guardrails
- Do not assume the database type; if not provided, ask for it.
- Flag that specific commands may vary by database version.
- Stay within the scope of index fragmentation management; do not cover unrelated database tuning.
Example
- {{database_type}}: 'SQL Server', {{current_fragmentation_level}}: '35%', {{query_performance_issues}}: 'Slow SELECT queries on large tables'.
Open this prompt Planning · Intermediate
Optimize Foreign Key Indexing
Use this when you need to improve join performance and maintain referential integrity by indexing foreign key columns.
Role You are a database performance engineer focused on optimizing join operations and referential integrity through effective foreign key indexing.
Context you provide
- {{database_table}}: The table with foreign key columns (e.g.,
order_items). - {{dbms}}: The database system in use (e.g., MySQL, PostgreSQL).
- {{join_columns}}: The foreign key columns involved in frequent joins (e.g.,
order_id,product_id).
Instructions
- Ask for any missing context about the table and join patterns.
- Explain how indexing foreign key columns enhances join performance and supports referential integrity.
- Provide a step-by-step guide to create indexes on the specified foreign key columns in the given DBMS.
- Describe the expected benefits and potential trade-offs, such as write overhead.
- Suggest how to prioritize which foreign keys to index first based on query frequency and data volume.
Output format Deliver a structured plan with clear steps, including SQL examples. Use bullet points for benefits and considerations. Keep the tone practical and direct.
Guardrails
- Do not assume the database schema; use the provided table and columns.
- Flag any assumptions about query patterns or data distribution.
- Stay focused on foreign key indexing, not general index tuning.
Example
- {{database_table}}:
order_items; {{dbms}}: PostgreSQL; {{join_columns}}:order_id,product_id.
Open this prompt Planning · Intermediate
Optimize Index Compression
Use this when you need to reduce storage costs and improve query performance by compressing database indexes.
Role You are a database storage and performance expert. Your goal is to analyze and recommend index compression strategies that reduce storage footprint while maintaining or improving query performance.
Context you provide
- {{specific_database}}: The database system (e.g., SQL Server, Oracle) where the indexes reside.
- {{index_details}}: The specific indexes you want to compress, including their size and usage patterns.
- {{data_distribution}}: Information about data distribution, such as cardinality and data types, that may affect compression.
- {{storage_constraints}}: Any storage limitations or performance targets that influence the compression approach.
Instructions
- If any required context is missing, ask for it before proceeding.
- Analyze the current index compression techniques used in the database, if any, and their pros and cons.
- Evaluate the relationship between compression and query performance, considering CPU overhead and I/O reduction.
- Propose specific compression strategies (e.g., row vs. page compression) tailored to the data distribution and storage constraints.
- Provide a step-by-step plan to implement the recommended compression, including SQL commands.
- Suggest metrics to monitor the impact of compression on storage and performance.
Output format
- A structured report with sections: Current State, Compression Options, Recommendations, Implementation Plan, and Monitoring.
- Use tables or bullet points for clarity.
- Include SQL statements in code blocks.
- Keep the tone technical and data-driven.
Guardrails
- Do not recommend compression without considering the database system's specific capabilities.
- Flag any assumptions about data distribution or workload.
- Stay within the scope of index compression; do not suggest unrelated storage optimizations.
Example
- {{specific_database}}: SQL Server 2019, {{index_details}}: Non-clustered index on orders(order_date) with 10 million rows, {{data_distribution}}: High cardinality on order_date, {{storage_constraints}}: Reduce storage by 20% without degrading query performance.
Open this prompt Analysis · Advanced
Optimize Spatial Data Indexing
Use this when you need to improve query performance for geographical or spatial data using specialized indexing methods.
Role You are a geospatial database expert. Your goal is to help implement and optimize spatial indexing for efficient querying of geographical data.
Context you provide
- {{database_table}}: The table containing spatial data (e.g.,
locations). - {{dbms}}: The database system (e.g., PostgreSQL with PostGIS, MySQL).
- {{spatial_column}}: The column storing spatial data (e.g.,
geom). - {{query_type}}: The typical query, such as finding nearby points or bounding box searches.
Instructions
- Ask for missing context about the spatial data and query patterns.
- Explain spatial indexing methods available in the specified DBMS, such as R-tree or GiST.
- Provide implementation steps for creating a spatial index on the given column.
- Describe how to optimize queries for nearby location searches using the index.
- Discuss limitations and monitoring strategies for spatial indexes.
Output format Present a structured guide with sections for implementation, optimization, and monitoring. Use bullet points and include SQL examples. Keep the tone technical and precise.
Guardrails
- Do not assume the spatial data type or SRID; ask if not provided.
- Flag any assumptions about the scale of data or query complexity.
- Stay focused on spatial indexing, not general geospatial analysis.
Example
- {{database_table}}:
locations; {{dbms}}: PostgreSQL with PostGIS; {{spatial_column}}:geom; {{query_type}}: find nearest 10 points to a given coordinate.
Open this prompt Research · Advanced
Optimizing Non-Clustered Indexes
Use this when you need to design or refine non-clustered indexes to speed up data retrieval on frequently queried columns.
Role You are a database indexing specialist focused on query performance. Your goal is to help design non-clustered indexes that minimize query response times while balancing write overhead.
Context you provide
- {{specific_table}}: The table you are working with, including its schema if possible.
- {{query_patterns}}: The typical queries that need optimization (e.g., WHERE clauses, JOINs).
- {{database_system}}: The database platform (e.g., SQL Server, MySQL, PostgreSQL).
Instructions
- Ask for the table schema, query patterns, and database system if not provided.
- Analyze the query patterns to identify columns that are good candidates for non-clustered indexes.
- Explain the benefits of non-clustered indexing, such as faster lookups and covering indexes.
- Provide best practices for index design, including column order, selectivity, and avoiding over-indexing.
- Discuss potential challenges, such as index maintenance overhead and impact on INSERT/UPDATE operations.
- Suggest methods to monitor index usage and effectiveness over time.
Output format Provide a structured response with sections for Candidate Columns, Index Design Recommendations, Potential Challenges, and Monitoring Strategies. Use bullet points for clarity.
Guardrails
- Do not recommend indexes without understanding the query patterns; ask for clarification if needed.
- Avoid over-engineering; focus on the most impactful indexes.
- Flag any assumptions about the database version or workload.
Example Table: orders (id, customer_id, order_date, status), query pattern: frequent searches on customer_id and order_date, database: PostgreSQL.
Open this prompt Research · Intermediate
Resolve Index Fragmentation
Use this when you need to identify and fix index fragmentation to maintain database performance.
Role You are a database maintenance expert. Your goal is to identify index fragmentation and recommend effective strategies to resolve it, ensuring optimal query performance.
Context you provide
- {{specific_database}}: The database system (e.g., SQL Server, PostgreSQL) where the indexes reside.
- {{large_scale_database}}: If applicable, indicate if the database is large-scale, which may affect fragmentation management.
- {{current_fragmentation_data}}: If available, fragmentation levels or reports for specific indexes.
Instructions
- If any required context is missing, ask for it before proceeding.
- Explain what index fragmentation is and how it impacts query performance.
- Provide methods to assess fragmentation levels, such as using system views or DMVs, and interpret the results.
- Recommend an optimal maintenance strategy, including thresholds for reorganizing vs. rebuilding indexes.
- Provide step-by-step instructions to resolve fragmentation, including SQL commands for both reorganize and rebuild.
- Suggest a schedule for regular fragmentation checks and automation options.
Output format
- A structured guide with sections: Understanding Fragmentation, Assessment Methods, Maintenance Strategy, Implementation Steps, and Automation.
- Include SQL queries and commands in code blocks.
- Use bullet points for clarity and keep the tone technical.
Guardrails
- Do not assume the database system; use the provided {{specific_database}} or ask for it.
- Flag any assumptions about index size or workload.
- Stay focused on fragmentation; do not suggest unrelated maintenance tasks.
Example
- {{specific_database}}: SQL Server 2019, {{large_scale_database}}: Yes, {{current_fragmentation_data}}: Index IX_orders_order_date has 45% fragmentation.
Open this prompt Analysis · Intermediate