Relational and non-relational databases

Source: Internet
Author: User
Tags cassandra ibm db2 memcached couchdb value store

NoSQL, refers to a non-relational database. From the above narrative, you can see that the tables in the relational database are stored in a formatted data structure, and the composition of each tuple field is the same, even though not all of the fields are required for each tuple, but the database assigns all the fields to each tuple, which makes it easier to connect the table to the table, But from another point of view it is also a factor in relational database performance bottlenecks. Instead of relational databases stored in key-value pairs, its structure is not fixed, each tuple can have a different field, each tuple can increase or decrease some of its own key-value pairs as needed, so that the fixed structure will not be limited, you can reduce the cost of some time and space.

relational databases store data in rows and columns for easy user understanding. This series of rows and columns is called a table, and a set of tables makes up a database. The user uses a query to retrieve data from the database. A query is a SELECT statement that specifies rows and columns for a database. A relational database typically contains the following components:
Client applications (clients)
Database Server (server)
Databases (database)
Structured Query Language (SQL) client-side and server-side bridges, the client uses SQL to send requests as server-side, and the server returns the results required by the client side. Today's popular large relational databases include IBM DB2, IBM UDB, Oracle, SQL Server, SyBase, Informix, and more.
The basic form of data storage and management in relational database management system is two-dimensional table.
A relational database is a set of information that has been organized into a table structure. This information is stored as a table in physical media such as disk, tape, and so on. Each table can have more than one row, and each row is split into multiple columns.

A set of mathematical foundations for relational databases, such as relational algebra and relational operations, are the only theoretical basis for relational databases.

We are familiar with the table structure in our daily life, such as students ' grades, curriculum, etc., which are organized in two-dimensional ways, both in rows and columns. This information can exist in various forms, such as printed on paper, displayed on the computer's screen, recorded in people's minds, on the server's disk, and so on.

Now need a convenient means to manage this information, preferably at any time can query, add, delete and update, this is the data

Relationship:

• A relationship is a two-dimensional table that satisfies a certain condition, and a row in a table is called a tuple of relationships used to store an instance of a thing;

A column is called a property of a relationship that describes a feature of an entity. A table is a collection of related entities that are made up of a group. So the table and

Entity sets these two words can often be used interchangeably.

• A relationship is a two-dimensional table that crosses rows and columns, and all data for each column (attribute) is of the same data type, and each column has a

Column name, the order of the columns in the table is irrelevant; any two rows (tuples) in the table cannot be the same, and the order of the rows in the table is irrelevant.

To

Characteristics of the relationship:

• Each row of a relationship defines an entity for an entity set, and each column defines an attribute of the entity

• Each row must have a master code, which is an attribute group (which can be a property) that uniquely identifies an entity

• Each column represents an attribute and the column name cannot be duplicated

• Each value of the column must be the same as the type of the corresponding property

• column has a range of values called domains

• Columns are indivisible minimum data items

• The order of rows and columns does not matter to the user

relational database and NoSQL

The relational database represents all of the data through the two-dollar representation of rows and columns.

The benefits of a relational database:

1. Maintain data consistency (transaction processing)

2. Due to standardization, the cost of updating data is small (the same fields are basically only one place)

3. Complex queries such as joins can be made

One of the best advantages of relational databases is the ability to maintain data consistency.

The lack of a relational database:

Not good at handling

1. Write processing of large amounts of data

2. Index or table structure (schema) changes for tables with data updates

3. Apply when field is not fixed

4. Handling of Quick return results for simple queries

--write processing of large amounts of data

Read and write are concentrated on a database overwhelmed by the database, most sites have used master-slave replication technology to achieve read and write separation to improve read and write performance and the scalability of reading library.

Therefore, the database master-slave mode is used when a large number of data operations are performed. Data writing is responsible for the main database, the data read in by the database is responsible for, can be relatively simple by increasing the scale from the database, but there is no easy way to write data to solve the scale problem.

First, if you want to scale the data write, you can consider the main database from one to two, as a mutual associated replication of the two-yuan primary database use, it is possible to reduce the load per primary database, but the update processing will conflict, may result in inconsistent data, in order to avoid such a problem, Each table request needs to be assigned to the appropriate primary database for processing.

Second, the database can be divided into separate, placed on different database servers, such as the different tables placed on different database servers, database segmentation can reduce the amount of data on each database server, in order to reduce the input of hard disk IO, output processing, to achieve high-speed memory processing. However, because the separate storage words on different server tables can not be join processing, the database segmentation needs to consider these issues in advance, after the database segmentation, if it is necessary to join processing, it must be in the program to associate, this is very difficult.

--indexing or table structure changes for tables with data updates

When using the relational database, in order to speed up the query needs to create an index, in order to increase the necessary fields must change the table structure, in order to do these processing, the table needs to be shared lock, during which data changes, updates, insertions, deletions and so on are not possible. If you need to take some time-consuming actions, such as creating an index on a table with a larger amount of data or altering its table structure, you need to pay special attention to the fact that data may not be updated over a long period of time.

