blob: 6e668eb64ed62b4b353c2ba8c9421d099dabc0f0 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MADlib: CountMin (Cormode-Muthukrishnan)</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<script src="../mathjax/MathJax.js">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
</head>
<body>
<div id="top"><!-- do not remove this div! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">MADlib
&#160;<span id="projectnumber">0.6</span> <span style="font-size:10pt; font-style:italic"><a href="../latest/./group__grp__countmin.html"> A newer version is available</a></span>
</div>
<div id="projectbrief">User Documentation</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="dynsections.js"></script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
initNavTree('group__grp__countmin.html','');
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">CountMin (Cormode-Muthukrishnan)</div> </div>
<div class="ingroups"><a class="el" href="group__grp__sketches.html">Sketch-based Estimators</a></div></div>
<div class="contents">
<div id="dynsection-0" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;">
<img id="dynsection-0-trigger" src="closed.png" alt="+"/> Collaboration diagram for CountMin (Cormode-Muthukrishnan):</div>
<div id="dynsection-0-summary" class="dynsummary" style="display:block;">
</div>
<div id="dynsection-0-content" class="dyncontent" style="display:none;">
<center><table><tr><td><div class="center"><iframe scrolling="no" frameborder="0" src="group__grp__countmin.svg" width="494" height="40"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</td></tr></table></center>
</div>
<dl class="user"><dt><b>About:</b></dt><dd>This module implements Cormode-Muthukrishnan <em>CountMin</em> sketches on integer values, implemented as a user-defined aggregate. It also provides scalar functions over the sketches to produce approximate counts, order statistics, and histograms.</dd></dl>
<dl class="user"><dt><b>Usage:</b></dt><dd></dd></dl>
<ul>
<li>Get a sketch of a selected column specified by <em>col_name</em>. <pre>SELECT <a class="el" href="sketch_8sql__in.html#a323b932332f2db302469f14dc5fae369">cmsketch</a>(<em>col_name</em>) FROM table_name;</pre></li>
</ul>
<ul>
<li>Get the number of rows where <em>col_name = p</em>, computed from the sketch obtained from <code>cmsketch</code>. <pre>SELECT <a class="el" href="sketch_8sql__in.html#a3498d2c778d1289154f61d34e84c609e">cmsketch_count</a>(<em>cmsketch</em>,<em>p</em>) FROM table_name;</pre></li>
</ul>
<ul>
<li>Get the number of rows where <em>col_name</em> is between <em>m</em> and <em>n</em> inclusive. <pre>SELECT <a class="el" href="sketch_8sql__in.html#aeff9e36cfb3338c4e405d4ac77d3968c">cmsketch_rangecount</a>(<em>cmsketch</em>,<em>m</em>,<em>n</em>) FROM table_name;</pre></li>
</ul>
<ul>
<li>Get the <em>k</em>th percentile of <em>col_name</em> where <em>count</em> specifies number of rows. <em>k</em> should be an integer between 1 to 99. <pre>SELECT <a class="el" href="sketch_8sql__in.html#a2f2ab2fe3244515f5f73d49690e73b39">cmsketch_centile</a>(<em>cmsketch</em>,<em>k</em>,<em>count</em>) FROM table_name;</pre></li>
</ul>
<ul>
<li>Get the median of <em>col_name</em> where <em>count</em> specifies number of rows. This is equivalent to <code><a class="el" href="sketch_8sql__in.html#a2f2ab2fe3244515f5f73d49690e73b39">cmsketch_centile</a>(<em>cmsketch</em>,50,<em>count</em>)</code>. <pre>SELECT <a class="el" href="sketch_8sql__in.html#a0ef6428fa7ba4b7f7b1f633e6f8003ea">cmsketch_median</a>(<em>cmsketch</em>,<em>count</em>) FROM table_name;</pre></li>
</ul>
<ul>
<li>Get an n-bucket histogram for values between min and max for the column where each bucket has approximately the same width. The output is a text string containing triples {lo, hi, count} representing the buckets; counts are approximate. <pre>SELECT <a class="el" href="sketch_8sql__in.html#a8482f62849adf40a2c7df78c23ea33a4">cmsketch_width_histogram</a>(<em>cmsketch</em>,<em>min</em>,<em>max</em>,<em>n</em>) FROM table_name;</pre></li>
</ul>
<ul>
<li>Get an n-bucket histogram for the column where each bucket has approximately the same count. The output is a text string containing triples {lo, hi, count} representing the buckets; counts are approximate. Note that an equi-depth histogram is equivalent to a spanning set of equi-spaced centiles. <pre>SELECT <a class="el" href="sketch_8sql__in.html#a9e6d30f20b724b96249cc4a0f67a279e">cmsketch_depth_histogram</a>(<em>cmsketch</em>,<em>n</em>) FROM table_name;</pre></li>
</ul>
<dl class="user"><dt><b>Examples:</b></dt><dd></dd></dl>
<ol type="1">
<li>Generate some data <div class="fragment"><pre class="fragment">
sql&gt; CREATE TABLE data(class INT, a1 INT);
sql&gt; INSERT INTO data SELECT 1,1 FROM generate_series(1,10000);
sql&gt; INSERT INTO data SELECT 1,2 FROM generate_series(1,15000);
sql&gt; INSERT INTO data SELECT 1,3 FROM generate_series(1,10000);
sql&gt; INSERT INTO data SELECT 2,5 FROM generate_series(1,1000);
sql&gt; INSERT INTO data SELECT 2,6 FROM generate_series(1,1000);
</pre></div></li>
<li>Count number of rows where a1 = 2 in each class <div class="fragment"><pre class="fragment">
sql&gt; SELECT class,cmsketch_count(cmsketch(a1),2) FROM data GROUP BY data.class;
class | cmsketch_count
-------+----------------
2 | 0
1 | 15000
(2 rows)
</pre></div></li>
<li>Count number of rows where a1 is between 3 and 6 <div class="fragment"><pre class="fragment">
sql&gt; SELECT class,cmsketch_rangecount(cmsketch(a1),3,6) FROM data GROUP BY data.class;
class | cmsketch_rangecount
-------+---------------------
2 | 2000
1 | 10000
(2 rows)
</pre></div></li>
<li>Compute the 90th percentile of all of a1 <div class="fragment"><pre class="fragment">
sql&gt; SELECT cmsketch_centile(cmsketch(a1),90,count(*)) FROM data;
cmsketch_centile
------------------
3
(1 row)
</pre></div></li>
<li>Produce an equi-width histogram with 2 bins between 0 and 10 <div class="fragment"><pre class="fragment">
sql&gt; SELECT cmsketch_width_histogram(cmsketch(a1),0,10,2) FROM data;
cmsketch_width_histogram
------------------------------------
[[0L, 4L, 35000], [5L, 10L, 2000]]
(1 row)
</pre></div></li>
<li>Produce an equi-depth histogram of a1 with 2 bins of approximately equal depth <div class="fragment"><pre class="fragment">
sql&gt; SELECT cmsketch_depth_histogram(cmsketch(a1),2) FROM data;
cmsketch_depth_histogram
-----------------------------------------------------------------------
[[-9223372036854775807L, 1, 10000], [2, 9223372036854775807L, 27000]]
(1 row)
</pre></div></li>
</ol>
<dl class="user"><dt><b>Literature:</b></dt><dd></dd></dl>
<p>[1] G. Cormode and S. Muthukrishnan. An improved data stream summary: The count-min sketch and its applications. LATIN 2004, J. Algorithm 55(1): 58-75 (2005) . <a href="http://dimacs.rutgers.edu/~graham/pubs/html/CormodeMuthukrishnan04CMLatin.html">http://dimacs.rutgers.edu/~graham/pubs/html/CormodeMuthukrishnan04CMLatin.html</a></p>
<p>[2] G. Cormode. Encyclopedia entry on 'Count-Min Sketch'. In L. Liu and M. T. Ozsu, editors, Encyclopedia of Database Systems, pages 511-516. Springer, 2009. <a href="http://dimacs.rutgers.edu/~graham/pubs/html/Cormode09b.html">http://dimacs.rutgers.edu/~graham/pubs/html/Cormode09b.html</a></p>
<dl class="see"><dt><b>See also:</b></dt><dd>File <a class="el" href="sketch_8sql__in.html" title="SQL functions for sketch-based approximations of descriptive statistics.">sketch.sql_in</a> documenting the SQL functions. <br/>
<br/>
Module <a class="el" href="group__grp__quantile.html">Quantile</a> for a different implementation of <a class="el" href="quantile_8sql__in.html#a6955e44659a0817803ab7a11a9a7e8a5" title="Computes quantile.">quantile</a> function. </dd></dl>
</div>
</div>
<div id="nav-path" class="navpath">
<ul>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<li class="footer">Generated on Tue Apr 2 2013 14:57:03 for MADlib by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
</ul>
</div>
</body>
</html>