Home » Performance » MySQL » More on autoincrement vs guid vs natural key
More on autoincrement vs guid vs natural key [message #3526] Fri, 12 September 2008 03:40 Go to next message
AlexN  is currently offline AlexN
Messages: 20
Registered: October 2007
Location: Moscow,Russia
Junior Member
I've read several articles about autoincrements and I'm still in doubt. I understand that long GUIDs results in large index files and possibly slow access. Also I tested 32-byte GUIDs versus autoincrenent keys and found a very little difference. Also I've been told by our admins that autoincrement columns are bad in scaling. They asked us, programmers, to change application logic in orde to use natural keys or UUIDs. Is it possible to make a little summary on this subject ? Advantages and disadvantages of autoincrements, uuids and natural keys could depend on:

* table size
* key size
* whether the key is composite or not
* number of connections
* what else ?

Currently I have two cases. A table that requires many inserts from many connections. This table has several millions of rows and acts as a kind of a log. Another table holds session information. There are several thousand rows, but there is a very intensive process of selection-insertion-deletion of rows.
Currently the first table uses autoincrement and the second one uses GUID. Is this correct ?



Re: More on autoincrement vs guid vs natural key [message #3588 is a reply to message #3526 ] Sun, 28 September 2008 17:50 Go to previous messageGo to next message
artur8ur  is currently offline artur8ur
Messages: 23
Registered: September 2008
Junior Member
Hi,

The auto_increment is not a special type, it is a "default" value for Primary Key Int-Type columns for Inserting new values on.

If you do use a autoincrement id, or a UUID depends on your application structure.

In general, I would advice to use a autoincrement, specially if you use InnoDB tables.
InnoDB rows are stored in order of the PK on disk. Using a UUID, which is random like, results in storing the rows in random order. New rows, will have to be inserted between existing rows, resulting in moving existing rows out of the way, to make room for the new row...
Autoincremented rows will be stored at the end of the table..

The data is stored in a B-Tree structure. Inserting data in random order will result in many nodes, which are only partly filled. Using up more space on disk and in memory.
Inserting in order (autoincrement), will result in very dense nodes...


In your case: For the Log Table, where no rows will be deleted, the autoincrement is a good choice.
For your session table, where many inserts and deletes occur, the table will be "fragmented" anyway. (MyISAM Fragmentation, InnoDB partly filled nodes). If you do access the table, using your GUID, there is no need for adding another "autoincrement" PK column. Using an autoincrement would not result in a more dense data structure (because of the random deletes) and it may make the ID predictable, which might be a Security-Concern...
Re: More on autoincrement vs guid vs natural key [message #3591 is a reply to message #3526 ] Sun, 28 September 2008 20:39 Go to previous messageGo to next message
MarkRose  is currently offline MarkRose
Messages: 94
Registered: January 2008
Member
AutoIncrement is bad in scaling because it makes distributed insertion complex. If you have several servers, how do you coordinate the autoincrement? That's a major disadvantage.
Re: More on autoincrement vs guid vs natural key [message #4991 is a reply to message #3526 ] Mon, 30 November 2009 03:33 Go to previous message
anusha  is currently offline anusha
Messages: 1
Registered: November 2009
Junior Member
i have field on table. it is for example it has 1 to 20 digits as 20 records. when i delete 15 to 20 records from end of it then insert new record to it with: INSERT INTO dynamic VALUES(Ɔ')

, it give "21" digit instead of "16".

how to reset the auto increment field ? without using truncate option ,as truncate can not rollback .

[Updated on: Mon, 30 November 2009 03:38]


Anu
Previous Topic:Buffer Pool Size limited by mysql kernel?
Next Topic:Real Performance of Stored Procedure Testing
Goto Forum:
  


Current Time: Tue Mar 16 01:46:11 EDT 2010

Total time taken to generate the page: 0.06339 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.