Query Circuit Breaker
Use query circuit breakers to reject unwanted SQL or cancel work that exceeds resource or time thresholds in a warehouse. Combine them with query tuning, workload group limits, and appropriate cluster capacity.
| Control | When it acts | Use it for |
|---|---|---|
| SQL block rule | Statement matching and query planning | Block SQL patterns or hashes, or restrict planned scan rows, partitions, and tablets. |
| Workload policy | Periodic checks during backend execution | Cancel supported running work based on elapsed time, scanned rows or bytes, memory, or SQL username. |
A circuit breaker reduces exposure to expensive work. It does not guarantee cluster availability, enforce SQL access privileges, or set an exact runtime resource ceiling. Planning estimates and asynchronous checks have different limitations.
Use a warehouse SQL user with ADMIN_PRIV to manage these controls. Test a rule on a representative workload before enabling a broad scope.
SQL block rules
Choose either SQL matching (sql or sqlHash) or scan limitations in a rule. SQL matching and scan limitations cannot be combined in the same rule.
| Property | Purpose |
|---|---|
sql | Java regular expression matched against submitted SQL text. Matching text is rejected. |
sqlHash | Match the statement's SQL hash, for example, one obtained from an audit record. Mutually exclusive with sql. |
cardinality | Limit planned scan rows for an individual table scan. |
partition_num | Limit planned partitions for an individual table scan. |
tablet_num | Limit planned tablets for an individual table scan. |
require_partition_filter | Require a usable partition predicate for supported partitioned internal and Hive table scans. Starting from Core 26.1.3. |
global | true applies the rule globally. The default false requires assignment through the SQL user's sql_block_rules property. |
enable | Enable or disable the rule. The default is true. |
The scan row, partition, and tablet thresholds compare values calculated during planning, not runtime counters. Ordinary filters can reduce actual rows without reducing the planning value used by the rule. Pruning and statistics therefore affect which queries are blocked.
global describes the SQL rule's scope within the warehouse. It does not change organization access. Internal statements and configured administrator exemptions can bypass some rule checks, so do not use SQL text rules as an access-control boundary.
Create a global rule
CREATE SQL_BLOCK_RULE rule_001
PROPERTIES (
"sql" = "select \\* from t",
"global" = "true",
"enable" = "true"
);
The escaped * is literal in the regular expression. A matching select * from t statement is rejected with an error that names the block rule. Matching is case-sensitive unless the expression includes a flag such as (?i).
Assign a rule to a SQL user
Create a rule with global = false, then bind it to the intended warehouse SQL user:
CREATE SQL_BLOCK_RULE rule_user
PROPERTIES (
"sql" = "select \\* from t",
"global" = "false",
"enable" = "true"
);
SET PROPERTY FOR 'reporting_user' 'sql_block_rules' = 'rule_user';
Replace reporting_user with an existing SQL user. List multiple rule names separated by commas. Setting this property replaces the user's current list, so include every rule that should remain assigned.
To remove all assigned rules for that user:
SET PROPERTY FOR 'reporting_user' 'sql_block_rules' = '';
Change, disable, or remove a rule
SHOW SQL_BLOCK_RULE;
ALTER SQL_BLOCK_RULE rule_001 PROPERTIES ("enable" = "false");
DROP SQL_BLOCK_RULE rule_001;
See CREATE SQL_BLOCK_RULE, ALTER SQL_BLOCK_RULE, and DROP SQL_BLOCK_RULE for the complete syntax.
Example 1: Limit planned scan rows
Reject a table scan whose planned row count exceeds 1,000
CREATE SQL_BLOCK_RULE rule_card
PROPERTIES (
"cardinality" = "1000",
"global" = "true",
"enable" = "true"
);
This threshold applies to each table scan, not the final result's row count or the total across every table in the query. Partition and tablet pruning affect the scan estimate. A query that ultimately reads fewer than 1,000 rows can still be blocked.
Example 2: Limit planned partitions
Reject a table scan that retains more than 30 partitions
CREATE SQL_BLOCK_RULE rule_part_num
PROPERTIES (
"partition_num" = "30",
"global" = "true",
"enable" = "true"
);
Incomplete pruning can retain more partitions than the query eventually needs. Check the plan and partition predicates if a useful query is blocked.
Example 3: Limit planned tablets
Reject a table scan that retains more than 200 tablets
CREATE SQL_BLOCK_RULE rule_tablet_num
PROPERTIES (
"tablet_num" = "200",
"global" = "true",
"enable" = "true"
);
The limit counts tablets, not partitions. It is a planning-time restriction and does not measure execution CPU or I/O directly.
Example 4: Block a SQL pattern
Block SQL text that matches an ABS function pattern
CREATE SQL_BLOCK_RULE rule_abs
PROPERTIES (
"sql" = "(?i)abs\\s*\\(.+\\)",
"global" = "true",
"enable" = "true"
);
(?i) makes matching case-insensitive. \s* allows whitespace before the opening parenthesis, and \(.+\) matches a parenthesized argument. A text pattern can also match comments or string literals. It is not semantic SQL analysis.
You can use similar patterns for operational controls, such as restricting a known expensive statement pattern. Use SQL privileges to control authorization for operations such as SET GLOBAL or TRUNCATE TABLE.
Example 5: Require a partition filter
Reject supported partitioned-table scans without a usable partition predicate
Starting from Core 26.1.3, use:
CREATE SQL_BLOCK_RULE rule_partition_filter
PROPERTIES (
"require_partition_filter" = "true",
"global" = "true",
"enable" = "true"
);
This check applies to supported partitioned internal and Hive table scans. Adding an arbitrary WHERE clause is insufficient. The query must contain a usable partition predicate.
FAQ
Can regex rules slow down queries?
Yes. Rules use Java regular expressions and matching consumes frontend CPU. Complex expressions or many rules can add overhead. Test representative statements and avoid unnecessary patterns.
Can I temporarily disable a rule?
Yes. Set its enable property to false with ALTER SQL_BLOCK_RULE. Re-enable it by setting the property to true.
Which regex syntax is supported?
Rules use Java regular expression syntax. Account for SQL string escaping when writing backslashes.
Workload policy
A workload policy evaluates runtime counters and cancels matching backend work. Multiple conditions in CONDITIONS(...) have an AND relationship.
Starting from Core 26.1.2, policies also support remote scan bytes and a backend username selector. See the Core release notes. The v26.1 series is in Public Preview.
Conditions and actions
| Condition | Meaning |
|---|---|
username | SQL username recorded on the backend task. Combine it with runtime thresholds to target that user. A missing backend username does not match. |
be_scan_rows | Rows scanned by the query's tasks on one backend. |
be_scan_bytes | Bytes scanned by the query's tasks on one backend. |
be_scan_bytes_from_remote_storage | Remote-storage scan bytes recorded for the query on one backend. |
query_time | Running time recorded on one backend, in milliseconds. |
query_be_memory_bytes | Current memory tracked for the query on one backend, in bytes. |
Backend metrics are not warehouse-wide sums. Tasks for the query on the same backend contribute to the relevant runtime counters.
Use ACTIONS(cancel_query) to cancel matching work. Older Apache Doris examples that use set_session_variable are not applicable to this guide. Set session variables directly, through SQL user properties where supported, or with a SET_VAR hint instead.
Policy properties
| Property | Meaning |
|---|---|
enabled | true enables the policy and false disables it. Default: true. |
priority | Integer from 0 to 100, default 0. The matching cancellation policy with the highest priority is selected. Do not rely on a stable choice between equal-priority matches. |
workload_group | Restrict the policy to one workload group. In VeloDB Cloud, use <cluster>.<workload_group>, such as analytics.reporting. Empty or omitted means no workload group restriction. |
The named cluster and workload group must exist. A bare group name such as normal is not a valid Cloud binding. The workload_group session variable still uses only the group name, because the session already has a selected cluster.
Create a cancellation policy
The following policy applies only to workload group reporting in cluster analytics:
CREATE WORKLOAD POLICY cancel_slow_reporting
CONDITIONS(query_time > 3000)
ACTIONS(cancel_query)
PROPERTIES (
"enabled" = "true",
"priority" = "10",
"workload_group" = "analytics.reporting"
);
Replace the cluster and group names. For a user-specific policy, combine a username with the threshold:
CREATE WORKLOAD POLICY cancel_slow_user_queries
CONDITIONS(username = 'reporting_user', query_time > 3000)
ACTIONS(cancel_query)
PROPERTIES ("workload_group" = "analytics.reporting");
Inspect policies through the system table:
SELECT * FROM information_schema.workload_policy;
Verify and manage a policy
-
Wait for policy changes to propagate, then run a representative query in the intended workload group using a test SQL identity.
-
Confirm that the client receives a cancellation error naming the expected policy and matching metric. A short query can finish before a periodic check detects it.
-
Check that unrelated users, groups, and queries remain unaffected.
-
Disable a policy before investigating unexpected cancellations:
ALTER WORKLOAD POLICY cancel_slow_reportingPROPERTIES ("enabled" = "false"); -
Remove a demonstration or obsolete policy:
DROP WORKLOAD POLICY cancel_slow_reporting;
The original Apache Doris example used a ClickBench hits query that completed in approximately 4.5 seconds before a 3-second policy was added. That observation depends on the original workload and environment and has not been reproduced on VeloDB Cloud. Test your own query instead of using that duration as an expected result.
Limitations
- Policy propagation and evaluation are asynchronous. The Core 26.1.3 compiled check interval is 500 ms, but the effective service setting and scheduling delay can differ. A threshold is a cancellation trigger, not an exact maximum.
- Policies monitor supported backend query and load tasks, including
SELECT,INSERT ... SELECT, Stream Load, Broker Load, and Routine Load tasks. A statement with no corresponding backend runtime task is outside this mechanism. Canceling one load task does not necessarily stop a parent load job from scheduling or retrying work. - A simple
INSERT ... VALUESstatement, backup, or compaction is not a supported circuit-breaker target in this guide. - Conditions and actions cannot be changed with
ALTER WORKLOAD POLICY. Change properties in place, or remove and recreate the policy to change its conditions or action. - Runtime cancellation occurs after work has started. Use suitable SQL privileges, planning rules, and workload group limits as complementary controls.
Common errors
| Symptom | Cause and action |
|---|---|
| A rule blocks a query that returns few rows | A scan rule uses planning values, not result rows. Inspect pruning and the plan before changing the limit. |
| A Cloud policy binding is rejected | Use an existing <cluster>.<workload_group> pair. Do not pass a bare workload group name. |
A policy rejects set_session_variable | Use cancel_query for runtime policies. Configure session settings through their supported SQL mechanisms. |
| A query exceeds a runtime threshold briefly | Propagation and periodic checks introduce delay. Check the policy scope and use representative queries for verification. |
| Creating a control is denied | Use a warehouse SQL administrator with ADMIN_PRIV. Organization permissions alone are insufficient. |