You need every "product × region" pair, "user × date" slot, or an "account × month" grid with no gaps. It's tempting to pull both tables into Python and run a nested loop:
# Row-by-row loop in app code: extra traffic and boilerplate
pairs = []
for product in products:
for region in regions:
pairs.append((product["id"], region["id"]))
On a hundred rows, you won't notice. Against a live database, your app burns bandwidth and memory—especially if another query hides inside the loop. This is a job for set-based thinking: describe the result you want and let the database plan it. In PostgreSQL and standard SQL, CROSS JOIN pairs every row from the first table with every row from the second without an ON clause:
-- Cartesian product of active products and regions
SELECT p.id AS product_id, r.id AS region_id
FROM products AS p
CROSS JOIN regions AS r
WHERE p.is_active = TRUE
AND r.is_active = TRUE;
The engine returns the Cartesian product in one query, and adding a LEFT JOIN on top lets you zero-fill missing dates cleanly. Just watch out for row explosions: output scales at N × M (100,000 products × 1,000 regions = 100 million rows). Filter rows before joining via WHERE, check EXPLAIN, and write explicit CROSS JOIN instead of comma syntax FROM a, b—with three tables, JOIN takes higher precedence.
