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
1629
November 10, 2015 08:57AM
871
November 11, 2015 12:33PM
714
November 12, 2015 12:49AM
862
November 12, 2015 03:20AM
816
November 12, 2015 07:24PM
940
November 12, 2015 07:08AM
817
November 12, 2015 07:18AM
794
November 12, 2015 07:43AM
863
November 13, 2015 12:37AM
794
November 13, 2015 12:45AM
Re: distinct clause issue for 600000 records
832
November 13, 2015 02:42AM
864
November 13, 2015 05:56AM
857
November 13, 2015 06:38AM
884
November 13, 2015 07:15AM
920
November 13, 2015 08:11AM
862
November 13, 2015 11:35AM
925
November 16, 2015 03:04AM
846
November 16, 2015 04:12AM
764
November 16, 2015 05:54AM