Operations Manual
Working Around Non-Determinism
For the majority of use cases, non-determinism is not causing any issues.
However, there are some cases where deterministic results are desirable.
In these cases, try the following workarounds:  
1. Limit the number of threads to prevent non-determinism introduced by multi-threading.  
```sql
SET threads = 1;
```  
2. Enforce ordering. For example, you can use the [`ORDER BY ALL` clause](#docs:sql:query_syntax:orderby::order-by-all):  
```sql
SELECT *
FROM (
SELECT 'A' AS x
UNION
SELECT 'B' AS x
)
ORDER BY ALL;
```  
You can also sort lists using [`list_sort`](#docs:sql:functions:list::list_sortlist):  
```sql
SELECT list_sort(array_distinct(['A', 'A', 'B', NULL, NULL])) AS i
ORDER BY i;
```  
It's also possible to introduce a [deterministic shuffling](https://duckdb.org/2024/08/19/duckdb-tricks-part-1#shuffling-data).