当前位置:网站首页>How to store null value on the disk of yyds dry inventory?
How to store null value on the disk of yyds dry inventory?
2022-07-03 21:40:00 【Official account javaedge】
1 Why not save it directly NULL?
NULL List of values , The possible field values in a row of data are NULL, such as nickname Field , Allow for NULL, When the storage , If there is no assignment , The field value is NULL.
Suppose this field is NULL When the value is stored on disk , Is in accordance with the “NULL” String storage , Isn't it a waste of storage space and strange ?
2 How to store ?
Not through string , But through binary bit Bit storage , It is assumed that the values of multiple fields in a row of data are NULL, So the of these fields NULL, It'll take bit The bit form is stored in NULL List of values .
The following table :
CREATE
TABLE customer
(
name
VARCHAR
(
10
)
NOT
NULL
,
address
VARCHAR
(
20
)
, gender
CHAR
(
1
)
,
job
VARCHAR
(
30
)
,
school
VARCHAR
(
50
)
) ROW_FORMAT
=COMPACT
;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
Yes 4 Variable length fields , There is also a fixed length field ,name Statement NOT NULL, other 4 All fields are possible NULL
How can the following row of data be stored on disk :
jack NULL m NULL xx_school
- 1.
There are two fields NULL
3 Disk storage format of a row of data
Think about the row of case data in the table above , How to store on disk , Because it has multiple variable length fields , Multiple fields are allowed to be NULL. First of all, let's review , The storage format of a row of data on disk should be as follows :
Variable length field length list
NULL List of values Header information column1
=value1 column2
=value2 ... columnN
=valueN
- 1.
4 Variable length fields , Put first in reverse order school Length of field , Put again job、address、name The value length of several fields ?
But there is one problem to distinguish , If this variable length field value is NULL, There is no need to store its value length in the variable length field length list , So the data in the above line , Only name and school Two variable length fields have values , Put their lengths in the variable length field length list in reverse order :
0x09
0x04
NULL List of values Header information column1
=value1 column2
=value2 ... columnN
=valueN
- 1.
All allowable values are NULL Field of , It doesn't have to be worth NULL, As long as it is allowed to NULL Field of , Each field has a binary bit A value :
- bit The value is 1 That is the NULL
- bit The value is 0 The explanation is not NULL
For example, above 4 Both fields are allowed to be NULL, Everyone will have one bit position , The value of this row of data is
jack NULL m NULL xx_school
- 1.
among 2 The fields are null,2 A field is not null, therefore 4 individual bit It should be :1010
But in fact NULL Value list , Put in reverse order , therefore NULL In the value list :0101, The overall data in this row is as follows :
0x09 0x04 0101 Header information column1=value1 column2=value2 ... columnN=valueN
- 1.
actual NULL When storing the value list , Generally at least 8 individual bit Multiple of bits , Insufficient 8 individual bit The high position is filled 0, So the actual storage is as follows :
0x09 0x04 00000101 Header information column1=value1 column2=value2 ... columnN=valueN
- 1.
4 How to read a row of data on the disk ?
Disk data storage format :
0x09 0x04 00000101 Header information column1=value1 column2=value2 ... columnN=valueN
- 1.
First reading :
- Variable length field length list
You know there are several variable length fields
- NULL List of values
Which variable length fields are NULL
From the variable length field length list, it is resolved that it is not NULL Value length of variable length field , Then you also know which fields are NULL. Based on this information , From the actual column value storage area , Read out the value of each field .
- Variable length field value , Just read by the length of the value , if NULL, I knew he was a NULL, No value stored
- Fixed length field , Read according to the fixed length
边栏推荐
- Mysql - - Index
- Functions and differences between static and Const
- The "boss management manual" that is wildly spread all over the network (turn)
- Redis data migration (II)
- 内存分析器 (MAT)
- Global and Chinese market of AC induction motors 2022-2028: Research Report on technology, participants, trends, market size and share
- Persistence of Nacos
- Experience summary of database storage selection
- Remember the experience of automatically jumping to spinach station when the home page was tampered with
- (5) User login - services and processes - History Du touch date stat CP
猜你喜欢

How PHP drives mongodb

What is the difference between res.send() and res.end() in the node express framework

Hcie security Day10: six experiments to understand VRRP and reliability

Is it OK for fresh students to change careers to do software testing? The senior answered with his own experience

Persistence of Nacos

Memory analyzer (MAT)

Getting started with postman -- environment variables and global variables

No matter how hot the metauniverse is, it cannot be separated from data

Décompiler et modifier un exe ou une DLL non source en utilisant dnspy

Nacos common configuration
随机推荐
MySQL——索引
鹏城杯 WEB_WP
Compréhension de la technologie gslb (Global Server load balance)
Après 90 ans, j'ai démissionné pour démarrer une entreprise et j'ai dit que j'allais détruire la base de données Cloud.
How PHP drives mongodb
内存分析器 (MAT)
Why use pycharm to run the use case successfully but cannot exit?
常用sql集合
Link aggregation based on team mechanism
Decompile and modify the non source exe or DLL with dnspy
How PHP adds two numbers
运维各常用命令总结
Scientific research document management Zotero
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
The post-90s resigned and started a business, saying they would kill cloud database
Notes on MySQL related knowledge points (startup, index)
Experience summary of database storage selection
[gd32l233c-start] 5. FLASH read / write - use internal flash to store data
Getting started with postman -- environment variables and global variables
Collections SQL communes