snippetModerate
Understanding how to choose between fields and tags in InfluxDB
Viewed 0 times
understandingfieldschoosetagsbetweeninfluxdbhowand
Problem
What are some good rules and examples of how to choose between storing data in fields vs. tags when designing InfluxDB schemas?
What I've found so far is:
a measurement that changes over time should be a field, and metadata about the measurement should be in tags
tags and fields are effectively columns in the table. tags are indexed, fields are not
the values that are highly variant and not usually part of a WHERE clause are put into fields
Store data in fields if you plan to use them with an InfluxQL function
Tags containing highly variable information like UUIDs, hashes, and random strings will lead to a large number of series in the database, known colloquially as high series cardinality. High series cardinality is a primary driver of high memory usage for many database workloads.
But let's say you store filled orders in an e-commerce application: order id, sale price, currency.
What I've found so far is:
a measurement that changes over time should be a field, and metadata about the measurement should be in tags
tags and fields are effectively columns in the table. tags are indexed, fields are not
the values that are highly variant and not usually part of a WHERE clause are put into fields
Store data in fields if you plan to use them with an InfluxQL function
Tags containing highly variable information like UUIDs, hashes, and random strings will lead to a large number of series in the database, known colloquially as high series cardinality. High series cardinality is a primary driver of high memory usage for many database workloads.
But let's say you store filled orders in an e-commerce application: order id, sale price, currency.
- Should the order id be a tag, or a field?
- Should the currency be a tag, or a field?
Solution
I just read a tutorial that said fields are data and tags are metadata. That is a very intuitive definition.
The example had pressure and temperature fields and a weather station tag. Again, crystal clear and perfectly matches the description.
Unfortunately, they then said that if you are querying on pressure or temperature and not weather station, you should flip the field and tag designations around. In other words the definitions provided for field and tag are meaningless.
The simple solution is to stipulate that fields can either be indexed or not indexed. Fields that are indexed are called tags. Use tag when you need to index a field (to dramatically improve query speed for example).
The example had pressure and temperature fields and a weather station tag. Again, crystal clear and perfectly matches the description.
Unfortunately, they then said that if you are querying on pressure or temperature and not weather station, you should flip the field and tag designations around. In other words the definitions provided for field and tag are meaningless.
The simple solution is to stipulate that fields can either be indexed or not indexed. Fields that are indexed are called tags. Use tag when you need to index a field (to dramatically improve query speed for example).
Context
StackExchange Database Administrators Q#163292, answer score: 10
Revisions (0)
No revisions yet.