reduce-unoptimized-query-oracle
Simplifies complex CockroachDB test failures into minimal SQL queries to reproduce and fix bugs.
Install
mkdir -p .claude/skills/reduce-unoptimized-query-oracle && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/3423" && unzip -o skill.zip -d .claude/skills/reduce-unoptimized-query-oracle && rm skill.zipInstalls to .claude/skills/reduce-unoptimized-query-oracle
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Reduce an unoptimized-query-oracle test failure log to the simplest possible reproduction case. Use when you have unoptimized-query-oracle*.log files from a failed roachtest and need to find the minimal SQL to reproduce the bug.Key capabilities
- →Identify test failure artifacts
- →Build reduced reproduction cases
- →Automate SQL log cleaning
- →Execute failure reproduction commands
- →Bisect regression commits
How it works
It analyzes roachtest logs to isolate the minimal SQL query causing divergence, then uses a reduction tool to simplify the reproduction case for debugging.
Inputs & outputs
When to use reduce-unoptimized-query-oracle
- →Diagnosing CockroachDB oracle test failures
- →Isolating minimal SQL reproduction cases
- →Analyzing roachtest logs for query optimization bugs
About this skill
Reduce Unoptimized Query Oracle Test Failure
Reduce an unoptimized-query-oracle test failure log to the simplest possible reproduction case.
The unoptimized-query-oracle roachtest runs a series of random SQL statements to create a random dataset, and then executes a random "Query of Interest" twice, with different optimization settings. If the two executions return different results, it indicates a bug in CockroachDB.
When to Use
Use this skill when:
- You have a test failure from the unoptimized-query-oracle roachtest.
- You need to find the minimal SQL to reproduce the test failure.
Step 1: Locate artifacts
Ask the user where the artifacts directory is.
Find the relevant files in the artifacts directory:
- Test parameters:
params.log(the parameters from the roachtest) - Test log:
test.log(the log from the roachtest) - Failure log:
failure*.log(the failure log from the roachtest) - Full SQL log:
unoptimized-query-oracle*.log(the SQL statements that led to failure) - Query of interest log:
unoptimized-query-oracle*.failure.log(containing the query of interest and possibly more information about the failure) - Cockroach log:
logs/1.unredacted/cockroach.logorlogs/unredacted/cockroach.log(contains the git commit)
Step 2: Determine test configuration
Determine the git commit from cockroach.log:
grep "binary: CockroachDB" cockroach.log
Look for the commit hash in the version string (e.g., cb94db961b8f55e3473f279d98ae90f0eeb0adcb).
Determine if runtime assertions are enabled by checking for:
"runtimeAssertionsBuild": "true"inparams.log- or
Runtime assertions enabledintest.log
Determine if metamorphic settings apply by looking for:
- lines like these in
params.log:"metamorphicBufferedSender": "true", "metamorphicWriteBuffering": "true", - or lines like these in
test.log:metamorphically setting "kv.rangefeed.buffered_sender.enabled" to 'true' metamorphically setting "kv.transaction.write_buffering.enabled" to 'true'
Determine environment variables from the beginning of cockroach.log:
grep -A10 "using local environment variables:" cockroach.log
Important environment variables include:
COCKROACH_INTERNAL_CHECK_CONSISTENCY_FATALCOCKROACH_INTERNAL_DISABLE_METAMORPHIC_TESTINGCOCKROACH_RANDOM_SEEDCOCKROACH_TESTING_FORCE_RELEASE_BRANCHBut there might be more important environment variables, so best to get all of them.
Determine if this is a multi-region test or single-region test by checking:
- the test name (e.g.,
seed-multi-regionintest.logindicates multi-region) - or the presence of
\connectlines in the full SQL log If both of these are missing, it's a single-region test.
Step 3: Check Out and Build
For a normal build use:
git checkout <commit-hash>
./dev build short
If runtime assertions were enabled, use a test build instead:
git checkout <commit-hash>
./dev build short -- --crdb_test
Note: Only build libgeos if the reproduction uses geospatial functions (BOX2D, geometry, geography, etc.):
./dev build libgeos
Step 4: Prepare the Full SQL Log File
First, check that the following statements are at the top of the full SQL log file. If they are not, add them:
SET statement_timeout='1m0s';
SET sql_safe_updates = false;
If metamorphic settings were used, also add them to the top of the full SQL log file:
SET CLUSTER SETTING kv.rangefeed.buffered_sender.enabled = true;
SET CLUSTER SETTING kv.transaction.write_buffering.enabled = true;
Create an appropriate directory either in the artifacts directory or in the repository root for holding temp files.
Step 5: Initial Reproduction
Determine the correct demo command based on test type:
- Multi-region test: Use
--nodes=9 - Single-region test: Omit
--nodesoption
Use a command like this to try reproducing the test failure from the full SQL log file. This command could take up to 20 minutes to finish.
<env vars> ./cockroach demo --multitenant=false --nodes=9 --insecure --set=errexit=false --no-example-database --format=tsv -f <full-sql-log-file>
Check that the output reproduces the test failure described in the failure log. There are many possible failure modes. Look for one of the following, which should match the failure log:
- Different results between the two executions of the "Query of Interest" (which is the randomly generated SELECT statement repeated twice near the end of the log, wrapped in various SET and RESET staements). These different results could take the form of different result sets, or could also be an error in one case and no error in the other case. This is an "oracle" failure.
- Or,
internal erroror assertion failure. Note the error message for the reduce step. - Or, a panic. Note the error message for the reduce step.
- Or, a timeout. Note the statement that timed out.
Troubleshooting
IMPORTANT: Many failures are nondeterministic, especially for multi-region tests. If no failure happens on the first run, try up to 10 times before concluding it doesn't reproduce.
It can be helpful at this point to compare the output with the failure*.log
which should show the failure from the original test run.
If the initial run fails to reproduce after 10 times, pause here and report to the user that the failure cannot be reproduced, and show the command that was tried. The user might have additional instructions.
If it looks like it reproduces, it's time to move on to the next step.
Step 6: Use the Reduce Tool
Build the reduce tool:
./dev build reduce
Prepare the Full SQL Log File again
For multi-region tests, remove \connect lines (they cause syntax errors in the
reduce tool):
grep -v '^\\connect' <full-sql-log-file> > <cleaned-log>
Run Reduce
IMPORTANT: The reduce tool must be run from the cockroach repository root
directory, because it looks for ./cockroach in the current directory.
Use the -multi-region option for multi-region tests, or omit it for
single-region tests.
For "oracle" failures (different results):
./bin/reduce -unoptimized-query-oracle -multi-region -chunk 25 -v -file <cleaned-log> 2>&1 | tee reduce-output.log
The -unoptimized-query-oracle option checks whether the two executions of the
"Query of Interest" produce the same results.
For internal errors/assertion failures/panics:
./bin/reduce -contains "<error-regex>" -multi-region -chunk 25 -v -file <cleaned-log> 2>&1 | tee reduce-output.log
Use a distinctive part of the error message as the -contains regex (e.g.,
"nil LeafTxnInputState").
The reduce tool might take up to an hour to run.
Extract the Reduced SQL
The reduce tool outputs progress lines followed by the final SQL. Extract just the SQL:
grep -A1000 "^reduction: " reduce-output.log | tail -n +2 > reduced.sql
IMPORTANT: Immediately save a backup of the reduce output before manual simplification:
cp reduced.sql reduced_original.sql
This provides a recovery point if the working file gets corrupted during simplification.
If the reduce tool fails to reproduce, pause here and report this to the user. They might have additional instructions. Occasionally we have to modify the reduce tool itself, if the test failure is not reproducing.
Step 7: Create Test Script and Determine Reproduction Rate
IMPORTANT: Many bugs are nondeterministic. Before manual simplification, create a reusable test script and determine the reproduction rate.
Create a small test script (adjust as needed):
cat > test_repro.sh << 'EOF'
#!/bin/bash
# Test if reduced_v2.sql reproduces the error (exits on first success, up to 10 attempts)
for i in {1..10}; do
if ./cockroach demo --multitenant=false --nodes=9 --insecure \
--set=errexit=false --no-example-database --format=tsv \
-f reduced_v2.sql 2>&1 | grep -q "<error-pattern>"; then
echo "Run $i: REPRODUCED"
exit 0
else
echo "Run $i: no error"
fi
done
echo "FAILED"
EOF
chmod +x test_repro.sh
For "oracle" failures, instead of checking for an error pattern, the test script probably needs to isolate and diff the results of the two executions of the "Query of Interest".
Run the test script to determine the reproduction rate. It's not always 100%.
This rate determines how many attempts you need when testing simplifications:
- 100% rate: Single attempt sufficient
- 50% rate: 2-3 attempts usually sufficient
- 10% rate: Need ~10 attempts to be confident
- <5% rate: May need 20+ attempts
Note that in some cases, the following settings might need to be added back to the reduced file to get a repro:
SET statement_timeout='1m0s';
SET sql_safe_updates = false;
If the reduced SQL fails to reproduce after 10 attempts, pause here and report this to the user. They might have additional instructions.
Step 8: Manual Simplification
Now iteratively simplify the SQL while maintaining reproduction.
CRITICAL: For nondeterministic failures, you MUST test each simplification with enough attempts based on the repro rate. A single failed attempt does NOT mean the simplification broke the repro - it may just be nondeterminism.
Workflow for Each Simplification
- Copy
reduced.sqltoreduced_v2.sql - Make ONE small change to
reduced_v2.sql - Run
./test_repro.sh(which testsreduced_v2.sql) - If it reproduces: Copy
reduced_v2.sqltoreduced.sql, continue simplifying - If it doesn't reproduce after enough attempts: Discard
reduced_v2.sql, try a different change (i.e. backtrack).
This workflow avoids needing to restore files - you always keep the last working
version in reduced.sql.
IMPORTANT: Run copy, edit, and test as separate bash commands (not chained with `&&
Content truncated.
When not to use it
- →When test failures are not oracle-related
- →Without access to roachtest artifacts
Prerequisites
Limitations
- →Nondeterministic failures require multiple runs
- →Requires manual intervention for complex bugs
How it compares
It provides a systematic, automated approach to isolating complex database bugs, replacing the manual process of sifting through large test logs.
Compared to similar skills
reduce-unoptimized-query-oracle side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| reduce-unoptimized-query-oracle (this skill) | 1 | 6mo | Review | Advanced |
| differential-fuzzer | 1 | 6mo | Review | Intermediate |
| zinc-unittest | 0 | 6mo | Review | Intermediate |
| fix-pr | 0 | 1mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by cockroachdb
View all by cockroachdb →You might also like
differential-fuzzer
tursodatabase
Information about the differential fuzzer tool, how to run it and use it catch bugs in Turso. Always load this skill when running this tool
zinc-unittest
Crainax
War3Lib 的 Zinc 单元测试流程规范(.j + .cfg + _Test.j + 可选 w3a/w3u/w3i):使用 TaskCreateUT.lua 生成测试壳、维护 cfg 注入与 chain 依赖、使用 UnitTestFramwork.assert 断言与 Trace 日志输出。用于创建/重构 Jass 模块单测时。
fix-pr
questdb
Validate and fix pasted QuestDB pull-request review findings one at a time, with claim verification, a failing regression test where feasible, robust and performant implementation, testing, and an independent review/fix loop. Use when Codex is asked to fix Critical, Moderate, or other actionable PR
testing-workflow
amo-tech-ai
Comprehensive testing workflow for E2E, integration, and unit tests. Use when testing applications layer-by-layer, validating user journeys, or running test suites.
web3-testing
wshobson
Test smart contracts comprehensively using Hardhat and Foundry with unit tests, integration tests, and mainnet forking. Use when testing Solidity contracts, setting up blockchain test suites, or validating DeFi protocols.
sqlite-inspector
mikopbx
Проверка консистентности данных в SQLite баз данных MikoPBX после операций REST API. Использовать при валидации результатов API, отладке проблем с данными, проверке связей внешних ключей или инспектировании CDR записей для тестирования.