[LRUG] Scoping sequences to a parent

Andrew Stewart boss at airbladesoftware.com
Fri Sep 2 02:49:17 PDT 2016


> Is it impractical to just use an autoincrementing column (as you suggest) to give the children an explicit ordering, but then “number” them by their derived index rather than the concrete value of that column?

I suppose it depends on whether the number can be derived in an efficient, lock-free way.

Did you have a particular derivation in mind?  The first two that come to mind are:

  select max(number) from children where parent_id = blah

  select count(id) from children where parent_id = blah

I'm aiming for client code to be able to create a child of the parent, such that once creation has finished the child has its "number" already.


More information about the Chat mailing list