What is the difference between relational and non-relational databases?

The current mainstream relational databases include Oracle, DB2, Microsoft SQL Server, Microsoft Access, MySQL, etc.

Non-relational databases include NoSql and Cloudant.

Nosql and relational database comparison?
Advantages:
1) Cost: The nosql database is simple and easy to deploy, and it is basically open source software. It does not need to spend a lot of money to purchase and use it like using oracle, and it is cheaper than relational databases.
2) Query speed: nosql database stores data in cache, relational database stores data in hard disk, and the natural query speed is far less than that of nosql database.
3) Format of stored data: The storage format of nosql is key, value form, document form, image form, etc., so it can store various formats such as basic types and objects or collections, while the database only supports basic types.
4) Scalability: Relational databases have the limitation of multi-table query mechanisms like join, which makes it difficult to expand.
Disadvantages:
1) The tools and materials for maintenance are limited, because nosql is a new technology and cannot be compared with the technology of relational databases for more than 10 years.
2) It does not provide support for sql. If it does not support industry standards such as sql, it will result in a certain cost for users to learn and use.
3) Does not provide relational database processing of things.

Advantages of non-relational databases: 1. Performance NOSQL is based on key-value pairs, which can be imagined as the correspondence between the primary key and value in the table, and does not need to be parsed by the SQL layer, so the performance is very high. 2. Scalability is also based on key-value pairs, and there is no coupling between data, so it is very easy to scale horizontally.

Advantages of relational databases: 1. Complex queries can use SQL statements to easily do very complex data queries between one table and multiple tables. 2. Transaction support enables the realization of data access requirements with high security performance. For these two types of databases, each other's strengths are their weaknesses, and vice versa.

Relational databases represent all data in binary representations of rows and columns.

Advantages of relational databases:

  1. Keeping data consistent (transactions)

2. Due to the premise of standardization, the overhead of data update is very small (the same field basically has only one place)

  1. Complex queries such as Join can be performed

The ability to maintain data consistency is the biggest advantage of relational databases.

Disadvantages of relational databases:

bad handling

  1. Write processing of large amounts of data

  2. Make index or table schema changes for tables with data updates

  3. Applies when the field is not fixed

  4. Processing of simple queries that need to return results quickly

– Write processing of large amounts of data

The concentration of reading and writing on one database makes the database overwhelmed. Most websites have used master-slave replication technology to achieve read-write separation to improve the read-write performance and the scalability of the read database.

Therefore, when a large number of data operations are performed, the database master-slave mode will be used. The main database is responsible for data writing, and the secondary database is responsible for data reading. It is relatively simple to add secondary databases to achieve scale, but there is no simple way to solve the problem of scale when writing data.

First, if you want to scale data writing, you can consider increasing the number of primary databases from one to two, and use them as binary primary databases that are replicated with each other. Indeed, this can reduce the load of each primary database by half. However, there will be conflicts in the update processing, which may cause data inconsistency. In order to avoid such problems, it is necessary to allocate requests for each table to the appropriate master database for processing.

Second, you can consider dividing the database and placing them on different database servers, such as placing different tables on different database servers. Database segmentation can reduce the amount of data on each database server, so as to reduce hard disk IO It can realize high-speed processing on memory. However, since the join processing cannot be performed between the tables on different servers that store the words separately, these problems need to be considered in advance when the database is divided. After the database is divided, if the join processing must be performed, it must be associated in the program. This is very difficult.

– Do indexes or table structure changes for tables with data updates

When using a relational database, in order to speed up the query, it is necessary to create an index, and in order to add necessary fields, the table structure must be changed. are impossible. If you need to perform some time-consuming operations, such as creating an index for a table with a large amount of data or changing its table structure, you need to pay special attention, and the data may not be updated for a long time.

– Application when the field is not fixed

If the fields are not fixed, it is also difficult to use a relational database. Some people will say that it is enough to add a field when needed. This method is not impossible, but in actual application, repeated table structure changes are made every time. is very painful. You can also pre-set a large number of preliminary fields, but in this case, it is easy to lose the corresponding state of the fields and data over time, that is, which fields hold which data.

– Processing of simple queries that need to return results quickly (“simple” here means no complex query conditions)

