# Workflow

## Goal

Convert:

- user schema
- representative SQL
- EXPLAIN / EXPLAIN ANALYZE / stats evidence
- customer background or business description when available

into:

- dbgen templates
- generated CSV data
- TiDB playground import
- verification output

## Checklist

### 1. Inspect inputs

- Read schema DDL
- Read SQL
- Read plans and statistics
- Read customer and business background
- Identify root tables
- Identify join keys
- Identify hot predicates

### 2. Decide distribution mode

- Natural mode:
  preferred default
- Reproduction-oriented mode:
  only when the user explicitly wants tight replay

If the user does not specify target scale, choose a medium-sized simulation by default.

### 3. Choose template split

Split when:

- root table families are independent
- one family is messaging-wide and another is CRM or conversations
- the target dbgen environment is sensitive to multi-root templates

### 4. Generate templates

For each template:

- preserve joinability
- preserve filter classes
- preserve skew
- keep example literals synthetic unless asked otherwise

### 5. Smoke test dbgen

- generate a small sample first
- inspect produced files
- inspect first few rows

### 6. Start playground if needed

- start minimal local TiDB playground
- default to `tiup playground nightly`
- only use a preexisting remote host when the user explicitly asks for it
- wait for `127.0.0.1:4000`
- create target databases
- apply normalized user schema

### 7. Import

- use `IMPORT INTO ... FROM '<server-local-path>'`
- set `skip_rows=1` for CSV with headers
- import one table at a time

### 8. Verify

- table row counts
- representative join sample
- representative filtered sample
- optional `SHOW IMPORT JOBS`

## Reporting

When closing the task, report:

- which templates were created
- whether templates were split
- what was imported
- row counts after import
- whether representative joins and samples worked
- any compatibility notes or residual caveats
