This topic describes the possible causes of the error code ODPS-0130252: Cartesian product is not allowed and provides solutions.
Error Message 1: cartesian product is not allowed without mapjoin
Sample
ODPS-0130252:[m,n] Cartesian product is not allowed - cartesian product is not allowed without mapjoin
Description
When no join conditions are specified for a join operation between two tables, the tables are not joined and a Cartesian product operation is performed between the tables. The preceding error message is also returned if odps.sql.allow.cartesian
is set to false.
Solutions
Modify the query statement by adding join conditions.
If one of the two tables is a small table, set
odps.sql.allow.cartesian
to true or add join conditions.If both of the two tables are large tables, we recommend that you do not set
odps.sql.allow.cartesian
to true. If you set odps.sql.allow.cartesian to true, data bloat occurs after the join operation. We recommend that you add join conditions to resolve the issue.
Examples of query statements
-- Incorrect statement. After the following statement is executed, the error message is returned because Cartesian product operations are not allowed.
odps> SET odps.sql.allow.cartesian=false;
odps> SELECT t1. *
FROM src t1
JOIN src t2;
FAILED: ODPS-0130252:[3,1] Cartesian product is not allowed - cartesian product is not allowed without mapjoin
-- Correct statement. The expression t1.key = t2.key is added as a join condition.
odps> SELECT t1. *
FROM src t1
JOIN src t2
ON t1.key = t2.key;
-- Correct statement. The expression t1.key > t2.key is added as a join condition, and a MAPJOIN hint is added.
odps> SELECT /*+mapjoin(t1) * / t1.*
FROM src t1
JOIN src t2
ON t1.key > t2.key;