<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1835413779;
        mso-list-type:hybrid;
        mso-list-template-ids:2096285276 134807567 134807577 134807579 134807567 134807577 134807579 134807567 134807577 134807579;}
@list l0:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi All,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In 10.2.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have a query:<o:p></o:p></p>
<p class="MsoNormal">SELECT count(*)<o:p></o:p></p>
<p class="MsoNormal">FROM comms c<o:p></o:p></p>
<p class="MsoNormal"> LEFT JOIN researcher r ON c.launch_id = r.researcher_id AND c.launch_type in (0,2)<o:p></o:p></p>
<p class="MsoNormal"> LEFT JOIN user_details ud ON ud.user_id = r.user_id<o:p></o:p></p>
<p class="MsoNormal">WHERE c.active=1 AND c.comm_type=2<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The part of the qep which handles the left join between comms and researcher looks like this:<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> /
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> left join
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> K Join(launch_id)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Sort on(tidp)
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Pages 1
<span style="background:yellow;mso-highlight:yellow">Tups 11</span><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> D203 C539<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> / \<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Proj-rest researcher_id_idx<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Heap I(r)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Pages 4 <span style="background:yellow;mso-highlight:yellow">
Tups 745</span> B-Tree(researcher_id)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> D170 C525 Pages 36 Tups 6117<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">/<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">comms<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">(c)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">B-Tree(NU)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Pages 680 Tups 52520<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">How can a left join have fewer result rows (11) than the left table (745)?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The fun part is that this only occurs if:<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="mso-list:Ignore">1.<span style="font:7.0pt "Times New Roman"">
</span></span><![endif]> the left join between comms and researcher has the ON cond1 AND cond2<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="mso-list:Ignore">2.<span style="font:7.0pt "Times New Roman"">
</span></span><![endif]>The query has multiple left joins.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">If you remove either of those then the tuple estimate returns to 745. So it looks like the it has treated the second join condition as a row restriction just like it had been in the where clause of the query.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Martin Bowes<o:p></o:p></p>
</div>
</body>
</html>