Change table data and schemas in the new interactive mode of the SQL Console (Public Preview)
The new interactive mode of the SQL Console is an upgraded version that lets you back up data before execution, schedule SQL execution, estimate the execution duration, and run SQL statements asynchronously.
Background information
The new interactive mode of the SQL Console in DMS supports the following SQL execution methods:
Direct Execution: Use this method for SQL statements with a small estimated impact, such as a low number of affected rows and a short execution duration. The statement runs synchronously in the SQL Console. You cannot run other SQL statements in the current tab until the execution is complete.
Asynchronous Background Execution: This method is suitable for SQL statements with a large estimated impact. It generates an asynchronous task by submitting a data change ticket that does not require approval. This method does not block the SQL Console from executing other SQL statements and prevents task interruptions caused by browser or network issues.
Prerequisites
The control mode of the instance is Flexible Management or Stable Change.
Notes
Instances in Flexible Management mode have five trial attempts for asynchronous SQL execution. The system allocates five trial attempts to each tenant. If you run out of trials and need to continue using asynchronous SQL execution, you can purchase the Stable Change feature and change the control mode of the instance.
Instances in Stable Change mode support only asynchronous SQL execution, not direct execution, when not in Super SQL mode.
NoteIn Super SQL mode, if lockless change is enabled for the instance and the data volume of the change is less than 1 million rows, both SQL execution methods are supported. If lockless change is not enabled or the data volume exceeds 1 million rows, only asynchronous SQL execution is supported.
The new interactive mode of the SQL Console is in public preview. If you encounter any issues, search for the DingTalk group number 21991247 in DingTalk and join the group to provide feedback.
The lockless change option is available only when you change the data or schema of a large table (2 million or more rows).
Limits
Backups are not supported for schema evolution.
The new interactive mode of the SQL Console is not supported for instances in Security Collaboration mode.
Access the SQL console
You can use one of the following methods to open the sql console.
From the top navigation bar
Log in to DMS 5.0.
In the top navigation bar, choose .
NoteIf you use the DMS console in simple mode, move the pointer over the
icon in the upper-left corner of the console and choose . -
In the Select Database dialog box, search for and select a database, and then click Confirm.
From the instance list
Log in to DMS 5.0.
-
In the Database Instances list on the left side of the page, find the database that you want to manage.
-
Double-click the database name to go to the sql console.
Preparations
For this example, a table named `test_table` is created and populated with data.
Change table data using an SQL statement
In the SQL Console window, enter and select the SQL statement, and then click Execute.
Example SQL statement:
UPDATE `test_table` SET `name` = 'Johnn' WHERE `name` = 'John';Before the SQL statement is executed, the SQL task enters a verification phase. During this phase, the system automatically performs the following operations:
Parses and splits the SQL statement.
Verifies that the user who executes the SQL statement has the required permissions. If the permission verification fails, the execution process is blocked and an error is returned. If the verification succeeds, the process continues.
Verifies the SQL statement against development standards.
Reviews the SQL statement for compliance with development standards and provides optimization suggestions. You can adjust the SQL statement based on these recommendations.
Preview the SQL statement and check the Estimated Affected Rows and Estimated Runtime (in milliseconds). This helps you assess the business impact of the change before execution.
If you find an issue with the SQL statement, modify it as follows:
Click the
icon in the SQL area to modify the SQL statement.After you finish, click the
icon to lock it again. The system then re-verifies the SQL statement.
In the Change Suggestions area, select whether to enable Lockless Change, Backup, or Scheduled Execution for the change.
Lockless Change: If you enable this feature, the SQL statement can be executed only asynchronously in the background. This prevents the table from being locked during the data update. You can also view the progress of the change in real time. For more information about lockless change, see Lock-free data change.
Scheduled Execution: Set a time to execute the data change.
Backup: Back up the data before the change. This lets you roll back the data to its previous state if an issue occurs. For more information, see SQL backup and rollback.
Click Direct Execution or Asynchronous Background Execution.
View the execution result.
In the execution result area, click the
icon to view the task details. The details include the executed script, logs, backup retrieval information, and task execution progress. For information about how to retrieve a backup, see SQL backup and rollback.
Change table schema using an SQL statement
The lockless schema evolution feature is available only after you enable lockless schema evolution for the instance.
In the SQL Console window, enter and select the SQL statement, and then click Execute.
Example SQL statement:
ALTER TABLE `test_table`ADD score DECIMAL ;Before the SQL statement is executed, the SQL task enters a verification phase. During this phase, the system automatically performs the following operations:
Parses and splits the SQL statement.
Verifies that the user who executes the SQL statement has the required permissions. If the permission verification fails, the execution process is blocked and an error is returned. If the verification succeeds, the process continues.
Verifies the SQL statement against development standards.
Reviews the SQL statement for compliance with development standards and provides optimization suggestions. You can adjust the SQL statement based on these recommendations.
Preview the SQL statement and check the Estimated Affected Rows and Estimated Runtime (in milliseconds). This helps you assess the business impact of the change before execution.
If you find an issue with the SQL statement, modify it as follows:
Click the
icon in the SQL area to modify the SQL statement.After you finish, click the
icon to lock it again. The system then re-verifies the SQL statement.
In the Change Suggestions area, select whether to enable Lockless Change and Scheduled Execution for the change.
Lockless Change: If you enable this feature, the SQL statement can be executed only asynchronously in the background. This prevents the table from being locked during the schema update. You can also view the progress of the change in real time. For more information about lockless change, see Lock-free schema evolution.
Scheduled Execution: Set a time to execute the data change.
Click Direct Execution or Asynchronous Background Execution.
View the execution result.
In the execution result area, click the
icon to view the task details. The details include the executed script, logs, and task execution progress, such as the estimated progress and runtime parameters.