Agent skill
plan-replayer-testing
Expertise in adding new test cases for the TiDB plan replayer. Use when the user provides a plan replayer zip file and wants to create a new test.
Install this agent skill to your Project
npx add-skill https://github.com/hawkingrei/tidb-dev-prompt/tree/main/plan-replayer-testing
SKILL.md
Plan Replayer Testing Expert
You are an expert in creating new test cases for the TiDB plan replayer. When a user asks you to add a new test, follow this procedure precisely.
Prerequisites
Before you begin, ensure the user has provided the following information. If not, you must ask for it:
- The file path to the plan replayer zip file.
- The target path for the new test case (e.g.,
abc/123).
Procedure
1. Create Directories
Based on the user-provided target path, create the necessary directories for the test file and the replayer file.
# For a target path like "abc/123"
mkdir -p t/abc/123
mkdir -p replayer/abc/123
2. Copy Plan Replayer File
Copy the user-provided zip file into the new replayer/ subdirectory. Do not change the filename.
3. Extract Information from Zip File
To get the necessary components for the test, you must extract them from the zip file.
a. Create a temporary directory: TMP_DIR=$(mktemp -d)
b. Unzip the file into it: unzip /path/to/replayer.zip -d "$TMP_DIR"
c. Extract SQL Query: Find and read the SQL file in the $TMP_DIR/sql/ subdirectory.
d. Extract Database Name: Find any file in $TMP_DIR/schema/ and read its content. Extract the database name from the CREATE DATABASE statement.
e. Extract Timestamp: Read the $TMP_DIR/variables.toml file and extract the string value for the timestamp variable. This is critical for making the test deterministic.
f. Check for TiFlash Replica: Check if the file $TMP_DIR/table_tiflash_replica.txt exists and is not empty. This determines if a special wait flag is needed.
g. Cleanup: Remember to remove the temporary directory: rm -rf "$TMP_DIR"
4. Create the .test File
a. Determine Filename:
* If the zip filename is replayer_pZHg0IzNHaG9moOOzB0UqA==_1763627785193823416.zip, the test filename should be pZHg0.test.
* If the filename is query95.zip, the test filename should be query95.test.
* If there's a naming conflict, append the date (YYYYMMDD) before the .test extension.
b. Write Content: Create the .test file in the t/ subdirectory you created. Use the following template, replacing all placeholders.
drop database if exists <database_name>;
plan replayer load './relative path of the replayer file relative to the project root';
--wait_tiflash_replica_ready
-- Replace date/time functions in the query with the extracted timestamp
-- e.g., CURRENT_DATE() becomes '<timestamp_value>'
explain format = 'plan_tree' <test query>;
select @@last_plan_from_cache,@@last_sql_use_alloc,@@last_plan_from_binding;
drop database if exists <database_name>;
- If a TiFlash replica was detected (step 3.f), keep the
--wait_tiflash_replica_readyline. Otherwise, remove it.
5. Verify the Test
a. Execute the test using the script bundled with the skill. The test path should not include the .test suffix.
```shell
.gemini/skills/plan-replayer-testing/scripts/run-tests.sh -r <test_path>
```
b. Check for SQL Binding: After the run, check the output. If the result for @@last_plan_from_binding; is 1, you must modify the test to run twice: once with the binding and once without.
c. Modify for Binding: If a binding was used, insert the following SQL block right after the first select ...; line in the .test file.
```sql
set @old=@@timestamp;
set @@timestamp=0;
UPDATE mysql.bind_info SET status = 'deleted', update_time = NOW(6) WHERE source != 'builtin';
admin reload bindings;
set @@timestamp=@old;
```
Then, duplicate the `explain ...;` and the final `select ...;` lines and append them to the file.
d. Re-record Result: Run the test again with the -r flag to record the new, dual output.
```shell
.gemini/skills/plan-replayer-testing/scripts/run-tests.sh -r <test_path>
```
If any step fails, analyze the error output and attempt to fix it before reporting back to the user.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
tidb-optimizer-bugfix
Fix TiDB optimizer bugs with minimal diffs, hypothesis-driven validation, and regression tests aligned with tidb-test-guidelines. Use when reproducing, fixing, and validating planner/optimizer behavior bugs.
pr-review-helper
Gather PR review context: all comments (including review suggestions), diff context, and CI status; download GitHub Actions logs on failures. Prefer GitHub MCP for reads, fall back to gh CLI when needed.
tidb-profiler-analyzer
Processes and analyzes TiDB profiler zip packages (CPU or heap) for components like TiDB, TiKV, PD, or TiFlash. It unzips, aggregates the profiler data, and uses `go tool pprof` to report on the most time-consuming functions (CPU) or highest memory allocations (heap).
tidb-doc-finder
TiDB-specific documentation lookup guided by this repo's llms.txt hub: read llms.txt, pick the best linked source (tidb-dev-guide llms-full.txt, TiDB user guide llms.txt, or Uber Go style guide), fetch it, then search within it to answer with precise references. Use when asked to find docs, research, or provide doc-grounded answers about TiDB development or usage.
context-management
Use for projects, tasks, or code that involve context engineering and context management for AI agents: keep prompt prefixes stable for KV-cache, use append-only context, prefer tool masking over tool removal, offload large observations into filesystem memory, recite goals/todos to control attention, preserve errors for recovery, and avoid few-shot pattern lock-in. Use when building or debugging agent loops, prompt/context schemas, memory strategies, or tool-availability policies.
edit-article
Edit and improve articles by restructuring sections, improving clarity, and tightening prose. Use when user wants to edit, revise, or improve an article draft.
Didn't find tool you were looking for?