<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: MySQL foreign key data types</title>
	<atom:link href="http://www.distantparts.com/2007/06/05/159/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.distantparts.com/2007/06/05/159/</link>
	<description>Random thoughts from a far off place</description>
	<pubDate>Mon, 01 Dec 2008 18:25:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
		<item>
		<title>By: ichilton</title>
		<link>http://www.distantparts.com/2007/06/05/159/#comment-9035</link>
		<dc:creator>ichilton</dc:creator>
		<pubDate>Thu, 07 Jun 2007 19:51:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.distantparts.com/2007/06/05/159/#comment-9035</guid>
		<description>Ahh, gotcha.</description>
		<content:encoded><![CDATA[<p>Ahh, gotcha.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven</title>
		<link>http://www.distantparts.com/2007/06/05/159/#comment-8972</link>
		<dc:creator>Steven</dc:creator>
		<pubDate>Thu, 07 Jun 2007 10:12:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.distantparts.com/2007/06/05/159/#comment-8972</guid>
		<description>Hi Ian,

I thought that I might use the foreign key to refer to several different tables (reviews, but maybe also articles and images tables that I hadn't created yet), and then differentiate between them using a type field. Perhaps the other tables (articles, images etc) would not have numeric primary keys, so I hedged my bets and went with a varchar.

Not a great idea in hindsight, but I didn't realise it would have such a terrible impact on performance. Basically direct lookups were fine, but large joins weren't using indices that were available. So nasty full or partial table scans were happening, rather than using nice efficient index lookups. Once I switched the foreign key to an integer, the indices came into play, and performance was transformed.

None of this was obvious initially, as a few table scans don't matter too much with a few thousand rows, but once you're approaching 200,000 rows, it becomes more of an issue.</description>
		<content:encoded><![CDATA[<p>Hi Ian,</p>
<p>I thought that I might use the foreign key to refer to several different tables (reviews, but maybe also articles and images tables that I hadn&#8217;t created yet), and then differentiate between them using a type field. Perhaps the other tables (articles, images etc) would not have numeric primary keys, so I hedged my bets and went with a varchar.</p>
<p>Not a great idea in hindsight, but I didn&#8217;t realise it would have such a terrible impact on performance. Basically direct lookups were fine, but large joins weren&#8217;t using indices that were available. So nasty full or partial table scans were happening, rather than using nice efficient index lookups. Once I switched the foreign key to an integer, the indices came into play, and performance was transformed.</p>
<p>None of this was obvious initially, as a few table scans don&#8217;t matter too much with a few thousand rows, but once you&#8217;re approaching 200,000 rows, it becomes more of an issue.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Chilton</title>
		<link>http://www.distantparts.com/2007/06/05/159/#comment-8959</link>
		<dc:creator>Ian Chilton</dc:creator>
		<pubDate>Thu, 07 Jun 2007 07:28:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.distantparts.com/2007/06/05/159/#comment-8959</guid>
		<description>Hi,

lol - how could you have flexibility beyond integer id's if the primary key is an integer :)

Oh well... - most things you wrote in the past can be improved if you look back over them!!

Ian</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>lol - how could you have flexibility beyond integer id&#8217;s if the primary key is an integer <img src='http://www.distantparts.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Oh well&#8230; - most things you wrote in the past can be improved if you look back over them!!</p>
<p>Ian</p>
]]></content:encoded>
	</item>
</channel>
</rss>
