Always ensure database queries produce deterministic results by including explicit ORDER BY clauses when using LIMIT operations. This prevents unpredictable result ordering and potential data inconsistencies.
Key practices:
Example:
-- Incorrect: Non-deterministic ordering
SELECT *
FROM traces
WHERE project_id = ${projectId}
LIMIT 1;
-- Correct: Deterministic ordering
SELECT *
FROM traces
WHERE project_id = ${projectId}
ORDER BY event_ts DESC, id
LIMIT 1;
This practice is especially important when:
Enter the URL of a public GitHub repository