<?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; parser</title>
	<atom:link href="http://torum.net/tag/parser/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 the SQL Parser work</title>
		<link>http://torum.net/2009/03/progress-on-sql-parser/</link>
		<comments>http://torum.net/2009/03/progress-on-sql-parser/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 03:11:15 +0000</pubDate>
		<dc:creator>Toru Maesaka</dc:creator>
				<category><![CDATA[drizzle]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://torum.net/?p=748</guid>
		<description><![CDATA[Continued from my previous post on making the SQL parser pluggable in Drizzle. So despite mentioning that I wanted to get the prototype done by the MySQL Users Conference 09 in april, it only took three motivated days to get what I stated done. One day on code reading (grasping the execution flow), one day [...]]]></description>
			<content:encoded><![CDATA[<p>Continued from my previous post on <a href="http://torum.net/2009/02/pluggable-sql-parser/">making the SQL parser pluggable</a> in Drizzle.</p>
<p>So despite mentioning that I wanted to get the prototype done by the <a href="http://en.oreilly.com/mysql2009/public/content/home">MySQL Users Conference 09</a> in april, it only took three motivated days to get what I stated done. One day on code reading (grasping the execution flow), one day on hacking it, and another day on testing and debugging. If you&#8217;re interested in the outcome, <a href="https://code.launchpad.net/~tmaesaka/drizzle/pluggable-parser">you can see the branch</a> on Launchpad.</p>
<p>Pushing out the SQL parser from the core was easy since all I had to do was override the mysql_parse() entry point. The only issue I came across was how MySQL is designed to execute the query <strong>inside the parser</strong>. Needless to say, this was troublesome since a given component must be completely decoupled from the system for it to be separated.</p>
<p>To get around this obstacle, I ended up ripping out the query execution routine from the parser and to compensate this, I introduced a new wrapper function in the Drizzle core called sql_parse_and_execute().</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">void</span> sql_parse_and_execute<span style="color: #009900;">&#40;</span>Session <span style="color: #339933;">*</span>session<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>query<span style="color: #339933;">,</span>
                                  <span style="color: #993333;">const</span> size_t query_len<span style="color: #339933;">,</span>
                                  <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>found_semicolon<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  bool error<span style="color: #339933;">=</span> sql_parse<span style="color: #009900;">&#40;</span>session<span style="color: #339933;">,</span> query<span style="color: #339933;">,</span> query_len<span style="color: #339933;">,</span> found_semicolon<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>error <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>session<span style="color: #339933;">-&gt;</span>is_error<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    mysql_execute_command<span style="color: #009900;">&#40;</span>session<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  clean_parsed_tree<span style="color: #009900;">&#40;</span>session<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Admittedly this solution is rough and I wasn&#8217;t 100% confident but it passed all the test cases so I pushed it to my experimental branch and <a href="https://lists.launchpad.net/drizzle-discuss/msg03236.html">threw it at the list</a> anyway. This was a really good move since it brought up various discussions and the fundamental question of,</p>
<p style="text-align: center;"><strong>&#8220;is MySQL doing the right thing?&#8221;</strong></p>
<p>from fellow Drizzle and MySQL developers.</p>
<p>As I previously mentioned, the current SQL Parser does too much by design. Ideally a parser should just create and return a <a href="http://en.wikipedia.org/wiki/Parse_tree">Parse Tree</a> from the query it was given. The core would then do whatever it needs to do with the tree (like create a execution plan) and free it when it&#8217;s done. Whether the execution planner should be part of the Parser Module or not is a different story of course.</p>
<p>The current parser is also tightly coupled with the Session object (known as THD class in MySQL) which needs to be dealt with. There are many other issues pointed out by the community and for those that are interested, you can view the thread here:</p>
<ul>
<li><a href="https://lists.launchpad.net/drizzle-discuss/threads.html#03236">https://lists.launchpad.net/drizzle-discuss/threads.html#03236</a></li>
</ul>
<p>Doesn&#8217;t this show how transparent the Drizzle project is? :)</p>
<p>Admittedly, I&#8217;m too inexperienced at this stage to go any further on my own so I&#8217;m now planning on working closely with the veterans in the community and slowly learn as I go.</p>
<p>Happy Hacking!</p>
]]></content:encoded>
			<wfw:commentRss>http://torum.net/2009/03/progress-on-sql-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Next Mission, Pluggable SQL Parser</title>
		<link>http://torum.net/2009/02/pluggable-sql-parser/</link>
		<comments>http://torum.net/2009/02/pluggable-sql-parser/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 03:01:59 +0000</pubDate>
		<dc:creator>Toru Maesaka</dc:creator>
				<category><![CDATA[drizzle]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://torum.net/?p=695</guid>
		<description><![CDATA[Lately I&#8217;ve been fairly busy tackling bugs in Drizzle that I wanted to fix before we start rolling out tarballs which should be announced by the community soon. I&#8217;ve now committed fixes for those bugs so I am going to spend the spare time I&#8217;ve gained on something else, namely making the SQL parser pluggable. [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been fairly busy tackling bugs in <a href="https://code.launchpad.net/drizzle">Drizzle</a> that I wanted to fix before we start rolling out tarballs which should be announced by the community soon. I&#8217;ve now committed fixes for those bugs so I am going to spend the spare time I&#8217;ve gained on something else, namely making the SQL parser pluggable.</p>
<p>It is a known fact that most of the time spent in processing a query in MySQL and Drizzle is in the SQL parser and naturally, many people are eager to improve it. For example, take a look at <a href="http://www.jpipes.com/index.php?/archives/284-A-Better-Parser-Needed.html">this blog post by Jay</a> on how the current parser is expensive.</p>
<p>When people approach me about Drizzle in Japan, most people seem to request a pluggable query parser as well, simply because they know that it can be improved. So it makes sense for Drizzle, as a project to provide a easy way to improve the damn thing without forcing the developers to study extra things like server architecture and concurrency control (though it&#8217;s nice to know these things!).</p>
<p>The first version is going to be very simple. Everything behind the current entry point of the SQL Parser will be modularized and pushed out from the core, leaving only the plugin hook. Ultimately, a parser module will only have to do the following:</p>
<ul>
<li>Check if the given SQL string is malicious</li>
<li>Process/Parse the given SQL string</li>
<li>Update/Populate the Session object (known as THD in MySQL)</li>
</ul>
<p>As for the interface, I&#8217;m suspecting that it will remain the same as the mysql_parse() function :</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">bool sql_parse<span style="color: #009900;">&#40;</span>Session <span style="color: #339933;">*</span>session<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>query<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> size_t query_len<span style="color: #339933;">,</span>
               <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>found_semicolon<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>But I can&#8217;t say for sure at this stage of course. Also as mentioned by Brian, we ideally need a multi-stage interface that will take care of parser failure, which I&#8217;m hoping to introduce in the second version.</p>
<p> This task is really high in my priority queue so hopefully this entry will help pressure me into concentrating on it (I&#8217;m terrible at this since I tend to hop between OSS projects).</p>
<p>My goal is to get the first version done by the <a href="http://en.oreilly.com/mysql2009/public/content/home">MySQL Conference</a> in Santa Clara, CA in april.</p>
]]></content:encoded>
			<wfw:commentRss>http://torum.net/2009/02/pluggable-sql-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

