All Products
Search
Document Center

AnalyticDB:Spark SQL execution modes

Last Updated:Mar 28, 2026

AnalyticDB for MySQL supports two Spark SQL execution modes: batch and interactive. Both modes let you read and write AnalyticDB for MySQL databases and tables through the metadata feature.

Choose an execution mode

BatchInteractive
Best forETL jobs, dependent SQL sequences, large data volumesAd hoc queries, DDL-heavy workflows, immediate DQL results
Resource isolationApplication-level (each SQL runs in a dedicated Spark application)Thread-level (multiple users share one Spark application)
Result outputExecution status only; SELECT sample results appear in logsUp to 1,000 rows returned directly
Configuration scopePer-submission — set independently with SET statementsThread-level settings take effect after configuration; application-level settings require a restart
Resource groupJob resource groupSpark interactive resource group

Batch execution mode

Use cases

  • SQL statements with mutual dependencies

  • Workloads requiring strict resource isolation

  • Large-scale data processing, such as extract, transform, and load (ETL) jobs

  • Workflows that upload and iterate on complex third-party dependency packages

How it works

Each SQL submission runs in its own Spark application, which ensures stability and prevents interference between jobs. You can include independent configuration statements such as SET spark.sql.adaptive.coalescePartitions.minPartitionSize = 2MB; in the same submission.

If your SQL includes SELECT statements, sample results appear in the application logs. For DML, DDL, and DQL statements, the system returns an execution success or failure message — not data. To view the full log output, see the View information about a Spark application section of the Spark editor topic.

Usage notes

  • Run USE <database_name>; before any SQL statements to select a database.

  • Always qualify table names in the database_name.table_name format.

Start batch mode

On the SQLConsole tab, select the Spark engine and a job resource group. Enter your SQL statement, then click Execute.

Interactive execution mode

Use cases

  • Ad hoc queries where returning all rows is not required

  • Workflows with many DDL statements

  • Immediate DQL execution where strict resource isolation is not required

How it works

Interactive mode runs SQL statements inside a shared Spark application using thread-level resource isolation. Multiple users executing SQL in the same Spark application may affect each other.

Configuration changes apply at two levels:

Configuration levelWhen it takes effect
Thread-levelAfter you configure SQL statements
Application-levelOnly after you restart the Spark interactive resource group

To apply application-level configuration changes: stop the Spark interactive resource group, update the parameters, then restart the Spark interactive resource group.

Usage notes

  • DDL or DML statements return up to 1,000 rows of result data.

  • DDL statements (such as CREATE TABLE) return an execution success or failure message, not table data. This is consistent with standard open-source SQL behavior.

  • The Spark interactive resource group takes time to start. If it fails to start, wait a moment and try again.

Because multiple users share one Spark application, SQL statements can interfere with each other under high concurrency. For workloads requiring strict isolation, use batch execution mode instead.

Start interactive mode

On the SQLConsole tab, select the Spark engine and a Spark interactive resource group. Enter your SQL statement, then click Execute.