# 4.1. Managing tables with Tags¶

At QuasarDB, we encourage the use of many different tables: it improves write and read speed, and in most cases also improves your compression ratio. It is not uncommon for users to use tens of thousands of tables (or in rare occasions even millions).

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

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.

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


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

## 4.1.3. 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

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')