Re: [GENERAL] Dealing with ordered hierarchies

Поиск
Список
Период
Сортировка
От Achilleas Mantzios
Тема Re: [GENERAL] Dealing with ordered hierarchies
Дата
Msg-id 3843ccee-1341-edca-f430-49a0518f62e9@matrix.gatewaynet.com
обсуждение исходный текст
Ответ на [GENERAL] Dealing with ordered hierarchies  (Tim Uckun <timuckun@gmail.com>)
Список pgsql-general
On 24/07/2017 10:02, Tim Uckun wrote:
> I have read many articles about dealing with hierarchies in postgres including nested sets, ltree, materialized
paths,using arrays as parentage,  CTEs etc but nobody talks about the following scenario. 
>
> Say I have a hierarchy like this
>
> 1
> 1.1
> 1.1.1
> 1.1.2
> 1.2
> 1.3
> 2
> 2.1
>
> In this hierarchy the order is very important and I want to run frequent(ish) re-ordering of both subsets and entire
treesand even more frequent inserts. 
>
> Scenario 1: I want to insert a child into the 1.1 subtree. The next item should be 1.1.3 and I can't figure out any
otherway to do this other than to subquery the children and to figure out the max  
> child ID, add one to it which is a race condition waiting to happen.
>
> Scenario 2: I now decide the recently inserted item is the second most important so I reset the ID to 1.1.2 and then
increment1.1.2 (and possibly everything below).  Again this is both prone to  
> race conditions and involves a heavy update.
>
> Is there a better way to deal with this or is the complexity unavoidable?
Maybe you could try a hybrid approach with genealogical paths, represented by arrays, and a (possible bidirectional)
linkedlist storing the siblings of the same parent. 
Basically what you'd normally want is to convert your problem into something that can be represented in such a way that
itcan run fast on postgresql. 
>
> I should state that like most database reads will be much more frequent than writes and inserts will be more frequent
thanupdates (re-ordering) 


--
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt



В списке pgsql-general по дате отправления:

Предыдущее
От: Tim Uckun
Дата:
Сообщение: [GENERAL] Dealing with ordered hierarchies
Следующее
От: Dmitry Lazurkin
Дата:
Сообщение: Re: [GENERAL] Perfomance of IN-clause with many elements and possiblesolutions