Help Center/ MapReduce Service/ Component Operation Guide (LTS)/ Using Hive/ Common Issues About Hive/ OR Statement in JOIN Query Conditions Causes Slow Hive SQL Execution
Updated on 2026-06-27 GMT+08:00

OR Statement in JOIN Query Conditions Causes Slow Hive SQL Execution

Symptom

If there is an OR statement in JOIN statement of Hive SQL in MRS 3.2.0-LTS or later, the SQL task runs slowly. In extreme cases, column concatenation may occur (in MRS 3.6.0-LTS.1 or later). The following is an example of the SQL statement:

Figure 1 Hive SQL statement

Cause Analysis

If there is an OR statement in the JOIN ON condition of Hive SQL, the Cartesian product is generated during the JOIN operation because there is no JOIN key. You can confirm this problem in the execution plan. For example, the task of the SQL JOIN statement in Figure 2 has no key value.

Figure 2 Printing the execution plan

Procedure

Modify Hive SQL statements. You can replace the OR statement with the UNION or UNION ALL statement based on the site requirements.