How do you design a schema to efficiently query nested elements in a key database?

I use Mnesia with Erlang, but this question applies to any db key value like couchdb etc.

I am trying to get out of the thinking process of an RDBMS, but I cannot wrap my head around how to effectively implement this scheme.

Let's say I have a user entry and it has many SubItemA entries, many SubItem B entries, so:

User
-SubItem A
--SubItem B
...

I need to run queries in SubItem B. Is it efficient to do this when it is nested? Should I just normalize it so it is faster?

I heard about some people using data duplication, so the data is both nested and separate, is it funny or is it really useful in some cases?

+3
source share
4 answers

The main question is: when is the performance good enough ?

Scanning tables A user dictionary is not overhead if you really need to examine each SubItem B element in detail, and size B dominates the overall size of the dictionary.

If this is not so good, normalize it so that you cannot read data in all User and SubItem files. Before you query SubItem B. Use a composite key, such as (UserId, SubItemAId, SubItemBId), in the SubItem B dictionary, if the table is ordered so that you can execute range queries.

User/SubItem A, , .

+3

CouchDb SubItems. . , , , , , /.

+1

Mnesia, CouchDB, , CouchDB, ( "" ), .

:

function(doc) {
    for(var i in doc.subitems_a) {
        var subitem_a = doc.subitems_a[i];

        for(var j in doc.subitems_a[item_a].subitems_b) {
            var subitem_b = subitem_a.subitems_b[j];

            emit(subitem_b, doc)
        }
    }
}

SubItem Bs, , .

+1

. CouchDB , Mnesia - . ? ? ?

, , . , . .

0

Source: https://habr.com/ru/post/1704153/


All Articles