<?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>Toru Maesaka &#187; index</title>
	<atom:link href="http://torum.net/tag/index/feed/" rel="self" type="application/rss+xml" />
	<link>http://torum.net</link>
	<description>Hackaholic and a Web Addict based in Tokyo</description>
	<lastBuildDate>Sat, 01 Oct 2011 18:46:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Progress on BlitzDB&#8217;s Index Component</title>
		<link>http://torum.net/2010/02/progress-on-blitzdb-index-component/</link>
		<comments>http://torum.net/2010/02/progress-on-blitzdb-index-component/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:55:07 +0000</pubDate>
		<dc:creator>Toru Maesaka</dc:creator>
				<category><![CDATA[drizzle]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[blitzdb]]></category>
		<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://torum.net/?p=2335</guid>
		<description><![CDATA[I recently gained some decent momentum on developing the indexing component of BlitzDB. Most of my time spent on BlitzDB for the last couple of weeks have been studying the indexing API and digging into how other engines have implemented it. I even referred back to MySQL 4.x to see how the BDB engine pulls [...]]]></description>
			<content:encoded><![CDATA[<p>I recently gained some decent momentum on developing the indexing component of BlitzDB. Most of my time spent on BlitzDB for the last couple of weeks have been studying the indexing API and digging into how other engines have implemented it. I even referred back to MySQL 4.x to see how the BDB engine pulls off the Indexing API.</p>
<p>The actual coding wasn&#8217;t too bad thanks to Tokyo Cabinet&#8217;s awesome B+Tree API. I&#8217;ve been busier adding new tests and fixing silly bugs as they arise. I also implemented the <a href="http://torum.net/2010/01/further-thoughts-on-blitzdb-index/">Primary Key optimization</a> that I blogged about a while back. As a result of all this, the following goodness has been added to <a href="http://bazaar.launchpad.net/~tmaesaka/blitzdb/trunk/changes">BlitzDB&#8217;s Trunk</a>.</p>
<ul>
<li>Index Lookup</li>
<li>Forward Index Scan</li>
<li>Reverse Index Scan</li>
</ul>
<p>This means that BlitzDB is now equipped with both a Table Scanner and an Index Scanner which are two essential components for a general purpose storage engine. As much as I&#8217;d like to work on optimizing the code and adding features (like recovery), I&#8217;m going to take a break and spend the rest of the month working on testing and debugging. There&#8217;s no point in adding features if the base has notable flaws in it.</p>
<h3>Challenges Encountered</h3>
<p>Writing the Index Scanner itself is easy. The most difficult thing that slowed me down was developing the comparison function for index keys. The end result was a simple piece of code but I had to study various things before I could start writing any code.</p>
<ul>
<li>How to respect collation</li>
<li>How keys are represented internally</li>
<li>How types are represented internally</li>
<li>How to write a custom comparison function for Tokyo Cabinet</li>
<li>&#8230; and so on</li>
</ul>
<p>I&#8217;ve also started using <a href="http://www.evernote.com">Evernote</a> to jot down my spontaneous ideas on optimizing BlitzDB. I&#8217;ve made these notes public and they will most likely be updated while I&#8217;m commuting on the train.</p>
<ul>
<li><a href="http://www.evernote.com/pub/tmaesaka/blitzdb">http://www.evernote.com/pub/tmaesaka/blitzdb/</a></li>
</ul>
<p>There are much more that I&#8217;d like to write about like how I intend on developing the table recovery routine without simply using <a href="http://torum.net/2010/01/how-to-recover-a-tokyo-cabinet-database-file/">TC&#8217;s recovery mechanism</a> but I shall restrain myself for another day.</p>
]]></content:encoded>
			<wfw:commentRss>http://torum.net/2010/02/progress-on-blitzdb-index-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Further thoughts on BlitzDB&#8217;s Index Handling</title>
		<link>http://torum.net/2010/01/further-thoughts-on-blitzdb-index/</link>
		<comments>http://torum.net/2010/01/further-thoughts-on-blitzdb-index/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 09:05:30 +0000</pubDate>
		<dc:creator>Toru Maesaka</dc:creator>
				<category><![CDATA[drizzle]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[blitzdb]]></category>
		<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://torum.net/?p=2328</guid>
		<description><![CDATA[I&#8217;ve been thinking quite a bit about collation handling in BlitzDB for the last couple of days. The more I think about it, the more stuck I&#8217;ve been getting with BlitzDB&#8217;s index design. I&#8217;m actually so frustrated with myself at the moment that I want to hit my head against a wall or something. So, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thinking quite a bit about collation handling in BlitzDB for the last couple of days. The more I think about it, the more stuck I&#8217;ve been getting with BlitzDB&#8217;s index design. I&#8217;m actually so frustrated with myself at the moment that I want to hit my head against a wall or something.</p>
<p>So, I&#8217;m writing this entry to clear up my mind. Heh, my blog is slowly becoming BlitzDB&#8217;s design document draft. This should hopefully be good though since by blogging it, people can tell me whether I&#8217;m moving towards a stupid direction or not.</p>
<h3>Collation Importance</h3>
<p>When writing database software that is intended for International use, it is important to handle textual data by respecting collation order. It is arguable that most people are only interested in English lexicographic ordering but unfortunately the world is not so standard.</p>
<h3>Internal Primary Key Handling</h3>
<p>I want to motivate people to actively define a PRIMARY KEY with BlitzDB. I plan to make this attractive by providing the best performance when PK is defined. In <a href="http://torum.net/2009/12/end-of-year-progress-on-blitzdb/">December 2009</a>, my answer to this was to write the PK value as the key for the data dictionary (where actual rows are stored in BlitzDB). This allows BlitzDB to do a direct lookup on the data dictionary for PK based lookup, instead of consulting the B+Tree index. I&#8217;m still fond of this lookup optimization approach but it introduces problems too. </p>
<p><strong>Problem 1.</strong> Consider the following textual keys: &#8220;key&#8221; and &#8220;KEY&#8221;. They obviously have different binary representations but in certain cases they can be logically equivalent. Because the data dictionary is a hash database, this is a problem. The solution that instantly pops up is to normalize the key before writing or reading it. This however, causes a problem in cases where the two keys are inequivalent. Perhaps Drizzle/MySQL provides an internal normalization function that respects this. I still need to study this area of the storage subsystem.</p>
<p><strong>Problem 2.</strong> Directly writing a PK to the data dictionary means fast lookup but because of the data structure, it&#8217;s not possible to fetch the next &#8220;logical&#8221; key, meaning I can&#8217;t implement index scanning on PK as it is. Quick solution for users is to create an index on the PK column (this would create a separate B+Tree for it) but this is not so friendly because it requires the user to have prior knowledge of all this. So, my plan is to provide the best of both worlds. I&#8217;ll elaborate on how I&#8217;m planning on tackling this problem next.</p>
<h3>Current Primary Key Read/Write Behavior</h3>
<p>In general, keys of BlitzDB&#8217;s data dictionary is a unique 8 byte integer. The idea is that BlitzDB writes this unique ID along with the key to the B+Tree Index so that it can later identify that row. The difference with PK is that, if a PK is present in a table, BlitzDB will not generate an internal unique ID and use PK for the data dictionary&#8217;s key instead. BlitzDB won&#8217;t create a B+Tree index for PK at the time I wrote this blog entry.</p>
<h3>Next Step</h3>
<p>Create a B+Tree index for PK anyway. BlitzDB will still use the PK value as the key for data dictionary if it exists. For PK based lookup requests, BlitzDB will look directly at the data dictionary and for PK based requests that involve index scanning, BlitzDB will look at the B+Tree index.</p>
<p>This approach can consume more space when textual data is used for keys but I think it&#8217;s worth it. At the same time, you can <strong>save space</strong> if you use use types that are smaller than 8 bytes for PK. For example, using a 4 byte integer would reduce BlitzDB&#8217;s key space by 50%.</p>
<p>Hmm, I think my mind has cleared a little.</p>
]]></content:encoded>
			<wfw:commentRss>http://torum.net/2010/01/further-thoughts-on-blitzdb-index/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>BlitzDB and Keyless Tables</title>
		<link>http://torum.net/2009/10/blitzdb-keyless-tables/</link>
		<comments>http://torum.net/2009/10/blitzdb-keyless-tables/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 05:44:12 +0000</pubDate>
		<dc:creator>Toru Maesaka</dc:creator>
				<category><![CDATA[drizzle]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[blitzdb]]></category>
		<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://torum.net/?p=2294</guid>
		<description><![CDATA[Previously you couldn&#8217;t create a table without defining a primary key with BlitzDB. This actually sounds like a nice constraint since you should always define a primary key. However, I went ahead and made this possible since one of the reasons that I&#8217;m developing BlitzDB is to get a better understanding of how the MySQL/Drizzle [...]]]></description>
			<content:encoded><![CDATA[<p>Previously you couldn&#8217;t create a table without defining a primary key with <a href="https://launchpad.net/blitzdb">BlitzDB</a>. This actually sounds like a nice constraint since you should always define a primary key. However, I went ahead and made this possible since one of the reasons that I&#8217;m developing BlitzDB is to get a better understanding of how the  MySQL/Drizzle storage subsystem works. So, implementing a hidden key-generator and using it internally was something I wanted to do for sometime.</p>
<p>Previously this is what you got if you tried to create a table without a primary key:</p>

<div class="wp_syntax"><div class="code"><pre class="null" style="font-family:monospace;">drizzle&gt; create table t1 (col1 int, col2 int, col3 text) engine=blitz;
ERROR 1173 (42000): This table type requires a primary key</pre></div></div>

<p>Now:</p>

<div class="wp_syntax"><div class="code"><pre class="null" style="font-family:monospace;">drizzle&gt; create table t1 (col1 int, col2 int, col3 text) engine=blitz;
Query OK, 0 rows affected (0 sec)</pre></div></div>

<p>Inserting rows work as you would expect:</p>

<div class="wp_syntax"><div class="code"><pre class="null" style="font-family:monospace;">drizzle&gt; insert into t1 values (1, 1, &quot;first row&quot;);
Query OK, 1 row affected (0 sec)
&nbsp;
drizzle&gt; insert into t1 values (1, 2, &quot;second row&quot;);
Query OK, 1 row affected (0 sec)
&nbsp;
drizzle&gt; insert into t1 values (1, 3, &quot;third row&quot;);
Query OK, 1 row affected (0 sec)
&nbsp;
drizzle&gt; insert into t1 values (2, 1, &quot;fourth row&quot;);
Query OK, 1 row affected (0 sec)
&nbsp;
drizzle&gt; insert into t1 values (2, 2, &quot;fifth row&quot;);
Query OK, 1 row affected (0 sec)
&nbsp;
drizzle&gt; insert into t1 values (2, 3, &quot;sixth row&quot;);
Query OK, 1 row affected (0 sec)</pre></div></div>

<p>Selecting rows works fine although since there isn&#8217;t a key column in this table, every operation would require a full table scan which is not sexy:</p>

<div class="wp_syntax"><div class="code"><pre class="null" style="font-family:monospace;">drizzle&gt; select * from t1;
+------+------+------------+
| col1 | col2 | col3       |
+------+------+------------+
|    1 |    1 | first row  | 
|    1 |    2 | second row | 
|    1 |    3 | third row  | 
|    2 |    1 | fourth row | 
|    2 |    2 | fifth row  | 
|    2 |    3 | sixth row  | 
+------+------+------------+
&nbsp;
drizzle&gt; select * from t1 where col1 = 1;
+------+------+------------+
| col1 | col2 | col3       |
+------+------+------------+
|    1 |    1 | first row  | 
|    1 |    2 | second row | 
|    1 |    3 | third row  | 
+------+------+------------+
3 rows in set (0 sec)
&nbsp;
drizzle&gt; select * from t1 where col2 = 2;
+------+------+------------+
| col1 | col2 | col3       |
+------+------+------------+
|    1 |    2 | second row | 
|    2 |    2 | fifth row  | 
+------+------+------------+
2 rows in set (0 sec)</pre></div></div>

<h3>How the internal works</h3>
<p>BlitzDB does what most people would assume. It atomically generates a sequential unsigned 64bit integer then if necessary, converts it to big endian (network byte order). It then uses that value as a key to store the row into TC. The auto-generated key is made sure to be big-endian because I want BlitzDB tables to work on all platforms. That is, admins should be able to copy the &#8220;data files&#8221; over to another server and happily keep using the database. Keys are converted and _always_ used as little-endian inside BlitzDB.</p>
<h3>Next Step</h3>
<p>There&#8217;s still some bits and pieces on update related code that I need to work on but in general things are looking good. When I get those tasks done, I can then start working on supporting secondary index which I have cool ideas for.</p>
]]></content:encoded>
			<wfw:commentRss>http://torum.net/2009/10/blitzdb-keyless-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

