<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">

<channel>
<title>Hackszine: SQL</title>
<link>http://www.hackszine.com/blog/archive/sql/</link>
<description>O&apos;Reilly&apos;s Hacks Series reclaims the term &apos;hacking&apos; for the good guys--innovators who explore and experiment, unearth shortcuts, create useful tools, and come up with fun things to try on their own</description>
<language>en-us</language>
<copyright>Copyright 2008, O'Reilly Media, Inc.</copyright>
<lastBuildDate>Sat, 26 Jul 2008 12:11:35 -0800</lastBuildDate>
<pubDate>Sun, 27 Jul 2008 21:48:27 -0800</pubDate>
<generator>http://www.movabletype.org/?v=4.1</generator>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<itunes:author>O'Reilly Media, Inc.</itunes:author>
<itunes:subtitle>Clever solutions to interesting problems.</itunes:subtitle>
<itunes:summary>Hackszine Podcast</itunes:summary>
<itunes:owner>
<itunes:email>webmaster@makezine.com</itunes:email>
</itunes:owner>
<category>Technology</category>
<itunes:category text="Technology">
</itunes:category>
<itunes:category text="Technology">
  <itunes:category text="Gadgets" />
</itunes:category>
<itunes:category text="Games &amp; Hobbies" >
</itunes:category>
<itunes:category text="Science">
</itunes:category>
<itunes:image href="http://makezine.com/images/hackszine/rss_icon.jpg" />
<itunes:explicit>no</itunes:explicit>


<item>
<title>MySQL performance tuning</title>
<itunes:summary> Jay Pipes, MySQL employee and co-author Pro MySQL, gave a great presentation to Google employees which covers a number of techniques for tuning performance on MySQL. His examples include debugging and analyzing problems as well as best practices for...</itunes:summary>
<description>
<![CDATA[<p><embed id="VideoPlayback" style="width:500px;height:405px" allowFullScreen="true" src="http://video.google.com/googleplayer.swf?docid=2524524540025172110&hl=en&fs=true" type="application/x-shockwave-flash"> </embed></p>

<p>Jay Pipes, MySQL employee and co-author Pro MySQL, gave a great presentation to Google employees which covers a number of techniques for tuning performance on MySQL. His examples include  debugging and analyzing problems as well as best practices for table and index design, query and join operations, and server variable adjustments. </p>

<p>It's a little over 40 minutes long, but incredibly informative, whether you're a casual querier or a power MySQL user. Though some of this stuff is MySQL (or MyISAM or InnoDB) specific, the majority of the content is essential material for the average database application developer.</p>

<p>If you don't have time to sit through it (shame on you) or you're looking to jump right to a specific topic, there's a nice time-coded dissection of the talk over at Peteris Krumins' blog. There's something so appropriate about adding a search index to a video about MySQL optimization.</p>

<p><a href="http://video.google.com/videoplay?docid=2524524540025172110">Performance Tuning Best Practices for MySQL</a><br />
<a href="http://www.catonmat.net/blog/performance-tuning-best-practices-for-mysql/">Video Index</a></p>]]>
[&lt;a href="http://www.hackszine.com/blog/archive/2008/07/mysql_performance_tuning.html?CMP=OTC-7G2N43923558" /&gt;Read More&lt;/a&gt;]  
[&lt;a href="http://www.hackszine.com/blog/archive/2008/07/mysql_performance_tuning.html?CMP=OTC-7G2N43923558#comments" /&gt;Comments&lt;/a&gt;]
</description>
<link>http://www.hackszine.com/blog/archive/2008/07/mysql_performance_tuning.html?CMP=OTC-7G2N43923558</link>
<guid>http://www.hackszine.com/blog/archive/2008/07/mysql_performance_tuning.html?CMP=OTC-7G2N43923558</guid>
<category>MySQL</category>
<pubDate>Sat, 26 Jul 2008 12:11:35 -0800</pubDate>

</item>

