fixes for nullable.md

This commit is contained in:
Ivan Blinkov 2018-09-06 19:32:20 +03:00
parent 21712a5ea9
commit a2a808c68a

View File

@ -2,27 +2,20 @@
# Nullable(TypeName)
Allows you to work with the `TypeName` value or without it ([NULL](../query_language/syntax.md#null-literal)) in the same variable, including storage of `NULL` tables with the `TypeName` values. For example, a `Nullable(Int8)` type column can store `Int8` type values, and the rows that don't have a value will store `NULL`.
Allows to store special marker ([NULL](../query_language/syntax.md#null-literal)) that denotes "missing value" alongside normal values allowed by `TypeName`. For example, a `Nullable(Int8)` type column can store `Int8` type values, and the rows that don't have a value will store `NULL`.
For a `TypeName`, you can't use composite data types [Array](array.md#data_type is array) and [Tuple](tuple.md#data_type-tuple). Composite data types can contain `Nullable` type values, such as `Array(Nullable(Int8))`.
A `Nullable` type field can't be included in indexes.
A `Nullable` type field can't be included in table indexes.
`NULL` is the default value for the `Nullable` type, unless specified otherwise in the ClickHouse server configuration.
`NULL` is the default value for any `Nullable` type, unless specified otherwise in the ClickHouse server configuration.
##Storage features
## Storage features
For storing `Nullable` type values, ClickHouse uses:
- A separate file with `NULL` masks (referred to as the mask).
- The file with the values.
The mask determines what is in a data cell: `NULL` or a value.
When the mask indicates that `NULL` is stored in a cell, the file with values stores the default value for the data type. So if the field has the type `Nullable(Int8)`, the cell will store the default value for `Int8`. This feature increases storage capacity.
To store `Nullable` type values in table column, ClickHouse uses a separate file with `NULL` masks in addition to normal file with values. Entries in masks file allow ClickHouse to distinguish between `NULL` and default value of corresponding data type for each table row. Because of additional file, `Nullable` column consumes additional storage space compared to similar normal one.
!!! info "Note"
Using `Nullable` almost always negatively affects performance, so keep this in mind when designing your databases.
Using `Nullable` almost always negatively affects performance, keep this in mind when designing your databases.
## Usage example
@ -48,7 +41,7 @@ Ok.
1 rows in set. Elapsed: 0.007 sec.
:) SELECT x + y from t_null
:) SELECT x + y FROM t_null
SELECT x + y
FROM t_null
@ -59,5 +52,4 @@ FROM t_null
└────────────┘
2 rows in set. Elapsed: 0.144 sec.
```
``