Showing entries 38461 to 38470 of 44045
« 10 Newer Entries | 10 Older Entries »
Trees in SQL

The problem of how to handle trees in SQL has been talked about alot. The basic 3 ways are:

  • store the full path for each entry
  • store the parent for each node
  • use nested tree

Nested tree is good for read-many-write-less applications where the tree doesn't check over time too much as a write-operation is heavy-weight most of the time.

Referencing the Parent through the full path

Using the variant of the path involves a lot of string handling and is always slow. See below:

# use a full path to each node
CREATE TABLE tree_path (
  node_path VARCHAR(1024) PRIMARY KEY,
  name VARCHAR(32) NOT NULL,
  INDEX (name)
) ENGINE = innodb;

INSERT INTO tree_path VALUES
  ( '/0',     'Earth' ),
  ( '/0/0',   'Europe' ),
  ( '/0/0/1', 'Germany' ),
  ( '/1',     'Moon' ),
  ( '/0/1',   'Asia' );

# search for parent of 'Asia'
SELECT t1.name
  FROM tree_path AS t1
 WHERE t1.node_path = ( …
[Read more]
Another handy MySQL function

This time it's a quick function to validate email addresses, based on regexp.
It can be used in a trigger to add data validation, or to check data already in your database that needs a clean up ... really a simple wrapper around a simple regexp query, but it can be helpful.
Here it is:

  1. DELIMITER $$
  2. DROP FUNCTION IF EXISTS `test`.`is_valid_email` $$
  3. CREATE DEFINER=`root`@`localhost` FUNCTION `is_valid_email`(p_email varchar(64)) RETURNS tinyint(1)
  4. BEGIN
  5. CASE
  6. WHEN NOT (SELECT p_email REGEXP '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$')
  7. THEN
  8. -- bad data
  9. RETURN FALSE;
  10. ELSE
  11. -- good email
  12. RETURN TRUE;
  13. END CASE;
  14. END $$
  15. DELIMITER ;


As per Mushu's comment, this is much cleaner, oops:

[Read more]
Oven which can do things for you if you send it email or call it!

I was browsing the web today and stumbled upon this. This oven line is great! but come to think of it, how many people can afford to buy this $7k+ gadget (see this MSN coverage). Even if they could buy it, how many will actually would call their oven or email their oven and tell it to cook? I do have to say its a great concept and honestly if I was a millionaire who could afford to buy cool gadgets, I wouldn’t mind getting one of these. Heck, if I owned a house here in LA, it would be something I would consider putting in my kitchen. It would be interesting to see what happens in next few years when gadgets like these might become normal appliances you get for your high end kitchen. Just like how everybody loves to get stainless steel appliances right now for …

[Read more]
How to find out if an outer join was converted to inner

After this post I've got a question how one can tell if his outer join was converted to inner. You can find it out by looking at the warning generated by EXPLAIN EXTENDED. If the outer join wasn't converted, you'll see it in the rewritten query in the warning:

mysql> explain extended select * from t1 left join (t2, t3) on t2.a= t1.a;
...
3 rows in set, 1 warning (0.00 sec)

mysql> show warnings\G
*************************** 1. row ***************************
  Level: Note
   Code: 1003
Message: select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t3`.`a`
AS `a` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on ((`test`.`t2`.
`a` = `test`.`t1`.`a`)) where 1

In this query LEFT JOIN is not converted to inner.

Now let's try a query where outer join will be converted:

mysql> explain extended select * from t1 left join (t2, t3) on …
[Read more]
CU@UC07


I’ll be speaking at the upcoming 2007 MySQL Conference & Expo (Why they dropped the word User, who knows), this time with Guy Harrison (Author of many books including MySQL Stored Procedures). We will be talking on MySQL for Oracle DBAs and Developers.

Anyway, good friend Paul McCullagh, creator of PBXT will be also speaking on PrimeBase XT: Design and Implementation of a Transactional Storage Engine. He coined to me in an email “CU at the UC”. I’ve done a further level of refactoring, and added marketing. You …

[Read more]
MySQL Multi-Master Replication

Changing hats


Note: I have updated this article as of April 24, 2008 to indicate that you do not have to set auto_increment_increment or auto_increment_offset for the slaves. If you see this in the diagrams, please ignore.

The master sets the auto_increment value in it's binary log which the slave reads via replication. I may write an update to this article at some point soon.


I have put on the hat of a MySQL user, a customer, as opposed to a developer (Federated Storage Engine, DBD::mysql) these last couple months with my new employer, Grazr. One of the things we need is a whole replication set-up, with read-only slaves, and write masters. Thats master(s), with an 's', plural. We need a set-up where we have two data centers. In each of the data centers, there is a master and its slaves, all on the same network. That master needs …

[Read more]
Log Buffer #33: a Carnival of the Vanities for DBAs

Welcome to the 33rd edition of Log Buffer, the weekly review of database blogs. We’ll look at some of the standout blog items from the week gone by. To start, you might be surprised by what is in your DBMS. An item on the Oracle Contractors Blog asks whether artificial intelligence is in Oracle, [...]

Cluster Certification and the MySQL User's Conference

So far, I've never blogged about the work I've been doing for the MySQL Certification Team. Time to change that: I'd like to tell you a little bit more about the things I've been doing since I joined MySQL AB.

I started in July 2006 and from the on, I've been almost exclusively occupied with activities to develop certification for MySQL 5.1 Cluster.
A summary of the things I have done so far:


  • Working with the training department to design an outline for the cluster exam
  • Interviewing MySQL Cluster developers to check all kinds of facts and details of the behaviour of MySQL 5.1 Cluster
  • Creating, reviewing …
[Read more]
Alfresco Goes GPL

Alfresco, the leader in open source document management, has now made a subtle but significant change in their licensing.  Effective immediately, Alfresco is being released under the GPL rather than their previous Mozilla-derived license. 

While there's nothing wrong with the Mozilla license they used, my take is, it had two things that were slowing things down.  First of all, it's yet-another-license, even if it is based on a reasonably well-known and accepted license.  So inevitably that means that lawyers start asking lots of questions, at least compared to the GPL which is fairly well understood.  (The GPL is not perfect, but in my view, it's the best going.  And partly because it's widely used by Linux, MySQL and others, it's understood.)  The second issue is that …

[Read more]
MySQL Multi-master replication

Changing hats

I have put on the hat of a MySQL user, a customer, as opposed to a developer (Federated Storage Engine, DBD::mysql) these last couple months with my new employer, Grazr. One of the things we need is a whole replication set-up, with read-only slaves, and write masters. Thats master(s), with an 's', plural. We need a set-up where we have two data centers. In each of the data centers, there is a master and it's slaves, all on the same network. That master needs to replicate to another slave, which is also a master, in its own data center, where it has its own slaves. The idea is that the web servers running mod_perl applications in each data center send all their read-only queries to slaves running on the same server, and all write-only queries to the master in that data center.

How does one go about setting up a multi-master replication scheme, also having slaves in the mix? There are several articles …

[Read more]
Showing entries 38461 to 38470 of 44045
« 10 Newer Entries | 10 Older Entries »