Not loaded · from iris-dev
Reads IRIS SQL query plans to diagnose slow queries and index problems. Covers master vs index maps, Cost, %BuildIndices, INSERT %NOINDEX, CREATE INDEX, TUNE TABLE, and statistics.
Claude Code won't load this skill
It ships in iris-dev at skills/, but Claude Code only loads skills/<name>/SKILL.md and folders listed under skills in plugin.json. Installing the plugin doesn't add it.
iris_query(mode="explain", query="SELECT ... WHERE ...") returns the plan IRIS will run. Two lines matter most:
| Plan line | Meaning |
|---|---|
Read master map Pkg.Table.IDKEY, looping on the subrange of ID | full scan of the data rows |
Read index map Pkg.Table.StatusIdx | the query uses the index StatusIdx |
Cost | relative estimate; compare plans with it |
On a 5,000-row table, WHERE Status = 'OPEN' with no index costs 33000 and reads the master map. After CREATE INDEX StatusIdx ON Pkg.Orders (Status) the same query reads the index map at cost 13720.
Adding Index CustIdx On Customer; to a persistent class and compiling it defines the index but does not fill it. Queries that the planner sends through the index then return short, with SQLCODE = 0 and no error. On a table with 10 rows for customer C1:
SELECT COUNT(*) FROM Pkg.Orders WHERE Customer = 'C1' -- 0
SELECT COUNT(*) FROM Pkg.Orders WHERE %NOINDEX Customer = 'C1' -- 10
%NOINDEX in the WHERE clause tells the planner not to use an index for that condition, so it reads the data. When the two counts differ, the index is stale. Build it:
Set tSC = ##class(Pkg.Orders).%BuildIndices($ListBuild("CustIdx"))
If $$$ISERR(tSC) { Return tSC }
After the build, both counts are 10.
DDL is different. CREATE INDEX on a table that already has rows builds the index as part of the statement.
INSERT %NOINDEX leaves the index behindINSERT %NOINDEX INTO Pkg.Orders ... writes the row but skips index maintenance. A count through the index then misses the new row (0), and the same count with WHERE %NOINDEX finds it (1). So the method that does the INSERT %NOINDEX has to call %BuildIndices when its inserts are done:
For i = 1:1:tCount {
Set tRs = tStmt.%Execute(...)
If tRs.%SQLCODE < 0 { Return $$$ERROR($$$SQLError, tRs.%SQLCODE, tRs.%Message) }
}
Quit ##class(Pkg.Orders).%BuildIndices($ListBuild("CustIdx"))
A rebuild by hand lasts until the next load. If the loader clears the extent and inserts with %NOINDEX again, the index is empty again, and a fix that only ran %BuildIndices once is gone. Change the loader, or drop %NOINDEX from it.
TUNE TABLETUNE TABLE Pkg.Orders measures extent size (row count), selectivity per field, outlier values, average field size and block counts. Run it on data shaped like production, after a large load or when the distribution changes. iris_query refuses TUNE TABLE in both modes, so run it through iris_execute: Set r=$SYSTEM.SQL.Execute("TUNE TABLE Pkg.Orders") Write r.%SQLCODE (0 when it ran). On the test table the CustIdx plan stayed on the index map and its cost went from 3272 to 2672.
Since 2025.2 (release notes) a table can hold two sets of the same statistics (GSOD_opttable):
TUNE TABLE and by the system task %SYS.Task.AutoStatsCollection.ExtentSize, Selectivity), written by ALTER TABLE ... FIX STATISTICS, $SYSTEM.SQL.Stats.Table.SetExtentSize/SetFieldSelectivity, or Import.What 2026.3 does, each point measured:
WHERE Flag = 'Y' cost 20,707,000 and ran a parallel scan; on collected alone it cost 12,200. The fixed set also hid the collected outlier selectivity, so the plan's "Using the outlier selectivity" note went away.TUNE TABLE writes only the collected set. It leaves the Storage definition alone. While a fixed set exists, TUNE changes nothing the planner reads. The TUNE TABLE page still describes the older behaviour, where TUNE wrote the class.INFORMATION_SCHEMA.STATEMENTS.Timestamp stays the same when TUNE runs, and a new prepare of the same text after TUNE gets a new timestamp. If you prepare again without a TUNE in between, the cached plan is reused.CREATE TABLE starts with no fixed set. Export with type 1 still reports <extentsize>100000</extentsize> for it, which is the default and not a fixed value.ClearTableStats("Pkg.T") (and ClearSchemaStats) clears the fixed set only. The collected set survives.AutoStatsForFixedStatsTable=1, so collection still runs on tables that have a fixed set (RACS_AutoStatsForFixedStatsTable).Not tested here: the docs say collecting statistics updates the extent index in the namespace's default globals database, so collection fails when that database is read-only (GSOD_opttable).
So when a plan's cost ignores the real row count, look for a fixed set before running TUNE again:
SELECT ExtentSize FROM %Dictionary.StorageDefinition WHERE parent = 'Pkg.Orders'
An empty ExtentSize means the planner uses collected statistics.
Save what is there now. Type 1 is the fixed set, 2 the latest collected set, 3 both:
Set tSC = $SYSTEM.SQL.Stats.Table.Export("/tmp/orders-stats.xml", "Pkg", "Orders", 0, 3)
If $$$ISERR(tSC) { Return tSC }
Check for a fixed set (the query above).
To let collected statistics through, run ALTER TABLE Pkg.Orders DROP FIXED STATISTICS (ALTER TABLE STATS), then TUNE TABLE Pkg.Orders.
Explain the query again and compare its Cost.
To roll back, run $SYSTEM.SQL.Stats.Table.Import("/tmp/orders-stats.xml", 0). Importing a type 1 export restores the fixed set.
To pin plans that are good now, run ALTER TABLE Pkg.Orders FIX STATISTICS. It copies the latest collected set into the Storage definition, so later TUNE runs no longer move the plan.
If one value covers most of the rows, the planner skips the index for that value. With Status = 'DONE' on 98% of rows and StatusIdx present, the plan for WHERE Status = 'DONE' reads the master map at cost 33000, with the note "Using the outlier selectivity". That plan is correct. Reading nearly every row through an index costs more than a scan. A plan without the index is not always a missing index. Check which value the query uses before you add one.
WHERE %NOINDEX. Different counts mean a stale index.Index to a class that already has data, run %BuildIndices. A loader that uses INSERT %NOINDEX calls it itself, after its last insert.TUNE TABLE. If the plan's cost does not move, look for a fixed set in the Storage definition.iris-sql: SQL dialect, table naming, SQLCODEobjectscript-sql-patterns: %SQL.Statement error checksWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub intersystems-community/iris-agentic-dev --plugin iris-dev40 skills in this plugin
/ensemble-productionManage and observe IRIS Interoperability productions — lifecycle, logs, queues, and message tracing. Covers pyprod Python API, ObjectScript Ens.Director, and MCP tool flow./iris-agentic-devConfigure, connect, and troubleshoot the iris-agentic-dev MCP server (iris_execute/iris_query/iris_doc/docs_introspect/kb/etc.) against an IRIS container or instance. Use when its tools return IRIS_UNREACHABLE, when pointing it at a new IRIS, or when a connection edit "isn't taking effect." Covers the .iris-agentic-dev.toml config, live file-watch reload, the OrbStack port-discovery gotcha, and the docker-exec fallback./iris-agentic-dev-setupOther plugins' skills for the same job