query_script_eval

eval: evaluate statement by dynamically invoking result set test.

SYNOPSIS

eval select text_col ...;

DESCRIPTION

eval is a META statement, which executes a given statement, gets its text output - assumed to be SQL, and invokes this resulting SQL.

That is, eval is given a statement as argument. eval expects a SELECT statement which produces a single text column, and the text in that columns is expected to be valid SQL statements.

The eval statement invokes the eval() routine, and therefore produces the same result/output.

Many views in common_schema produce SQL statements as columns. Consider processlist_grantees, redundant_keys, sql_alter_table, sql_foreign_keys, sql_grants and more. It is possible, then, to eval directly on columns of these views:

eval SELECT sql_revoke FROM sql_grants WHERE user='gromit';

common_schema also offers programmatic alternatives to eval. For example, instead of evaluating queries on INFORMATION_SCHEMA.TABLES, one can use the foreach statement.

EXAMPLES

Drop foreign keys from the sakila database:

eval SELECT drop_statement FROM sql_foreign_keys WHERE TABLE_SCHEMA='sakila';

KILL long running queries which were invoked by 'normal' users:

eval SELECT sql_kill_query FROM processlist_grantees WHERE COMMAND != 'Sleep' AND TIME > 20 AND is_super = 0 AND is_repl = 0;

SEE ALSO

eval(), foreach, killall()

AUTHOR

Shlomi Noach
 
common_schema documentation