<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;}
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;}
--></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 II 11.0.0 (a64.lnx/100) + p15255<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have a query which is causing lock escalation messages in my log because its estimate for a key join is way wrong.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The relevant part of the query plan reads:<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""> K Join(basket_id,
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> item_type)
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Sorted(basket_id)
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <span style="background:yellow;mso-highlight:yellow">Tups 1 Pages 1</span>
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> D6 C2<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 basket_item<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Sorted(basket_id) (x)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Tups 1 Pages 1 B-Tree(basket_id,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> D3 C0 item_type,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> item_id)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Tups 1596419 Pages 24957<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"">basket_main<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">(bm)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">B-Tree(basket_id)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Tups 4067 Pages 91<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">So it says that it is getting a single row from basket_main (correct) and it expects a single row out of the K Join to basket_item…but in reality it gets 1686.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The stats for table basket_item are:<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Key Avg Count<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Column Name Type Length Nulls Defaults Seq Per Value<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New";background:yellow;mso-highlight:yellow">basket_id integer 4 no no 1 433.0</span><span style="font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New";background:yellow;mso-highlight:yellow">item_type integer 1 no no 2 529435.0</span><span style="font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">item_id integer 4 no no 3 362.2<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">filter_id integer 4 no yes 1737.9<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New";background:yellow;mso-highlight:yellow">status integer 1 no yes 1588305.0</span><span style="font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">res_upd_id integer 4 no no
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">tupdate ingresdate no value
<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">So given a single basket_id from basket_main we should on average see 433 entries in basket_item.<o:p></o:p></p>
<p class="MsoNormal">The query has restrictions item_type = 1 AND status = 0. I suppose those restrictions have caused it to lower the join tuple estimate.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">But we have stats on the fields involved and as can be seen above the item_type and status are not particularly restrictive settings in a table with 1596419 rows.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’ve attempted to build composite statistics on the table with:<o:p></o:p></p>
<p class="MsoNormal">optimizedb -zcpk -rbasket_item -abasket_id -aitem_type –astatus<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">But the QEP still insists on a single row resulting from the K Join.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Anyone got any ideas?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Martin Bowes<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>