DO

DO executes the expressions but does not return any results. In most cases, DO is equivalent to SELECT expr, ... that does not return a result.

DO - 图1

Note

DO only executes expressions. It cannot be used in all cases where SELECT can be used. For example, DO id FROM t1 is invalid because it references a table.

In MySQL, a common use case is to execute stored procedure or trigger. Since TiDB does not provide stored procedure or trigger, this function has a limited use.

Synopsis

DoStmt

DO - 图2

ExpressionList

DO - 图3

Expression

DO - 图4

  1. DoStmt ::= 'DO' ExpressionList
  2. ExpressionList ::=
  3. Expression ( ',' Expression )*
  4. Expression ::=
  5. ( singleAtIdentifier assignmentEq | 'NOT' | Expression ( logOr | 'XOR' | logAnd ) ) Expression
  6. | 'MATCH' '(' ColumnNameList ')' 'AGAINST' '(' BitExpr FulltextSearchModifierOpt ')'
  7. | PredicateExpr ( IsOrNotOp 'NULL' | CompareOp ( ( singleAtIdentifier assignmentEq )? PredicateExpr | AnyOrAll SubSelect ) )* ( IsOrNotOp ( trueKwd | falseKwd | 'UNKNOWN' ) )?

Examples

This SELECT statement pauses, but also produces a result set.

  1. mysql> SELECT SLEEP(5);
  2. +----------+
  3. | SLEEP(5) |
  4. +----------+
  5. | 0 |
  6. +----------+
  7. 1 row in set (5.00 sec)

DO, on the other hand, pauses without producing a result set.

  1. mysql> DO SLEEP(5);
  2. Query OK, 0 rows affected (5.00 sec)
  3. mysql> DO SLEEP(1), SLEEP(1.5);
  4. Query OK, 0 rows affected (2.50 sec)

MySQL compatibility

The DO statement in TiDB is fully compatible with MySQL. If you find any compatibility differences, report a bug.

See also