CROSS JOIN Results: Size and Structure
You'll learn: How to calculate the size of a CROSS JOIN result set and understand why it can explode your memory and performance.
The Multiplication Effect
When you perform a CROSS JOIN between two tables, the resulting rows equal the product of both table sizes. If TableA has 100 rows and TableB has 50 rows, the CROSS JOIN produces 100 × 50 = 5,000 rows.
This is called the Cartesian product — every row from the first table pairs with every row from the second table.
The Size Formula
Result Rows = (Rows in Table1) × (Rows in Table2)
Even modest tables create enormous results:
- 1,000 × 1,000 = 1 million rows
- 10,000 × 10,000 = 100 million rows
Structure of Results
The result contains all columns from both tables, side-by-side. If TableA has 5 columns and TableB has 3 columns, the result has 8 columns (5 + 3).
Memory and Performance Impact
CROSS JOINs can:
- Consume massive memory — your database must store or stream millions of rows
- Crash queries — some databases have row limits or timeouts
- Slow down dramatically — processing scales with the product, not the sum
- Create unexpected results — accidental CROSS JOINs are a common SQL mistake
When Is This Acceptable?
CROSS JOINs are safe when:
- Both tables are small (< 100 rows typically)
- You genuinely need all combinations (e.g., generating a calendar grid)
Key Takeaway: A CROSS JOIN multiplies table sizes together (rows₁ × rows₂), creating potentially massive result sets that can overwhelm memory and performance — always verify table sizes before using one.