1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
# name: test/sql/storage/compression/bitpacking/bitpacking_compression_ratio.test_slow
# description: Assert bitpacking compression ratio is within reasonable margins for each mode
# group: [bitpacking]
# This test defaults to another compression function for smaller block sizes,
# because the bitpacking groups no longer fit the blocks.
require block_size 262144
load __TEST_DIR__/test_bitpacking.db
#### CONSTANT MODE Compression ratio calculation:
# For single row group (note we choose values such that we don't create the constant segments):
# 59 vectors with CONSTANT mode, the last one will be FOR mode
# Total compressed bytes = 59*(8+4) + 1*(2048/8 + 8 + 8 + 4) = 984
# Total uncompressed bytes = 120000*8 = 960000
# Ratio ~= 975x
# However, because this completely fills up a block and we do not support block sharing yet, we waste a lot of space
statement ok
PRAGMA force_compression='bitpacking'
statement ok
PRAGMA force_bitpacking_mode='constant'
statement ok
CREATE TABLE test_bitpacked AS SELECT (i//119000::INT64)::INT64 AS i FROM range(0, 120000000) tbl(i);
statement ok
checkpoint
statement ok
PRAGMA force_compression='uncompressed'
statement ok
CREATE TABLE test_uncompressed AS SELECT i::INT64 FROM range(0, 120000000) tbl(i);
statement ok
checkpoint
query I
SELECT compression FROM pragma_storage_info('test_bitpacked') WHERE segment_type != 'VALIDITY' AND compression != 'BitPacking';
----
query I
SELECT compression FROM pragma_storage_info('test_uncompressed') WHERE segment_type != 'VALIDITY' AND compression != 'Uncompressed';
----
query II
select (uncompressed::FLOAT / bitpacked::FLOAT) > 700, (uncompressed::FLOAT / bitpacked::FLOAT) < 1000 FROM (
select
(select count(distinct block_id) from pragma_storage_info('test_bitpacked') where segment_type not in('VARCHAR', 'VALIDITY')) as bitpacked,
(select count(distinct block_id) from pragma_storage_info('test_uncompressed') where segment_type not in('VARCHAR', 'VALIDITY')) as uncompressed
)
----
True True
statement ok
drop table test_bitpacked;
drop table test_uncompressed;
#### CONSTANT DELTA MODE Compression ratio calculation:
# For single row group
# 60 vectors with a constant increase (1)
# Total compressed bytes = 60*(8+8+4) = 1200
# Total uncompressed bytes = 120000*8 = 960000
# Expected Ratio ~= 800x
statement ok
PRAGMA force_compression='bitpacking'
statement ok
PRAGMA force_bitpacking_mode='constant_delta'
statement ok
CREATE TABLE test_bitpacked AS SELECT i::INT64 AS i FROM range(0, 120000000) tbl(i);
statement ok
checkpoint
statement ok
PRAGMA force_compression='uncompressed'
statement ok
CREATE TABLE test_uncompressed AS SELECT i::INT64 AS i FROM range(0, 120000000) tbl(i);
statement ok
checkpoint
query I
SELECT compression FROM pragma_storage_info('test_bitpacked') WHERE segment_type != 'VALIDITY' AND compression != 'BitPacking';
----
query I
SELECT compression FROM pragma_storage_info('test_uncompressed') WHERE segment_type != 'VALIDITY' AND compression != 'Uncompressed';
----
statement ok
checkpoint
query II
select (uncompressed::FLOAT / bitpacked::FLOAT) > 600, (uncompressed::FLOAT / bitpacked::FLOAT) < 800 FROM (
select
(select count(distinct block_id) from pragma_storage_info('test_bitpacked') where segment_type not in('VARCHAR', 'VALIDITY')) as bitpacked,
(select count(distinct block_id) from pragma_storage_info('test_uncompressed') where segment_type not in('VARCHAR', 'VALIDITY')) as uncompressed
)
----
True True
statement ok
drop table test_bitpacked;
drop table test_uncompressed;
#### DELTA FOR MODE Compression ratio calculation:
# For single row group
# 60 vectors with DELTA_FOR mode smallest possible compression
# Total compressed bytes = 60*(8+8+4+(2048/8)) = 16560
# Total uncompressed bytes = 120000*8 = 960000
# Expected Ratio ~= 58x
statement ok
PRAGMA force_compression='bitpacking'
statement ok
PRAGMA force_bitpacking_mode='delta_for'
statement ok
CREATE TABLE test_bitpacked AS SELECT i//2::INT64 AS i FROM range(0, 120000000) tbl(i);
statement ok
checkpoint
statement ok
PRAGMA force_compression='uncompressed'
statement ok
CREATE TABLE test_uncompressed AS SELECT i AS i FROM range(0, 120000000) tbl(i);
statement ok
checkpoint
query I
SELECT compression FROM pragma_storage_info('test_bitpacked') WHERE segment_type != 'VALIDITY' AND compression != 'BitPacking';
----
query I
SELECT compression FROM pragma_storage_info('test_uncompressed') WHERE segment_type != 'VALIDITY' AND compression != 'Uncompressed';
----
statement ok
checkpoint
query II
select (uncompressed::FLOAT / bitpacked::FLOAT) > 50, (uncompressed::FLOAT / bitpacked::FLOAT) < 60 FROM (
select
(select count(distinct block_id) from pragma_storage_info('test_bitpacked') where segment_type not in('VARCHAR', 'VALIDITY')) as bitpacked,
(select count(distinct block_id) from pragma_storage_info('test_uncompressed') where segment_type not in('VARCHAR', 'VALIDITY')) as uncompressed
)
----
True True
statement ok
drop table test_bitpacked;
drop table test_uncompressed;
# FOR MODE Compression ratio calculation:
# For single row group
# 60 vectors with DELTA_FOR mode smallest possible compression
# Total compressed bytes = 60*(8+4+(2048/8)) = 16080
# Total uncompressed bytes = 120000*8 = 960000
# Expected Ratio ~= 60x
statement ok
PRAGMA force_compression='bitpacking'
statement ok
PRAGMA force_bitpacking_mode='for'
statement ok
CREATE TABLE test_bitpacked AS SELECT i%2::INT64 AS i FROM range(0, 120000000) tbl(i);
statement ok
checkpoint
statement ok
PRAGMA force_compression='uncompressed'
statement ok
CREATE TABLE test_uncompressed AS SELECT i::INT64 AS i FROM range(0, 120000000) tbl(i);
statement ok
checkpoint
query I
SELECT compression FROM pragma_storage_info('test_bitpacked') WHERE segment_type != 'VALIDITY' AND compression != 'BitPacking';
----
query I
SELECT compression FROM pragma_storage_info('test_uncompressed') WHERE segment_type != 'VALIDITY' AND compression != 'Uncompressed';
----
statement ok
checkpoint
query II
select (uncompressed::FLOAT / bitpacked::FLOAT) > 50, (uncompressed::FLOAT / bitpacked::FLOAT) < 60 FROM (
select
(select count(distinct block_id) from pragma_storage_info('test_bitpacked') where segment_type not in('VARCHAR', 'VALIDITY')) as bitpacked,
(select count(distinct block_id) from pragma_storage_info('test_uncompressed') where segment_type not in('VARCHAR', 'VALIDITY')) as uncompressed
)
----
True True
statement ok
drop table test_bitpacked;
drop table test_uncompressed;
statement ok
PRAGMA force_bitpacking_mode='auto'
# Assert that all supported types do in fact compress
foreach type int8 int16 int32 int64 uint8 uint16 uint32 uint64 decimal(4,1) decimal(8,1) decimal(12,1) decimal(18,1) bool
statement ok
PRAGMA force_compression='uncompressed';
statement ok
CREATE TABLE test_uncompressed AS SELECT (i%2)::${type} FROM range(0, 2500000) tbl(i);
statement ok
checkpoint
statement ok
PRAGMA force_compression='bitpacking'
statement ok
CREATE TABLE test_bitpacked AS SELECT (i%2)::${type} FROM range(0, 2500000) tbl(i);
statement ok
checkpoint
# assert compression ratio >2 wich should be achieved for even the smallest types for this data
query II
select (uncompressed::FLOAT / bitpacked::FLOAT) > 2, CAST(1 as ${type}) FROM (
select
(select count(distinct block_id) from pragma_storage_info('test_bitpacked') where segment_type not in('VARCHAR', 'VALIDITY')) as bitpacked,
(select count(distinct block_id) from pragma_storage_info('test_uncompressed') where segment_type not in('VARCHAR', 'VALIDITY')) as uncompressed
)
----
1 1
statement ok
drop table test_bitpacked
statement ok
drop table test_uncompressed
endloop
|