Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

What does ORDER BY tuple() do in clickhouse exactly?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-pro’s answer.
  1. User

    What does ORDER BY tuple() do in clickhouse exactly?

  2. Claude Assistant

    In ClickHouse, ORDER BY tuple() creates an ordering based on an empty tuple, which effectively means "no ordering" or random ordering.

    Here's what happens exactly:

    When you use ORDER BY tuple(), ClickHouse evaluates tuple() for each row, which returns an empty tuple (). Since all rows have the same empty tuple value, there's no meaningful basis for ordering the results. This means:

    1. No guaranteed order: The rows can be returned in any order that's convenient for the query engine
    2. Performance optimization: ClickHouse can skip the sorting step entirely since there's nothing to sort by
    3. Implementation-dependent results: The actual order you see depends on how ClickHouse processes the data internally - it might be the order data was inserted, the order it was read from disk, or based on parallel processing

    This is commonly used when:

    • You want to explicitly indicate that order doesn't matter for your query
    • You're using it with LIMIT to get a random sample of rows (though the randomness isn't cryptographically random)
    • You want to avoid any default ordering behavior that might be applied

    For example:

    SELECT * FROM my_table ORDER BY tuple() LIMIT 10;
    

    This would return 10 rows in whatever order is most efficient for ClickHouse to produce, rather than applying any specific ordering logic.

    If you actually want random ordering, you'd typically use ORDER BY rand() instead, which provides true randomization.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.