Optimize Hive query with similar tables

Viewed 23

I have two big tables that are very similar to each other and are made of 6 left joins. The only difference between them is in the first table to which the others are left joined, otherwise the main select clause and the rest of the tables are the same.

A simple example would be:

Create table A as
Select a.attr, b.attr, ...
From 
   (Select attr
    From table a
    Where cond1, cond2, cond3) a
Left join 
   (Select attr
    From table) b
on a.whatever = b.whatever
Left join ...;


Create table B as
Select a.attr, b.attr ...
From 
   (Select attr
    From table a
    Where cond1) a
Left join 
   (Select attr
    From table) b
on a.whatever = b.whatever
Left join...;

I hope this is clear. The only difference is the where conditions of table 'a' to which everything else is joined. How could I optimize this so I don't have to write two almost identical queries?

1 Answers

Maybe you can get rid of the restrictions of table a in first, get the result, add it when use

Related