MySQL
  Home arrow MySQL arrow Page 5 - Taking a Look at MySQL 4.1
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
Moblin 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Taking a Look at MySQL 4.1
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2006-04-20

    Table of Contents:
  • Taking a Look at MySQL 4.1
  • MySQL 4.1
  • Subqueries As Scalar Values
  • Benefits of Subqueries
  • Other New Features in MySQL 4.1

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Taking a Look at MySQL 4.1 - Other New Features in MySQL 4.1


    (Page 5 of 5 )

    While subqueries are the principal new attraction in MySQL 4.1, there are some additional new features that you should be aware of.

    INSERT ON DUPLICATE KEY UPDATE: Using this new option forINSERTstatements, it’s possible to cause an insert that would duplicate a primary key to update the row matching that key instead. This means it’s no longer necessary for you to check in your application code to see if a given key exists; MySQL will handle this for you.

    NewGROUP_CONCAT()function: This function returns all the concatenated values from a group. The syntax is

    GROUP_CONCAT([DISTINCT] expr [order-by-clause] [SEPARATOR separator-string])

    Here,expr  is a column name or expression. Multiple expressions or columns (separated by commas) may be used. The optionalorder-by-clause follows the same rules forORDER BYas used in aSELECTquery. Also, an optionalseparator-string to be used in concatenating the values may be specified using theSEPARATORkeyword. Note that all of these arguments must be placed inside the parentheses followingGROUP_CONCAT.

    For example, referring to the same products table that we’ve been using in the previous sections, we could generate a list of prices of products for each product category as a single string, in which the names are separated by a colon with a space on either side of it as shown here:

    Another enhancement from the viewpoint of efficiency is the addition of a new key cache system for MyISAM tables in MySQL 4.1.1 and a new command,CACHE INDEX, whose syntax is shown here:

    CACHE INDEX table_name IN key_cache_name;

    Prior to assigning indexes to a key cache, you must first create the key cache, as shown here:

    SET GLOBAL key_cache_name.key_buffer_size = size;

    This can also be done in the my.ini or my.cnf configuration file. Thesize parameter is an integer that is usually specified as a multiple of 1024 and some power of 8. Currently, all indexes from a table are assigned to a given key cache; eventually, it will be possible to assign only specified indexes to a cache.

    By assigning table indexes to separate key caches, it’s possible to fine-tune MySQL’s performance by providing extra cache space for table indexes requiring it. The rationale behind this is more or less as follows: Tables normally “compete” for key cache space, and normally, this is a good thing. Tables that experience heavy usage will normally have their indexes kept in memory, and so MySQL will not have to retrieve their indexes from disk. However, you may have a table that is not used very often, but when it is queried, it’s very important that the query executes as quickly as possible. Using a key cache, you can guarantee that this table’s indexes will always be in memory and that MySQL won’t be slowed down by being required to read them in again from disk.

    Finally, we should mention that the behavior forTIMESTAMPcolumns changes in MySQL 4.1.2 and above. From this release, it’s possible to createTIMESTAMPcolumns that default to the current date/time value and update this value whenever a record is updated. To illustrate this, let’s create a table named ts_test, as shown here:

    In order to take advantage of the last_modified column’s properties in this regard, we must insert a null value into the column—using any other value, including 0 (zero) or the empty string, won’t work. Let’s insert a few rows into ts_test and see what happens:

    When we select all the values in the table, this is what we see: Only the rows into which we inserted NULL actually stored the current date/time. Furthermore, we received no warning about the row into which we inserted a zero. Now let’s try updating three of the rows in ts_test:

    Because of the ON UPDATE clause in the column definition, the last_modified column for any record in ts_test will be updated to the current date and time whenever that record is updated. However, if you set a timestamp column to an explicit value as part of an INSERT or UPDATE query, that value will be used instead:

     


     

    NOTE  This auto-updating behavior for TIMESTAMP columns is effective only with tables created in MySQL 4.1.2 and above. If you’ve upgraded MySQL from a previous version and wish to take advantage
    of this feature for an existing table (created using the previous version of MySQL), you’ll need to drop the table, re-create it, and reinsert any records that were present in the original.


    Please be sure to come back next week for the next part of this article.

    TIMESTAMP

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Beginning MySQL Database Design and...
     

    Buy this book now. This article is excerpted from chapter eight of Beginning MySQL Database Design and Optimization: From Novice to Professional, written by Jon Stephens and Chad Russell (Apress, ISBN: 1590593324). Check it out today at your favorite bookstore. Buy this book now.

       

    MYSQL ARTICLES

    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL
    - Getting PHP to Talk to MySQL
    - Creating an RSS Reader: the Reader
    - MySQL Security Overview
    - Creating the Admin Script for a PHP/MySQL Bl...
    - Creating the Blog Script for a PHP/MySQL Blo...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway