On Sep 1, 2004, at 9:57 AM, Michele Cuozzo wrote:
> Hi everybody, I've got just one question:
>
> How 'auto_pk_support' works?
>
> thanks
Hi Michele,
It is just a default way to automatically generate primary keys
(http://objectstyle.org/cayenne/userguide/design/autopk.html). Each row
in this table stores the name of other table whose PK we are
generating, and the last (max) used value of the primary key.
When an application needs to determine a primary key for a given table,
it first selects the last used value from auto_pk_support, and then
runs an update on that same row to increment this value, so that each
value is used only once.
Cayenne optimizes this process by grabbing more than one value at once.
By default we increment it by 20, thus ensuring that only a given
Cayenne app instance will use PKs in the range of N..N-20 (where N is
the new NEXT_ID value for a given table).
Here is an example of how this procedure works on MySQL:
LOCK TABLES AUTO_PK_SUPPORT WRITE
SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE TABLE_NAME = 'ARTIST'
UPDATE AUTO_PK_SUPPORT SET NEXT_ID = NEXT_ID + 20 WHERE TABLE_NAME =
'ARTIST' AND NEXT_ID = 200
UNLOCK TABLES
Andrus
This archive was generated by hypermail 2.0.0 : Thu Sep 02 2004 - 09:49:00 EDT