This is not a disadvantage, but in any case, relational databases are not good at returning results quickly for simple queries, because relational databases use a special SQL language for data reading, and it needs to parse SQL and Vietnam , and there are additional overheads such as locking and unlocking tables. This is not to say that relational databases are too slow, but just want to tell you that if you want high-speed processing of simple queries, there is no need to use relational databases. Not possible.


NoSQL database

Relational databases are widely used and can perform complex queries such as transaction processing and table joins. In contrast, NoSQL databases are only used in specific fields and basically do not perform complex processing, but they just make up for the deficiencies of relational databases listed above.

advantage:

Easy data dispersal

The relationship between various data is the main reason for the name of the relational database. In order to perform join processing, the relational database has to store the data in the same server, which is not conducive to the dispersion of the data, which is also the relational database is not good at The reason for the write processing of large data volumes. On the contrary, NoSQL databases originally do not support Join processing, and each data is designed independently, so it is easy to distribute data on multiple servers, thus reducing the amount of data on each server. Even if a large amount of data is to be written, It becomes easier, and the reading of data is of course just as easy.

Typical NoSQL database

Transient key-value stores (memcached, Redis), persistent key-value stores (ROMA, Redis), document-oriented databases (MongoDB, CouchDB), column-oriented databases (Cassandra, HBase)

1. Key-value storage

Its data is stored in the form of key-value. Although it is very fast, it can basically only obtain data through a completely consistent query of the key. According to the way the data is saved, it can be divided into temporary, permanent and both. With three.

(1) Temporary

  所谓临时性就是数据有可能丢失,memcached把所有数据都保存在内存中,这样保存和读取的速度非常快,但是当memcached停止时,数据就不存在了。由于数据保存在内存中,所以无法操作超出内存容量的数据,旧数据会丢失。总结来说:

  。在内存中保存数据

  。可以进行非常快速的保存和读取处理

  。数据有可能丢失

(2) Permanent

   所谓永久性就是数据不会丢失,这里的键值存储是把数据保存在硬盘上,与临时性比起来,由于必然要发生对硬盘的IO操作,所以性能上还是有差距的,但数据不会丢失是它最大的优势。总结来说:

   。在硬盘上保存数据

   。可以进行非常快速的保存和读取处理(但无法与memcached相比)

   。数据不会丢失

(3) Both

   Redis属于这种类型。Redis有些特殊,临时性和永久性兼具。Redis首先把数据保存在内存中,在满足特定条件(默认是 15分钟一次以上,5分钟内10个以上,1分钟内10000个以上的键发生变更)的时候将数据写入到硬盘中,这样既确保了内存中数据的处理速度,又可以通过写入硬盘来保证数据的永久性,这种类型的数据库特别适合处理数组类型的数据。总结来说:

   。同时在内存和硬盘上保存数据

   。可以进行非常快速的保存和读取处理

   。保存在硬盘上的数据不会消失(可以恢复)

   。适合于处理数组类型的数据

The document-oriented database

MongoDB, CouchDB fall into this category, they are NoSQL databases but distinct from key-value stores.

(1) The table structure is not defined

   Even if the table structure is not defined, it can be used as if the table structure is defined, and the trouble of changing the table structure is also saved.

(2) Complex query conditions can be used

   Unlike key-value storage, document-oriented databases can obtain data through complex query conditions. Although they do not have the processing capabilities of relational databases such as transaction processing and Join, other processing other than initial processing can basically be achieved. .

3. Column-oriented database

Cassandra, HBae, HyperTable belong to this type, and due to the explosive growth of data volume in recent years, this type of NoSQL database is particularly attractive.

Ordinary relational databases store data in behavioral units, and are good at read-in processing in behavioral units, such as the acquisition of data under specific conditions. Therefore, relational databases are also known as row-oriented databases. In contrast, column-oriented databases store data in columns and are good at reading in data in columns.

The column-oriented database is scalable, and even if the data increases, it will not reduce the corresponding processing speed (especially the writing speed), so it is mainly used when a large amount of data needs to be processed. In addition, it is also very useful as a memory for batch programs to update large amounts of data. However, because the column-oriented database is very different from the current way of thinking about database storage, it is very difficult to apply.

Summary: Relational databases and NoSQL databases are not opposite but complementary, that is, relational databases are usually used, and NoSQL databases are used when NoSQL is suitable, so that NoSQL databases can make up for the deficiencies of relational databases.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324504528&siteId=291194637
Recommended