Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

@waleedlatif1 waleedlatif1 commented Oct 11, 2025

Summary

  • remove unused source/target indices
  • add index on snapshot id

Type of Change

  • Other: Performance

Testing

Tested manually/

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel vercel bot temporarily deployed to Preview – docs October 11, 2025 18:22 Inactive
@vercel vercel bot temporarily deployed to Preview – sim October 11, 2025 18:22 Inactive
@vercel
Copy link

vercel bot commented Oct 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 11, 2025 6:22pm
sim Skipped Skipped Oct 11, 2025 6:22pm

@waleedlatif1 waleedlatif1 marked this pull request as ready for review October 11, 2025 18:24
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Summary

This PR optimizes database indices for the workflow_edges and workflow_execution_logs tables.

Changes:

  • Removes redundant single-column indices workflow_edges_source_block_idx and workflow_edges_target_block_idx from the workflow_edges table. These indices are unnecessary because all queries filter by workflowId first, making the existing composite indices workflow_edges_workflow_source_idx (on workflowId, sourceBlockId) and workflow_edges_workflow_target_idx (on workflowId, targetBlockId) sufficient and more efficient.
  • Adds workflow_execution_logs_state_snapshot_id_idx on workflow_execution_logs.state_snapshot_id. This index optimizes join queries between workflow_execution_logs and workflow_execution_snapshots tables, which are used in multiple API endpoints to fetch execution state data.

The migration correctly synchronizes the SQL changes with the schema definition.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The changes are well-justified performance optimizations. The removed indices are redundant because all workflow_edges queries filter by workflowId first, making composite indices more effective. The added stateSnapshotId index directly addresses a real query pattern (joins with workflow_execution_snapshots) found in multiple API routes. The migration is properly structured and synchronized with the schema.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/db/migrations/0098_thick_prima.sql 5/5 Drops unused single-column indices on workflow_edges and adds new index on workflow_execution_logs.state_snapshot_id for join queries
packages/db/schema.ts 5/5 Removes redundant single-column indices from workflowEdges table and adds stateSnapshotIdIdx to workflowExecutionLogs table

Sequence Diagram

sequenceDiagram
    participant API as API Route
    participant DB as Database
    participant WEL as workflow_execution_logs
    participant WES as workflow_execution_snapshots
    participant WE as workflow_edges

    Note over WE: Before: Had redundant indices<br/>source_block_idx, target_block_idx
    Note over WE: After: Only composite indices<br/>workflow_source_idx, workflow_target_idx

    API->>DB: Query workflow edges
    DB->>WE: SELECT * WHERE workflowId = ?
    Note over WE: Uses workflow_id_idx<br/>(composite indices cover<br/>source/target filtering)
    WE-->>DB: Return edges
    DB-->>API: Edges data

    API->>DB: Query execution logs with state
    DB->>WEL: SELECT * WHERE executionId = ?
    WEL-->>DB: Return log with stateSnapshotId
    
    Note over WEL: New index added:<br/>state_snapshot_id_idx
    
    DB->>WES: SELECT * WHERE id = stateSnapshotId
    Note over WES: Join optimized by new index
    WES-->>DB: Return snapshot data
    DB-->>API: Complete execution data
Loading

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit 561448b into staging Oct 11, 2025
10 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/perforamnce branch October 11, 2025 18:28
@elviromercic23-cmyk
Copy link

elviromercic23-cmyk commented Oct 11, 2025 via email

waleedlatif1 added a commit that referenced this pull request Oct 12, 2025
waleedlatif1 added a commit that referenced this pull request Oct 12, 2025
waleedlatif1 added a commit that referenced this pull request Oct 12, 2025
* improvement(performance): remove unused source/target indices, add index on snapshot id (#1603)

* fix(blog): rename building to blogs with redirect (#1604)

* improvement(privacy-policy): updated privacy policy for google (#1602)

* updated privacy policy for google

* update terms, privacy, and emails to incl address and update verbiage

* feat(guardrails): added guardrails block/tools and docs (#1605)

* Adding guardrails block

* ack PR comments

* cleanup checkbox in dark mode

* cleanup

* fix supabase tools

* fix(inference-billing): fix inference billing when stream is true via API, add drag-and-drop functionality to deployed chat (#1606)

* fix(inference): fix inference billing when stream is true via API

* add drag-and-drop to deployed chat

* feat(mistal): added mistral as a provider, updated model prices (#1607)

* feat(mistal): added mistral as a provider, updated model prices

* remove the ability for a block to reference its own outluts

* fixed order of responses for guardrails block

* feat(versions): added the ability to rename deployment versions (#1610)

* fix(vulns): fix various vulnerabilities and enhanced code security (#1611)

* fix(vulns): fix SSRF vulnerabilities

* cleanup

* cleanup

* regen docs

* remove unused deps

* fix failing tests

* cleanup

* update deps

* regen bun lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants