<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Just Say No to Materialized MySQL Views</title>
	<atom:link href="http://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/</link>
	<description>Thoughts, rants, and even some code from the mind of Barney Boisvert.</description>
	<lastBuildDate>Thu, 11 Sep 2014 09:58:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: all</title>
		<link>https://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/comment-page-1/#comment-191269</link>
		<dc:creator>all</dc:creator>
		<pubDate>Thu, 17 Sep 2009 08:27:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/#comment-191269</guid>
		<description>Hi all, 
As a Oracle architect, ex developper, the MV (Materialized view) can be easily simulated with the SQL used to create a dynamic view (standard view) and replace the CREATE VIEW by CREATE TABLES MV_xxxx as select.....  I am convinced argument exist to go against this option. () drop table time, refresh (recreate the MV) frequency etc...  What so ever it is a KISS solution, and idiot-proof. B rgds - thierry</description>
		<content:encoded><![CDATA[<p>Hi all,<br />
As a Oracle architect, ex developper, the MV (Materialized view) can be easily simulated with the SQL used to create a dynamic view (standard view) and replace the CREATE VIEW by CREATE TABLES MV_xxxx as select&#8230;..  I am convinced argument exist to go against this option. () drop table time, refresh (recreate the MV) frequency etc&#8230;  What so ever it is a KISS solution, and idiot-proof. B rgds &#8211; thierry</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Cahill</title>
		<link>https://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/comment-page-1/#comment-174559</link>
		<dc:creator>Mark Cahill</dc:creator>
		<pubDate>Wed, 22 Apr 2009 17:24:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/#comment-174559</guid>
		<description>Wow. Way to resurrect a REALLY old post.</description>
		<content:encoded><![CDATA[<p>Wow. Way to resurrect a REALLY old post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/comment-page-1/#comment-174558</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Wed, 22 Apr 2009 17:19:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/#comment-174558</guid>
		<description>Vaughn,

You are correct; I chose my words poorly.  MySQL does not have true materialized views.  They have statement-rewriting views and temporary-table views.  I was referring to the latter, where the view IS materialized into a concrete table, but then thrown away at the conclusion of the statement.  So while it is materialized, it&#039;s not persistent, which is the whole point of true materialized views.  True materialized views have to be manually created/managed by application code (which is pretty straightforward).</description>
		<content:encoded><![CDATA[<p>Vaughn,</p>
<p>You are correct; I chose my words poorly.  MySQL does not have true materialized views.  They have statement-rewriting views and temporary-table views.  I was referring to the latter, where the view IS materialized into a concrete table, but then thrown away at the conclusion of the statement.  So while it is materialized, it's not persistent, which is the whole point of true materialized views.  True materialized views have to be manually created/managed by application code (which is pretty straightforward).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vaughn</title>
		<link>https://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/comment-page-1/#comment-174556</link>
		<dc:creator>Vaughn</dc:creator>
		<pubDate>Wed, 22 Apr 2009 17:14:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/#comment-174556</guid>
		<description>&quot;You keep using that word. I do not think it means what you think it means.&quot;

The error is the statement &quot;Materialized views are views that, as you might guess, are materialized when they&#039;re needed.&quot;

From http://en.wikipedia.org/wiki/Materialized_view : &quot;A materialized view takes a different approach in which the query result is cached as a concrete table that may be updated from the original base tables from time to time. This enables much more efficient access, at the cost of some data being potentially out-of-date. It is most useful in data warehousing scenarios, where frequent queries of the actual base tables can be extremely expensive.&quot;

From http://dev.mysql.com/doc/refman/5.1/en/faqs-views.html : 
&quot;23.6.5:  Does MySQL 5.1 have materialized views?

No. &quot;

(Same answer for MySQL 5.0, 5.1, and 6.0)</description>
		<content:encoded><![CDATA[<p>"You keep using that word. I do not think it means what you think it means."</p>
<p>The error is the statement "Materialized views are views that, as you might guess, are materialized when they're needed."</p>
<p>From <a href="http://en.wikipedia.org/wiki/Materialized_view" rel="nofollow">http://en.wikipedia.org/wiki/Materialized_view</a> : "A materialized view takes a different approach in which the query result is cached as a concrete table that may be updated from the original base tables from time to time. This enables much more efficient access, at the cost of some data being potentially out-of-date. It is most useful in data warehousing scenarios, where frequent queries of the actual base tables can be extremely expensive."</p>
<p>From <a href="http://dev.mysql.com/doc/refman/5.1/en/faqs-views.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/faqs-views.html</a> :<br />
"23.6.5:  Does MySQL 5.1 have materialized views?</p>
<p>No. "</p>
<p>(Same answer for MySQL 5.0, 5.1, and 6.0)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dom</title>
		<link>https://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/comment-page-1/#comment-54341</link>
		<dc:creator>Dom</dc:creator>
		<pubDate>Thu, 03 Jan 2008 06:21:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/#comment-54341</guid>
		<description>Thanks for your article! I seem to have hit the same problem with a test database on MySQL 5.1. In particular I wanted to mimic the behaviour of queries in Access (from which I am wishing to migrate the data). In Access you can &#039;stack&#039; queries on top of one another and supply parameter values to the top level query which are inherited and used by lower level queries.

MySQL does not allow parameter values (aka user variables) with views, but there is a workaround using a stored function (which can access and then return the user variable). But the performance is terrible.

Previously I have used sub-queries (in MySQL 4.1), though not with user variables, and they have always been impressively fast (but I had to write my own VBA code to nest sub-query definitions into higher-level queries). Views should be neater but with their inability to access user variables (except inefficiently as it seems through a stored function), and the performance hit you describe, I guess I must stick to coded sub-queries for now.</description>
		<content:encoded><![CDATA[<p>Thanks for your article! I seem to have hit the same problem with a test database on MySQL 5.1. In particular I wanted to mimic the behaviour of queries in Access (from which I am wishing to migrate the data). In Access you can 'stack' queries on top of one another and supply parameter values to the top level query which are inherited and used by lower level queries.</p>
<p>MySQL does not allow parameter values (aka user variables) with views, but there is a workaround using a stored function (which can access and then return the user variable). But the performance is terrible.</p>
<p>Previously I have used sub-queries (in MySQL 4.1), though not with user variables, and they have always been impressively fast (but I had to write my own VBA code to nest sub-query definitions into higher-level queries). Views should be neater but with their inability to access user variables (except inefficiently as it seems through a stored function), and the performance hit you describe, I guess I must stick to coded sub-queries for now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/comment-page-1/#comment-51705</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Thu, 13 Dec 2007 21:44:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/#comment-51705</guid>
		<description>Mark,

I&#039;m pretty sure that the issue in my case was that the view engine was rematerializing the view over and over again within the same query.  If it had just materialized it once and reused it, it would have been fine, even without an index.  But still a good thought to keep in mind.</description>
		<content:encoded><![CDATA[<p>Mark,</p>
<p>I'm pretty sure that the issue in my case was that the view engine was rematerializing the view over and over again within the same query.  If it had just materialized it once and reused it, it would have been fine, even without an index.  But still a good thought to keep in mind.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Cahill</title>
		<link>https://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/comment-page-1/#comment-51702</link>
		<dc:creator>Mark Cahill</dc:creator>
		<pubDate>Thu, 13 Dec 2007 21:18:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/#comment-51702</guid>
		<description>I had a similar problem with views on our web reporting platform. The culprit that time was that the view was not using the index from the underlying table. I forced a primary key on the ID, and the query times went down 1000%. Just something to look into...</description>
		<content:encoded><![CDATA[<p>I had a similar problem with views on our web reporting platform. The culprit that time was that the view was not using the index from the underlying table. I forced a primary key on the ID, and the query times went down 1000%. Just something to look into&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/comment-page-1/#comment-49631</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Sun, 25 Nov 2007 18:42:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/#comment-49631</guid>
		<description>Jordan,

Sadly, the row count is tiny: less than a thousand rows.

I didn&#039;t do exceptionally granular testing, but the main offenders were aggregating subqueries.  It would be possible to duplicate the subqueries in the &quot;view&quot; throughout the queries that leverage the view to get most of the performance benefit, but the maintenance downside was significat.  That&#039;s actually the path I went down first, because I didn&#039;t want to jack up my database, but it wasn&#039;t worth it.  The app is very SELECT-centric with relatively few updates, so manually managing the &quot;view&quot; tables isn&#039;t actually much of a headache.

There is a feed link at the bottom for subscribing to comments.  I&#039;d also naively assumed that WordPress would email thread participants when new comments were posted (like MovableType did), but I just looked it up, and that doesn&#039;t seem to be the case.  I found a plugin that will provide that functionality; I&#039;ll be installing it in just a sec.</description>
		<content:encoded><![CDATA[<p>Jordan,</p>
<p>Sadly, the row count is tiny: less than a thousand rows.</p>
<p>I didn't do exceptionally granular testing, but the main offenders were aggregating subqueries.  It would be possible to duplicate the subqueries in the "view" throughout the queries that leverage the view to get most of the performance benefit, but the maintenance downside was significat.  That's actually the path I went down first, because I didn't want to jack up my database, but it wasn't worth it.  The app is very SELECT-centric with relatively few updates, so manually managing the "view" tables isn't actually much of a headache.</p>
<p>There is a feed link at the bottom for subscribing to comments.  I'd also naively assumed that WordPress would email thread participants when new comments were posted (like MovableType did), but I just looked it up, and that doesn't seem to be the case.  I found a plugin that will provide that functionality; I'll be installing it in just a sec.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jordan CLark</title>
		<link>https://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/comment-page-1/#comment-49617</link>
		<dc:creator>Jordan CLark</dc:creator>
		<pubDate>Sun, 25 Nov 2007 17:20:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/#comment-49617</guid>
		<description>What part of the operation makes it CPU bound? Is the view aggregating data, or running functions to produce the output? Is it possible to denormalize just some fields manually into a new table and join, instead of duplicating everything? Or does this reduce the performance gains?

Also just out of curiosity how much data is this working with, thousands, tens of thousands of rows, more? Does this size matter, like the larger it is, the more you can save?

P.S. I wish your blog had a comment email subscription option.</description>
		<content:encoded><![CDATA[<p>What part of the operation makes it CPU bound? Is the view aggregating data, or running functions to produce the output? Is it possible to denormalize just some fields manually into a new table and join, instead of duplicating everything? Or does this reduce the performance gains?</p>
<p>Also just out of curiosity how much data is this working with, thousands, tens of thousands of rows, more? Does this size matter, like the larger it is, the more you can save?</p>
<p>P.S. I wish your blog had a comment email subscription option.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/comment-page-1/#comment-49595</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Sun, 25 Nov 2007 11:22:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/2007/11/25/just-say-no-to-materialized-mysql-views/#comment-49595</guid>
		<description>Jordan,

Yeah, it&#039;s absolutely denormalization.

When MySQL does it, it&#039;s an implementation detail of the server; if they changed to something else the DB client wouldn&#039;t care.  As such, it&#039;s not a denormalization you&#039;d care about.

When I do it manually, it&#039;s a much bigger deal.  I&#039;d love to have just changed my view to be of the &quot;rewritten/merged&quot; style, but with the current MySQL implementation, that&#039;s impossible.  With the database not able to directly address my problem, it&#039;s up to me to choose between performance and maintenance overhead.

For the cost of having to rebuild my &quot;view&quot; tables when data is updated and the potential to have slightly outdated statistics in the &quot;views&quot;, I can drop a significant number of queries from the 10-15 second range down to 40-100 milliseconds.  Often there are multiple instance per page request as well.  So the tradeoff seems a no-brainer to me.

I should also have mentioned that this is a CPU-bound limitation.  On my laptop (slower disks, faster CPU, equivalent free RAM), the queries with the views run around a second a piece, compared with 10-15 seconds on the server.</description>
		<content:encoded><![CDATA[<p>Jordan,</p>
<p>Yeah, it's absolutely denormalization.</p>
<p>When MySQL does it, it's an implementation detail of the server; if they changed to something else the DB client wouldn't care.  As such, it's not a denormalization you'd care about.</p>
<p>When I do it manually, it's a much bigger deal.  I'd love to have just changed my view to be of the "rewritten/merged" style, but with the current MySQL implementation, that's impossible.  With the database not able to directly address my problem, it's up to me to choose between performance and maintenance overhead.</p>
<p>For the cost of having to rebuild my "view" tables when data is updated and the potential to have slightly outdated statistics in the "views", I can drop a significant number of queries from the 10-15 second range down to 40-100 milliseconds.  Often there are multiple instance per page request as well.  So the tradeoff seems a no-brainer to me.</p>
<p>I should also have mentioned that this is a CPU-bound limitation.  On my laptop (slower disks, faster CPU, equivalent free RAM), the queries with the views run around a second a piece, compared with 10-15 seconds on the server.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
