Re: distinct clause issue for 600000 records
Hi,
Here are several things note:
1. LEFT JOIN: Don't use it if you do not mean it.
LEFT JOIN implies "optional". That is, for each row in the left hand table there might or might not be information in the right hand table. LEFT JOIN is used to make sure rows from the left hand table is included in the result even when there is no match in the right hand table. Example: We want to list persons in person table even if there is no registered address in address table.
Unnecessary use of LEFT JOIN restricts optimizer in what query plan it may use since left hand tables needs to be processed before right hand tables. In other words, your query only allows for one join order.
2. ON clause is for join conditions
Normally single table conditions in ON clause does not make much sense. Take for example your condition "ea2.address_type='Bil'. If using LEFT JOIN this will not filter out rows with other address_types. Those rows will still be included, but ea2 columns will be NULL instead of actual data. Is that what you want? If not, you should put this criteria in the WHERE clause instead.
3. Do not include tables that are not used in query.
In your case, the only effect of tables beship, beinv, and reginv is that they may generate duplicate rows in your result set.
Hope this helps,
Øystein Grøvlen,
Senior Principal Software Engineer,
MySQL Group, Oracle,
Trondheim, Norway
Subject
Views
Written By
Posted
1640
November 10, 2015 08:57AM
876
November 11, 2015 12:33PM
721
November 12, 2015 12:49AM
869
November 12, 2015 03:20AM
820
November 12, 2015 07:24PM
946
November 12, 2015 07:08AM
823
November 12, 2015 07:18AM
799
November 12, 2015 07:43AM
873
November 13, 2015 12:37AM
800
November 13, 2015 12:45AM
Re: distinct clause issue for 600000 records
841
November 13, 2015 02:42AM
868
November 13, 2015 05:56AM
863
November 13, 2015 06:38AM
891
November 13, 2015 07:15AM
927
November 13, 2015 08:11AM
868
November 13, 2015 11:35AM
930
November 16, 2015 03:04AM
852
November 16, 2015 04:12AM
771
November 16, 2015 05:54AM