I have two tables with several columns, and I want to join these tables using an outer join. However, it takes forever. I just think I made a mistake or maybe there are other solutions?
create table table_1 (
sn int(11) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
column1 int(6) NOT NULL,
column3 int(1) NOT NULL,
column4 date NOT NULL,
column5 char(2) NOT NULL,
column6 int(6) NOT NULL,
...
...
column15 int(1) NOT NULL
)
create table table_2 (
sn int(11) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
column1 int(6) NOT NULL,
column3 int(1) NOT NULL,
column4 date NOT NULL,
column5 char(2) NOT NULL,
column6 int(6) NOT NULL,
...
...
column8 int(1) NOT NULL
)
I've created an index on these 2 table with column1, column2, column3, column4, column5 and column6.
My problem is I want to right join these two tables with:
table_1.column1 = table_2.column1 AND
table_1.column2 = table_2.column2 AND
table_1.column3 = table_2.column3 AND
table_1.column4 = table_2.column4 AND
table_1.column5 = table_2.column5 AND
table_1.column6 = table_2.column6
When I execute this query, it takes a very long time. Is there any solution to make this query faster?
Table_1 size: 3 GB and table_2 size: 10 GB. Thanks.