-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
MDEV-11371 - Big column compressed(innodb) #261
Conversation
create table t1(c1 blob compressed, c2 varchar(1000) compressed); mean the table column c1,c2 have compress property. The data in table t1 have been compressed. The compress property is transparent to user. fix format
|
||
set default_storage_engine = @default_storage_engine_old; | ||
|
||
drop table t1,t2,t3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add more test cases about CHAR/MEDIUMBLOB/MEDIUMTEXT/LONGBLOB/LONGTEXT types.
And can you do a performance test by yourselves and show the results?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add more test cases.
Hi GCSAdmin, Thanks for your contribution. JIRA task has been created to track this pull request: https://jira.mariadb.org/browse/MDEV-11371 This task was added to 10.2.4 backlog, which is planned to be handled between 2016-12-15 and 2016-12-22. Thanks, |
Maybe you'd find something interesting in percona/percona-server@35d5d3f, testcases perhaps, although feature grammar is incompatible |
@GCSAdmin, before we continue could you explain what benefits gives column compression over two alternatives: InnoDB native compression and COMPRESS()/UNCOMPRESS()? Are you using indexes over compressed columns? Is it at all supported in this patch? |
@svoj @plinux
Performance Testing(The data comes from the real game DB) As column comperss has a better compression ratio and performance and more flexibility, we did it. We do not support indexes over compressed columns now. |
Also, why is it better than what Percona has (commit link above)? Percona implementation is more complex, but it'll also allow much better compression with their external dictionary feature. Why is it better than a special data type (we might have user defined types in 10.3) that is "like a blo b, but compresses everything before storage"? And, anyway, this feature cannot possibly go into 10.2, it's too late for that. It can go into 10.3. |
Thank you for your contribution, however I would implement compressed columns in upper layer not inside InnoDB. Benefits would include
|
You are right, but many users may expect to solve their problems in databases layer. Do we really need to uncompress these columns always to InnoDB buffer pool ? |
By upper layer I meant still inside a MariaDB server i.e. implementation somewhere in sql directory. |
@laurynas-biveinis thank you for your suggestion, we are reading percona's testcases, it maybe help. |
Also note column compression in AliSQL: https://jira.mariadb.org/browse/MDEV-11381 |
@vuvova hi vuvova, it is better to implement big column compressed in MariaDB server or innodb layer; because we can do some optimization about data export or import using mysqldump. For example, when the big column is compressed, we can add a grammar to keep data compressed while exporting data out of mysql and keep data compressed while importing into mysql. To finish this, while we use mysqldump to doing export, we use , in this case, data which is compressed does not need to be uncompress, and the general backup sqlfile, which format is , it means that when we use the backup sqlfile to do restoring job, the compressed data need not be compressed. This implementation means a lot to us. |
@janlindstrom , hi janlindstrom, the big column compressed feature can surely be implemented in the upper layer i.e. MariaDB Server, we choose to implement in innodb layer, because we think this implementation is simple enough to finish. |
@felixliang one of our developers wonder if you also considered trigger (compress) + view (uncompress) solution? Why didn't it work for you? I assume because you want simpler syntax. |
@felixliang, @plinux in your implementations you store compression algorithm for every row (also wrap flag in AliSQL). Do you really need this information in every row or per-table setting is acceptable? |
@svoj, FWIW in our implementation we decided to go with a per-row algorithm info so that we could do, in the future, if new algorithms are implemented, an ALTER TABLE (existing compressed table) (to a new algorithm), which is a metadata operation only, and rows are rewritten in the new algorithm as they are updated |
@laurynas-biveinis thanks! |
@felixliang, @plinux in your implementations you store compression algorithm for every row (also wrap flag in AliSQL). Do you really need this information in every row or per-table setting is acceptable? @svoj but right now TMySQL hasn't support changing column's compression algorithm for instantly yet. |
@felixliang one of our developers wonder if you also considered trigger (compress) + view (uncompress) solution? Why didn't it work for you? I assume because you want simpler syntax. @svoj |
@felixliang thanks for your answers. I'm almost done porting this to SQL-layer (mostly to class Field). Will send you an email with details soon. |
so you will pick up Tencent Game DBA Team's implementation into MariaDB 10.3, right? in the latest meet up, monty said you will evalute our implementation and AliSQL, so i don't know which one you will choose? |
@felixliang I evaluated Tencent, Alibaba and Percona code base. Unfortunately we can't take any implementation as is, because we want storage engine independent solution. To keep things simple we won't take compression dictionary from Percona for this first implementation. It will be possible to add it later though. Our first implementation will cover all Tencent and Alibaba requirements, except for Alibaba heap alloc (which can be added easily later anyway). Syntax wise we will be compatible with Tencent patch, but we had to rename system variables. .frm is not compatible with any implementation. Same for data: generally we store the same information, but we reserve 4 bits for compression algorithm and we don't store compressed flag. In our implementation compression_algorithm == 0 means uncompressed. |
One nice benefit of implementing this at SQL layer is that we can avoid data recompression in many cases when we need to copy data, like:
|
Hi, @svoj We hope that the new implementation of blob compressed in MariaDB can be binary compatible with what Tencent's patch done. In our Tencent implementation, for compressed header, one bit for compressed flag, 2 bits for compression algorithm, and 3 bits for Bytes of "Record Original Length"
And does it mean that higher 4 bits means compression algorithm and lower 4 bits means Bytes of "Record Original Length"? If so, we think it can be **binary compatible **. **And Zlibs algorithm should be 0x08. It should be the default algorithm. **
What do you think? |
@vinchen, I understand your wish to make it binary compatible. Our header format is as following:
The difference is: in your implementation you reserve 4 bits for compressed data length, in our implementation we reserve only 2 bits. We also store bytes_of_original_length - 1. In theory making your implementation binary compatible with ours is not that complex, but we'll have to discuss it with Monty. Adding support for Alibaba and Percona headers is a lot more complex. |
@felixliang, @GCSAdmin, @vinchen, @plinux patch is in bb-10.3-svoj: 733ddb9 Note that there're still a bunch of edge cases not covered (many explained in revision comment). Your feedback will be greatly appreciated. |
hi @svoj Maybe storage engine independent solution is better, because it can support any storage engines. But it is very interesting that: the code base of Tencent, Alibaba and Percona about column compressed implementation are very similar: doing that in the InnoDB layer. And implementation in InnoDB layer, we can also avoid data recompression in the following cases:
The above 2 and 3 cases, we may need to use HINT to avoid data recompression. Another thing, when we backup data in logic way, we use HINT in SELECT syntax to avoid data recompression. |
@HugeFelix are there any reasons to keep it in InnoDB? The only reason I got so far is simplicity. MariaDB compared to MySQL has a lot more storage engines available. Thus we have to care about all available storage engines equally. |
Yes. Simiplicity is important for us. And we really understand and support storage engine independent solution in MariaDB. |
@HugeFelix Nice, thanks! It was agreed to change row storage format to be compatible with Tencent. This is generic enough and doesn't cost us much effort. Metadata (the value stored in unireg_check) haven't been decided yet, but I guess we should come up with some nice solution too. |
Pushed fdc4779 |
Some big columns(blob/text/varchar/varbinary) waste a lot of space, we introduce “compressed” into column definition when create or alter a table.
When a column was defined as a compressed column, the column data will be compressed using zlib (other compress algorithm not support yet).
We could get a better compression ratio and performance, more flexibility (vs compressed row format)
For example:
Create table tcompress (
C1 int,
C2 blob compressed,
C3 text compressed,
C4 text) engine = innodb
We achieve this 'big columns compress' function by following step:
Compress Header is 1 Byte,
7 Bit: Always 1, mean compressed;
5-6 Bit: Compressed algorithm - Always 0, means zlib.It maybe support other compression algorithm in the future.
0-3 Bit: Bytes of "Record Original Length"
Record Original Length: 1-4 Bytes*/
We add system global variable 'field_compress_min_len' was used to control that only compress the column if the data length exceeds 'field_compress_min_len'. Default 128.
Also we add 3 error num:
ER_FIELD_TYPE_NOT_ALLOWED_AS_COMPRESSED_FIELD: support text/blob/varchar/varbinary column has compress attribute only.
ER_FIELD_CAN_NOT_COMPRESSED_AND_INDEX: column has compress attribute can not be an index
ER_FIELD_CAN_NOT_COMPRESSED_IN_CURRENT_ENGINESS: column compress be supported in innodb only