このトピックでは、軌道データを使用するためのベストプラクティスについて説明します。
適切な時空間インデックスの使用
アプリケーション要件に基づいて適切なインデックスを作成し、クエリを高速化できます。 軌道データは、次のインデックスタイプをサポートします。
空間インデックス: 空間上のインデックスで、軌道の空間データのみをクエリする場合に適用されます。
時間インデックス: 時間のインデックス。軌跡の時間範囲のみをクエリする場合に適用されます。
空間-時間複合インデックス: 空間と時間の両方の複合インデックス。軌道の空間データと時間範囲の両方をクエリするときに適用されます。
-- Create a function-based spatial index to accelerate the filtering of spatial data.
create index tr_spatial_geometry_index on trajtab using gist (st_trajectoryspatial(traj));
-- Create a function-based temporal index to accelerate the filtering of time.
create index tr_timespan_time_index on trajtab using gist (st_timespan(traj));
-- Create function-based indexes on the start time and end time of a trajectory object.
create index tr_starttime_index on trajtab using btree (st_starttime(traj));
create index tr_endtime_index on trajtab using btree (st_endtime(traj));
-- Create a btree_gist extension.
create extension btree_gist;
-- Use btree_gist to create a spatio-temporal composite index on the start time, end time, and spatial data of a trajectory object.
create index tr_traj_test_stm_etm_sp_index on traj_test using gist (st_starttime(traj),st_endtime(traj),st_trajectoryspatial(traj));適切なパーティション分割テーブルの使用
データベース内の軌跡データの量は、データベースの継続的な使用に伴って増加し続けます。 その結果、多数のデータベースインデックスが作成され、データ照会の速度が低下します。 この場合、パーティション分割テーブルを使用することで、1 つのテーブルのデータサイズを減らすことができます。
パーティションテーブルの使用方法の詳細については、「」「パーティションテーブル」をご参照ください。
文字列型の属性フィールドの使用を減らす
軌跡データ内の文字列型属性フィールドの数が多いと、記憶容量の浪費や性能低下につながる。
文字列型の属性フィールドに固定値がある場合は、整数に変換できます。 コードでデータ型を変換することを推奨します。
文字列タイプの属性フィールドが必要な場合は、フィールドのデフォルトの長さを設定して、スペースを節約できます。
文字列型の属性フィールドの既定の長さを設定するには、次のステートメントを実行します。
-- Set the default length of string-type attribute fields to 32. Set ganos.trajectory.attr_string_length = 32;
複数の軌道点を使用して軌道オブジェクトを生成する
複数の軌道ポイントを使用して軌道オブジェクトを生成し、軌道ポイントを1つずつ追加しないことを推奨します。
高度な圧縮モードを使用する
LZ4 は、より高い圧縮率と実行速度を備えた高度な圧縮アルゴリズムです。 LZ4圧縮アルゴリズムを有効または無効にするには、次のステートメントを実行します。
-- Enable LZ4 compression.
Set toast_compression_use_lz4 = true;
-- Disable LZ4 compression and use the default PostgreSQL compression algorithm.
Set toast_compression_use_lz4 = false;デフォルトでデータベース全体のLZ4圧縮アルゴリズムを有効または無効にするには、次のステートメントを実行します。
-- Enable LZ4 compression for the database.
Alter database dbname Set toast_compression_use_lz4 = true;
-- Disable LZ4 compression and use the default compression algorithm for the database.
Alter database dbname Set toast_compression_use_lz4 = false;