<?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>puRe - FL3X - Marcel Oelke &#187; MySQL</title>
	<atom:link href="http://blog.fl3x.de/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fl3x.de</link>
	<description>Thats all me!</description>
	<lastBuildDate>Sun, 25 Apr 2010 02:53:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Who is the Subversion King in your Company?</title>
		<link>http://blog.fl3x.de/2007/11/26/who-is-the-subversion-king-in-your-company/</link>
		<comments>http://blog.fl3x.de/2007/11/26/who-is-the-subversion-king-in-your-company/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 17:05:11 +0000</pubDate>
		<dc:creator>Marcel Oelke</dc:creator>
				<category><![CDATA[Discoveries]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://pure.rednoize.com/2007/11/26/who-is-the-subversion-king-in-your-company/</guid>
		<description><![CDATA[Have you ever wanted to know who&#8217;s the top committer in your company?
In my previous company we etablished the term &#8220;CVS King&#8221;, a title comparable to &#8220;Employee of the month&#8221;. The developer with the most cvs commits was the &#8220;CVS King of the month&#8221;. We determined who was the &#8220;CSV King&#8221; using commit emails that [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever wanted to know who&#8217;s the top <a href="http://en.wikipedia.org/wiki/Committer">committer</a> in your company?<br />
In my previous company we etablished the term &#8220;CVS King&#8221;, a title comparable to &#8220;Employee of the month&#8221;. The developer with the most cvs commits was the &#8220;CVS King of the month&#8221;. We determined who was the &#8220;CSV King&#8221; using commit emails that were sent to all developers on each cvs commit.<br />
Two years ago we switched to Subversion, so now we&#8217;re talking about the &#8220;Subversion King&#8221;. Naturally all this is anything but serious ;)</p>
<p>Anyway, today i programmed a little php script that uses a different approach to determine who is the &#8220;Subversion King of the Month&#8221;. It&#8217;s counting the line delta directly from the svn repository using <a href="http://svnbook.red-bean.com/en/1.4/svn.ref.svnlook.html">svnlook</a>. So the developer with the most lines added to the repository (not the most commits) is the number one.<br />
Here&#8217;s some example output (names are anonymized):</p>
<pre>--- Most productive users for 11/2007 ---
1   usera                6319      42.47%
2   userb                5797      38.96%
3   userc                1990      13.37%
4   userd                 773      05.20%
--- Most active commiters for 11/2007 ---
1   usera                  47         47%
2   userb                  34         34%
3   userc                   4          4%
4   userd                   2          2%
-----------------------------------------
</pre>
<p>The script reads all commits (revisions) for the current month, counts the line delta (how many lines have been added/removed) and the amount of commits.<br />
You can view the <a href="http://pure.rednoize.com/svnking/svnking.phps">highlighted source here</a> or <a href="http://pure.rednoize.com/svnking/svnking.php.txt">download the script here</a>. Use it on the command line like that:<br />
php -f /path/to/svn/repository</p>
<p>I know that the number of lines comitted may not be the one and only criteria to measure the productivity of a developer. But its an indicator to start with.<br />
So the question is: Are you the &#8220;Subversion King&#8221; in your company/project?</p>
<p>P.S.<br />
Again, please, dont take this serious ;)</p>
<img src="http://blog.fl3x.de/?ak_action=api_record_view&id=29&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.fl3x.de/2007/11/26/who-is-the-subversion-king-in-your-company/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Random Timestamps in MySQL</title>
		<link>http://blog.fl3x.de/2007/10/14/random-timestamps-in-mysql/</link>
		<comments>http://blog.fl3x.de/2007/10/14/random-timestamps-in-mysql/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 16:38:57 +0000</pubDate>
		<dc:creator>Marcel Oelke</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://pure.rednoize.com/2007/10/14/random-timestamps-in-mysql/</guid>
		<description><![CDATA[Have you ever needed a random timestamp in MySQL? For example to create demo data programmatically? Here&#8217;s my solution:

SELECT FROM_UNIXTIME(
  FLOOR(
    UNIX_TIMESTAMP('2007-01-01') +
        RAND() *
	(UNIX_TIMESTAMP('2007-01-03')-UNIX_TIMESTAMP('2007-01-01'))
    )
) as random_timestamp;

Or if you prefer a function:

CREATE FUNCTION random_timestamp (start TIMESTAMP, end TIMESTAMP)
RETURNS TIMESTAMP NOT [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever needed a random timestamp in MySQL? For example to create demo data programmatically? Here&#8217;s my solution:</p>
<pre name="code" class="sql">
SELECT FROM_UNIXTIME(
  FLOOR(
    UNIX_TIMESTAMP('2007-01-01') +
        RAND() *
	(UNIX_TIMESTAMP('2007-01-03')-UNIX_TIMESTAMP('2007-01-01'))
    )
) as random_timestamp;
</pre>
<p>Or if you prefer a function:</p>
<pre name="code" class="sql">
CREATE FUNCTION random_timestamp (start TIMESTAMP, end TIMESTAMP)
RETURNS TIMESTAMP NOT DETERMINISTIC
RETURN FROM_UNIXTIME(
  FLOOR(
    UNIX_TIMESTAMP(start) +
    RAND() *
    (UNIX_TIMESTAMP(end)-UNIX_TIMESTAMP(start))
  )
);

mysql> select random_timestamp('2007-10-01', NOW());
+---------------------------------------+
| random_timestamp('2007-10-01', NOW()) |
+---------------------------------------+
| 2007-10-05 23:07:11                   |
+---------------------------------------+
1 row in set (0.00 sec)
</pre>
<img src="http://blog.fl3x.de/?ak_action=api_record_view&id=27&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.fl3x.de/2007/10/14/random-timestamps-in-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to name something that imports and exports ?</title>
		<link>http://blog.fl3x.de/2007/10/11/how-to-name-something-that-imports-and-exports/</link>
		<comments>http://blog.fl3x.de/2007/10/11/how-to-name-something-that-imports-and-exports/#comments</comments>
		<pubDate>Thu, 11 Oct 2007 11:56:22 +0000</pubDate>
		<dc:creator>Marcel Oelke</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://pure.rednoize.com/2007/10/11/how-to-name-something-that-imports-and-exports/</guid>
		<description><![CDATA[Simple Question:
When a script/function/class exports something, I name it &#8220;exporter&#8221;.
When it imports something, I name it &#8220;importer&#8221;.
How do I name it when it does both?
What do you think? Write your thoughts into the comments please. Thanks!
]]></description>
			<content:encoded><![CDATA[<p>Simple Question:<br />
When a script/function/class exports something, I name it &#8220;exporter&#8221;.<br />
When it imports something, I name it &#8220;importer&#8221;.<br />
How do I name it when it does both?</p>
<p>What do you think? Write your thoughts into the comments please. Thanks!</p>
<img src="http://blog.fl3x.de/?ak_action=api_record_view&id=26&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.fl3x.de/2007/10/11/how-to-name-something-that-imports-and-exports/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>MySQL Performance: Use counter tables</title>
		<link>http://blog.fl3x.de/2007/04/03/mysql-performance-use-counter-tables/</link>
		<comments>http://blog.fl3x.de/2007/04/03/mysql-performance-use-counter-tables/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 11:17:58 +0000</pubDate>
		<dc:creator>Marcel Oelke</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://pure.rednoize.com/2007/04/03/mysql-performance-use-counter-tables/</guid>
		<description><![CDATA[I guess many of you know, that using SELECT count(*) FROM table is problematic and slow when using Innodb tables.
This actually only applies to COUNT(*) queries without WHERE a clause as mentioned in the MySQL Performance Blog.
But if you got some slow count query in your application the best way to increase its performance is [...]]]></description>
			<content:encoded><![CDATA[<p>I guess many of you know, that using SELECT count(*) FROM table is problematic and slow when using Innodb tables.<br />
This actually only applies to COUNT(*) queries without WHERE a clause as mentioned in the <a href="http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/">MySQL Performance Blog</a>.</p>
<p>But if you got some slow count query in your application the best way to increase its performance is to replace / remove it.</p>
<p>So if you are going do to &#8220;SELECT count(*) FROM products&#8221; the best way, is to have a separated table<br />
that stores the number of products. If you&#8217;re inserting a row increment the counter, if you&#8217;re deleting a row, decrement it.</p>
<p>Here is some example:</p>
<pre name="code" class="sql">CREATE TABLE counter( number_of_products int(10) DEFAULT '0' NOT NULL);</pre>
<p>Increment when you&#8217;re adding a new product to the products table:</p>
<pre name="code" class="sql">UPDATE counter SET number_of_products = number_of_products +1;</pre>
<p>Decrement when you&#8217;re removing a product:</p>
<pre name="code" class="sql">UPDATE counter SET number_of_products = number_of_products -1;</pre>
<p>In one of my applications i have the case that i have many reads on a table, but just a few updates / writes to the table. The count was in my case not related to a table, but specific to a row of it.</p>
<p>Example:</p>
<pre name="code" class="sql">CREATE TABLE user (
user_id int(10) DEFAULT '0' NOT NULL,
username int(10) DEFAULT '0' NOT NULL,
...
number_of_purchases int(10) DEFAULT '0' NOT NULL,
);</pre>
<p>Scenario:<br />
Just imagine that the number of purchases a user has made is somehow complicated to calculate and query. That&#8217;s why we store the number directly in the user table.<br />
We also have a website that produces a lot of reads to this table column, but (unfortunately) its quite seldom that a user purchases something. So using this complicated count query in each website impression would be slow.</p>
<p>What comes handy here is using MySQL 5 triggers.<br />
With triggers we can calculate the number_of_purchases each time a purchase is made by a user and update the users number_of_purchases column.</p>
<p>Example:</p>
<pre name="code" class="sql">
delimiter //
create trigger trg_update_user_purchases after update on purchases
 for each row begin
call count_and_update_user_purchases(new.user_id);
 end;
//
delimiter ;

delimiter //
create trigger trg_insert_user_purchases after insert on purchases
 for each row begin
call count_and_update_user_purchases(new.user_id);
 end;
//
delimiter ;

delimiter //
create trigger trg_delete_user_purchases after delete on purchases
 for each row begin
call count_and_update_user_purchases(new.user_id);
 end;
//
delimiter ;
</pre>
<p>So each time a records in the purchase table is inserted, updated or deleted the user table gets automaticly updated.</p>
<p>Your application gains the performance from selecting a static int field instead of executing complex count queries. Additionally your application is not bloated with unnecessary code to increment and decrement the count column, because the trigger does this automatically for you.</p>
<img src="http://blog.fl3x.de/?ak_action=api_record_view&id=23&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.fl3x.de/2007/04/03/mysql-performance-use-counter-tables/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL: Collation matters when using unique indexes</title>
		<link>http://blog.fl3x.de/2006/11/26/mysql-collation-matters-when-using-unique-indexes/</link>
		<comments>http://blog.fl3x.de/2006/11/26/mysql-collation-matters-when-using-unique-indexes/#comments</comments>
		<pubDate>Sun, 26 Nov 2006 15:52:35 +0000</pubDate>
		<dc:creator>Marcel Oelke</dc:creator>
				<category><![CDATA[Discoveries]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://pure.rednoize.com/2006/11/26/mysql-collation-matters-when-using-unique-indexes/</guid>
		<description><![CDATA[When using a uniqie index on a text field in mysql, the column collation setting is very important. The collation settings of a column does not only affect sorting and comparsion, but also unique indexes. So you can not insert "a" and "A" into a table that has a unique index on a column that has a case-insensitive collation.]]></description>
			<content:encoded><![CDATA[<p>When using a uniqie index on a text field in mysql, the column collation setting is very important. The collation settings of a column does not only affect sorting and comparsion, but also unique indexes. So you can not insert &#8220;a&#8221; and &#8220;A&#8221; into a table that has a unique index on a column that has a case-insensitive collation. The <a href="http://dev.mysql.com/doc/refman/5.0/en/charset-general.html">mysql manual</a> about collations: &#8220;A <em>character set</em> is a set of symbols and encodings. A <em>collation</em> is a set of rules for comparing characters in a character set.&#8221;</p>
<p>Here is an example:<br />
The column text in table text1 has a case-sensitive collation (_cs suffix), the column in text2 has a  case-insensitive collation (_ci suffix).</p>
<pre name="code" class="sql">
CREATE TABLE text1 (
  `text` varchar(50) character set latin1 collate latin1_general_cs NOT NULL default '',
  UNIQUE KEY uniq_text (text)
) ENGINE=MyISAM
;
INSERT INTO text1 (text) VALUES ('a');
Query OK, 1 row affected (0.00 sec)

INSERT INTO text1 (text) VALUES ('A');
Query OK, 1 row affected (0.00 sec)

CREATE TABLE text2 (
  `text` varchar(50) character set latin1 collate latin1_general_ci NOT NULL default '',
  UNIQUE KEY uniq_text (text)
) ENGINE=MyISAM
;
INSERT INTO text2 (text) VALUES ('a');
Query OK, 1 row affected (0.00 sec)

INSERT INTO text2 (text) VALUES ('A');
ERROR 1062 (23000): Duplicate entry 'A' for key 1
</pre>
<p>Constraints are also affected by collation:<br />
The queries on table text1 give different results (a and A), the two queries on table text2 result in the same row twice (a).</p>
<pre name="code" class="sql">
SELECT * FROM text1 WHERE text = 'a';
+------+
| text |
+------+
| a    |
+------+
1 row in set (0.01 sec)

SELECT * FROM text1 WHERE text = 'A';
+------+
| text |
+------+
| A    |
+------+
1 row in set (0.00 sec)

SELECT * FROM text2 WHERE text = 'a';
+------+
| text |
+------+
| a    |
+------+
1 row in set (0.00 sec)

SELECT * FROM text2 WHERE text = 'A';
+------+
| text |
+------+
| a    |
+------+
1 row in set (0.00 sec)
</pre>
<p>You can display all available collations using
<pre name="code" class="sql">SHOW COLLATION;</pre>
<p> or
<pre name="code" class="sql">SHOW COLLATION LIKE 'latin%';</pre>
<img src="http://blog.fl3x.de/?ak_action=api_record_view&id=21&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.fl3x.de/2006/11/26/mysql-collation-matters-when-using-unique-indexes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dynamic Materialized Views in MySQL</title>
		<link>http://blog.fl3x.de/2005/11/12/dynamic-materialized-views-in-mysql/</link>
		<comments>http://blog.fl3x.de/2005/11/12/dynamic-materialized-views-in-mysql/#comments</comments>
		<pubDate>Sat, 12 Nov 2005 22:05:25 +0000</pubDate>
		<dc:creator>Marcel Oelke</dc:creator>
				<category><![CDATA[Discoveries]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://pure.rednoize.com/?p=13</guid>
		<description><![CDATA[In one of my latest postings I mentioned a way to create semi materialized views in MySQL. The problem was that the solution required a stored procedure for every materialized view. That&#8217;s very annoying. So I looked for a more general and dynamic approach. The result is another stored procedure with 3 parameters:

the name for [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my<a href="http://pure.rednoize.com/archives/9/"> latest postings</a> I mentioned a way to create semi materialized views in MySQL. The problem was that the solution required a stored procedure for every materialized view. That&#8217;s very annoying. So I looked for a more general and dynamic approach. The result is another stored procedure with 3 parameters:</p>
<ul>
<li>the name for the source table / view</li>
<li>the primary key columns of the source table / view</li>
<li>the desired name for the materialized view</li>
</ul>
<p>Basically this procedure does the following:</p>
<ul>
<li>It drops the materialized view if it already exists</li>
<li>It creates the materialized view with the structure and data of the source table</li>
<li>It adds a primary key to the newly created materialized view</li>
</ul>
<p>However the procedure does not create triggers on the table. This could be an improvement for a next version ;)<br />
To call the procedure use:</p>
<pre name="code" class="sql">CALL create_mview('big_table', 'id', 'view_m_big_table');</pre>
<p>And here&#8217;s the procedure:</p>
<pre name="code" class="sql">DROP PROCEDURE IF EXISTS create_mview;
DELIMITER //
CREATE PROCEDURE create_mview (IN source_table VARCHAR(150), IN primary_key VARCHAR(150), IN target_table  VARCHAR(150))
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
MODIFIES SQL DATA
BEGIN
-- declare some variables ...
DECLARE m_view_name VARCHAR(150);
DECLARE create_m_view_sql TEXT;
DECLARE drop_m_view_sql TEXT;
DECLARE add_primary_key_sql TEXT;
--
-- create the sql queries to drop the materialized view, create the tmaterialized view
-- and add a primary key to the materialized view.
SET m_view_name:=concat('view_m_', source_table);
SET @drop_m_view_sql:=concat('DROP TABLE IF EXISTS ',target_table);
SET @create_m_view_sql:=concat('CREATE TABLE ', target_table , ' SELECT * FROM ', source_table);
SET @add_primary_key_sql:=concat('ALTER TABLE ', target_table , ' ADD PRIMARY KEY (', primary_key ,')');
--
-- drop the materialized view if it exists
PREPARE stmt1 FROM @drop_m_view_sql;
EXECUTE stmt1;
--
-- create the table
PREPARE stmt2 FROM @create_m_view_sql;
EXECUTE stmt2;
--
-- add the primary key
PREPARE stmt3 FROM @add_primary_key_sql;
EXECUTE stmt3;
--
DEALLOCATE PREPARE stmt1;
DEALLOCATE PREPARE stmt2;
DEALLOCATE PREPARE stmt3;
--
END; //
DELIMITER ;
</pre>
<p>You can <a href="http://pure.rednoize.com/download/create_mview.sql">download</a> the procedure also.</p>
<img src="http://blog.fl3x.de/?ak_action=api_record_view&id=13&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.fl3x.de/2005/11/12/dynamic-materialized-views-in-mysql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Checking password strength using md5.rednoize.com and AJAX</title>
		<link>http://blog.fl3x.de/2005/11/10/checking-password-strength-using-md5rednoizecom-and-ajax/</link>
		<comments>http://blog.fl3x.de/2005/11/10/checking-password-strength-using-md5rednoizecom-and-ajax/#comments</comments>
		<pubDate>Thu, 10 Nov 2005 13:36:25 +0000</pubDate>
		<dc:creator>Marcel Oelke</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://pure.rednoize.com/?p=12</guid>
		<description><![CDATA[With some inspiration from Ben Ramsey i created a little demo for using my md5 database during the signup process on a website.
This example demonstrates the use of the MD5 database at http://md5.rednoize.com and AJAX to check password strength during signup on a website. After supplying a username and a password, a md5 hash of [...]]]></description>
			<content:encoded><![CDATA[<p>With some inspiration from <a href="http://benramsey.com/archives/essential-php-security-and-md5-reversing/">Ben Ramsey</a> i created a little demo for using my md5 database during the signup process on a website.</p>
<p>This example demonstrates the use of the MD5 database at <a href="http://md5.rednoize.com">http://md5.rednoize.com</a> and <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29">AJAX</a> to check password strength during signup on a website. After supplying a username and a password, a md5 hash of the password is generated using Paul Johnston&#8217;s <a href="http://pajhome.org.uk/crypt/md5/">md5 javascript library</a>.</p>
<p>The hash of the password (not the password itself) is then sent to http://md5.rednoize.com. If the website returns a result for the given password (hence the hash password combination is stored in the md5 database) it can be regarded as &#8220;insecure&#8221;. Because the md5 hash of the password, and not the password itself is transferred, no sensitive data will be saved at md5.rednoize.com.</p>
<p>For sure not every password that is <em>not</em> stored in the MD5 database can be considered secure. I recommend adding some extra checks (existence of upper and lowercase characters, numbers, special characters and so on) to increase the password strength.</p>
<p>You can see the example in action here: <a href="http://md5.rednoize.com/ajax/">http://md5.rednoize.com/ajax/</a></p>
<p>Feel free to use the code in this example any play with it ;)<br />
To implement this on your own webserver you would need some kind of proxy script that redirects the AJAX calls from your own server to the md5 database.</p>
<p><ins datetime="2005-11-10T15:39:31+00:00">Update:</ins></p>
<p>I recommend saving passwords using <a href="http://en.wikipedia.org/wiki/Password_cracking#Salting">salted </a>md5 hashes. Salting in short: &#8220;When the user sets a password, a short string called the salt is suffixed to the password before encrypting it; the salt is stored along with the encrypted password so that it can be used during verification. Since the salt is different for each user, the attacker can no longer use a single encrypted version of each candidate password. If the salt is long enough, the attacker must repeat the encryption of every guess for each user, and this can only be done after obtaining the encrypted password record for that user.&#8221;</p>
<p>Here&#8217;s a little example using salted passwords:</p>
<p>To authenticate users on your website (login) your probably using a SQL statement like this one:<br />
<code>SELECT user_id, username FROM users WHERE passsword = MD5('thepassword');</code></p>
<p>This is insecure. If someone would know the md5 hash of the password, and the password is weak, it could be &#8220;reversed&#8221; using the MD5 database.</p>
<p>Use salted passwords to avoid this:<br />
<code>SELECT user_id, username FROM users WHERE passsword = MD5(user_id || 'some_secret_string' || 'thepassword');</code></p>
<p>Its also possible to store the salt along the password in the database.</p>
<img src="http://blog.fl3x.de/?ak_action=api_record_view&id=12&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.fl3x.de/2005/11/10/checking-password-strength-using-md5rednoizecom-and-ajax/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Materialized Views in MySQL</title>
		<link>http://blog.fl3x.de/2005/10/26/materialized-views-in-mysql/</link>
		<comments>http://blog.fl3x.de/2005/10/26/materialized-views-in-mysql/#comments</comments>
		<pubDate>Wed, 26 Oct 2005 19:17:59 +0000</pubDate>
		<dc:creator>Marcel Oelke</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://pure.rednoize.com/?p=9</guid>
		<description><![CDATA[Update: Dynamic Materialized Views
Please read this article also. Its an improved versio of the technique described below.
Today i found a workaround for a feature that was realy missing in MySQL.
Let&#8217;s say you got a really complicated query that requires a lot of cpu and time to complete, but the resulting data is quite static. That&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: <a href="http://pure.rednoize.com/2005/11/12/dynamic-materialized-views-in-mysql/">Dynamic Materialized Views</a><br />
Please read this article also. Its an improved versio of the technique described below.</strong></p>
<p>Today i found a workaround for a feature that was realy missing in MySQL.<br />
Let&#8217;s say you got a really complicated query that requires a lot of cpu and time to complete, but the resulting data is quite static. That&#8217;s the perfect opportunity to use a &#8220;Materialized View&#8221;. The Bad Thing™ is, mysql does not support what&#8217;s usually known as materialized views. But today i found a nice workaround for MySQL 5.<br />
But first let&#8217;s clarify what a materialized view is. I found a good explanation <a href="http://www.adp-gmbh.ch/ora/concepts/materialized_view.html">here</a>:<br />
&#8220;A materialized view is a stored summary containing precomputes results (originating from an SQL select statement).<br />
As the data is precomputed, materialized views allow for (seemingly) faster dataware query answers.&#8221;</p>
<p>Okay, so a materialized view saves the result of a query somewhere (e.g. into another table)  else.</p>
<p>In my case i had to calculate a rating of users based on votes from other users (Website of <a href="http://www.hiphop-battles.com">http://www.hiphop-battles.com</a> btw) .  I&#8217;m doing this with some nested views (also a new feature in MySQL5). The whole calculation and query took 0.5 seconds on my athlon xp 3200 machine. Thats way to much to run this query on each page impression.</p>
<p>The trick is a new feature that was introduced in MySQL 5. From the <a href="http://dev.mysql.com/doc/refman/5.0/en/create-table.html">MySQL Manual:</a><br />
&#8220;In MySQL 5.0, you can create one table from another by adding a SELECT statement at the end of the CREATE TABLE statement:</p>
<pre name="code" class="sql">CREATE TABLE new_tbl SELECT * FROM orig_tbl;</pre>
<p>So its possible to create a new table with structure based on an already existing table. The data of the table gets copied also.<br />
To create a table of a very processing intensive view we run the following query:</p>
<pre name="code" class="sql">CREATE TABLE view_m_demo SELECT * FROM view_demo;</pre>
<p>To make it little bit better we put this code into a procedure (also a new feature in MySQL5):</p>
<pre name="code" class="sql">DELIMITER //
CREATE PROCEDURE updateDemoView ()
BEGIN
    DROP TABLE IF EXISTS view_m_demo;
    CREATE TABLE view_m_demo SELECT * FROM view_demo;
END; //
DELIMITER ;</pre>
<p>Now we can call this procedure using a trigger:</p>
<pre name="code" class="sql">delimiter //
CREATE TRIGGER T_updateDemoView AFTER INSERT ON some_involved_table
  FOR EACH ROW BEGIN
  /* calls the procedure to update out materialized view on each insert */
    CALL updateDemoView ();
END //
delimiter ;</pre>
<p>The same can be done with an &#8220;AFTER UPDATE&#8221; trigger. dont use database triggers if the data in the original tables get updated frequently.<br />
Another option in this case is to update the view time triggerd via cron.<br />
To update the materialized view every minute use:</p>
<pre name="code" class="sql">*/1 * * * * echo "CALL updateDemoView ();"  |  mysql -u user --password=pass database</pre>
<p>I hope this helps somebody as much as it helps my projects website loading time ;)<br />
before: 0,48 sec<br />
after: 0,003 sec</p>
<img src="http://blog.fl3x.de/?ak_action=api_record_view&id=10&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.fl3x.de/2005/10/26/materialized-views-in-mysql/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>2,007,161 md5 strings</title>
		<link>http://blog.fl3x.de/2005/10/26/2007161-md5-strings/</link>
		<comments>http://blog.fl3x.de/2005/10/26/2007161-md5-strings/#comments</comments>
		<pubDate>Wed, 26 Oct 2005 18:27:51 +0000</pubDate>
		<dc:creator>Marcel Oelke</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://pure.rednoize.com/?p=8</guid>
		<description><![CDATA[Today i took a look at my md5 site and found out that i (we)  broke the 2 million barrier. The database has now  2,007,161 md5 strings with their counter part stored. 222,101 queries where run against the database till now. The size of the database has grown to 320 MB on the [...]]]></description>
			<content:encoded><![CDATA[<p>Today i took a look at my<a href="http://md5.rednoize.com/"> md5 site</a> and found out that i (we)  broke the 2 million barrier. The database has now  2,007,161 md5 strings with their counter part stored. 222,101 queries where run against the database till now. The size of the database has grown to 320 MB on the disk.</p>
<p>I even found out that some crazy people use my website in their scripts and programs. Someone (not me) created a <a href="http://mycroft.mozdev.org/download.html?submitform=Find&amp;category=6">search plugin</a> for mozilla. Another <a href="http://paradigma.pt/ja/slog/comments.php?y=05&amp;m=09&amp;entry=entry050908-154448">guy</a> created a <a href="http://paradigma.pt/ja/slog/downloads/reversemd5.phps">PHP Class</a> that uses my site. Again another guy created an <a href="http://66.249.93.104/search?q=cache:ZMd7O5TkCXoJ:pastebin.com/335909+md5.rednoize.com&amp;hl=en">IRC bot</a> that &#8220;reverses&#8221; given md5 strings on command &#8230; using my site.<br />
The website currently produces ~300 MB traffic per month, so thats okay for now.</p>
<p>I really never expected that this little project attracts so much attention ;)</p>
<img src="http://blog.fl3x.de/?ak_action=api_record_view&id=9&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.fl3x.de/2005/10/26/2007161-md5-strings/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
