TL;DR InfluxDB Tech Tips - Understanding Dependent Tags In Series Cardinality

Navigate to:

In this weekly post we recap the most interesting InfluxDB series cardinality and TICK-stack related issues, workarounds, how-tos and Q&A from GitHub, IRC and the InfluxDB Google Group that you might have missed in the last week or so.

Writing timestamps to InfluxDB

Q: I’m new to InfluxDB and am learning to work with line protocol. I have historical data that I’d like to write to my database - is that possible with line protocol? Could you give me an overview of the supported timestamp formats?

A: Sure! InfluxDB’s timestamps are always in Unix time; that’s the amount of time that has elapsed since midnight UTC on January 1, 1970.

Timestamps in line protocol, the text-based format for writing points to InfluxDB, are optional. If you do not supply a timestamp, InfluxDB writes the point to the database using your server’s local nanosecond time in UTC. If you do specify a timestamp, InfluxDB writes the point using that timestamp instead. So to answer your initial question: yes, you can write historical data to your database, you just need to specify the relevant timestamp in your line protocol.

There are a couple other things to know about writing timestamps to InfluxDB:

  • The maximum allowable timestamp is 9223372036854775806 or 2262-04-11 23:47:16.854775806.
  • The minimum allowable timestamp is -9223372036854775806 or 1677-09-21 00:12:43.145224194. Notice that InfluxDB supports negative Unix timestamps, that is, timestamps that occur before midnight UTC on January 1, 1970.
  • The HTTP API supports writing non-nanosecond timestamps. Just use the precision query string parameter to specify that timestamps are in microseconds (u), milliseconds (ms), hours (h), minutes (m), or seconds (s). We recommend using the coarsest precision possible when writing data to InfluxDB. It can result in significant improvements in compression.

Check out the line protocol and the HTTP API documentation for more information!

Understanding dependent tags in series cardinality

Q: I’ve started reading about InfluxDB schemas and series cardinality. Is series cardinality for a single measurement really just the product of the number of tag values per tag?

For example, I have a single measurement with the tag keys firstname, lastname, and email. If firstname has five different tag values, lastname has five different values, and email has five different values, then is my series cardinality 125 (5 * 5 * 5)?

A: Series cardinality for a single measurement is actually the number of the tag sets that exist.

Working with your example, if we have the tags firstname, lastname, and email, the total cardinality is purely driven by the email tag. Although there are many possible first names and last names, a given email address will only ever have one associated first and last name (assuming no one ever changes their name.) firstname and lastname are dependent variables, and email is the independent variable, so your series cardinality is actually five.

Selecting disparate time ranges

Q: I’m trying to SELECT data with a time range in the WHERE clause but I keep getting no results. Is there something wrong with my query?

SELECT * FROM "holidata" WHERE (time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:06:00Z') OR (time >= '2015-09-18T21:36:00Z' AND time <= '2015-09-18T21:42:00Z')

A: Currently, InfluxQL doesn’t support selecting disparate time ranges in the WHERE clause. Your query isn’t returning any results because there’s a time gap between your two time ranges. You can get around that by splitting your query into two separate queries:

# Query 1 for time range one

SELECT * FROM "holidata" WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:06:00Z'
# Query 2 for time range two

SELECT * FROM "holidata" WHERE time >= '2015-09-18T21:36:00Z' AND time <= '2015-09-18T21:42:00Z'

For more InfluxDB tips, see our Frequently Asked Questions page and feel free to post your questions in the InfluxDB users group!

What's next

  • Downloads for the TICK-stack are live on our "downloads" page
  • Deploy on the Cloud: Get started with a FREE trial of InfluxDB Cloud featuring fully-managed clusters, Kapacitor and Grafana.
  • Deploy on Your Servers: Want to run InfluxDB clusters on your servers? Try a FREE 14-day trial of InfluxDB Enterprise featuring an intuitive UI for deploying, monitoring and rebalancing clusters, plus managing backups and restores. 
  • Tell Your Story: Over 100 companies have shared their story on how InfluxDB is helping them succeed. Submit your testimonial and get a limited edition hoodie as a thank you.