发布

  • [NA] [BE] Performant ClickHouse bulk update queries to ensure latest row selection (#4206)

    frostbyte_neo 发布于 2025-11-24 15:03:29 +00:00

    • [BE] Fix ClickHouse TraceThreadDAO bulk update query to use latest row
    • Add ORDER BY tt.last_updated_at DESC LIMIT 1 BY tt.id to BULK_UPDATE query
    • Prevents bug where bulk updates could select old historical rows
    • Aligns with existing fixes in SpanDAO and TraceDAO which already have this protection
    • Add regression test batchUpdate__whenMultiplePartialUpdates__thenLatestValuesPreserved
    • Test verifies that multiple sequential bulk updates preserve the latest values

    Note: SpanDAO and TraceDAO already have ORDER BY + LIMIT 1 BY protection and did not need fixes

    • Optimize ORDER BY clauses in bulk update queries to follow primary key order
    • Update TraceDAO BULK_UPDATE to order by (workspace_id, project_id, id) DESC, last_updated_at DESC
    • Update TraceThreadDAO BULK_UPDATE to order by (workspace_id, project_id, thread_id, id) DESC, last_updated_at DESC
    • Aligns with ClickHouse best practice: ORDER BY primary key tuple, then last_updated_at for deduplication
    • Improves query performance by following table's natural sort order
    • ExperimentDAO and SpanDAO already follow this pattern correctly
    • Revision 2: Remove 'final' from TraceThreadDAO bulk update for consistency and performance

    • Format fix

    下载附件