Benchmark Lakehouse Table Layouts with Queries
In this article
Benchmarking lakehouse table layouts with representative queries helps you choose the right file format, partitioning, and sorting strategy before committing to a production schema. This guide walks you through a repeatable process: define query templates, generate or sample data, run controlled tests, and interpret the results. You'll need access to a lakehouse engine (Spark, Trino, DuckDB, or similar), a test dataset, and a way to record timings.
What You'll Need
- A lakehouse engine (e.g., Apache Spark, Trino, DuckDB) with SQL support.
- A test dataset that mimics your real data's size, cardinality, and distribution. At least 1–10 GB is recommended to see meaningful differences.
- Access to write files in a lakehouse format (Parquet, ORC, Delta Lake, Iceberg, Hudi).
- A script or notebook to run queries and capture execution time.
- Optional: a monitoring tool (like Grafana or a simple log parser) to track resource usage.
Step-by-Step
- Define your representative query set. Pick 5–10 queries that reflect your actual workload: point lookups (e.g.,
SELECT * FROM orders WHERE order_id = 12345), range scans (e.g.,WHERE order_date BETWEEN '2024-01-01' AND '2024-01-31'), aggregations (e.g.,SELECT region, SUM(amount) FROM sales GROUP BY region), and joins (e.g.,SELECT ... FROM orders JOIN customers ON ...). Include at least one query that filters on a high-cardinality column and one on a low-cardinality column. - Choose the layouts to test. Common variants: unsorted Parquet, Parquet partitioned by a date column, Parquet sorted by a filter column, ORC with bloom filters, Delta Lake with Z-order, and Iceberg with hidden partitioning. Limit to 3–4 layouts per run to keep the test manageable.
- Prepare the data. Generate or copy your dataset into each layout. Ensure the data content is identical across layouts—only the physical organization differs. Write files with a realistic compression codec (e.g., Snappy for Parquet, Zlib for ORC) and a file size that matches your production target (typically 64–256 MB per file).
- Warm up the cache. Run each query once on a small sample to load metadata and warm the OS cache. Then, for the actual benchmark, clear the cache if possible (e.g., restart the engine or drop the OS cache) to measure cold performance. Alternatively, run the queries multiple times and take the median to measure warm performance.
- Run the queries sequentially. For each layout, run the full query set in the same order. Record the execution time for each query using the engine's query history or a simple timer in your script. Use a consistent concurrency level (usually 1) to isolate layout effects.
- Repeat the run. Execute the entire benchmark 3–5 times per layout to account for variance. Take the median or geometric mean of the runs for each query.
- Collect additional metrics. Beyond wall-clock time, note the number of files scanned, bytes read, and partitions pruned. Most engines expose these in query plans or metrics. This helps explain why one layout is faster.
- Analyze the results. Create a table with rows as queries and columns as layouts, filled with median times. Normalize by the fastest layout for each query (e.g., show speedup factor). Look for patterns: which layout wins on point lookups vs. aggregations? Is the winner consistent across all queries?
- Consider storage cost. Measure the total size of each layout on disk. A layout that is 20% faster but 50% larger may not be worth it. Record compression ratio and file count.
- Validate with a production-like workload. If possible, run a mixed workload (e.g., 70% reads, 20% writes, 10% updates) for a longer period (1 hour) to see if the chosen layout degrades under real concurrency.
- Document and decide. Write a short report with your methodology, raw numbers, and a recommendation. Include the exact engine version, data size, and query text so the benchmark is reproducible.
Common Mistakes
- Testing on tiny data. With less than 100 MB, the engine may read everything into memory and layout differences vanish. Use at least 1 GB.
- Ignoring cache effects. Running the same query twice in a row on the same engine can give a false impression. Always separate runs or clear caches.
- Using different query plans. If the engine rewrites queries differently (e.g., due to statistics), you're not comparing layouts. Force the same join order or use hints if needed.
- Not checking data distribution. A layout that works for a uniform dataset may fail for skewed data. Use your real data or a realistic synthetic generator.
- Only measuring time. Time can be noisy. Also record bytes scanned and files opened—these are more stable and reveal why a layout is faster.
- Overlooking writes. A layout optimized for reads may slow down ingestion. If you have frequent writes, include an insert/update test.
Tips
- Use a script to automate. Manual running invites errors. Write a Python script that creates tables, runs queries, and logs times to a CSV.
- Start with a baseline. Always include an unsorted, unpartitioned layout as a reference point.
- Test with your actual query patterns. Don't rely on generic benchmarks—your data and queries are unique.
- Use explain plans. Before running, check if the engine prunes partitions or uses file statistics. This can predict which layout will win.
- Consider the engine's optimization features. For example, Delta Lake's Z-order and Iceberg's hidden partitioning are designed for specific query types. Read the documentation to know what to expect.
- Keep the benchmark short. A full run should take under 30 minutes. If it takes longer, reduce the number of queries or data size.
Troubleshooting
- Queries take too long. If a query runs for minutes, check if the layout is missing statistics or if the engine is doing a full scan. Add file-level statistics (e.g., Parquet footer) or increase file size. Also verify that the query predicate can actually be used for pruning.
- Results vary wildly between runs. This is often due to cluster contention or OS cache. Run on a dedicated cluster, use the same node count, and take the median of 5 runs. Also check if other jobs are running.
- Layout A is faster in one run, B in another. This suggests the difference is within noise. Increase the data size or run more repetitions. If the difference is less than 10%, it's probably not significant.
- Engine errors when writing a layout. Ensure you have the correct format-specific libraries (e.g., Delta Lake requires a separate package). Check the engine's documentation for format support and version compatibility.
- Partitioning doesn't help. If your query filters on a column that is not the partition key, partitioning won't help. Try sorting or Z-order instead. Also verify that the partition column has low cardinality—too many partitions (e.g., millions) can hurt.
- Bytes scanned is still high. Even with partitioning, the engine may read all files if the predicate is not pushdown-able. Use a columnar format and ensure the engine supports predicate pushdown (most do). For text-based filters, consider using a bloom filter or dictionary encoding.
Frequently Asked Questions
- How many queries should I include? Aim for 5–10 that cover your main access patterns. More than 10 adds time without much benefit.
- What data size is ideal? At least 1 GB, but ideally 10–100 times your typical query's scan size. If your production tables are 100 GB, test with 10 GB to keep the benchmark fast while still being representative.
- Should I test on a single node or a cluster? Start on a single node to remove network variance. Then, if your production uses a cluster, spot-check with a small cluster to ensure scaling behavior is similar.
- Can I use synthetic data? Yes, but make sure the cardinality, skew, and value distribution match your real data. For example, if your IDs are sequential, generate sequential IDs; if they're random, generate random ones.
- How do I measure bytes scanned? In Spark, use the SQL metrics (e.g.,
scanTimeandbytesRead). In Trino, the query details show 'processed bytes'. In DuckDB, useEXPLAIN ANALYZE. These metrics are more reliable than time alone. - What if the best layout for reads is bad for writes? That's common. If you have mixed workloads, run a combined test and weigh the trade-off. Sometimes a slightly slower read layout with faster writes is better overall.