Skip to content

Commit b5a2687

Browse files
committed
feat: composite index on spans table
1 parent eb5407e commit b5a2687

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

scripts/ddl/postgresql_schema.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,13 @@ create index ix_latency
529529
create index ix_cumulative_llm_token_count_total
530530
on public.spans ((cumulative_llm_token_count_prompt + cumulative_llm_token_count_completion));
531531

532+
create index ix_spans_trace_rowid_start_time
533+
on public.spans (trace_rowid, start_time);
534+
535+
create index ix_spans_trace_rowid_where_parent_id_is_null
536+
on public.spans (trace_rowid, start_time)
537+
where (parent_id IS NULL);
538+
532539
create table public.span_annotations
533540
(
534541
id serial

src/phoenix/db/migrations/versions/272b66ff50f8_drop_single_indices.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""drop single indices from traces and project_sessions
1+
"""drop single indices from traces, project_sessions, and spans
22
33
Revision ID: 272b66ff50f8
44
Revises: a20694b15f82
@@ -24,10 +24,14 @@ def upgrade() -> None:
2424
op.drop_index("ix_project_sessions_project_id", table_name="project_sessions")
2525
op.drop_index("ix_project_sessions_start_time", table_name="project_sessions")
2626

27+
op.drop_index("ix_spans_trace_rowid", table_name="spans")
28+
2729

2830
def downgrade() -> None:
2931
op.create_index("ix_traces_project_rowid", "traces", ["project_rowid"])
3032
op.create_index("ix_traces_start_time", "traces", ["start_time"])
3133

3234
op.create_index("ix_project_sessions_project_id", "project_sessions", ["project_id"])
3335
op.create_index("ix_project_sessions_start_time", "project_sessions", ["start_time"])
36+
37+
op.create_index("ix_spans_trace_rowid", "spans", ["trace_rowid"])

src/phoenix/db/migrations/versions/735d3d93c33e_add_composite_indices.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""add composite indices to traces and project_sessions
1+
"""add composite indices to traces, project_sessions, and partial index to spans
22
33
Revision ID: 735d3d93c33e
44
Revises: 272b66ff50f8
@@ -31,8 +31,19 @@ def upgrade() -> None:
3131
"ON project_sessions (project_id, start_time DESC)"
3232
)
3333
)
34+
op.execute(
35+
sa.text("CREATE INDEX ix_spans_trace_rowid_start_time ON spans (trace_rowid, start_time)")
36+
)
37+
op.execute(
38+
sa.text(
39+
"CREATE INDEX ix_spans_trace_rowid_start_time_where_parent_id_is_null "
40+
"ON spans (trace_rowid, start_time) WHERE parent_id IS NULL"
41+
)
42+
)
3443

3544

3645
def downgrade() -> None:
3746
op.drop_index("ix_traces_project_rowid_start_time", table_name="traces")
3847
op.drop_index("ix_project_sessions_project_id_start_time", table_name="project_sessions")
48+
op.drop_index("ix_spans_trace_rowid_start_time", table_name="spans")
49+
op.drop_index("ix_spans_trace_rowid_where_parent_id_is_null", table_name="spans")

0 commit comments

Comments
 (0)