Why GIIP AI Harness Excludes Query Hints
Published 2026-09-06 · Updated 2026-09-06 · Last Verified 2026-09-06
Answer
When you ask a general-purpose base AI model to tune a slow query, it often responds with suggestions that use FORCE INDEX or join hints for immediate improvement. However, hints prevent the CBO from selecting a different execution plan as data volume grows or distribution changes, and they tightly couple the index lifecycle to application code. GIIP AI Harness therefore excludes hints by design, constraining its proposals to CBO-friendly measures such as statistics maintenance and Sargability — so the optimizer can continue making autonomous decisions.
Applicability of This Document
| Product | GIIP AI Harness (compared to: a general-purpose base AI model generating SQL) |
|---|---|
| Verified Versions | A design-level explanation not tied to a specific product version (diagnostic SQL examples assume SQL Server 2008 or later) |
| Environment | AWS, Azure, on-premise |
| Required Permissions | Diagnostic SQL requires VIEW SERVER STATE or equivalent read permissions; code-base searches require repository read access |
| Execution Impact | Read-only (commands in this article do not change state) |
| Restart | Not required |
| Last Verified | 2026-09-06 |
Ready-to-Run Commands
- 対象
- Application and stored-procedure source code repositories
- 権限
- Repository read access
- 変更作業
- None (search only)
- Production実行
- N/A (run locally or in CI)
# Target: Application and stored-procedure source code repositories
# Permission: Repository read access
# Change: None (search only)
# Production: N/A (run locally or in CI)
# Search for common execution-plan-forcing patterns across the codebase
# WITH (INDEX(...)) / FORCESEEK / FORCESCAN / explicit join hints (LOOP|HASH|MERGE) / OPTION(FORCE ORDER)
grep -RniE "with[[:space:]]*\([[:space:]]*index[[:space:]]*\(|forceseek|forcescan|force[[:space:]]*order|loop[[:space:]]+join|hash[[:space:]]+join|merge[[:space:]]+join" --include=*.sql --include=*.cs --include=*.ts .Because this search is regex-based, hits are "investigation targets" not "confirmed forced references". Examine each hit individually before drawing conclusions.
- 対象
- SQL Server 2008 or later / Amazon RDS for SQL Server / Azure SQL
- 権限
- VIEW DEFINITION
- 変更作業
- None (read-only)
- Production実行
- Permitted
-- Target: SQL Server 2008 or later / Amazon RDS for SQL Server / Azure SQL
-- Permission: VIEW DEFINITION
-- Change: None (read-only)
-- Production: Permitted
SELECT
o.name AS object_name,
o.type_desc AS object_type
FROM sys.sql_modules AS m
INNER JOIN sys.objects AS o
ON o.object_id = m.object_id
WHERE m.definition LIKE '%INDEX(%'
OR m.definition LIKE '%FORCESEEK%'
OR m.definition LIKE '%FORCESCAN%'
OR m.definition LIKE '%FORCE ORDER%'
ORDER BY o.name;This supplementary query finds hints that may exist inside stored procedures or views even when they are not present in the application repository.
- 対象
- SQL Server 2008 or later / Amazon RDS for SQL Server / Azure SQL Managed Instance
- 権限
- VIEW SERVER STATE (VIEW DATABASE STATE for Azure SQL Database)
- 変更作業
- None (read-only)
- Production実行
- Permitted
-- Target: SQL Server 2008 or later / Amazon RDS for SQL Server / Azure SQL Managed Instance
-- Permission: VIEW SERVER STATE (VIEW DATABASE STATE for Azure SQL Database)
-- Change: None (read-only)
-- Production: Permitted
SELECT
OBJECT_NAME(i.object_id) AS table_name,
i.name AS index_name,
ius.user_seeks,
ius.user_scans,
ius.user_lookups,
ius.user_updates,
ius.last_user_seek,
ius.last_user_scan,
ius.last_user_lookup
FROM sys.indexes AS i
LEFT JOIN sys.dm_db_index_usage_stats AS ius
ON ius.object_id = i.object_id
AND ius.index_id = i.index_id
AND ius.database_id = DB_ID()
WHERE i.object_id = OBJECT_ID('dbo.SampleTable')
ORDER BY i.name;DMV counters reset on service restart, failover, or instance recreation. Do not treat "0% usage" as a deletion reason without also checking the code-base search above.
How to Read the Results
| Column | Meaning | What to Check |
|---|---|---|
| user_seeks / user_scans / user_lookups | Cumulative count of read operations that used this index | Even when all are 0, this may only reflect the period since the last service restart or failover |
| user_updates | Cumulative count of index-maintenance operations caused by writes | High updates with few reads may indicate the index is a deletion candidate |
| last_user_seek / last_user_scan / last_user_lookup | When the index was last used for a read operation | NULL means the index has not been used since the DMV was reset — previous history is lost |
When to Use This
- The same base AI model produces different tuning proposals for the same slow query depending on the tool used.
- CPU or I/O spikes occur months after applying an AI-proposed FORCE INDEX or join hint, even though performance improved immediately.
- Deleting an index flagged as unused based solely on usage metrics caused a specific query or stored procedure to throw an exception immediately afterward.
- Application-code coordination is required every time an index is redesigned or a DDL change is made, causing delays.
Possible Causes (Most Likely First)
01
Selectivity reversal caused by data-distribution changes
Even with the same schema, data volume and cardinality vary by country, service characteristics, and traffic patterns. An Index Seek + Key Lookup that was optimal when the table was small can generate large random I/O at tens of millions of rows or with skewed data distribution. Past a certain tipping point, an Index Scan or Clustered Index Scan is often faster and more stable. Hints prevent the CBO from making this adjustment.
02
Dangerous coupling between the index lifecycle and application code
Large databases continuously create new composite indexes and consolidate or remove duplicate or unused ones. When an index reference is hard-coded in source code or stored procedures, changing or deleting that index causes an immediate runtime exception in production. In large-scale services, it is not uncommon for a team to delete an index based on usage metrics, only to have a specific query or procedure force-referencing that index fail immediately.
03
Difference in Harness, not in the model
A general-purpose base model looks only at the query string in front of it and proposes local optimizations. GIIP AI Harness is designed to leave room for the CBO to decide — it explicitly excludes hints that force specific indexes or require static data assumptions, and it treats the index lifecycle as separate from application code.
Diagnostic Steps
- 1
Search the codebase for execution-plan-forcing hints
Read-onlyUse the grep pattern above to search both application code and stored procedures for WITH (INDEX(...)), FORCESEEK/FORCESCAN, explicit join hints, and FORCE ORDER.
- 2
Check real index usage statistics
Read-onlyUse sys.dm_db_index_usage_stats to review the count of read and write operations and the last time each index was used.
- 3
Check whether DMV counters have been reset
Read-onlyConfirm the dates of recent service restarts, failovers, or instance recreations. If the observation period is short, "0% usage" is not a reliable basis for decisions.
- 4
Compare estimated vs. actual row counts in execution plans
Read-onlyLook for selectivity reversal caused by data-distribution skew between the estimated and actual rows in execution plans.
- 5
Check for Sargability blockers
Read-onlyLook for WHERE-clause expressions that apply functions to columns or cause implicit type conversions, preventing the index from being used.
Solutions
Low-risk action that can be done immediately
Remove execution-plan-forcing hints from existing queries and stored procedures
MediumFor each FORCE INDEX, join hint, or FORCE ORDER found in the grep results, remove it after confirming the affected scope. Compare execution plans before and after removal to check for unexpected degradation.
Include code-base searches in index-deletion criteria
LowBefore deleting an index, require both a usage-statistics check and a code-base search confirming that no application code or stored procedure force-references the index.
Change requiring advance review
Establish a routine for keeping statistics up to date
LowReview and adjust the automatic statistics-update settings and frequency so the CBO can make decisions with accurate selectivity information.
Separate the index lifecycle from the application release pipeline
MediumMake it possible to create, consolidate, and delete indexes independently of application deployments. Build pre-change dependency checks into the index-change procedure.
Work requiring expert review
Redesign queries to achieve Sargability
Expert Review RequiredRemove WHERE-clause function wrapping and implicit type conversions so indexes can be used as-is. Seek expert review when the affected scope is large.
Design query structures that remain stable under scale-out and scale-up
HighDesign queries so they do not break regardless of which direction the execution plan takes, assuming data volume may grow by a factor of ten to one hundred.
!Warnings
- sys.dm_db_index_usage_stats counters reset on service restart, failover, or instance recreation. Do not conclude an index is "unused" based on a short observation period alone.
- Code-base searches use regex patterns; hits are investigation targets, not confirmed forced references. Examine each one individually.
- Removing execution-plan-forcing hints changes the execution plan. Compare before/after plans in a staging environment before applying to production.
- Changes based solely on single-query performance measurements — including hints proposed by AI — do not guarantee behavior as data volume changes.
If This Doesn't Resolve It
Did you check whether the target index remains in the execution-plan cache?
Use sys.dm_exec_query_stats and sys.dm_exec_sql_text to find recent execution plans that reference the index.
Did you check that the same hint patterns are not present in other repositories or stored-procedure groups?
A hint may exist in a different repository, batch process, or a procedure maintained by another team.
Did you check that statistics are not stale?
The CBO relies on sampled statistics. If statistics are outdated, removing hints will not allow the CBO to make accurate decisions.
Basis and Limitations of This Document
Content verified through real-world operations
This article is based on SQL Server public DMV and catalog-view specifications (sys.dm_db_index_usage_stats, sys.sql_modules, etc.) and on patterns commonly observed in large-scale service operations, generalized to avoid referencing specific incident counts, dates, or systems.
FAQ
Does this mean query hints should never be used?
GIIP AI Harness excludes query hints by principle, but this is not an absolute prohibition. In rare cases such as when you must temporarily work around a known optimizer issue, after a design review that documents the scope of impact and rollback procedure, limited use may be considered. Query hints should not be used as a routine tuning method.
Why does the same base AI model produce different proposals?
It is not a difference in the model's own capability — it is a difference in the constraints placed on the model's behavior (the Harness). Without constraints, the model proposes local optimizations for the query in front of it. With a Harness that prohibits execution-plan-forcing hints, the proposals stay within those constraints.
What is the minimum checklist before deleting an index?
Two things together: (1) sys.dm_db_index_usage_stats usage statistics, and (2) a code-base and stored-procedure search for any force-reference to that index. Usage statistics alone may only reflect the period since the last restart.
What is Sargability?
Sargability describes whether a WHERE-clause search condition can use an index as-is. Expressions that apply functions to columns or cause implicit type conversions prevent the index from being used, even when the index exists, leading to table scans. Rather than forcing usage with a hint, the correct approach is to revise the condition expression to achieve Sargability.
Are hints like MAXDOP (which control parallelism) prohibited for the same reason?
No. This article addresses hints that fix the index selection and join order in execution plans — such as FORCE INDEX, join hints, and FORCESEEK/FORCESCAN. MAXDOP and similar parallelism or resource-control hints are a different class of setting, covered in a separate article.
Questions This Document Covers
- Why do different AI tools produce different SQL tuning proposals?
- What are the risks of using query hints?
- What should I check before deleting an index?
What the Risk Labels Mean
- Read-onlyDoes not change data or settings.
- LowImpact is limited, but permissions and load should be checked.
- MediumMay affect performance, locking, or cost.
- HighMay cause an outage, data loss, or require recovery work.
- Expert Review RequiredRequires a separate review before applying to production.
GIIP's Scope of Support
GIIP AI Harness is designed to exclude FORCE INDEX and explicit join-order hints from all SQL it generates or proposes, and limits performance proposals to measures that do not interfere with CBO decisions — such as index-design review, statistics maintenance, and Sargability improvement. As part of the index lifecycle (create, consolidate, delete), it is an operational prerequisite to combine usage statistics with a code-base search confirming no force-reference exists, rather than relying on a single point-in-time snapshot of usage metrics.
Author & Technical Review
GIIP Production Operations Team
About 30 years of experience in designing, migrating, and operating large-scale web services, SQL Server, Oracle, AWS, and Azure. Experience includes 12 sets of x12large-class AWS RDS for SQL Server environments, an Oracle environment with roughly 120,000 tables, and migrating roughly 3TB from TiDB to Aurora MySQL. AI agents and human experts currently continue to monitor and operate multiple cloud databases and about 30 web services.
Why AI automated execution needs approval and rollback, and how to design for it
Design elements for automated execution — snapshots, approval gates, dry-run separation, allowlists, idempotency, audit logs, staged rollout, and a kill switch — are summarized, along with where to draw the line on what can run without approval.
sql-serverHow to Check and Change MAXDOP and Cost Threshold for Parallelism in SQL Server
A procedure for checking and changing the degree of parallelism at the server, database, and query levels, along with the differences in scope and impact at each level.
sql-serverCauses and Checks for High CXPACKET Waits in SQL Server
A procedure for evaluating CXPACKET using sys.dm_os_wait_stats and sys.dm_os_waiting_tasks, distinguishing it from CXCONSUMER, and moving toward a review of the degree of parallelism.
giipWhat is the difference between a coding agent and GIIP FDE Ops?
Coding agents and operations services differ in their "unit of work." We compare the boundary between the two across nine dimensions, with commands you can run to check your own organization.
Related Services
Audit your query-hint dependency and restructure for CBO-friendly design
If you need to repeat the same checks across multiple environments, we can discuss your entire operations setup.
Audit your query-hint dependency and restructure for CBO-friendly design