Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: support run-length encoding #255

Closed
skyzh opened this issue Dec 22, 2021 · 0 comments · Fixed by #507
Closed

storage: support run-length encoding #255

skyzh opened this issue Dec 22, 2021 · 0 comments · Fixed by #507
Assignees

Comments

@skyzh
Copy link
Member

skyzh commented Dec 22, 2021

It is a common case that users are storing nearly the same value in one column. For example, in TPC-H, we have a CHAR(1) column. There must be duplicated data in this column if we have 1000k rows, and therefore we can use running-length encoding to do some compression.

Guide-level Introduction

RLE encoding is a compression scheme instead of a typical encoding. It can be applied on any column. For example, given a int column:

1, 1, 2, 2, 3, 3
-> PrimitiveBlockBuilder(1, 1, 2, 2, 3, 3)

RLE encoding will check if the current value is the same as the previous one, and generate a RLE map:

1, 1, 2, 2, 3, 3
-> PrimitiveBlockBuilder(1, 2, 3)
-> RLE(2, 2, 2)

Implementation-level Introduction

Builder and Iterator

Contrary to primitive iterators, RLE block builder and iterator are simply a wrapper on primitive iterators. It will look like follows:

pub struct RLEBlockBuilder<B: BlockBuilder> {
  block_builder: B,
  rle_count: Vec<u16>,
  previous_value: Option<B::ArrayType::OwnedItem>
}

When finishing a block, RLEBlockBuilder simply append the RLE count data to the encoded block.

Column

L0 rowsets should not use RLE encoding. We can use distinct value statistics to decide whether to use RLE encoding to the compacted new rowsets.

We should modify factories in column correspondingly:

pub(super) enum BlockIteratorImpl<T: PrimitiveFixedWidthEncode> {
    Plain(PlainPrimitiveBlockIterator<T>),
    PlainNullable(PlainPrimitiveNullableBlockIterator<T>),
    /* new */ RLEPlainNullable(RLEBlockIterator<PlainPrimitiveNullableBlockIterator<T>>)
}

And in proto:

  enum BlockType {
    Plain = 0;
    RunLength = 1;
    ZstdCompress = 2;
    PlainNullable = 3;
    PlainFixedChar = 4;
    PlainVarchar = 5;
    RLEPlainNullable = 6; /* new */
  }
@skyzh skyzh mentioned this issue Jan 23, 2022
13 tasks
@skyzh skyzh changed the title storage: support running-length encoding storage: support run-length encoding Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants