<?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/"
xmlns:series="http://organizeseries.com/"
> <channel><title>SitePoint &#187; Databases</title> <atom:link href="http://www.sitepoint.com/category/databases/feed/" rel="self" type="application/rss+xml" /><link>http://www.sitepoint.com</link> <description>Learn CSS &#124; HTML5 &#124; JavaScript &#124; Wordpress &#124; Tutorials-Web Development &#124; Reference &#124; Books and More</description> <lastBuildDate>Mon, 13 May 2013 13:12:07 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.5.1</generator> <item><title>We&#8217;re Putting the (MySQL) Band Back Together</title><link>http://www.sitepoint.com/mysql-band-back-together/</link> <comments>http://www.sitepoint.com/mysql-band-back-together/#comments</comments> <pubDate>Mon, 29 Apr 2013 13:45:05 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[Databases]]></category> <category><![CDATA[News]]></category> <category><![CDATA[Open source]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[mariaDB]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[oracle]]></category> <category><![CDATA[SkySQL]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=65659</guid> <description><![CDATA[The original MySQL developers are back together to work on a rival to Oracle's open source database.]]></description> <content:encoded><![CDATA[<p></p><p>MySQL &#8212; the world&#8217;s most-used relational database &#8212; will be 18 next month. The first version was developed by Michael Widenius and David Axmark and released by MySQL AB on May 23, 1995. The open source product rapidly gained traction alongside PHP to become an integral part of the LAMP stack.</p><p>Sun Microsystems obtained MySQL for $1 billion in January 2008. 15 months later, Oracle acquired Sun for $7.4 billion and became the owner of Java, VirtualBox, OpenOffice and <a
href="http://www.sitepoint.com/oracle-sun-mysql/">MySQL</a>. The takeover caused significant controversy since the world&#8217;s biggest commercial database provider now controlled a major open source competitor.</p><p>Michael Widenius was particularly critical and released his own MySQL fork under the GNU General Public License from his own company, Monty Program AB. MariaDB is designed to maintain compatibility and be a drop-in replacement for MySQL.</p><p>Here&#8217;s where it gets interesting: Monty Program AB has <a
href="http://www.skysql.com/news-and-events/press-releases/skysql-merges-with-mariadb-developers">signed a merger agreement with SkySQL</a>. SkySQL was formed by former MySQL executives &#8212; including David Axmark &#8212; when Oracle acquired the database from Sun. The MySQL band are back together!</p><p>The new company will continue to use the SkySQL name to support and develop MariaDB. Michael Widenius stated:</p><blockquote><p> The MySQL database is named after my first daughter, My. The MariaDB database is named after my second daughter, Maria. With this merger and my own role in the MariaDB Foundation, I&#8217;m ensuring that the MariaDB project will remain &#8216;open source forever&#8217;, while knowing that enterprise and community users of both the MySQL and MariaDB databases will benefit from best-in-breed products, services and support provided by SkySQL. And who doesn&#8217;t want the best for their children?</p></blockquote><p>MySQL has a stronger rival. It&#8217;s reassuring news especially for those with any concerns regarding Oracle&#8217;s plans for the open source database.</p><p>See also:</p><ul><li><a
href="http://www.skysql.com/news-and-events/press-releases/skysql-merges-with-mariadb-developers">SkySQL Merges With MariaDB Developers To Create &#8216;Next Generation Open Source&#8217; Database Company</a></li><li><a
href="https://mariadb.org/">MariaDB.org</a></li><li><a
href="http://www.skysql.com/">SkySQL.com</a></li><li><a
href="https://kb.askmonty.org/en/mariadb-vs-mysql-compatibility/">MariaDB vs MySQL &#8212; compatibility</a></li></ul><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/mysql-band-back-together/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>MySQL Views</title><link>http://www.sitepoint.com/mysql-views/</link> <comments>http://www.sitepoint.com/mysql-views/#comments</comments> <pubDate>Tue, 23 Apr 2013 02:41:17 +0000</pubDate> <dc:creator>Richard Kotze</dc:creator> <category><![CDATA[Databases]]></category> <category><![CDATA[Open source]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[RMDBS]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=65554</guid> <description><![CDATA[Richard Kotze takes a look at the advantages and disadvantages of using MySQL views to manage database tables.]]></description> <content:encoded><![CDATA[<p></p><p>You have just written a new feature for your awesome application that searches through your database to find &#8216;x&#8217; and you run some tests to check that the returned result is correct.</p><p>Unfortunately, your test fails because it returns more results than expected. At first this is not obvious because it&#8217;s been a while since you worked on the application, but eventually you realise that every search should be automatically filtered out by a boolean field.</p><p>You may have run into a similar situation where you or someone has forgotten to filter by a value in field x and it&#8217;s now potentially showing incorrect data, thereby damaging business. Fortunately, there are some tests in place to catch this.</p><p>Let&#8217;s work through an example. You have a user table and, with good reason, you are utilizing a boolean field to represent what the state of the user is, perhaps to determine if it is disabled. You could copy data from a “live table” to a “disabled table” but you feel the complexity and overhead to implement this is too high, because of other user related tables.</p><p>With the above scenario in mind, I think <i>MySQL Views</i> can improve on this solution. Views are quite simple things. They present a table based on the defined SELECT query. We can create a view that will only return users that are enabled in the system and which will prevent future features from including disabled users.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>I&#8217;ll explain how to create this view and how to use it in your application. Something to note is MySQL views are only available from version 5.</p><p>Here is the basic user table the view will be based on:</p><pre>CREATE  TABLE `users` (
`user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`first_name` VARCHAR(100) NULL ,
`last_name` VARCHAR(100) NULL ,
`username` VARCHAR(100) NULL ,
`dob` DATETIME NULL ,
`disabled` BIT NULL DEFAULT 0 ,
PRIMARY KEY (`user_id`) );</pre><p>Below is the query that will<i> create a MySQL view </i>for the above user table.</p><pre>CREATE OR REPLACE ALGORITHM = MERGE VIEW `v_users_enabled`
(`firstName`, `lastName`, `username`, `dob`)
AS
SELECT `first_name`, `last_name`, `username`, `dob`
FROM `users`
WHERE `disabled` = 1;</pre><h2>How does it work?</h2><p>Here is a breakdown of the keywords used to create a view.</p><h3>CREATE OR REPLACE</h3><p>This creates a new view and is required. Optionally you can add OR REPLACE if you want to make certain it is created but if you know the view exists already you can use ALTER to make changes to an existing view.</p><h3>ALGORITHM = MERGE</h3><p>This is an optional statement and by not defining one or explicitly stating ALGORITHM = UNDEFINED, MySQL will choose between two options that best fit the SELECT statement, i.e. MERGE or TEMPTABLE. MySQL will try to choose MERGE over TEMPTABLE where possible because it is more efficient. I will discuss more about the algorithm after going through these core points.</p><h3>VIEW</h3><p>Is a required statement and is used to give a name to the view. Crucially a view <b>cannot </b>have the same name as a table because they share the same name space.</p><p>The column list part is optional and by default the column names in the SELECT statement are used. If you choose to define column names they are comma separated, must be unique and match the number of columns in the SELECT.</p><h3>AS</h3><p>Is required and where you define the SELECT query.</p><p>Querying a view is the same as when querying a table. Here&#8217;s a simple example:</p><pre>SELECT * FROM v_users_enabled</pre><h2>More about the algorithm</h2><p>When defining the algorithm, you have three options to choose from: MERGE, TEMPTABLE or UNDEFINED.</p><p>We now know that UNDEFINED lets MySQL choose the appropriate option, but what do the other two options mean?</p><p><b>MERGE </b>is the fastest out of the two options. The view column list replaces what is in the SELECT statement, essentially merging faster than <b>TEMPTABLE</b> as that generates a new temporary table that is queried upon and which has <b>no indexes</b>. MySQL will warn you if you try to use MERGE when a TEMPTABLE should be used and will change it to TEMPTABLE.</p><p>When will the <b>TEMPTABLE </b>option be used? If you use any aggregation function, DISTINCT, LIMIT, GROUP BY, HAVING, sub query or literal values (i.e. no table).</p><h2>Minor performance trade off</h2><p>Unfortunately, MySQL views will hinder performance rather than improve it. It is important to think about your views and to use MERGE where possible to minimise performance reduction.</p><p>Provided your performance budgets can take the hit to better manage complexity and create a useful separation this, in my view, is a worthy trade off because you are taking a query with certain where clauses that may need to be applied to other queries. This is nicely contained within a view and database level users can query against this returning them the correct results, without them having to remember they need these additional where clauses.</p><p>The downside of this containment is that it would be possible to write a complex query within the view which is now hidden. Queries with more where clauses on this view will make the overall query a monster and potentially inefficient. A judgement call will need to be made on how complex the view SELECT query can be without compromising performance.</p><p>To better optimize for performance when using a view, use the MERGE algorithm and when creating your index add the fields in your WHERE clauses that exist in the view first. It is important they are put in the correct order, as usual when creating indexes for expected queries. You can use EXPLAIN to check your query and make sure its behaving as you expect.</p><h2>Benefits and Negatives</h2><p>The <b>benefits </b>of using a view:</p><ul><li>Provide a useful data separation from application by containing the need to remember specific fields the query needs to filter by for all SELECT statements within the database.</li><li>Tables can change over time and you need to add some new fields that you intend to filter by for most SELECT queries. All that needs to change is the SELECT statement with the new fields after altering the tables. Then updating the application will be easier as you may only need to remember to change it in a few places.</li><li>They can make your SELECT queries more readable.</li></ul><p>The <b>negatives </b>of using a view:</p><ul><li>When the TEMPTABLE algorithm is used no index is used.</li><li>They could hide a complex query and with querying the view could turn it into a sluggish query.</li><li>Using the MERGE algorithm limits your view SELECT statement to basic querying only.</li><li>You may choose the MERGE algorithm but if MySQL thinks it should use TEMPTABLE then it will change it.</li><li>If your view does not have a one-to-one relationship with the table then it is not updatable.</li><li>When you do add or change a table you will still need to update the CUD statements in your application.</li><li>You <b>cannot </b>associate a trigger with a view.</li></ul><h2>Noteworthy quirks</h2><p>If you want to use ORDER BY in your view SELECT statement it is worth noting that this cannot be overridden when you query the view using a different order.</p><p>If you decide to put a LIMIT in your view and then use another LIMIT when you query the view it is undefined which LIMIT applies.</p><p>If you are interested in making a view updatable see <a
href="http://dev.mysql.com/doc/refman/5.6/en/view-updatability.html">MySQL</a><a
href="http://dev.mysql.com/doc/refman/5.6/en/view-updatability.html">website</a>.</p><h2>Conclusion</h2><p>MySQL views are a useful tool and provide a good solution in particular scenarios. It is clear that views have their limits and it is important to be aware of them. Used in the right way your next app can benefit from flexible containment and control over how the data is accessed.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/mysql-views/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 37/52 queries in 0.077 seconds using memcached
Object Caching 735/772 objects using memcached

Served from: www.sitepoint.com @ 2013-05-13 15:50:13 --