NULL如何存储在数据库中? [英] How are NULLs stored in a database?

查看:444
本文介绍了NULL如何存储在数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇如何将NULL存储到数据库中吗?



它当然取决于数据库服务器,但是我想对此有一个大致的了解






首先尝试:



假设服务器放置了



您是否很幸运,可以使用$
来获取NULL值?




  ... WHERE字段='未定义的值(请记住,可以是任何东西...)'






第二次尝试:



服务器是否有标志或某处指示该字段为NULL的任何元数据?



然后服务器必须读取此元数据以验证该字段。



如果元数据指示为NULL值,并且查询中没有 field IS NULL字段,则
则将忽略该记录。






似乎太简单了...

解决方案

在Pos上tgreSQL,它使用可选的位图,每列一位(0为null,1不为null)。如果位图不存在,则所有列都不为空。



这与数据本身的存储完全分开,但与行在同一页上(因此,将行和位图同时读取)。



参考:




I'm curious to know how NULLs are stored into a database ?

It surely depends on the database server but I would like to have an general idea about it.


First try:

Suppose that the server put a undefined value (could be anything) into the field for a NULL value.

Could you be very lucky and retrieve the NULL value with

...WHERE field = 'the undefined value (remember, could be anything...)'


Second try:

Does the server have a flag or any meta-data somewhere to indicate this field is NULL ?

Then the server must read this meta data to verify the field.

If the meta-data indicates a NULL value and if the query doesn't have "field IS NULL", then the record is ignored.


It seems too easy...

解决方案

On PostgreSQL, it uses an optional bitmap with one bit per column (0 is null, 1 is not null). If the bitmap is not present, all columns are not null.

This is completely separate from the storage of the data itself, but is on the same page as the row (so both the row and the bitmap are read together).

References:

这篇关于NULL如何存储在数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