# Workload and resource statements (/docs/reference/sql/statements/workload)



Workload and resource statements [#workload-and-resource-statements]

This page describes statements accepted by the Query API in RawTree Cloud
and RawTree BYOC. Its restrictions apply to the API, not to all RawTree SQL.
See [ClickHouse compatibility and API scope](/docs/reference/clickhouse-compatibility).

Syntax [#syntax]

```sql
CREATE [IF NOT EXISTS | OR REPLACE] WORKLOAD <name>
  [ON CLUSTER 'default'] [IN <parent>]
  [SETTINGS <name> = <value> [FOR <resource>]]
CREATE [IF NOT EXISTS | OR REPLACE] RESOURCE <name> (<operations>)
  [ON CLUSTER 'default']
DROP [IF EXISTS] WORKLOAD|RESOURCE <name> [ON CLUSTER 'default']
```

Workloads optionally use `IN <parent>` and numeric `SETTINGS` such as
`weight`, `priority`, and `max_concurrent_threads`. Add `FOR <resource>` to
apply a setting to a resource. Resources contain comma-separated
`MASTER THREAD`, `WORKER THREAD`, `READ DISK <name>`, `WRITE DISK <name>`,
`READ ANY DISK`, or `WRITE ANY DISK` entries.

Clauses [#clauses]

| Clause                 | Meaning                                                          |
| ---------------------- | ---------------------------------------------------------------- |
| `IN`                   | Place a workload under a parent.                                 |
| `SETTINGS`             | Set numeric scheduling values, optionally with `FOR <resource>`. |
| Resource entries       | Name thread or disk resources.                                   |
| `ON CLUSTER 'default'` | Apply the object to the default cluster.                         |

<a id="rawtree-behavior" />

Query API behavior [#query-api-behavior]

* **Supported:** Workload trees, numeric scheduling settings, and thread or
  disk resources.
* **Not exposed by the Query API:** Memory or query-slot resources, unknown settings, and
  clusters other than `default`.
* **Database storage behavior:** Keeper-backed workload storage omits
  `ON CLUSTER`; local storage uses the cluster clause to distribute DDL.

Errors [#errors]

Error: `Unsupported scheduling statement.`

Hint:

```text
Use CREATE [OR REPLACE] WORKLOAD/RESOURCE [IF NOT EXISTS], or DROP WORKLOAD/RESOURCE [IF EXISTS]. Only ON CLUSTER 'default' is supported. Submit one statement.
```

Examples [#examples]

Create a CPU resource.

```sql test
CREATE RESOURCE analytics_cpu ON CLUSTER 'default' (MASTER THREAD, WORKER THREAD)
```

Create a workload with a thread limit.

```sql test
CREATE WORKLOAD analytics_workload ON CLUSTER 'default' IN all SETTINGS max_concurrent_threads = 2 FOR analytics_cpu
```

Drop the workload before the resource.

```sql
DROP WORKLOAD IF EXISTS analytics_workload ON CLUSTER 'default'
```

```sql
DROP RESOURCE IF EXISTS analytics_cpu ON CLUSTER 'default'
```

The parser rejects memory resources.

```sql test expect-error="Unsupported scheduling statement."
CREATE RESOURCE memory_pool (READ ANY MEMORY)
```

The parser rejects query-slot resources.

```sql test expect-error="Unsupported scheduling statement."
CREATE RESOURCE query_slots (QUERY SLOTS)
```

The parser rejects other clusters.

```sql test expect-error="Unsupported scheduling statement."
CREATE WORKLOAD batch_workload ON CLUSTER 'other'
```

Related [#related]

* [Workload scheduling](/docs/concepts/workload-scheduling)
* [Isolate workloads](/docs/guides/operate/isolate-workloads)
