Internals
Vector Format
Vectors logically represent arrays that contain data of a single type. DuckDB supports different *vector formats*, which allow the system to store the same logical data with a different *physical representation*. This allows for a more compressed representation, and potentially allows for compressed execution throughout the system. Below the list of supported vector formats is shown.  
#### Flat Vectors {#docs:internals:vector::flat-vectors}  
Flat vectors are physically stored as a contiguous array, this is the standard uncompressed vector format.
For flat vectors the logical and physical representations are identical.  
<img src="/images/internals/flat.png" alt="Flat Vector example" style="max-width:40%;width:40%;height:auto;margin:auto"/>  
#### Constant Vectors {#docs:internals:vector::constant-vectors}  
Constant vectors are physically stored as a single constant value.  
<img src="/images/internals/constant.png" alt="Constant Vector example" style="max-width:40%;width:40%;height:auto;margin:auto"/>  
Constant vectors are useful when data elements are repeated – for example, when representing the result of a constant expression in a function call, the constant vector allows us to only store the value once.  
```sql
SELECT lst || 'duckdb'
FROM range(1000) tbl(lst);
```  
Since `duckdb` is a string literal, the value of the literal is the same for every row. In a flat vector, we would have to duplicate the literal 'duckdb' once for every row. The constant vector allows us to only store the literal once.  
Constant vectors are also emitted by the storage when decompressing from constant compression.  
#### Dictionary Vectors {#docs:internals:vector::dictionary-vectors}  
Dictionary vectors are physically stored as a child vector, and a selection vector that contains indexes into the child vector.  
<img src="/images/internals/dictionary.png" alt="Dictionary Vector example" style="max-width:40%;width:40%;height:auto;margin:auto"/>  
Dictionary vectors are emitted by the storage when decompressing from dictionary  
Just like constant vectors, dictionary vectors are also emitted by the storage.
When deserializing a dictionary compressed column segment, we store this in a dictionary vector so we can keep the data compressed during query execution.  
#### Sequence Vectors {#docs:internals:vector::sequence-vectors}  
Sequence vectors are physically stored as an offset and an increment value.  
<img src="/images/internals/sequence.png" alt="Sequence Vector example" style="max-width:40%;width:40%;height:auto;margin:auto"/>  
Sequence vectors are useful for efficiently storing incremental sequences. They are generally emitted for row identifiers.  
#### Unified Vector Format {#docs:internals:vector::unified-vector-format}  
These properties of the different vector formats are great for optimization purposes, for example you can imagine the scenario where all the parameters to a function are constant, we can just compute the result once and emit a constant vector.
But writing specialized code for every combination of vector types for every function is unfeasible due to the combinatorial explosion of possibilities.  
Instead of doing this, whenever you want to generically use a vector regardless of the type, the UnifiedVectorFormat can be used.
This format essentially acts as a generic view over the contents of the Vector. Every type of Vector can convert to this format.