Re: PK Increment Step

From: Neil Pierson (neil.pierso..mail.com)
Date: Fri Sep 02 2005 - 09:14:05 EDT

  • Next message: Eric Schneider: "Re: PK Increment Step"

    Andrus answered a previous person like this:

    "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"

    On 9/2/05, Gentry, Michael (Contractor) <michael_gentr..anniemae.com>
    wrote:
    >
    > I believe the 20 you are referencing is how many PKs will be cached by
    > default (and this can be changed at run-time). So if your PK table has
    > a value of 1000 for a given table and new PKs are requested, it'll bump
    > it up to 1020 and then not request PKs for 20 more inserts into that
    > table. So, when doing multiple inserts, the cache saves trips to the DB
    > which can speed things up.
    >
    > -----Original Message-----
    > From: noba..andex.ru [mailto:noban@yandex.ru]
    > Sent: Friday, September 02, 2005 6:46 AM
    > To: cayenne-use..bjectstyle.org
    > Subject: PK Increment Step
    >
    >
    >
    > Hi!
    >
    > Is it possible to change PK AUTO INCREMENT step from 20 to other.
    > I`ve looked for answer in XML conf files, but didn`t found anything as
    > well as in API docs.
    >
    > One more question why Increment Step is set to 20? And what will
    > happen when PK will reach its maximum capacity?
    >
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Fri Sep 02 2005 - 09:14:07 EDT