<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>entwicklungsgedanken &#187; large list</title>
	<atom:link href="http://www.entwicklungsgedanken.de/tag/large-list/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.entwicklungsgedanken.de</link>
	<description>Verschiedene Gedanken rund um die Softwareentwicklung</description>
	<lastBuildDate>Mon, 09 Jan 2012 14:47:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Incredible performance increase with very large lists via &#8220;QuickView-Method&#8221;</title>
		<link>http://www.entwicklungsgedanken.de/2008/01/10/incredible-performance-increase-with-very-large-lists-via-quickview-method/</link>
		<comments>http://www.entwicklungsgedanken.de/2008/01/10/incredible-performance-increase-with-very-large-lists-via-quickview-method/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 21:40:43 +0000</pubDate>
		<dc:creator>Eric Bartels</dc:creator>
				<category><![CDATA[SharePoint-Development]]></category>
		<category><![CDATA[GetItems]]></category>
		<category><![CDATA[large list]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[quickview]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.entwicklungsgedanken.de/2008/01/10/incredible-performance-increase-with-very-large-lists-via-quickview-method/</guid>
		<description><![CDATA[Preface One of my SharePoint projects contains a (still growing) list with currently more than 230,000 items. These items represent positions of a quotation. So one &#8220;quotation-item&#8221; references multiple &#8220;position-items&#8221; (1:n relation). In order to have a user-friendly user interface I developed a custom webpart which allows a quick way of editing the positions of [...]]]></description>
			<content:encoded><![CDATA[<div class="lang-en"></div>
<h3>Preface</h3>
<p>One of my SharePoint projects contains a (still growing) list with currently more than 230,000 items. These items represent positions of a quotation. So one &#8220;quotation-item&#8221; references multiple &#8220;position-items&#8221; (1:n relation).<br />
In order to have a user-friendly user interface I developed a custom webpart which allows a quick way of editing the positions of a selected quotation.</p>
<h3>How I got the items &#8230;</h3>
<p>To get all related items of the selected quotation CAML comes in. The very large list (referred to as &#8220;myList&#8221;) is queried to match the given &#8220;quotation-item&#8221; (lookup-field).</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">SPList myList <span style="color: #008000;">=</span> web<span style="color: #008000;">.</span><span style="color: #0000FF;">Lists</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;myList&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
SPQuery query <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPQuery <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
query<span style="color: #008000;">.</span><span style="color: #0000FF;">query</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&amp;lt;Where&amp;gt;&amp;lt;Eq&amp;gt;&amp;lt;FieldRef Name='Quotation' /&amp;gt;&quot;</span><span style="color: #008000;">;</span>
query<span style="color: #008000;">.</span><span style="color: #0000FF;">query</span> <span style="color: #008000;">+=</span> <span style="color: #666666;">&quot;&amp;lt;Value Type='Number'&amp;gt;1&amp;lt;/Value&amp;gt;&amp;lt;/Eq&amp;gt;&amp;lt;/Where&amp;gt;&quot;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Query the list to get all items of the selected quotation</span>
SPListItemCollection items <span style="color: #008000;">=</span> myList<span style="color: #008000;">.</span><span style="color: #0000FF;">GetItems</span> <span style="color: #008000;">&#40;</span>query<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">int</span> total <span style="color: #008000;">=</span> items<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span></pre></div></div>

<p>This takes some time. Too much time &#8230; I tried all possible SPQuery properties to get more performance. Nothing really worked.</p>
<p><span id="more-12"></span></p>
<h3>Heureka</h3>
<p>I created a new view (list settings -> Create a new view) for the &#8220;position-list&#8221; which contains only the columns needed in my custom webpart. This view is named <em>MyQuickView</em>. After that I updated my webpart-code and passed this view as second parameter in the GetItems-Method.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">SPList myList <span style="color: #008000;">=</span> web<span style="color: #008000;">.</span><span style="color: #0000FF;">Lists</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;myList&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
SPQuery query <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPQuery <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
query<span style="color: #008000;">.</span><span style="color: #0000FF;">query</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&amp;lt;Where&amp;gt;&amp;lt;Eq&amp;gt;&amp;lt;FieldRef Name='Quotation' /&amp;gt;&quot;</span><span style="color: #008000;">;</span>
query<span style="color: #008000;">.</span><span style="color: #0000FF;">query</span> <span style="color: #008000;">+=</span> <span style="color: #666666;">&quot;&amp;lt;Value Type='Number'&amp;gt;1&amp;lt;/Value&amp;gt;&amp;lt;/Eq&amp;gt;&amp;lt;/Where&amp;gt;&quot;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Query the list to get all items of the selected quotation</span>
<span style="color: #008080; font-style: italic;">// but now pass the newly created view as second paramter</span>
SPListItemCollection items <span style="color: #008000;">=</span> myList<span style="color: #008000;">.</span><span style="color: #0000FF;">GetItems</span> <span style="color: #008000;">&#40;</span>query,
     myList<span style="color: #008000;">.</span><span style="color: #0000FF;">Views</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;MyQuickView&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ID</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span> <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;B&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToUpper</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">int</span> total <span style="color: #008000;">=</span> items<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span></pre></div></div>

<p>I refreshed my browser and &#8230; Wow, this was extremly fast! To prove my feeling I build some &#8220;DateTime-Code&#8221; to measure the increase.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// ... web was declared before, query is the SPQuery instance from above</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Measure the first method</span>
DateTime start1 <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span>
SPList listPositions <span style="color: #008000;">=</span> web<span style="color: #008000;">.</span><span style="color: #0000FF;">Lists</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;myList&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
SPListItemCollection positions <span style="color: #008000;">=</span> listPositions<span style="color: #008000;">.</span><span style="color: #0000FF;">GetItems</span> <span style="color: #008000;">&#40;</span>query<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">int</span> testCount <span style="color: #008000;">=</span> positions<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span>
DateTime end1 <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Measure the second method</span>
DateTime start2 <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span>
SPList listPositions2 <span style="color: #008000;">=</span> web<span style="color: #008000;">.</span><span style="color: #0000FF;">Lists</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;myList&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
SPListItemCollection positions2 <span style="color: #008000;">=</span> listPositions2<span style="color: #008000;">.</span><span style="color: #0000FF;">GetItems</span> <span style="color: #008000;">&#40;</span>query,
    listPositions2<span style="color: #008000;">.</span><span style="color: #0000FF;">Views</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;MyQuickView&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ID</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span> <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;B&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToUpper</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">int</span> testCount2 <span style="color: #008000;">=</span> positions2<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span>
DateTime end2 <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Check the runtime</span>
<span style="color: #6666cc; font-weight: bold;">double</span> time2 <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>TimeSpan<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>end2 <span style="color: #008000;">-</span> start2<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TotalMilliseconds</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">double</span> time1 <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>TimeSpan<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>end1 <span style="color: #008000;">-</span> start1<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TotalMilliseconds</span><span style="color: #008000;">;</span></pre></div></div>

<h3>Result</h3>
<table border="1">
<tr>
<th>Iteration</th>
<th>Time1 (ms)</th>
<th>Time2 (ms)</th>
</tr>
<tr>
<td>1</td>
<td align="right">13,026.501</td>
<td align="right">452.4174</td>
</tr>
<tr>
<td>2</td>
<td align="right">12,995.299</td>
<td align="right">390.0150</td>
</tr>
<tr>
<td>3</td>
<td align="right">13,338.513</td>
<td align="right">452.4174</td>
</tr>
<tr>
<td>4</td>
<td align="right">15,538.197</td>
<td align="right">390.0150</td>
</tr>
<tr>
<td>5</td>
<td align="right">12,636.486</td>
<td align="right">374.4144</td>
</tr>
<tr>
<td>Avg:</td>
<td align="right"><strong><u>13,506.999</u></strong></td>
<td align="right"><strong><u>411.8558</u></strong></td>
</tr>
</table>
<p>Saving: <strong>~97%</strong></p>
<p>I save about 97% of time (and resources) when creating a custom view which contains the required columns and pass this to GetItems. I call this just incredible! <strong>Again</strong>: Querying the list with more than 230,000 items is now ~97% faster!</p>
<p>I call this method the &#8220;<em>QuickView-Method</em>&#8220;. Note that the view you refer to has to contain the required items. So one view is not enough!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.entwicklungsgedanken.de/2008/01/10/incredible-performance-increase-with-very-large-lists-via-quickview-method/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

