Home » Performance » MySQL » 2 Columns AUTO-INCREMENT emulation in InnoDB
2 Columns AUTO-INCREMENT emulation in InnoDB [message #57] Wed, 16 August 2006 06:21 Go to previous message
Speeple  is currently offline Speeple
Messages: 91
Registered: August 2006
Member
Hi,

In MyISAM you can set 2 columns to have auto-increment properties.

So, in a messaging system you could have:

user_id, message_id

INSERT INTO messages (user_id, message) VALUES (1, 'My Message');
INSERT INTO messages (user_id, message) VALUES (1, 'My Message');
INSERT INTO messages (user_id, message) VALUES (1, 'My Message');

A SELECT * would produce

user_id, message_id
1,1
1,2
1,3

InnoDB does not currently support this, so I've done the following work around:

INSERT INTO messages (user_id, message_id, message) VALUES (1, MAX(message_id), 'My Message') WHERE user_id=1;


Are there any known problems with self-implementing support this way?

It appears to be working fine in the development enviroment, however with thousands of users... might be a different story!

Cheers

[Updated on: Wed, 16 August 2006 06:21]


Martin Gallagher | Speeple: The latest news

Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic:more than one results in the subquery error
Next Topic:split huge tables or just query differently?
Goto Forum:

  


Current Time: Thu Jul 9 19:24:18 EDT 2009

Total time taken to generate the page: 0.02467 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.