CREATE QUERY POLICY

View as Markdown
PREVIEW This feature is in private preview. It is under active development and may have stability or performance issues. It isn't subject to our backwards compatibility guarantees.
To enable this feature for your environment, contact our team.

CREATE QUERY POLICY creates a query policy. 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 or CREATE CLUSTER.

Syntax

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.

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 read from an existing index matches neither rule, even if it returns many rows.

For which statements a policy checks, see Query policies.

Privileges

The privileges required to execute this statement are:

  • CREATEQUERYPOLICY privileges on the system.

Examples

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);
Back to top ↑