jargon

Data engineering·topic 8 of 8

Cost, layout and query performance

Warehouse compute is billed by what you read, so data layout is a budget decision rather than a tuning detail. These are the words for why one query costs pennies and the same answer costs four hundred pounds.

Read in order · tick what you already know

  1. 01

    you partitioned by customer id, there are two million customers, and now every query lists two million tiny folders.

    Partitioning strategy

  2. 02

    the table is partitioned by day and sorted within each day by customer, so filtering on a customer skips most blocks inside the partition.

    Clustering key

  3. 03

    the rows are stored in date order, so a range query reads a contiguous run of blocks instead of touching all of them.

    Sort key

  4. 04

    queries filter on either region or product, never both, and one linear sort order can only help one of them.

    Z-ordering

  5. 05

    the query returned four rows and the console says it read two point one terabytes.

    Bytes scanned

  6. 06

    one dashboard refreshing every five minutes turned out to be a third of the monthly warehouse bill.

    Query cost

  7. 07

    the second person to run the identical query got the answer instantly and was charged nothing.

    Result cache

  8. 08

    you doubled the warehouse size, the query took half as long, and the bill was identical.

    Warehouse sizing

  9. 09

    the cluster stayed up all weekend waiting for queries that never came, and the invoice noticed.

    Idle compute

  10. 10

    you scale up the query cluster for the month-end run and the data does not move anywhere.

    Storage-compute separation

  11. 11

    the join needs matching keys on the same machine, so the engine moves the whole dataset across the network before it can start.

    Shuffle

  12. 12

    the small dimension table is copied to every worker so the big table never has to move.

    Broadcast join

  13. 13

    both sides are too big to broadcast, so each is shuffled and sorted by the key and then walked through in step.

    Sort-merge join

  14. 14

    one side is built into an in-memory hash table and the other is streamed past it, and it is fast right up until the build side does not fit.

    Hash join

  15. 15

    the sort did not fit in memory, started writing to local disk, and the query went from forty seconds to nineteen minutes.

    Spill to disk

  16. 16

    ninety-nine tasks finished in twenty seconds and the hundredth ran for eleven minutes, because one key has forty percent of the rows.

    Data skew

  17. 17

    the stage is at nine hundred and ninety-nine of a thousand tasks complete and has been for six minutes.

    Straggler task

  18. 18

    the plan says it expects nine hundred rows from that filter, it actually returns forty million, and every choice after that is wrong.

    Cardinality estimate

  19. 19

    the engine started the join, saw that one side was much smaller than predicted, and switched strategy mid-query.

    Adaptive query execution

  20. 20

    the engine processes a thousand values of one column per operation instead of one row at a time through a chain of function calls.

    Vectorised execution

  21. 21

    the model rebuilds only the last three days each run instead of the whole four-year table, and once a month you rebuild it fully anyway.

    Incremental model

  22. 22

    you drop the table and rebuild it entirely from source, which is expensive, slow and definitely correct.

    Full refresh

  23. 23

    every query is tagged with a team, so the monthly bill can be broken down by who actually spent it.

    Cost attribution