# CREATE QUERY POLICY
`CREATE QUERY POLICY` creates a query policy that warns about or rejects queries whose execution plan builds temporary dataflows or reads from object storage.

> For the complete documentation index, see [llms.txt](https://materialize.com/docs/llms.txt).




`CREATE QUERY POLICY` creates a [query policy](https://materialize.com/docs/markdown-docs/clusters/query-policies/index.md). A
query policy contains rules that warn about or reject queries based on their
execution plan. A policy has no effect until you attach it to a cluster with
[`ALTER CLUSTER`](https://materialize.com/docs/markdown-docs/sql/alter-cluster/index.md) or [`CREATE
CLUSTER`](https://materialize.com/docs/markdown-docs/sql/create-cluster/index.md).

## Syntax



```mzsql
CREATE QUERY POLICY <name> (
  [MODE = '<mode>',]
  RULES (
    <rule_name> (action = 'reject', metric = 'query_plan_includes', value = '<plan_feature>')
    [, ...]
  )
)
;

```

| Syntax element | Description |
| --- | --- |
| `<name>` | The name of the query policy.  |
| `MODE` | *Optional.* What happens when a query matches a rule.  \| Mode \| Behavior \| \|------\|----------\| \| `'warn'` \| The query runs, and Materialize emits a `NOTICE` naming the policy, rule, and cluster. Use this mode to assess a policy before you enforce it. \| \| `'enforce'` \| The query fails with SQLSTATE `53000` (`insufficient_resources`). \|  Default: `'warn'`  |
| `RULES` | The rules in the policy. Specify `RULES ()` to create a policy with no rules.  |
| `<rule_name>` | The name for the rule. Must be unique within the query policy.  |
| `<plan_feature>` | The execution plan feature the rule rejects.  \| Value \| Matches \| \|-------\|---------\| \| `'temporary_dataflow'` \| Queries that build a temporary dataflow, including one that reads only from indexes. \| \| `'storage_read'` \| Queries that read from object storage, either directly or through a temporary dataflow. \|  See [Choosing a rule](https://materialize.com/docs/markdown-docs/clusters/query-policies/index.md#choosing-a-rule).  |


## Details

Query policies are plan-based admission controls, not resource limits.
Materialize checks the optimized execution plan of a query before it runs. A
[fast path](https://materialize.com/docs/markdown-docs/sql/explain-plan/index.md#fast-path-queries) read from an existing index
matches neither rule, even if it returns many rows.

For which statements a policy checks, see [Query
policies](https://materialize.com/docs/markdown-docs/clusters/query-policies/index.md#what-a-policy-checks).

## Privileges

The privileges required to execute this statement are:

- `CREATEQUERYPOLICY` privileges on the system.

## Examples

```mzsql
CREATE QUERY POLICY indexed_reads_only (
  MODE = 'enforce',
  RULES (
    no_temporary_dataflows (action = 'reject', metric = 'query_plan_includes', value = 'temporary_dataflow')
  )
);

ALTER CLUSTER serving SET (QUERY POLICY = indexed_reads_only);
```

## Related pages

- [Query policies](https://materialize.com/docs/markdown-docs/clusters/query-policies/index.md)
- [`ALTER QUERY POLICY`](https://materialize.com/docs/markdown-docs/sql/alter-query-policy/index.md)
- [`DROP QUERY POLICY`](https://materialize.com/docs/markdown-docs/sql/drop-query-policy/index.md)
- [`SHOW QUERY POLICIES`](https://materialize.com/docs/markdown-docs/sql/show-query-policies/index.md)