<item>
<title>Relational database using jQuery and HTML tables</title>
<itunes:summary><![CDATA[Here's a novel use for the HTML &lt;TABLE&gt; tag: storing client side database tables. Nick Kallen came up with a slick hack that uses the jQuery syntax to perform simple selects and joins on HTML tables. By using CSS3 selectors,...]]></itunes:summary>
<description>
<![CDATA[<p>Here's a novel use for the HTML &lt;TABLE&gt; tag: storing client side database tables. Nick Kallen came up with a slick hack that uses the jQuery syntax to perform simple selects and joins on HTML tables. By using CSS3 selectors, you can easily target fields which match or contain your search terms, and Nick's jQuery-based API provides a simple query language, similar to a rudimentary SQL:</p>

<blockquote>
Today I was thinking aloud about <a href="http://research.microsoft.com/Users/luca/Slides/2003-11-132s2n2g2s20&amp;#40;Lisbon&amp;#41;.pdf">Tree Regular Expressions</a> and how they might make a nice query language for document databases like CouchDB. Someone pointed out that CSS3 selectors might make a great concrete syntax for this. One thing lead to another and I thought, why not build a relational database in HTML? So I did. I even got <strong>inner joins</strong> working.

<p>Let's start with a few tables:</p>

<pre><code>&lt;table class="users"&gt;
  &lt;tr&gt;
    &lt;td class="id"&gt;1&lt;/td&gt;
    &lt;td class="first_name"&gt;amy&lt;/td&gt;
    &lt;td class="last_name"&gt;bobamy&lt;/td&gt;
  &lt;/tr&gt; 
  ...
&lt;/table&gt;
&lt;table class="photos"&gt;
  &lt;tr&gt;
    &lt;td class="id"&gt;1&lt;/td&gt;
    &lt;td class="user_id"&gt;1&lt;/td&gt;
    &lt;td class="url"&gt;http://www.example.com/foo.png&lt;/td&gt;
  &lt;/tr&gt; 
&lt;/table&gt;
</code></pre>

<p>Now we can express some queries:</p>

<pre><code>$&#40;'.users'&#41;
  .where&#40;'.id:eq&#40;1&#41;'&#41;
  .select&#40;'*'&#41;
</code></pre>

<p>This is equivalent to <code>SELECT * FROM users WHERE id = 1</code></p>

<pre><code>$&#40;'.users'&#41;
  .where&#40;'.id:eq&#40;1&#41;'&#41;
  .select&#40;'.id, .name'&#41;
</code></pre>

<p>This is equivalent to <code>SELECT id, name FROM users WHERE id = 1</code><br />
</blockquote></p>

<p>How cool is that? Check out Nick's blog post for an example of text search and an inner join. The API in his jquery.db.js is quite straightforward and only about 50 lines of code. Adding a sort function shouldn't be too difficult. </p>

<p>I'm pretty much convinced now that jQuery is black magic.</p>

<p><br />
<a href="http://pivots.pivotallabs.com/users/nick/blog/articles/434-now-i-understand-what-they-mean-by-tabular-data-or-building-a-relational-database-using-jquery-and-lt-table-gt-tags-">Building a relational database using jQuery and &lt;TABLE&gt; tags</a><br />
<a href="http://github.com/nkallen/jquery-database/tree/master">Download the jquery.db.js library</a></p>]]>
[&lt;a href="http://www.hackszine.com/blog/archive/2008/04/relational_database_using_jque.html?CMP=OTC-7G2N43923558" /&gt;Read More&lt;/a&gt;]  
[&lt;a href="http://www.hackszine.com/blog/archive/2008/04/relational_database_using_jque.html?CMP=OTC-7G2N43923558#comments" /&gt;Comments&lt;/a&gt;]
</description>
<link>http://www.hackszine.com/blog/archive/2008/04/relational_database_using_jque.html?CMP=OTC-7G2N43923558</link>
<guid>http://www.hackszine.com/blog/archive/2008/04/relational_database_using_jque.html?CMP=OTC-7G2N43923558</guid>
<category>Ajax</category>
<pubDate>Tue, 08 Apr 2008 22:02:21 -0800</pubDate>

</item>

<item>
<title>Point polygon intersection in SQL</title>
<itunes:summary> update: As readers noted, it&apos;s not the 0 degrees longitude that&apos;s the problem, it&apos;s at 180 degrees where you could encounter issues. I&apos;ve also escaped the gt and lt symbols. Sorry about that. I spent the weekend participating in...</itunes:summary>
<description>
<![CDATA[<p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="pointpoly_20080302.jpg" src="http://www.hackszine.com/pointpoly_20080302.jpg" width="500" height="301" class="mt-image-none" style="" /></span></p>

<p><b>update:</b> As readers noted, it's not the 0 degrees longitude that's the problem, it's at 180 degrees where you could encounter issues.  I've also escaped the gt and lt symbols. Sorry about that.</p>

<p>I spent the weekend participating in the <a href="http://www.f1webchallenge.com/">F1 Website Challenge</a>, a coding marathon in which competing teams each produce a mythical man-month's worth of web site for a worthy non-profit organization&mdash;all in the space of 24 hours.</p>

<p>One of the challenges my team faced during development was finding an efficient way for detecting a particular service region for a given address.  Our client, Metro Meals on Wheels, has a number of different regions in which they deliver meals, with each region being served by a particular Meals on Wheels organization.  These regions are defined by non-overlapping complex polygons.  It's not as simple as a normal vendor search, where you return the nearest location to the requested address. Instead you need to search a database of polygons to find the particular one which intersects the address location.</p>

<p>One of my teammates, Mark Seemann, ended up providing a fairly elegant solution to the problem, and was able to implement it in a simple SQL query.  To find out if a point intersects a polygon, it's as simple as drawing a vector from the point and seeing how many line segments of the polygon it crosses.  If the number is even, it's outside the polygon. If it's odd, you have an intersection.</p>

<p>So let's say you have a polygon database which has a row for each line segment of a polygon. You can quickly pull all segments that intersect a vector pointing directly east of your geocoded location like this:</p>

<blockquote><pre>SELECT poly_id, segment_id
    FROM segments
    WHERE ( lnga &gt; thelng OR lngb &gt; thelng )
          AND ( (lata &gt; thelat AND latb &lt; thelat )
              OR (latb &gt; thelat AND lata &lt; thelat ) )
</pre></blockquote>

<p>That will return you a list of all line segments that you would cross if you walked directly east from the location at [thelat,thelng] (yes, this assumes you don't cross 180 degrees longitude). To determine the polygon (or polygons) that intersect our address, it's as simple as grouping by poly and returning all rows that have an odd number of matches:</p>

<blockquote><pre>
SELECT poly_id, COUNT(segment_id) AS segment_count
    FROM segments
    WHERE ( lnga &gt; thelng OR lngb &gt; thelng )
          AND ( (lata &gt; thelat AND latb &lt; thelat )
              OR (latb &gt; thelat AND lata &lt; thelat ) )
          AND segment_count%2 = 1
    GROUP BY poly_id
</pre></blockquote>

<p>Of course, the world isn't flat, though I've treated it this way for simplicity.  If you wanted this to work for all cases, you'd need to limit your search to a particular distance and translate the coordinates so that the search didn't cross 180 degrees longitude.</p>]]>
[&lt;a href="http://www.hackszine.com/blog/archive/2008/03/point_polygon_intersection_in.html?CMP=OTC-7G2N43923558" /&gt;Read More&lt;/a&gt;]  
[&lt;a href="http://www.hackszine.com/blog/archive/2008/03/point_polygon_intersection_in.html?CMP=OTC-7G2N43923558#comments" /&gt;Comments&lt;/a&gt;]
</description>
<link>http://www.hackszine.com/blog/archive/2008/03/point_polygon_intersection_in.html?CMP=OTC-7G2N43923558</link>
<guid>http://www.hackszine.com/blog/archive/2008/03/point_polygon_intersection_in.html?CMP=OTC-7G2N43923558</guid>
<category>Mapping</category>
<pubDate>Sun, 02 Mar 2008 19:15:45 -0800</pubDate>

</item>


</channel>
</rss>