6.1. Managing tables with Tags#

QuasarDB supports organizing data in many tables and querying them together through tags. Separate tables can distribute work and provide independent schemas, access control and retention policies. It is common for deployments to use thousands of tables.

Column partitioning, available since QuasarDB 4.0.0, provides another option: keep one logical time-series table and select physical partitions by an ordinary column. Review its current limitations before choosing it, especially if you need TTL, asynchronous ingestion or ingestion deduplication.

To make the management and querying of these tables work at scale, QuasarDB provides a tags abstraction on top of the timeseries tables. This document outlines strategies for defining your tables using tags, and shows you how to use them in practice.

6.1.1. Defining your tables#

Before you can start tagging your tables, you need to figure out an appropriate way to split your data model into multiple tables, if possible. To do this, you need to determine the most appropriate partition identifier for your dataset: the best choice depends upon your dataset, but in most circumstances it is fairly straightforward to find out.

A good rule of thumb is to use the single key you most frequently query or group by, and use that as identifier for the tables.

Examples of schemes that work well are customer_id, stock_id or sensors_id. If you need help figuring out the best partitioning scheme, consult your solution architect.

6.1.2. Separate tables or column partitions?#

Use separate tables when entities need different schemas, table-level access control, tags or retention settings. Tags select tables; they do not select individual partitions or provide access control per key.

Consider column partitioning when entities share one schema and you want queries, groups or windows over one logical table. For example, one sensor_readings table can store many sensor IDs with PARTITION BY sensor_id. A predicate on that key can prune storage partitions without expanding a list of table names.

Distinct keys isolate entities but create one partition per value. HASH limits the number of physical partitions; RANGE groups nearby integer keys; TIMESTAMP uses intervals of a selected timestamp column. These choices do not automatically improve every workload. Measure key-filtered queries, time-only queries and incremental writes with realistic cardinality and skew.

Moving existing data to another layout requires an explicit destination table and INSERT SELECT or COPY/IMPORT. ALTER TABLE cannot repartition an existing table. Copying rows does not copy table tags, privileges or a partition policy; configure the destination separately. See Supported operations and limitations for unsupported operations.

6.1.3. Defining your tags#

It is a common misconception that tags operate on the level of rows, similar to how a secondary index would work: this is not the case. Tags operate solely on the level of tables, and are in place to make querying easier.

As such, your tagging strategy depends upon your query patterns: when you find yourself wanting to join certain groups of tables frequently, the chance is likely that these tables should share a common tag.

Example: tagging stock tables by exchange:

CREATE TABLE stocks.apple (open DOUBLE, close DOUBLE, high DOUBLE, low DOUBLE, volume INT64)
CREATE TABLE stocks.facebook (open DOUBLE, close DOUBLE, high DOUBLE, low DOUBLE, volume INT64)
CREATE TABLE stocks.google (open DOUBLE, close DOUBLE, high DOUBLE, low DOUBLE, volume INT64)

ATTACH_TAG stocks.apple nasdaq
ATTACH_TAG stocks.facebook nasdaq
ATTACH_TAG stocks.google nasdaq

You can attach multiple tags to the same table, so you can query it in multiple dimensions.

6.1.4. Querying using tags#

Since timeseries are stored as plain key/value objects under the hood, we are able to query them using the FIND instruction as well. Assuming you followed the stock exchange example from the previous paragraph, we can query these tables as follows:

FIND(tag='nasdaq')

1. stocks.apple
2. stocks.facebook
3. stocks.google

Because QuasarDB allows for expansion of the table selection using the FIND operator, we can take this one step further and query the contents of these tables:

SELECT * FROM FIND(tag='nasdaq')

timestamp                      timeseries      open             close            high             low              volume
-----------------------------------------------------------------------------------------------------------------------------
2018-01-01T00:00:00.000000000Z stocks.apple    10.240000        10.170000        10.360000        10.070000        1027389
2018-01-01T00:00:00.000000000Z stocks.facebook 902.750000       909.510000       925.000000       890.120000       8437
2018-01-01T00:00:00.000000000Z stocks.google   25.210000        24.910000        27.010000        25.190000        32497