I am running a query in an Oracle SQL environment using Toad where I build a table by joining 16 different tables and I am running out of temp tablespace and was hoping I could get some advice on how to make my query more efficient. I don't have a background in this so I am not sure if the best way is to use intermediary tables or change the order of my joins.
There are two main tables, Header and Detail, the header has 26 million rows, the detail has 175 million rows. I use an inner join with these tables which will result in 175 million rows. The other 14 tables are smaller description tables that I join using left joins. Three of those tables are 350k rows and less, the other 11 are under 1,000 rows. My current pseudo code is as follows:
create table END_TABLE as
select *
from Detail
inner join Header
left join description_table_1
left join description_table_2
left join description_table_3
left join description_table_4
left join description_table_5
left join description_table_6
left join description_table_7
left join description_table_8
left join description_table_9
left join description_table_10
left join description_table_11
left join description_table_12
left join description_table_13
left join description_table_14;
Since I am starting with my detail table and then joining the header is that less efficient than if I did it the other way around? I assumed since it was an inner join it wouldn't matter but like I said before I am not very knowledgeable on making queries more efficient.
My idea is to create a separate table joining the header and detail together and then create a final table where I join the smaller detail tables. Would this help? Would changing my join order help?