時系列データ
Oracle
-- Range partitioning by date:
CREATE TABLE measurements (
ts TIMESTAMP, sensor_id NUMBER, value NUMBER)
PARTITION BY RANGE (ts)
INTERVAL (NUMTODSINTERVAL(1,'DAY'))
( PARTITION p0 VALUES LESS THAN (TIMESTAMP '2026-01-01 00:00:00') );Oracle では、時系列データは通常 RANGE(INTERVAL)パーティショニングで管理する。新しいパーティションは自動的に作成され、古いパーティションは容易に削除できる(パーティションプルーニングによりクエリが高速化する)。圧縮(ILM/ADO)と集計用のマテリアライズドビューも使用される。
PostgreSQL
-- Hypertable with the TimescaleDB extension:
CREATE EXTENSION IF NOT EXISTS timescaledb;
CREATE TABLE measurements (ts TIMESTAMPTZ, sensor_id INT, value DOUBLE PRECISION);
SELECT create_hypertable('measurements', 'ts');
-- Summarize with a continuous aggregate.PostgreSQL はネイティブのパーティショニング(PARTITION BY RANGE)で時系列を保持できる。TimescaleDB 拡張は、時間ベースの自動チャンク化、圧縮、保持ポリシー、継続的集計を備えたハイパーテーブルを追加する。大規模な IoT/メトリクスのワークロードで一般的なソリューション。
MySQL
-- RANGE partitioning by date:
CREATE TABLE measurements (
ts DATETIME, sensor_id INT, value DOUBLE,
PRIMARY KEY (ts, sensor_id))
PARTITION BY RANGE (TO_DAYS(ts)) (
PARTITION p2026_01 VALUES LESS THAN (TO_DAYS('2026-02-01')),
PARTITION pmax VALUES LESS THAN MAXVALUE);MySQL には専用の時系列エンジンがない。RANGE パーティショニング(TO_DAYS/UNIX_TIMESTAMP を使用)により、古いデータの高速な削除とパーティションプルーニングが可能。大容量の時系列には、通常は外部ソリューション(TimescaleDB、InfluxDB)またはサマリーテーブルが推奨される。
SQL Server
-- Partitioned table (partition function + scheme) or
-- system-versioned temporal table (history kept automatically):
CREATE TABLE dbo.measurements (
id INT PRIMARY KEY, value DECIMAL(10,2),
valid_from DATETIME2 GENERATED ALWAYS AS ROW START,
valid_to DATETIME2 GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (valid_from, valid_to))
WITH (SYSTEM_VERSIONING = ON);SQL Server は、パーティション関数/構成によるパーティショニングで時系列を管理する。これにより広い日付範囲にわたるデータのプルーニングと高速なアーカイブが可能になる。加えて、システムバージョン管理されたテンポラルテーブル(SYSTEM_VERSIONING)は行の変更履歴を自動的に保持し、ポイントインタイムのクエリ(FOR SYSTEM_TIME)を可能にする。
MongoDB
// Time-series collection (MongoDB 5.0+):
db.createCollection("measurements", {
timeseries: {
timeField: "ts",
metaField: "sensor_id",
granularity: "seconds"
}
})MongoDB 5.0 で導入された time-series コレクションは、時刻とメタフィールドによりデータを圧縮された列に似た(バケット化された)形式で自動的に格納する。ディスクとインデックスの使用量を削減し、範囲クエリを高速化する。timeField は必須で、metaField(ソース/タグ)と granularity がパフォーマンスを決める。
Redis
# Requires the RedisTimeSeries module (Redis Stack).
# Create a series with a retention period:
TS.CREATE sensor:1 RETENTION 86400000 LABELS type temperature
# Add a sample (with an automatic timestamp):
TS.ADD sensor:1 * 23.5コアの Redis には時系列の型がない。RedisTimeSeries モジュール(Redis Stack)は、TS.CREATE/TS.ADD による高速なサンプル取り込み、自動保持(RETENTION)、ダウンサンプリング(TS.CREATERULE)、TS.RANGE/TS.MRANGE によるラベルベースの範囲クエリを提供する。モジュールがない場合は Sorted Set で代用する。
Elasticsearch
# Data stream: automatically rolling indexes for time series
PUT _index_template/measurements-tpl
{ "index_patterns": ["measurements*"], "data_stream": {},
"template": {
"settings": { "index.mode": "time_series", "index.routing_path": ["sensor_id"] },
"mappings": { "properties": {
"@timestamp": { "type": "date" },
"sensor_id": { "type": "keyword", "time_series_dimension": true },
"temperature": { "type": "double", "time_series_metric": "gauge" } } } } }
PUT _data_stream/measurementsElasticsearch は時系列データをデータストリームで管理する。新しいバッキングインデックスは時間とともに自動的に作成され(rollover)、ILM が古いデータを hot/warm/cold の階層に移動して削除する。TSDS(index.mode: time_series)はメトリクスデータに特化したストレージ最適化を提供する。少なくとも 1 つの time_series_dimension フィールド、それを指す index.routing_path、@timestamp フィールドが必須(そうでないとテンプレートが拒否される)。