DBAtlas · 데이터베이스 운영 아틀라스

병렬 쿼리 실행 / 병렬도 설정

Oracle

-- At query level with a hint:
SELECT /*+ PARALLEL(t, 4) */ * FROM big_table t;
-- Force at session level:
ALTER SESSION FORCE PARALLEL QUERY PARALLEL 4;

PARALLEL 힌트는 테이블에 병렬 스캔을 적용한다. degree=DOP. 과도한 DOP는 서버 자원을 고갈시키므로 신중하게 선택한다. parallel_degree_policy=AUTO는 이를 자동으로 관리한다.

PostgreSQL

-- Set the number of parallel workers for the session:
SET max_parallel_workers_per_gather = 4;
-- The planner adds a Gather/Gather Merge node:
EXPLAIN (ANALYZE) SELECT count(*) FROM big_table;

실행 계획에 Gather/Parallel Seq Scan이 나타나면 병렬 처리가 적용된 것이다. max_parallel_workers와 min_parallel_table_scan_size도 영향을 준다.

MySQL

-- Limited InnoDB parallelism (certain operations only):
SET GLOBAL innodb_parallel_read_threads = 4;
-- Effective for COUNT(*) and primary key scans.

MySQL은 범용 병렬 쿼리 실행을 제공하지 않는다. innodb_parallel_read_threads는 clustered 인덱스 스캔(예: COUNT(*))만 병렬화한다. 복잡한 JOIN은 싱글 스레드로 실행된다.

SQL Server

-- MAXDOP hint at query level:
SELECT * FROM dbo.big_table OPTION (MAXDOP 4);
-- Instance level: sp_configure 'max degree of parallelism', 4;

MAXDOP은 병렬 스레드 수를 제한하며, MAXDOP 1은 병렬 처리를 비활성화한다. 'cost threshold for parallelism'을 초과하면 실행 계획이 병렬로 전환된다.

MongoDB

// Allow disk use for a large aggregation:
db.sale.aggregate([ { $group: { _id: "$city", t: { $sum: "$amount" } } } ], { allowDiskUse: true })
// A sharded cluster processes each shard in parallel.

샤딩된 클러스터에서는 쿼리가 각 샤드에서 병렬로 실행된다. 단일 노드에서는 aggregation 단계가 대부분 순차적이다. allowDiskUse는 메모리 한도를 넘는 작업을 가능하게 한다.

Redis

# Not applicable: there is no concept of query parallelism.

명령 실행은 싱글 스레드다. Cluster(샤딩)로 확장하거나 네트워크 I/O 병렬화에 io-threads를 사용한다.

Elasticsearch

# Shard count = unit of parallelism; a query runs in parallel across shards.
# Parallelism by slicing within a single shard (with scroll/PIT):
GET <index>/_search
{ "slice": { "id": 0, "max": 4 }, "query": { "match_all": {} } }

검색은 관련된 모든 샤드에서 동시에 실행된다. primary 샤드 수가 기본 병렬 수준을 결정한다. slices는 대규모 scroll/reindex 작업을 분할한다.

DBAtlas에서 열기 →