QueryingClausesUSING PARALLEL EXECUTION

USING PARALLEL EXECUTION Enterprise

The USING PARALLEL EXECUTION clause allows you to instruct the query planner to execute the query using multiple threads. This can significantly improve performance for analytical queries on large datasets.

Syntax

USING PARALLEL EXECUTION [num_threads]
MATCH ...
RETURN ...
  • num_threads (Optional): An integer specifying the number of threads to use. If omitted, Memgraph determines the optimal number of threads.

Usage

Place the USING PARALLEL EXECUTION clause at the beginning of your query.

Basic Usage

Run a query with default parallel settings:

USING PARALLEL EXECUTION
MATCH (n:Transaction)
WHERE n.amount > 1000
RETURN count(n);

Specifying Thread Count

Run a query using exactly 4 threads:

USING PARALLEL EXECUTION 4
MATCH (n:Transaction)
RETURN avg(n.amount);

Considerations

  • Enterprise Feature: Requires Memgraph Enterprise.
  • Privileges: Requires PARALLEL_EXECUTION privilege.
  • Plan Caching: Queries with a specified thread count are not cached.
  • Fallback: If parallel execution is not possible for the given query plan, Memgraph falls back to single-threaded execution.
  • Performance: Best for aggregation queries that split into independent work. Operators like DISTINCT, SKIP, LIMIT, or hops limits require cross-worker synchronization and may yield little or no speedup. See Parallel execution for details.

For more details on how parallel execution works, see the Parallel execution guide.