Search Timeout on Log Queries: Casting Operations in Custom Columns Cause Performance Issues

Last updated: February 20, 2026

Summary

Search timeouts on log queries can occur when custom columns use to_string() functions in their definitions. The to_string() operation forces the database to perform a full table scan instead of using optimized inverted indexes, resulting in significantly degraded query performance and potential timeouts. In most cases, the to_string operation is unnecessary for display purposes in custom columns and can be safely removed to restore normal query performance.

Symptoms

  • Search queries timing out when filtering or querying logs with custom columns

  • Queries that previously completed quickly now taking excessively long to execute

  • Timeout errors appearing specifically when custom columns containing to_string() operations are involved in the query

  • Performance degradation correlating with the addition or use of custom columns that include type casting

Workarounds

Option 1: Remove Casting Operations from Custom Columns (Recommended)

Update your custom column definitions to remove unnecessary to_string() operations. This allows Braintrust to use inverted indexes for efficient queries. In most cases, type casting is not required for custom columns to display correctly in the UI.

Example: Before (Slow)


-- Custom column with to_string (causes full table scan)
to_string(metadata.user_id)

Example: After (Fast)


-- Custom column without to_string (uses inverted index)
metadata.user_id

Steps to Update Custom Columns

  1. Navigate to your project's log view in the Braintrust UI

  2. Locate the custom columns that are using to_string() operations

  3. Edit each custom column definition to remove the to_string() function

  4. Save the updated custom column definition

  5. Test your queries to verify performance has improved

Technical Details

When a to_string() function is used in a custom column definition, the database query planner cannot utilize inverted indexes that would normally accelerate searches on JSON fields and metadata. Instead, the query engine must scan every row in the table and apply the cast operation, which becomes increasingly expensive as your log volume grows. This behavior is consistent with standard database query optimization principles where operations that transform indexed values prevent index usage.