Why can CROSS JOINs be dangerous in BigQuery, and how do you avoid accidental ones?

Quick Overview

Asks why cross joins are risky in BigQuery and how to prevent accidental Cartesian products. Tests understanding of row explosion, slot and runtime cost, many-to-many fan-out that inflates aggregates, safe join patterns, and correct use of UNNEST for arrays.

Why can CROSS JOINs be dangerous in BigQuery, and how do you avoid accidental ones?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

Why can `CROSS JOIN`s be dangerous in BigQuery, and how do you avoid accidental ones? ```hint Count the rows If the left input has m rows and the right input has n, how many rows can the join produce, and which BigQuery resources does producing them consume? ``` ```hint Look beyond the keyword List the ways a query can pair rows that should not be paired, including joins that do have an `ON` clause. ``` ### What a Strong Answer Covers - What a cross join returns and how the output size grows - How the blow-up affects runtime, slot usage, failed queries and the correctness of aggregates - The query patterns that create accidental cross products or fan-out - Concrete ways to prevent and detect them - When a cross join is intended and how to write it safely ### Follow-up Questions - Would a dry run's bytes-processed estimate warn you about an accidental cross join? Why or why not? - An order has two payments and three shipments. What goes wrong if you join both tables to orders and sum the payment amounts? - What is the difference between `CROSS JOIN UNNEST` and `LEFT JOIN UNNEST` when an array is empty? - When is a deliberate cross join the right tool?

Overview: Asks why cross joins are risky in BigQuery and how to prevent accidental Cartesian products. Tests understanding of row explosion, slot and runtime cost, many-to-many fan-out that inflates aggregates, safe join patterns, and correct use of UNNEST for arrays.

PracHub logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

Why can CROSS JOINs be dangerous in BigQuery, and how do you avoid accidental ones?

What a Strong Answer Covers Guidance

  • What a cross join returns and how the output size grows
  • How the blow-up affects runtime, slot usage, failed queries and the correctness of aggregates
  • The query patterns that create accidental cross products or fan-out
  • Concrete ways to prevent and detect them
  • When a cross join is intended and how to write it safely

Follow-up Questions Guidance

  • Would a dry run's bytes-processed estimate warn you about an accidental cross join? Why or why not?
  • An order has two payments and three shipments. What goes wrong if you join both tables to orders and sum the payment amounts?
  • What is the difference between CROSS JOIN UNNEST and LEFT JOIN UNNEST when an array is empty?
  • When is a deliberate cross join the right tool?