<?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>Rusty Razor Blade &#187; mysql</title>
	<atom:link href="http://www.rustyrazorblade.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rustyrazorblade.com</link>
	<description>Tech Thoughts, Mostly on LAMP - by Jon Haddad</description>
	<lastBuildDate>Wed, 21 Jul 2010 20:42:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Lack of Flexibility of Stored Procedures in MySQL</title>
		<link>http://www.rustyrazorblade.com/2010/01/the-lack-of-flexibility-of-stored-procedures-in-mysql/</link>
		<comments>http://www.rustyrazorblade.com/2010/01/the-lack-of-flexibility-of-stored-procedures-in-mysql/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 23:22:21 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=968</guid>
		<description><![CDATA[Over three years ago I wrote about how you cannot use a stored procedure in a subquery.  Well, it&#8217;s 2010, and I&#8217;m still annoyed by this and a handful of other things.
I was just working today on a report consisting of a series of queries, taking about a minute to generate.  Some of [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.rustyrazorblade.com/wp-content/uploads/2009/12/sakila.png" alt="sakila.png" hspace=10 vspace = 4 border="0" width="121" height="79" align="left" />Over three years ago <a href="http://www.rustyrazorblade.com/2006/09/can-you-use-a-stored-procedure-in-a-subquery-i-dont-think-so-mysql/">I wrote about how you cannot use a stored procedure in a subquery</a>.  Well, it&#8217;s 2010, and I&#8217;m still annoyed by this and a handful of other things.</p>
<p>I was just working today on a report consisting of a series of queries, taking about a minute to generate.  Some of the data would be created in a temporary table and queried against multiple times for performance reasons, and ultimately spit out into a CSV file for someone to examine later.  I also would like to be able to return the result set, and perform queries on it, which is much faster than querying a view.</p>
<p>Fortunately, MySQL&#8217;s awesome <a href="http://dev.mysql.com/doc/refman/5.0/en/select.html">SELECT &#8230; INTO OUTFILE</a> can easily write CSV files to disk, so I&#8217;m covered there.  </p>
<p>So when I started working on this, I was thinking this would be a great opportunity to demonstrate the flexibility and usefulness of stored procedures &#8211; after all, we will likely be needing this report again.  However, there&#8217;s an issue.  You can&#8217;t return a result set from a stored proc that you can actually do anything with.  Everything gets spit directly back to the client.  So, what are the alternatives?  </p>
<p><span id="more-968"></span><br />
Perhaps generate the data into a new table and swap with the old via a <a href="http://dev.mysql.com/doc/refman/5.0/en/rename-table.html">RENAME TABLE</a> (if it exists)?   Maybe not a bad solution.  It works (<a href="#example1">see example 1 below</a>), but now we&#8217;ve coupled the dataset to a global copy of the table, and any references we have to it are now hard coded, rather than passing back a workable dataset we can do anything we want with.  Furthermore, if we want to make any changes to the dataset (UPDATE/DELETE) we are unable to &#8211; we must make a copy of the table and work from that, unless we don&#8217;t mind messing with someone work.  </p>
<p><del datetime="2010-01-07T02:16:19+00:00">Temporary tables created in a stored procedure for the rest of the connection, so they can&#8217;t be used either (<a href="#example2">example 2</a>), which is somewhat contrary to the manual.</del></p>
<p>Temporary tables are available past the execution of a stored procedure, contrary to what I wrote earlier.  (<a href="#example2">example 2</a>)</p>
<blockquote><p>You can use the TEMPORARY keyword when creating a table. A TEMPORARY table is visible only to the current connection, and is dropped automatically when the connection is closed. This means that two different connections can use the same temporary table name without conflicting with each other or with an existing non-TEMPORARY table of the same name. (The existing table is hidden until the temporary table is dropped.) To create temporary tables, you must have the CREATE TEMPORARY TABLES privilege.</p></blockquote>
<p><del datetime="2010-01-07T02:18:18+00:00">Bummer.  I&#8217;m assuming the stored procedure runs on its&#8217; own isolated connection, which does make sense from a garbage collection point of view.</del></p>
<p>What about returning the data through the useful OUT parameter?  Nope.  Since I can&#8217;t store more than 1 row in a variable, that&#8217;s not happening either (<a href="#example3">example 3</a>)</p>
<p>You also can&#8217;t generate the data in a new table and pass back the table name in an OUT variable. (<a href="#example4">example 4</a>)</p>
<p>In conclusion: of the above methods, it seems the most likely route I&#8217;ll follow in the future will be to store the results in some permanent table, and run the proc off hours to regenerate the table, hoping that no one&#8217;s using it.  It would need to be read only &#8211; and working with it would require creating your own copy of the table.  It has the advantage of being easily understood &#8211; you can quickly DESCRIBE the columns and know what you&#8217;re getting back &#8211; so I suppose it&#8217;s going to have to be good enough.  But what I really wanted was </p>
<pre>
mysql> call some_proc() into outfile "/tmp/myfile.txt";
</pre>
<p>For more information on stored procedures, check out the <a href="http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html">Stored procedure syntax</a>.</p>
<p><strong><a name="#example1">Example 1</a>: Swapping tables within a stored procedure</strong></p>
<pre >drop procedure test_proc;
delimiter //

CREATE procedure test_proc ()
begin
create table jon_new LIKE jon;
rename table jon to jon_old, jon_new to jon;
drop table jon_old;
end;
//
delimiter ;

mysql> show tables;
+------------------+
| Tables_in_test   |
+------------------+
| jon              |
+------------------+
4 rows in set (0.00 sec)

mysql> insert into jon values (1);
Query OK, 1 row affected (0.04 sec)

mysql> select * from jon;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)

mysql> call test_proc();
Query OK, 0 rows affected (1.53 sec)

mysql> select * from jon;
Empty set (0.00 sec)</pre>
<p><strong><a name="example2">Example 2</a>: Trying to create a temporary table in a stored procedure (updated)</strong></p>
<pre>
mysql> delimiter //
mysql> create procedure test_proc3()
    -> begin
    -> CREATE TEMPORARY TABLE my_table (id serial);
    -> end
    -> //
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;
mysql>
mysql> call test_proc3();
Query OK, 0 rows affected (0.08 sec)

mysql>
mysql> select * from my_table;
Empty set (0.00 sec)
t</pre>
<p><strong><a name="example3">Example 3</a>: Trying to store multiple rows in a variable</strong></p>
<pre>
mysql> create table my_table (id int primary key);
Query OK, 0 rows affected (1.46 sec)

mysql> set @v = (select * from my_table);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into my_table values (1),(2),(3);
Query OK, 3 rows affected (0.03 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> set @v = (select * from my_table);
ERROR 1242 (21000): Subquery returns more than 1 row
</pre>
<p><strong><a name="example4">Example 4</a>: Trying to select from a table where the name was defined in a variable</strong></p>
<pre>
mysql> set @tab = "my_table";
Query OK, 0 rows affected (0.00 sec)

mysql> select @tab;
+----------+
| @tab     |
+----------+
| my_table |
+----------+
1 row in set (0.00 sec)

mysql> select * from @tab;
ERROR 1064 (42000): You have an error in your SQL syntax;
check the manual that corresponds to your
MySQL server version for the right syntax to use near '@tab' at line 1
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2010/01/the-lack-of-flexibility-of-stored-procedures-in-mysql/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Stored Procedure For Finding Columns In MySQL</title>
		<link>http://www.rustyrazorblade.com/2009/12/stored-procedure-for-finding-columns/</link>
		<comments>http://www.rustyrazorblade.com/2009/12/stored-procedure-for-finding-columns/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 19:13:34 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[stored procedure]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=931</guid>
		<description><![CDATA[
Looking for instances particular column in a large schema can be a pain.  Fortunately the information schema makes this pretty easy, if your columns have a consistent naming convention.  

SELECT table_schema, table_name, column_name
FROM information_schema.columns
WHERE column_name LIKE '%some_name%';

Now, if we want to wrap this up into an easy to use stored procedure, we can [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.rustyrazorblade.com/wp-content/uploads/2009/12/sakila.png" alt="sakila.png" border="0" width="121" height="79" align="right" vspace = 10 hspace=10 /></p>
<p>Looking for instances particular column in a large schema can be a pain.  Fortunately the information schema makes this pretty easy, if your columns have a consistent naming convention.  </p>
<pre>
SELECT table_schema, table_name, column_name
FROM information_schema.columns
WHERE column_name LIKE '%some_name%';
</pre>
<p>Now, if we want to wrap this up into an easy to use stored procedure, we can do something like this:</p>
<pre>
drop procedure find_column;
delimiter //
CREATE PROCEDURE find_column(c varchar(255))
begin
	SET @a = CONCAT("%", c, "%");
	SELECT table_schema, table_name, column_name, column_type
		FROM information_schema.columns
		WHERE column_name LIKE @a;
end
//
delimiter ;
</pre>
<p>We need to use the concat statement in order to properly get the quotes in there without using the literal string &#8220;c&#8221; in the LIKE statement.</p>
<p>You can do a search as follows:</p>
<pre>
CALL find_column("some_column");
</pre>
<p>Learn more on the <a href="http://dev.mysql.com/doc/refman/5.1/en/stored-routines.html">MySQL Stored Procedures</a> section of <a href="http://mysql.com/">mysql.com</a></p>
<p><em>Edit: added column type on suggested by <a href="http://rpbouman.blogspot.com/">Roland Bouman</a>. </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2009/12/stored-procedure-for-finding-columns/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL 5.1.34 and Innodb</title>
		<link>http://www.rustyrazorblade.com/2009/06/mysql-5134-and-innodb/</link>
		<comments>http://www.rustyrazorblade.com/2009/06/mysql-5134-and-innodb/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 18:47:31 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[innodb]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=810</guid>
		<description><![CDATA[I don&#8217;t remember having to do this before, but I had compiled MySQL 5.1.34 recently on my dev box (os x) and I saw a warning on a create table statement.  It turns out InnoDB was not enabled (or even listed in the list of storage engines.
Before:
mysql> show engines;
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+
&#124; Engine     [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t remember having to do this before, but I had compiled MySQL 5.1.34 recently on my dev box (os x) and I saw a warning on a create table statement.  It turns out InnoDB was not enabled (or even listed in the list of storage engines.</p>
<p>Before:</p>
<blockquote><p>mysql> show engines;<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
| Engine     | Support | Comment                                                   | Transactions | XA   | Savepoints |<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
| CSV        | YES     | CSV storage engine                                        | NO           | NO   | NO         |<br />
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                     | NO           | NO   | NO         |<br />
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables | NO           | NO   | NO         |<br />
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance    | NO           | NO   | NO         |<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
4 rows in set (0.00 sec)
</p></blockquote>
<p>After:</p>
<blockquote><p>
mysql> show engines;<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
| Engine     | Support | Comment                                                    | Transactions | XA   | Savepoints |<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
| CSV        | YES     | CSV storage engine                                         | NO           | NO   | NO         |<br />
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |<br />
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |<br />
| InnoDB     | YES     | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |<br />
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance     | NO           | NO   | NO         |<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
5 rows in set (0.00 sec)</p></blockquote>
<p>I had to recompile MySQL with the following:</p>
<blockquote><p>./configure &#8211;prefix=/usr/local/mysql &#8211;with-plugins=innobase</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2009/06/mysql-5134-and-innodb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Interesting Programmer Links</title>
		<link>http://www.rustyrazorblade.com/2009/04/interesting-programmer-links/</link>
		<comments>http://www.rustyrazorblade.com/2009/04/interesting-programmer-links/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 19:47:08 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=606</guid>
		<description><![CDATA[
Peeping into memcached.
Really interesting read about how to examine what&#8217;s stored in memcached.  
Peep uses ptrace to freeze a running memcached server, dump the internal key metadata, and return the server to a running state. If you have a good host ejection mechanism in your client, such as in the Twitter libmemcached builds, you [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://blog.evanweaver.com/articles/2009/04/20/peeping-into-memcached/">Peeping into memcached</a>.</li>
<p>Really interesting read about how to examine what&#8217;s stored in memcached.  </p>
<blockquote><p>Peep uses ptrace to freeze a running memcached server, dump the internal key metadata, and return the server to a running state. If you have a good host ejection mechanism in your client, such as in the Twitter libmemcached builds, you won&#8217;t even have to change the production server pool. The instance is not restarted, and no data is lost.</p></blockquote>
<li><a href="http://dev.mysql.com/tech-resources/articles/mysql-54.html">Quick look at MySQL 5.4</a>
</li>
<p>Highlights include scalability improvements, subquery optimizations and join improvements, improved stored procedure management, out parameters in prepared statements, and new information schema additions.</p>
<li><a href="http://www.easyvmx.com/new-easyvmx.shtml">EasyVMX</a></li>
<p>EasyVMX lets you create empty VMWare images.  Very useful when coupled with the <a href="http://www.vmware.com/products/player/">VMWare player</a>.</p>
<li><a href="http://www.atlassian.com/starter/?s_kwcid=HM_Starter">For the next 5 days you can get Jira 5 user license for $5.</a></li>
<p>I used Jira about 3 years ago at Infosearch Media, which I don&#8217;t think exists any more.  Anyway, it trounced bugzilla then and still does.  </p>
<li><a href="http://geektips.patg.net/?p=24">A cool rundown on what you can do with the information schema in MySQL.  </a></li>
<p>I like this post, it makes a few really cool points.  It explains how to get a list of all tables and their engine and how to get a list of foreign keys in your schema.  Very cool.</p>
<li><a href="http://q4m.31tools.com/">Q4M</a>, a Queue storage engine</li>
<p>Q4M looks like a pretty cool storage engine that aims to address twitter-like features.  I&#8217;ll be trying this out for myself in the near future.</p>
<blockquote><p>Q4M (Queue for MySQL) is a message queue licensed under GPL that works as a pluggable storage engine of MySQL 5.1, designed to be robust, fast, flexible. It is already in production quality, and is used by several web services (see Users of Q4M).</p></blockquote>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2009/04/interesting-programmer-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL: Innodb Memory Usage Formula</title>
		<link>http://www.rustyrazorblade.com/2008/12/mysql-innodb-memory-usage-formula/</link>
		<comments>http://www.rustyrazorblade.com/2008/12/mysql-innodb-memory-usage-formula/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 22:43:22 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=455</guid>
		<description><![CDATA[I hate looking for this&#8230;.
This will give you a rough idea of your innodb memory usage.  I know it&#8217;s in a hundred spots, but i hate looking for it when i double check things.
innodb_buffer_pool_size
+ key_buffer_size
+ max_connections*(sort_buffer_size+read_buffer_size+binlog_cache_size +2MB)
]]></description>
			<content:encoded><![CDATA[<p>I hate looking for this&#8230;.</p>
<p>This will give you a rough idea of your innodb memory usage.  I know it&#8217;s in a hundred spots, but i hate looking for it when i double check things.</p>
<p>innodb_buffer_pool_size<br />
+ key_buffer_size<br />
+ max_connections*(sort_buffer_size+read_buffer_size+binlog_cache_size +2MB)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2008/12/mysql-innodb-memory-usage-formula/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MySQL: ERROR 1267 (HY000): Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation &#8216;=&#8217;</title>
		<link>http://www.rustyrazorblade.com/2008/08/mysql-error-1267-hy000-illegal-mix-of-collations-utf8_unicode_ciimplicit-and-utf8_general_ciimplicit-for-operation/</link>
		<comments>http://www.rustyrazorblade.com/2008/08/mysql-error-1267-hy000-illegal-mix-of-collations-utf8_unicode_ciimplicit-and-utf8_general_ciimplicit-for-operation/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 03:00:07 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=154</guid>
		<description><![CDATA[I have never, ever seen this before.  I don&#8217;t even know how the table was created with a different collation.  However, I had all my other tables created with the character set utf8, no collation specified.
I had to convert the second table to match the character set.  This probably wouldn&#8217;t have been [...]]]></description>
			<content:encoded><![CDATA[<p>I have never, ever seen this before.  I don&#8217;t even know how the table was created with a different collation.  However, I had all my other tables created with the character set utf8, no collation specified.</p>
<p>I had to convert the second table to match the character set.  This probably wouldn&#8217;t have been a problem if I wasn&#8217;t joining on a character field.</p>
<blockquote><p>alter table exclusion CONVERT TO CHARACTER SET utf8;
</p></blockquote>
<p>First time I&#8217;ve ever seen that one.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2008/08/mysql-error-1267-hy000-illegal-mix-of-collations-utf8_unicode_ciimplicit-and-utf8_general_ciimplicit-for-operation/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Executing MySQL queries within VIM</title>
		<link>http://www.rustyrazorblade.com/2008/08/executing-mysql-queries-within-vim/</link>
		<comments>http://www.rustyrazorblade.com/2008/08/executing-mysql-queries-within-vim/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 19:51:11 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=139</guid>
		<description><![CDATA[I haven&#8217;t been using vim for very long, but I&#8217;ve gotten over the initial learning curve of getting used to the different editing modes.  With some help from the guys in #vim on irc.freenode.net, I managed to get this gem:
 map &#60;C-d&#62; :call SwitchDB()&#60;CR&#62;
 :function SwitchDB()
 :   let g:current_db = input("Database &#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t been using vim for very long, but I&#8217;ve gotten over the initial learning curve of getting used to the different editing modes.  With some help from the guys in #vim on irc.freenode.net, I managed to get this gem:</p>
<blockquote><p><code> map &lt;C-d&gt; :call SwitchDB()&lt;CR&gt;<br />
 :function SwitchDB()<br />
 :   let g:current_db = input("Database &gt; ")<br />
 :endfunction</p>
<p> map &lt;C-m&gt; :call Doquery()&lt;CR&gt;<br />
 :function Doquery()<br />
 :   if !exists("g:current_db")<br />
 :       call SwitchDB()<br />
 :   endif<br />
 :   let query_string = input(g:current_db . " &gt; " )<br />
 :   if query_string != ""<br />
 :       exe "!mysql " . g:current_db . "  -e \"" .  escape(query_string, '"') . "\""<br />
 :   endif<br />
 :endfunction<br />
 </code></p></blockquote>
<p>Control-m to execute a query.  Control-d to switch databases.  It&#8217;ll prompt you the first time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2008/08/executing-mysql-queries-within-vim/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL ALTER table Progress Bar?</title>
		<link>http://www.rustyrazorblade.com/2008/05/mysql-alter-table-progress-bar/</link>
		<comments>http://www.rustyrazorblade.com/2008/05/mysql-alter-table-progress-bar/#comments</comments>
		<pubDate>Fri, 16 May 2008 04:48:09 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=128</guid>
		<description><![CDATA[Altering a big table sucks, and to make it worse you have no idea what&#8217;s happening or how long it will take.  I&#8217;d like a progress bar, or some status output, or something that gives me the feeling like my server didn&#8217;t die.  
]]></description>
			<content:encoded><![CDATA[<p>Altering a big table sucks, and to make it worse you have no idea what&#8217;s happening or how long it will take.  I&#8217;d like a progress bar, or some status output, or something that gives me the feeling like my server didn&#8217;t die.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2008/05/mysql-alter-table-progress-bar/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>MySQL and Materialized Views</title>
		<link>http://www.rustyrazorblade.com/2008/05/mysql-and-materialized-views/</link>
		<comments>http://www.rustyrazorblade.com/2008/05/mysql-and-materialized-views/#comments</comments>
		<pubDate>Tue, 13 May 2008 08:01:25 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[db2]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=126</guid>
		<description><![CDATA[I was poking around the MySQL Worklog again over the weekend, and found a request for materialized views for MySQL.  This feature has existed in Oracle for a while, in DB2 as a materialized query table, and appeared in MS SQL Server 2000 and 2005 as indexed views.
What is a materialized view?
A materialized view [...]]]></description>
			<content:encoded><![CDATA[<p>I was poking around the MySQL Worklog again over the weekend, and found a <a href="http://forge.mysql.com/worklog/task.php?id=2866">request for materialized views for MySQL</a>.  This feature has existed in <a href="http://download-uk.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_6002.htm#i2063793">Oracle</a> for a while, in <a href="http://publib.boulder.ibm.com/infocenter/db2help/index.jsp?topic=/com.ibm.db2.udb.doc/core/c0009318.htm">DB2</a> as a materialized query table, and appeared in <a href="http://www.microsoft.com/technet/prodtechnol/sql/2005/impprfiv.mspx">MS SQL Server 2000 and 2005</a> as indexed views.</p>
<p>What is a materialized view?</p>
<p>A materialized view is a database object that contains the results of a query. The FROM clause of the query can name tables, views, and other materialized views. (from Oracle).</p>
<p>Essentially a materialized view lets you tell the database to periodically refresh a table with the results of a query.  You may join, group, and perform calculations.  The goal is to increase query performance in a read-heavy environment.  </p>
<p>Additionally, at least in the other DBs listed, you can put indexes on the fields within the view.  </p>
<p>Disadvantages:</p>
<ul>
<li>There can be issues with altering underlying tables, just as if you were to remove a column that a standard view references.</li>
<li>If you&#8217;re inserting and updating into the base tables frequently, you will either see a performance hit or have to deal with stale data.</li>
<li>Since the data is actually stored as a table on disk, it can take up considerable space</li>
</ul>
<p>According to the high level architecture</p>
<blockquote><p>Support creation of materialized views, with only the bare  minimum &#8212; no automatic refresh, no query rewrite.
</p></blockquote>
<p>Which would be a shame, because it seems that adding in automatic refresh would be a pretty small part of a very complex feature. I haven&#8217;t dealt with any of the MySQL codebase so this is just my speculation.</p>
<p>Of course, when looking at any feature, it&#8217;s important to determine how useful it actually would be to implement.  What is the target audience, and are they the existing customers?  What&#8217;s the goal of adding this feature?  </p>
<p>For ther reading, <a href="http://www.databasejournal.com/features/mssql/article.php/2119721">Database journal</a> has a very good overview of indexed views in SQL Server. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2008/05/mysql-and-materialized-views/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>MySQL: Time Delayed Replication</title>
		<link>http://www.rustyrazorblade.com/2008/05/mysql-time-delayed-replication/</link>
		<comments>http://www.rustyrazorblade.com/2008/05/mysql-time-delayed-replication/#comments</comments>
		<pubDate>Wed, 07 May 2008 19:12:39 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=123</guid>
		<description><![CDATA[I was cruising the MySQL Forge Worklog when I came across the idea of Time Delayed Replication.  I had never considered the benefits of deliberately keeping a slave server behind a master. 
Kristian Koehntopp gives a good example:
Kristian Koehntopp writes:
TDS: Time delayed SQL_THREAD (Have a replication slave that is always
lagging 30 minutes behind).
Currently, replication [...]]]></description>
			<content:encoded><![CDATA[<p>I was cruising the MySQL Forge Worklog when I came across the idea of <a href="http://forge.mysql.com/worklog/task.php?id=344">Time Delayed Replication</a>.  I had never considered the benefits of deliberately keeping a slave server behind a master. </p>
<p>Kristian Koehntopp gives a good example:</p>
<blockquote><p>Kristian Koehntopp writes:</p>
<p>TDS: Time delayed SQL_THREAD (Have a replication slave that is always<br />
lagging 30 minutes behind).</p>
<p>Currently, replication is a rolling recovery: To set up replication you<br />
restore from a full dump with a binlog position. You then continously<br />
download binlog and roll forward. In case of a master crash a slave is a<br />
readily recovered instance (as opposed to a backup, which still has to be<br />
restored).</p>
<p>This protects against crashes, but not against oopses.</p>
<p>A time delayed slave (TDS) is a nice protection against oopses.</p>
<p>Sugar on top addendum: With the binlog being a table, any table type,<br />
it will be very easy to delete an oopsing statement out of the<br />
unapplied binlog queue. Currently, a simple time delayed slave will<br />
protect you against oopses, but it will be very hard to extract the<br />
relevant binlog portion out of the TDS replication log skipping the<br />
oopsing statement.</p>
<p>With a MyISAM binlog table, it is just a matter of DELETE FROM<br />
REPLICATION.BINLOG WHERE STATEMENT_ID = 1717;
</p></blockquote>
<p>Definately a cool idea.  Instead of having to restore from a backup, you just take down your master, pull out the busted query, let the server catch up, and bring the slave up as the new master.  Doing a restore from our current database backups takes about 3-4 hours, and we&#8217;re not even huge.  It seems like your downtime here would be limited to however long it takes your slave to catch up.  Additionally, once you take down your master and remove your bogus query (truncate table perhaps?) you can allow the slave to replicate everything and catch up (no longer limited to 30 min behind, ideally).  Depending on your traffic, this could limit your downtime in the case of a catastrophic loss to 20 minutes or so instead of hours, and your data loss would be far less.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2008/05/mysql-time-delayed-replication/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
