Jump to content

Cartesian explosion

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Citation bot (talk | contribs) at 02:05, 3 April 2025 (Altered url. URLs might have been anonymized. Added publisher. | Use this bot. Report bugs. | Suggested by CorrectionsJackal | Category:Database stubs | #UCB_Category 102/194). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

A Cartesian explosion is an effect that occurs when applying the Cartesian product to multiple sets, which results in geometric growth in the number of outputted combinations.[1]

In database querying

[edit]

This problem most often occurs in the realm of database querying in languages such as SQL. If a join operator is applied to multiple tables without specifying a join condition (such as a foreign key reference), the resulting data set ends up growing multiplicatively, producing a result that has a row count equal to the product of the row count of all tables involved in the query.[2]

For example, if a Customers table has 5 rows and a Products table has 10 rows, running a naive SQL join query such as SELECT * FROM Customers, Products produces a result that has 5×10 (50) rows: every row in the first table is mapped to every row in the second table. If each table had thousands of rows, then doing this query would result in millions of rows of output, which may have severe performance impacts. If more than two tables are involved in the query, the impact is even more pronounced.

References

[edit]
  1. ^ Gulutzan, Peter; Pelzer, Trudy (2003). SQL Performance Tuning. Addison-Wesley. p. 88. ISBN 9780201791693.
  2. ^ Zagni, Roberto (30 June 2023). Data Engineering with DBT: A Practical Guide to Building a Cloud-Based, Pragmatic, and Dependable Data Platform with SQL. Packt Publishing. p. 28. ISBN 9781803241883.