MySQL Forums
Forum List  »  Performance

Re: distinct clause issue for 600000 records
Posted by: Øystein Grøvlen
Date: November 13, 2015 02:42AM


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

Options: ReplyQuote

Written By
Re: distinct clause issue for 600000 records
November 13, 2015 02:42AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.