Any databases that allow you to specify versions of optimized versions of the data in your tables

I know that Redis allows you to optimize the structure of complex data structures. But I am wondering if there are any databases or design patterns that allow you to specify optimized versions of the blocks of your database.

For example, to quickly search through text, you need to resort to solr to search, which is its own database to optimize string browsing.

Another example: if you want to return an easily movable role object to the user, you might need the following:

var user = { roles: { admin: true, principal: true, ... } } 

But the database probably has a table rolesand a table users, so you do a join and retrieve them back and end up creating this data structure manually in your code.

The question is, is there something that allows you to specify the data structure / form of your data directly in the database for faster searches. Databases allow you to have indexes, which are a primitive solution. Consider if there are more complex examples. For example, a great way to check if an element has a tag:

user.tags[tagName]

This means your tags look like this:

{ tagA: true, tagB: true, ... }

But you will probably get them from the database as follows:

[ { name: tagA }, { name: tagB } ]

, , , " " "", , . , - .

+4
3

, , , SQLite , PostgreSQL, . . , - Django , RMDB, .

RMDB OODB , (, , ). - /.

+1

key-val (, Redis ) , .

, - - , redis, , rdbms

Id -

- , , .

, mongodb

MongoDB - ,

var user = { roles: { admin: true, principal: true, ... } }

> db.createCollection('user');
{ "ok" : 1 }
> db.user.insert({roles: ['admin', 'principal']})
WriteResult({ "nInserted" : 1 })

> db.user.insert({roles: ['admin']})
WriteResult({ "nInserted" : 1 })

> db.user.find()
{ "_id" : ObjectId("5a8f1ae9442b9e31f71b156c"), "roles" : [ "admin", "principal" ] }
{ "_id" : ObjectId("5a8f1c46442b9e31f71b156d"), "roles" : [ "admin" ] }

? .

{ tagA: true, tagB: true, ... }

( - , )

> db.user.find({roles: {$in: ['principal']}})
{ "_id" : ObjectId("5a8f1ae9442b9e31f71b156c"), "roles" : [ "admin", "principal" ] }

!

> db.user.ensureIndex({roles: 1})

> db.user.find({roles: {$in: ['principal']}}).explain()
...
        "winningPlan" : {
            "stage" : "FETCH",
            "inputStage" : {
                "stage" : "IXSCAN",
                "keyPattern" : {
                    "roles" : 1
                },
                "indexName" : "roles_1",
...

CRUD, , aggregation, ,

Theres , , , // .

, , rdbms + k/v, , memcached/ redis

0

(OODB) , . , .

https://en.wikipedia.org/wiki/Object_database

https://en.wikipedia.org/wiki/Comparison_of_object_database_management_systems

( NoSQL) ( JSON). , ( ). , . (.. , / ?)

, - . ( ). --Mappers (ORMS).

Some traditional relational databases can store hierarchical structures in JSON or XML columns. This provides some benefit from a schema-based document database (noSQL). You can use XPath or special JSON expressions to query the structure stored in a column.

CREATE TABLE `book` (
  `id` int(ii) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL default '',
  `tags` json DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

SELECT * FROM `book` 
WHERE JSON_CONTAINS(tags, '["JavaScript"]');

These descriptions are broad generalizations, and you can find examples of various functions and methods in the products that one of these labels refers to. For example, not all noSQL databases have the following schema: Solr and Cassandra require that schemas be defined before a record.

0
source

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


All Articles