extractTables extracts the affected table references from a single DML node.
(databaseName string, node ast.Node, fullSQL string, dbMetadata *model.DatabaseMetadata, isCaseSensitive bool)
| 108 | |
| 109 | // extractTables extracts the affected table references from a single DML node. |
| 110 | func extractTables(databaseName string, node ast.Node, fullSQL string, dbMetadata *model.DatabaseMetadata, isCaseSensitive bool) ([]statementInfo, error) { |
| 111 | switch n := node.(type) { |
| 112 | case *ast.DeleteStmt: |
| 113 | infos, err := extractTablesFromDelete(databaseName, n, fullSQL, isCaseSensitive) |
| 114 | return requireTargets(infos, err, "DELETE") |
| 115 | case *ast.UpdateStmt: |
| 116 | infos, err := extractTablesFromUpdate(databaseName, n, fullSQL, dbMetadata, isCaseSensitive) |
| 117 | return requireTargets(infos, err, "UPDATE") |
| 118 | case *ast.BatchStmt: |
| 119 | // TiDB BATCH (non-transactional DML) is not supported by prior backup. |
| 120 | // Reject it explicitly rather than returning an empty list, which the |
| 121 | // task executor would treat as a successful no-op and then run the |
| 122 | // mutation with no backup. |
| 123 | return nil, errors.New("prior backup does not support TiDB BATCH (non-transactional DML) statements") |
| 124 | case *ast.ExplainStmt: |
| 125 | // EXPLAIN ANALYZE executes the wrapped statement (TiDB modifies data for |
| 126 | // a DML), but prior backup can't unwrap/restore it — reject the ANALYZE |
| 127 | // form of an UPDATE/DELETE/BATCH. Plain EXPLAIN does not execute, so it |
| 128 | // needs no backup and is skipped. |
| 129 | if n.Analyze { |
| 130 | switch s := n.Stmt.(type) { |
| 131 | case *ast.UpdateStmt, *ast.DeleteStmt, *ast.BatchStmt: |
| 132 | return nil, errors.New("prior backup does not support EXPLAIN ANALYZE of an UPDATE/DELETE/BATCH statement") |
| 133 | case *ast.InsertStmt: |
| 134 | if isOverwritingInsert(s) { |
| 135 | return nil, errors.New("prior backup does not support EXPLAIN ANALYZE of a REPLACE or INSERT ... ON DUPLICATE KEY UPDATE statement") |
| 136 | } |
| 137 | default: |
| 138 | } |
| 139 | } |
| 140 | return nil, nil |
| 141 | case *ast.InsertStmt: |
| 142 | // REPLACE and INSERT ... ON DUPLICATE KEY UPDATE can overwrite or delete |
| 143 | // existing rows, but prior backup cannot back them up. Reject them rather |
| 144 | // than returning an empty list, which the task executor would treat as a |
| 145 | // successful no-op and then run the mutation unprotected. A plain INSERT |
| 146 | // only adds rows (nothing to restore), so it needs no backup. |
| 147 | if isOverwritingInsert(n) { |
| 148 | return nil, errors.New("prior backup does not support REPLACE or INSERT ... ON DUPLICATE KEY UPDATE statements") |
| 149 | } |
| 150 | return nil, nil |
| 151 | default: |
| 152 | return nil, nil |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // isOverwritingInsert reports whether an INSERT can overwrite or delete |
| 157 | // existing rows (REPLACE, or INSERT ... ON DUPLICATE KEY UPDATE), which prior |
no test coverage detected