当前位置:网站首页>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
边栏推荐
- 请教大家一个问题,用人用过flink sql的异步io关联MySQL中的维表吗?我按照官网设置了各种
- Capturing and sorting out external articles -- autoresponder, composer, statistics [III]
- [secretly kill little buddy pytorch20 days -day02- example of image data modeling process]
- 鹏城杯 WEB_WP
- Introduction to kubernetes
- Capture de paquets et tri du contenu externe - - autoresponder, composer, statistiques [3]
- Luogu deep foundation part 1 Introduction to language Chapter 7 functions and structures
- Basic preprocessing and data enhancement of image data
- Visiontransformer (I) -- embedded patched and word embedded
- 2022-2-14 acwing1027 grid access
猜你喜欢
Software testing skills, JMeter stress testing tutorial, obtaining post request data in x-www-form-urlencoded format (24)
UI automation test: selenium+po mode +pytest+allure integration
Basic preprocessing and data enhancement of image data
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
APEC industry +: father of the king of the ox mill, industrial Internet "king of the ox mill anti-wear faction" Valentine's Day greetings | Asia Pacific Economic media | ChinaBrand
gslb(global server load balance)技術的一點理解
Pengcheng cup Web_ WP
leetcode-540. A single element in an ordered array
Visiontransformer (I) -- embedded patched and word embedded
Hcie security Day10: six experiments to understand VRRP and reliability
随机推荐
What if the Flink SQL client exits and the table is emptied?
An expression that regularly matches one of two strings
gslb(global server load balance)技術的一點理解
Mysql database ----- common commands of database (based on database)
QFileDialog
Dahua series books
Base ring tree Cartesian tree
十大券商开户注册安全靠谱吗?有没有风险的?
flink sql-client 退出,表就会被清空怎么办?
Monkey/ auto traverse test, integrate screen recording requirements
MySQL - database backup
抓包整理外篇——————autoResponder、composer 、statistics [ 三]
Luogu deep foundation part 1 Introduction to language Chapter 6 string and file operation
Last week's content review
Analyse de REF nerf
Collection | pytoch common loss function disassembly
Mysql - - Index
90 后,辞职创业,说要卷死云数据库
Is it OK for fresh students to change careers to do software testing? The senior answered with his own experience
(5) Web security | penetration testing | network security operating system database third-party security, with basic use of nmap and masscan