Re: [GENERAL] Dealing with ordered hierarchies - Mailing list pgsql-general

From Peter J. Holzer
Subject Re: [GENERAL] Dealing with ordered hierarchies
Date
Msg-id 20170731201100.GE29214@hjp.at
Whole thread Raw
In response to Re: [GENERAL] Dealing with ordered hierarchies  (Tim Uckun <timuckun@gmail.com>)
List pgsql-general
On 2017-07-25 01:15:56 +1200, Tim Uckun wrote:
> I don't like the approach with a large increment. It would mean complicated
> logic to see if you filled the gap and then update all the other peers if you
> did. It sounds like the re-order is going to be expensive no matter what. My
> primary concern are race conditions though. What if two or more users are
> trying to update the hierarchy either by inserts or updates? I can definitely
> see a situation where we have issues transactions trip over each other.

You could add a unique index over (parent, sequence_number). That way
two transactions won't be able to add a node with the same sequence
number under the same parent. You will have to handle duplicate key
errors, though.

        hp

--
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp@hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>

Attachment

pgsql-general by date:

Previous
From: Dmitry Lazurkin
Date:
Subject: Re: [GENERAL] Perfomance of IN-clause with many elements and possiblesolutions
Next
From: Tom Lane
Date:
Subject: Re: [GENERAL] Partitioned TEMP tables