<?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>JJB Blog &#187; mysql</title>
	<atom:link href="http://blog.johnjosephbachir.org/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.johnjosephbachir.org</link>
	<description></description>
	<lastBuildDate>Wed, 04 Jan 2012 05:47:01 +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>There is something very strange about the MySQL forums</title>
		<link>http://blog.johnjosephbachir.org/2007/03/01/there-is-something-very-strange-about-the-mysql-forums/</link>
		<comments>http://blog.johnjosephbachir.org/2007/03/01/there-is-something-very-strange-about-the-mysql-forums/#comments</comments>
		<pubDate>Thu, 01 Mar 2007 19:59:52 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://blog.johnjosephbachir.org/2007/03/01/there-is-something-very-strange-about-the-mysql-forums/</guid>
		<description><![CDATA[Is it just me, or is there not a single section for discussing actual MySQL queries? It seems that all the query discussion ends up in the newbie section. Am I right?]]></description>
			<content:encoded><![CDATA[<p>Is it just me, or is there not a single section for discussing actual MySQL queries? It seems that all the query discussion ends up in the newbie section.</p>
<p><a href="http://forums.mysql.com/">Am I right?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.johnjosephbachir.org/2007/03/01/there-is-something-very-strange-about-the-mysql-forums/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>INNER JOIN syntax</title>
		<link>http://blog.johnjosephbachir.org/2007/01/21/inner-join-syntax/</link>
		<comments>http://blog.johnjosephbachir.org/2007/01/21/inner-join-syntax/#comments</comments>
		<pubDate>Sun, 21 Jan 2007 09:09:28 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[code-formatting]]></category>
		<category><![CDATA[innerjoin]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://blog.johnjosephbachir.org/2007/01/21/inner-join-syntax/</guid>
		<description><![CDATA[It&#8217;s too bad that ON (column = column) comes after and not before INNER JOIN table, because if it came before it would make for much cuter code formatting: [sql] SELECT DISTINCT $columns FROM $this-&#62;comments ON (comment_post_ID = post_id) INNER JOIN $this-&#62;post2cat ON (category_id = cat_ID) INNER JOIN $this-&#62;categories WHERE blog = &#8216;$blog&#8217; AND $criteria [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s too bad that <code>ON (column = column)</code> comes after and not before <code>INNER JOIN table</code>, because if it came before it would make for much cuter code formatting:</p>
<p>[sql]<br />
SELECT DISTINCT $columns<br />
FROM<br />
  $this-&gt;comments<br />
    ON (comment_post_ID = post_id) INNER JOIN<br />
  $this-&gt;post2cat<br />
    ON (category_id = cat_ID) INNER JOIN<br />
  $this-&gt;categories<br />
WHERE<br />
  blog = &#8216;$blog&#8217; AND<br />
  $criteria<br />
[/sql]</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.johnjosephbachir.org/2007/01/21/inner-join-syntax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL CHALLENGE</title>
		<link>http://blog.johnjosephbachir.org/2007/01/19/sql-challenge/</link>
		<comments>http://blog.johnjosephbachir.org/2007/01/19/sql-challenge/#comments</comments>
		<pubDate>Fri, 19 Jan 2007 09:38:55 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[challenge]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[group-by]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[order-by]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.johnjosephbachir.org/2007/01/19/sql-challenge/</guid>
		<description><![CDATA[Arrrrre you readyyyyy&#8212; for an es Q elllllllll&#8212; CHALLENGE!!!!! I have a user table, let&#8217;s say with name and zipcode. I can do the following successfully: Select a random user with SELECT * FROM users ORDER BY RAND(UNIX_TIMESTAMP()) LIMIT 1 Select all users, with only 1 from each zipcode, using SELECT * FROM users GROUP [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Arrrrre you readyyyyy&#8212; for an es Q elllllllll&#8212; CHALLENGE!!!!!</strong></em></p>
<p>I have a user table, let&#8217;s say with name and zipcode. I can do the following successfully:</p>
<ol>
<li>Select a random user with <code>SELECT * FROM users ORDER BY RAND(UNIX_TIMESTAMP()) LIMIT 1</code></li>
<li>Select all users, with only 1 from each zipcode, using <code>SELECT * FROM users GROUP BY zipcode</code> <em><strong>update:</strong> I simplified this as per Danny&#8217;s suggestion below</em></li>
</ol>
<p>The only problem is, in case 2, it&#8217;s always the same user per-zipcode. I want to randomize which in the grouping gets pulled out. I would prefer that the solution not involve joining the table on itself, although if I don&#8217;t find another solution I will probably whip up the self-join solution just for fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.johnjosephbachir.org/2007/01/19/sql-challenge/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Everything you need to know about designing MySQL InnoDB primary keys</title>
		<link>http://blog.johnjosephbachir.org/2006/10/22/everything-you-need-to-know-about-designing-mysql-innodb-primary-keys/</link>
		<comments>http://blog.johnjosephbachir.org/2006/10/22/everything-you-need-to-know-about-designing-mysql-innodb-primary-keys/#comments</comments>
		<pubDate>Sun, 22 Oct 2006 18:53:12 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[b_tree]]></category>
		<category><![CDATA[clustered_index]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[indexes]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[primary]]></category>
		<category><![CDATA[primary_key]]></category>

		<guid isPermaLink="false">http://blog.johnjosephbachir.org/2006/10/22/everything-you-need-to-know-about-designing-mysql-innodb-primary-keys/</guid>
		<description><![CDATA[There are two aspects of how MySQL/InnoDB use a table&#8217;s primary key on the file system that have important ramifications for the key&#8217;s design: The primary key determines the order in which the data is physically stored in the main data file, aka &#8220;the clustered index&#8221;. Another way of saying this: the main data file [...]]]></description>
			<content:encoded><![CDATA[<p>There are two aspects of how MySQL/InnoDB use a table&#8217;s primary key on the file system that have important ramifications for the key&#8217;s design:</p>
<ul>
<li>The primary key determines the order in which the data is physically stored in the main data file, aka &#8220;the clustered index&#8221;. Another way of saying this: the main data file is a B-tree index that directly contains all of a table&#8217;s columns, and the key on this B-tree is the primary key. This can result in one less I/O operation (compared to MyISAM) on many queries.</li>
<li>The primary key is what is used to associate <em>all</em> of a table&#8217;s indexes with the main data file. So the primary key is replicated in every row of every index.</li>
</ul>
<p>How to design your InnoDB primary keys:</p>
<ol>
<li><strong>Do explicitly define a primary key, and make it numeric.</strong> If no primary key is specified, or a non-numeric column is used as a primary key, InnoDB will used its own internal auto-incremented row ID to link between the main data table and the other indexes. This row ID is 6 bytes. The biggest numeric type in MySQL, BIGINT, is 8 bytes, and the next smallest type, INT, is 4 bytes. So not only is this &#8220;hidden&#8221; row ID an entire extra redundant column, it is also bigger than the data type that would be used in the vast majority of cases where a primary key is explicitly specified. Furthermore, when InnoDB falls back to using this internal row ID, <em>the rows in the main data file are ordered by insertion order instead of your primary key, rendering InnoDB&#8217;s clustering behavior useless, and adding an entire extra I/O operation on some queries</em>. This is a big loss.</li>
<li>As alluded to above, <strong>the primary key should be sequential.</strong> Because the structure of the data on the disk is dictated by the primary key, it should be sequential, to avoid extremely expensive I/O on writes (when the B-Tree has to be reorganized), and to take advantage of the native clustering.</li>
<li><strong>The primary key should be as small as possible.</strong> Because the primary key is replicated in every entry of every index, designing the primary key to be as small as possible impacts the efficiency of all the indexes.</li>
</ol>
<p>Using these 3 simple guidelines on a well-designed schema, InnoDB can perform at its full potential.</p>
<p>Above I mentioned that the primary key is stored in every row of every index. This includes the entire contents of a multi-column primary key. In a future article I will discuss scenarios/designs that can take advantage of this behavior.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.johnjosephbachir.org/2006/10/22/everything-you-need-to-know-about-designing-mysql-innodb-primary-keys/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

