Section 3 • Relational Database Scale-Out Ingestion
Reading & Writing RDBMS via Parallel Partitioned JDBC
Never do a single-threaded JDBC read again. Learn how PySpark distributes parallel JDBC connections across Oracle, PostgreSQL, MySQL, and Microsoft SQL Server to extract 100M+ rows in minutes.
The Single-Threaded JDBC Bottleneck vs. The Partitioned Solution
The #1 beginner mistake in PySpark
THE TRAP
Basic
Basic spark.read.jdbc()
When you call spark.read.jdbc(url, table, properties) without partitioning parameters:
- Spark sends ONE single SQL query (
SELECT * FROM table). - Exactly 1 Executor Task is scheduled. All other 50+ cores in your cluster sit 100% idle!
- The single executor driver process buffers all rows, often leading to
java.lang.OutOfMemoryError.
THE SOLUTION
Parallel Partitioned Read
By providing partitionColumn, lowerBound, upperBound, and numPartitions:
- Spark calculates partition strides and generates N independent parallel SQL queries.
- N tasks run concurrently across all worker executors in the cluster.
- Each executor fetches its partition stream in parallel directly into memory partitions.
2. Interactive Parallel JDBC Partitioning Simulator
See how Spark splits SQL query boundariesAdjust the parameters below to see the exact SQL queries generated by the JDBC driver and how executor tasks distribute:
numPartitions:
4 Parallel Connections
Concurrent DB connections & Spark tasks
lowerBound (Min ID):
1
Smallest primary key value
upperBound (Max ID):
1,000,000
Highest primary key value
Concurrent Database Queries Sent Simultaneously:
Stride: 250,000 rows/partition
Production Tip: Always partition on an indexed integer column (like auto-increment
id) or sequential timestamp. If you partition on an unindexed column, the database will perform N simultaneous full-table scans, crashing the database engine!