Data Model

MynaDB uses a time series data model compatible with InfluxDB Line Protocol. Understanding the data model helps you design efficient schemas and write optimal queries.

Overview

Time series data in MynaDB consists of:

  +------------------------------------------------------------------+
  |                         Data Point                                |
  +------------------------------------------------------------------+
  |                                                                   |
  |  Measurement     Tags                  Fields           Timestamp |
  |  (table name)    (indexed metadata)    (values)         (time)    |
  |                                                                   |
  |  cpu             host=server01         usage=75.5       1699900000|
  |                  region=us-west        temp=45                    |
  |                                                                   |
  +------------------------------------------------------------------+
        
Component Description Indexed Required
Measurement Table name (e.g., "cpu", "memory") Yes Yes
Tags Key-value metadata for filtering Yes No
Fields Actual metric values No Yes (at least one)
Timestamp Time of the data point Yes No (defaults to now)

Line Protocol Format

Data is written using InfluxDB Line Protocol:

Line Protocol
<measurement>,<tag_key>=<tag_value>,... <field_key>=<field_value>,... [timestamp]

# Examples:
cpu,host=server01,region=us-west usage=75.5,temp=45i 1699900000000000000
memory,host=server01 used=16.5,total=32.0
disk,host=server01,mount=/data free=100.5,used=50.2
💡 Syntax Rules
  • Measurement and tags are separated by commas (no spaces)
  • Tags and fields are separated by a space
  • Multiple tags/fields are separated by commas
  • Timestamp is optional and separated by a space

Measurements

A measurement is like a table in a relational database. It groups related time series data together.

Naming Conventions

# Good measurement names
cpu
memory
disk_io
http_requests
application_errors

# Bad measurement names (use tags instead)
cpu_server01           # Use: cpu,host=server01
memory_us_west         # Use: memory,region=us-west

Tags

Tags are indexed key-value pairs used for filtering and grouping. They're stored as strings and are ideal for metadata that you'll query by.

When to Use Tags

# Tags enable efficient filtering
cpu,host=server01,region=us-west,env=prod usage=75.5

# Query by tags
SELECT * FROM cpu WHERE host = 'server01'
SELECT * FROM cpu WHERE region = 'us-west' AND env = 'prod'
SELECT region, AVG(usage) FROM cpu GROUP BY region
⚠ Cardinality Warning

Avoid high-cardinality tags (unique IDs, timestamps, random values). High cardinality increases storage and slows queries. Use fields for high-cardinality data.

Tag Best Practices

Do Don't
host=server01 request_id=abc123... (use field)
region=us-west timestamp=1699900000 (use timestamp)
env=prod user_id=12345 (high cardinality)

Fields

Fields contain the actual metric values. They're not indexed, so filtering by fields requires scanning data, but they support multiple data types.

Field Types

Type Suffix Example Storage Type
Float (none) usage=75.5 Float64
Integer i count=42i Int64
Unsigned Integer u bytes=1024u UInt64
String quotes status="ok" Utf8
Boolean t/f/true/false active=t Boolean
# Different field types
system,host=server01 cpu=75.5,memory=16384i,active=t,status="healthy"

# Multiple fields per measurement
http_request,endpoint=/api/users latency=45.2,status_code=200i,success=t

When to Use Fields

Timestamps

Timestamps represent when the data point occurred. MynaDB stores timestamps as nanoseconds since Unix epoch (January 1, 1970).

Timestamp Precision

Precision Digits Example
Nanoseconds 19 1699900000000000000
Microseconds 16 1699900000000000
Milliseconds 13 1699900000000
Seconds 10 1699900000
# With explicit timestamp (nanoseconds)
cpu,host=server01 usage=75.5 1699900000000000000

# Without timestamp (uses server time)
cpu,host=server01 usage=75.5

# Query by time range
SELECT * FROM cpu
WHERE time > 1699900000000000000
  AND time < 1699986400000000000

Schema Structure

MynaDB organizes data in a Catalog.Schema.Table hierarchy:

  Catalog (Database)
  └── mydb
      ├── Schema (Service)
      │   ├── default
      │   │   ├── Table (Measurement)
      │   │   │   ├── cpu
      │   │   │   ├── memory
      │   │   │   └── disk
      │   │   └── ...
      │   ├── web
      │   │   ├── cpu
      │   │   └── requests
      │   └── api
      │       └── latency
      └── _system
          └── series_stats
        

Schema Strategies

ServiceAsSchema (Default)

Service tag becomes the schema name.

  • Schema = service tag value
  • Table = measurement name
cpu,service=web → mydb.web.cpu

ServiceAsTable

Service tag becomes the table name.

  • Schema = "default"
  • Table = service tag value
cpu,service=web → mydb.default.web

Column Types in Parquet

When stored in Parquet, data is converted to Arrow types:

Line Protocol Arrow Type Parquet Type
Tag values Utf8 BYTE_ARRAY (STRING)
Float fields Float64 DOUBLE
Integer fields Int64 INT64
Boolean fields Boolean BOOLEAN
Timestamp Int64 INT64

Example: Complete Data Model

bash
# Write data with proper structure
curl -X POST http://localhost:7000/write/mydb -d '
cpu,host=server01,region=us-west,env=prod usage=75.5,temp=45i,cores=8i
cpu,host=server02,region=us-east,env=prod usage=82.3,temp=50i,cores=16i
memory,host=server01,region=us-west used=16.5,total=32.0,cached=8.2
disk,host=server01,mount=/data free=100i,used=50i,iops=1500.5
'

# Query with proper filtering
curl 'http://localhost:7000/query/mydb' -d "
SELECT
  host,
  region,
  AVG(usage) as avg_cpu,
  MAX(temp) as max_temp
FROM cpu
WHERE env = 'prod'
GROUP BY host, region
ORDER BY avg_cpu DESC
"

Next Steps