--Application when the field is not fixed

If the field is not fixed, the use of relational database is also more difficult, some people will say, need to add a field to be able to, such a method is not not possible, but in the actual use of each time repeated table structure changes is very painful. You can also preset a large number of pre-fields, but in this case, it is easy to get rid of the corresponding state of the field and data, that is, which field holds the data.

--the processing of a simple query that requires a quick return of results ("simple" here refers to the absence of complex query conditions)

This is not a disadvantage, but in any case, the relational database is not good at quickly return the results of simple queries, because the relational database is the use of specialized SQL language for data reading, it needs to parse SQL and Vietnam, as well as locking and unlocking the table and so on, such as the additional cost, This is not to say that relational databases are too slow, but just to tell you that if you want to handle simple queries quickly, it is not necessary to use a relational database.

---------------------------

NoSQL Database

The relational database is widely used, and can perform complex queries such as transaction processing and table connection. In contrast, NoSQL databases are only used in specific areas and are largely non-complex, but they compensate for the shortcomings of the relational databases enumerated earlier.

Advantages:

Easy dispersion of data

The relationship between the data is the main reason for the name of the relational database, in order to join processing, the relational database has to store the data in the same server, which is not conducive to the dispersion of data, which is the relational database is not good at large data volume of the write processing reasons. In contrast, NoSQL databases do not support join processing, each data is designed independently, it is easy to spread the data across multiple servers, so reduce the amount of data on each server, even to deal with a large number of data write, it becomes easier, the data read into the operation of course also easy.

A typical NoSQL database

Temporary key-value storage (memcached, Redis), persistent key-value storage (ROMA, Redis), document-oriented database (MongoDB, CouchDB), column-oriented database (Cassandra, HBase)

One, key value storage

Its data is stored in the form of a key value, although it is very fast, but basically only through the key of the full consistent query to obtain data, according to the way the data can be divided into temporary, permanent and both of the three.

(1) Temporary

The so-called temporary is the data can be lost, memcached all the data in memory, so that the speed of saving and reading is very fast, but when the memcached stopped, the data will not exist. Data that exceeds the memory capacity cannot be manipulated because the data is kept in memory, and the old data is lost. To summarize, say:

。 Saving data in memory

。 Enables very fast save and read processing

。 Data is likely to be lost

(2) Permanent

The so-called permanent is the data will not be lost, here the key value of the store is to save data on the hard disk, compared with the temporary, because the inevitable to occur to the hard disk IO operation, so there is still a gap in performance, but the data will not be lost is its greatest advantage. To summarize, say:

。 Saving data on a hard disk

。 Very fast save and read processing possible (but not comparable to memcached)

。 Data is not lost

(3) both

Redis belongs to this type. Redis is special, temporary and permanent. Redis first stores the data in memory and writes the data to the hard disk when certain conditions are met (by default, more than 15 minutes, more than 10 in 5 minutes, and more than 10,000 keys in 1 minutes), which ensures the processing speed of the in-memory data. You can also write to the hard disk to ensure that the data is permanent, this type of database is particularly suitable for processing array type of data. To summarize, say:

。 Save data on both memory and hard disk

。 Enables very fast save and read processing

。 The data saved on the hard drive will not disappear (can be restored)

。 Suitable for handling data of array types

II. Document-oriented database

MongoDB, couchdb belong to this type, they belong to a NoSQL database, but differ from the key-value store.

(1) Do not define table structure

Even if you do not define a table structure, you can use it as you would define a table structure, and save the hassle of altering the table structure.

(2) Complex query conditions can be used

Unlike a key-value store, a document-oriented database can fetch data through complex query conditions, although it does not have the processing power of transactional and join relational databases, but other processing is basically possible outside of the initial process.

Third, column-oriented database

Cassandra, Hbae, and hypertable are of this type, and this type of NoSQL database is especially noticeable because of the explosive growth in data volumes in recent years.

The common relational database is to store the data in the behavioral unit, which is good at the reading processing of the behavior unit, such as the acquisition of the specific condition data. Therefore, the relational database is also a row-oriented database. In contrast, a column-oriented database stores data as a unit, and is adept at reading the data in columns.

A column-oriented database is extensible, and it is primarily used in situations where large amounts of data need to be processed, even if the data increase does not degrade the processing speed (especially the write speed). It is also useful to update large amounts of data as a batch program's memory. However, because the column-oriented database is very different from the current thinking mode of database storage, it is very difficult to apply.

Summary: relational databases and NoSQL databases are not opposites but complementary relationships, that is, using relational databases in general, and using NoSQL databases when it is appropriate to use NoSQL, to make up for the lack of a relational database for NoSQL databases.

Relational and non-relational databases

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.