You can convert this to a single row in array form, like this:
This section explains how to enable native compression, and then goes into
detail on the most important settings for compression, to help you get the
best possible compression ratio.
Key aspects of compression
Every table has a different schema but they do share some commonalities that you need to think about. Consider the tablemetrics with the following attributes:
All s have a primary dimension which is used to partition the table into chunks. The primary dimension is
given when the is created. In the example below, you can see a classic
time-series use case with a
time column as the primary dimension. In addition, there are two columns cpu and
disk_io containing the values that are captured over time, and a column device_id for the device that captured the
values.
Columns can be used in a few different ways:
- You can use values in a column as a lookup key, in the example above
device_idis a typical example of such a column. - You can use a column for partitioning a table. This is typically a time column like
timein the example above, but it is possible to partition the table using other types as well. - You can use a column as a filter to narrow down on what data you select. The column
device_typeis an example of where you can decide to look at, for example, only solid state drives (SSDs).
cpu and disk_io are typical examples of such columns.
Indexes set on the hypertable are used only on chunks containing uncompressed data. creates and uses
custom indexes to incorporate the
segmentby and orderby parameters during compression which are used when reading
compressed data. More on this in the next section.Ordering and segmenting
Ordering the data will have a great impact on the compression ratio and performance of your queries. Rows that change over a dimension should be close to each other. Since we are mostly dealing with time-series data, time dimension is a great candidate. Most of the time data changes in a predictable fashion, following a certain trend. We can exploit this fact to encode the data so it takes less space to store. For example, if you order the records over time, they will get compressed in that order and subsequently also accessed in the same order. Using the following configuration setup on our example table:time column is used for ordering data, which makes filtering it using time column much more efficient.
device_id value (either all records or maybe for
a specific time range), you would need to filter all those records one by one during row access time. To get around
this, you can use device_id column for segmenting. This would allow you to run analytical queries on compressed data
much faster if you are looking for specific device IDs.
Consider the following query:
device_id identifier by grouping all its values together. We
can use this fact to speed up these types of queries by setting up compression to segment the data around the values in
this column.
Using the following configuration setup on our example table:
Segmenting column
device_id is used for grouping data points together based on the value of that column. This makes
accessing a specific device much more efficient.
Number of rows that are compressed together in a single batch (like the ones we see above) is 1000. If your chunk does
not contain enough data to create big enough batches, your compression ratio will be reduced. This needs to be taken
into account when defining your compression settings.