B
B
beduin012015-07-30 22:21:28
Database
beduin01, 2015-07-30 22:21:28

Where are graphs useful?

I met a couple of times about graph databases, where, along with NoSQL, graphs are also used. In what cases it in a DB can be useful?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2015-07-31
@beduin01

> where, along with NoSQL, graphs are also used in
an interesting formulation)
> In what cases can this be useful in a database?
in all tasks where the depth and "diversity" of relationships between entities is comparable to the number of these entities.
Let's take two simple situations as an example:
1) there is an order in the online store with a certain number of ordered goods. Regardless of whether you use a relational model or some other one, you will most likely be comfortable considering two entities: Order and OrderItem. In the first one, you will add information about the entire order (information about the client, order date, selected delivery method, payment method, etc.). In the second entity, you will have, for example, the id of the product and its quantity (1 microwave, 2 flash drives, 5 CD-Rs). Now, in order for you to know that some OrderItems are related to a particular Order, you should model the relationship in one way or another. If you have a SQL database, you will add the Id field to the Order, and the OrderId field to the OrderItem and make a foreign key. If you have a document base, then, for example, you can place the entire order with its elements in one json document, and the elements of the order will be sub-objects in the items array of the order object. Over time, you will have many orders and many elements of orders. However, the links between them will always be quite simple: each order will have a certain number of elements. You will not link the orders themselves, just as you will not link the elements of the order. The depth of entity relationships will be limited to one transition.
2) you have a social network (yes, I know, a banal example), and of course you have the "add to friends" function. Unlike the previous example, we can take only one entity for consideration - "user", however, due to the fact that everyone can friend everyone, even for one entity you will have a very large set of actual connections, potentially with great depth (acquaintances of acquaintances etc.).
Both problems can theoretically be solved using SQL databases, but graph databases will win in the second task in complex queries for processing relationships (say, find all my friends who go to such and such an event). This gain stems from the architectural features of a graph database, for example, in a graph database, a “pointer” to the physical location of the related data is often saved while saving a link, while in a relational database, links are modeled by foreign keys, and require search operations to be performed during processing (even if indexed). In general, in a sense, links in a graph database are first-class citizens, but in a relational database, links are modeled by the programmer (integrity constraints like foreign keys just help him keep the data in a consistent state).

M
Maxim Moseychuk, 2015-07-30
@fshp

In cartography.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question