Appearance
Runtime Rule Examples
Runtime rules take actions during actual query execution on the workers. These rules are evaluated only for queries with a duration of at least 5 seconds and are evaluated repetitively at 5-second intervals after queries enter the run
state.
Set Priority to Critical for Queries Against Specific Tables
The following runtime rule makes sure that CPU resources are available to queries against tables that contain matchstats
in their names. The rule action sets the priority of these queries to critical
:
Rule Preview:
if (w.referencedTables.contains('matchstats') &&
w.priority === 'low' ||
w.priority === 'normal' ||
w.priority === 'high') {
w.priority = 'critical';
}
Note that if only one query is running on the system, it could be allocated 100% of the available CPU, regardless of its priority. Setting the priority only has an effect when concurrent queries are running.
Log an INFO Message for Large DELETE Queries
The following runtime rule, runtime_log_info_msg
, logs an INFO
message when more than 1 million rows are deleted from any table:
Rule Preview:
if (w.stats.rowsDeleted > 1000000) {
log.info('More than 1 million rows deleted');
}
The ybsql
user sees, for example:
premdb=> delete from newmatchstats where seasonid=7;
DELETE 849801600
The DELETE
succeeded, but an INFO
message is logged as expected:
More than 1 million rows deleted
Note that runtime rules are processed at 5-second intervals.
Do Not Store Stats for a Database
The following runtime rule, runtime_no_stats_for_premdb
, turns off statistics logging for queries against the premdb
database. This means that sys.log_query
will not have a record of these queries.
Rule Preview:
if (w.database === 'premdb') {
w.statsStored = false;
log.info('No stats for a premdb query!');
}