当前位置:网站首页>Read and write models and organize notes
Read and write models and organize notes
2022-07-25 08:40:00 【Four fires】
Read the model
1、 Primary key read
The most common reading model , Say primary key , In fact, it also includes other index keys , Or union primary key .
Common implementation :hash, The time complexity can be close to O(1);B Trees or varieties : Time complexity is close to O(log(n)).
About B Trees and varieties :
B Trees (B- Trees ): In essence, it is an upgraded version of binary search tree , Become balanced N Fork search tree , This N The range of is adjusted according to the block size read by the disk at a time , This complexity log n The base number of is from 2 Into a larger number , Reduced the height of the tree . in addition to , There are some additional optimizations , For example, for the performance of insertion and deletion , Usually prepare some reserved space , As long as the space is found in the current block or adjacent blocks , It avoids all the backward offset operations of records with huge overhead .
B The steps of the tree :
- A tree m Step B Trees have at most m Kezi tree ;
- The root node has at least two subtrees ;
- Each non root branch node has at least ceil(m/2) Kezi tree ;
- Leaf nodes are all on the same layer ;
- Yes x Children's non leaf nodes happen to have x-1 Keywords in ascending order .
The picture is from This page .
B+ Trees : and B Trees are compared to , Changes include :
- All keyword information is placed in the leaf node ;
- All leaf nodes are strung into one linked list In order to search ;
- Store duplicate search keys .
For specific differences, please refer to 《Difference between B Tree and B+ Tree》,( The following is from ).
B* Trees in B+ Further improvements have been made on the basis of tree :
- Non leaf nodes add pointers to sibling nodes ( Used when the node is full , You can put data into brother nodes , Reduce node creation );
- Non leaf nodes must be at least 2/3 Full of ( The number of keywords must be at least the maximum 2/3).
2、 Specify page query
Specifying pages means having the concept of paging , For example DynamoDB Query interface design , You can pass in a LastEvaluatedKey Such an object , Locate the starting position of this page by reading the primary key . however , If you want to randomly specify the page number of the query , The complexity of this situation varies greatly in different implementations , Some can directly calculate the position of the page , Others need to start from the first page and go down page by page .
Common implementation : Specify starting position , In the case of conditional query, the data subset is returned .
3、 Range queries
First , Data can be sorted according to a certain attribute , Then there is the concept of range query . For example, queries where the user's age is within a certain range .
Common implementation :B Trees and their varieties ( In this case B+ Tree ratio B The superiority of trees is reflected ,B+ Trees can scan leaf nodes directly linked list that will do ).
4、 Full data scanning
This access model usually means low speed and high overhead , Generally used as asynchronous tasks , For example, report system , Do regular data statistics during low access periods . Generally, non key queries are also full data scanning in nature .
Example : Database full table scan ,Hadoop Data set processing task on .
5、 Full text search
Common implementation : Inverted index .
6、 Prefix / The suffix match
Prefix matching :Trie Trees ; The suffix match : Suffix tree . See 《Trie Comparison between tree and other data structures 》.
7、 Conditions of the query
Common implementation : Full table scan ;R Trees ;Space-filling Curve.
Write model
1、 Asynchronous update
Back first , Do not pay attention to the transactional nature of updates , The update operation is completed in the background , This method has the fastest result return speed .
2、 queue / deque
This situation is applicable to the case that the throughput is relatively large and very unstable , With the buffer function of queue ; There is also a problem of writing order , With the help of the order of priority queue .
3、 Batch write
In many cases, it is asynchronous data processing , Such as data backfilling 、 Batch data export, etc .
4、 Update according to the query results
Is to merge the two-step process of query and update , Make it atomic . such as Java Medium compareAndSet operation , For example, database update Statement follow where Clauses and so on .
5、 Insert or update
upsert, Like hash map Medium put, No matter whether the record exists before , Existence covers , Insert if it doesn't exist .
6、 Update to multiple replication
Almost all production storage systems will consider replication, For the problem of data reliability , Redundancy of multiple data at the software level is the only way .
The articles are all original without special indication , It shall not be used for any commercial purpose without permission , Please keep the integrity of reprint and indicate the source link 《 Four fire's nagging 》
边栏推荐
- Graduation project of wechat small program ordering system of small program completion works (7) Interim inspection report
- 【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)
- @Autowired注解的实现原理
- 游戏外挂怎么做?
- Wechat reservation applet graduation design of applet completion works (2) applet function
- Sun Tzu's art of war
- @Principle of Autowired annotation
- 【黑马程序员】Redis学习笔记002:持久化:RDB 和 AOF
- 记录两次多端排查问题的过程
- Graduation project of wechat small program ordering system of small program completion works (6) opening defense ppt
猜你喜欢

Foundation 32: page element positioning method XPath --- axis positioning method

Idea failed to start the project yamlexception Chinese file encoding format

QA robot sequencing model

The fifth day of MATLAB learning (cycle type)

This week's big news | FCC exposed Pico 4 VR all-in-one machine, and leipeng's parent company established a smart glasses laboratory

NVIDIA可编程推理加速器TensorRT学习笔记(二)——实操

How to set up a personal website for free

Redis best practices

【黑马程序员】Redis学习笔记002:持久化:RDB 和 AOF

PHP reports an error: classes\phpexcel\cell php Line(594) Invalid cell coordinate ESIGN1
随机推荐
ArcGIS Pro scripting tool (10) -- generate.Stylx style symbols from layers
DIY can decorate the mall system, you can also have!
R language error
Brush the title "sword finger offer" day01
为什么要使用MQ消息中间件?这几个问题必须拿下!
Foundation 32: page element positioning method XPath --- axis positioning method
[5g NR] UE registration rejection reason
Nuscenes dataset 3D mot demo, end-to-end target detection and tracking, joint detection and tracking framework
Wechat applet ordering system graduation design of applet completion works (2) applet function
How to do the game plug-in?
How to set up a personal website for free
Network solutions for Alibaba cloud services
Redis分片集群
【黑马程序员】Redis学习笔记001:Redis简介+五种基本数据类型
[dark horse programmer] redis learning notes 005: enterprise level solutions
How can hospitals achieve efficient and low-cost operation and maintenance? Is there any software that can meet it?
Mogdb 3.0 how to add a standby database in the environment of one active and one standby
Wechat reservation applet graduation design of applet completion works (3) background function
Message Oriented Middleware
技术面②Mysql中的索引(index)类型有哪些并简要介绍一下?什么时候需要创建索引?什么时候不需要创建索引?为什么创建索引后查询速度会提高?