Skill: Enterprise Lakehouse Performance Optimization
Description
Equips the agent with the ability to detect performance bottlenecks in data lakehouses, such as the small-file problem, poor partitioning, missed query optimization opportunities, and provide actionable recommendations like Liquid Clustering and Bloom Filters.
Context
Lakehouse performance degrades significantly without routine maintenance. The agent must proactively suggest advanced tuning capabilities across Spark, Trino, and Databricks.
Instructions
1. Small-File Detection & Compaction
- Action: If the average file size is < 50 MB, trigger a "Small File Warning".
- Advanced Action: Recommend setting target file sizes on the table properties so writers automatically optimize.
-- Delta Lake (Databricks)
ALTER TABLE table_name SET TBLPROPERTIES ('delta.targetFileSize' = '134217728');
2. Advanced Layout & Clustering
Stop recommending simple ZORDER blindly. Evaluate the table size and write pattern:
- Databricks Liquid Clustering: For tables experiencing frequent updates or varying query patterns, strongly recommend Liquid Clustering over Z-Ordering.
ALTER TABLE table_name CLUSTER BY (col1, col2); - Iceberg Hidden Partitioning: Check if users are extracting date strings manually (e.g.,
date_format(ts, 'yyyy-MM-dd')). Recommend Iceberg's native partition transforms (partition by days(ts)).
3. Data Skipping & Bloom Filters
If queries filtering on high-cardinality strings (like user_id or uuid) are slow:
- Suggest enabling Bloom Filter indexes.
-- Databricks Delta
CREATE BLOOMFILTER INDEX ON TABLE my_table FOR COLUMNS(user_id OPTIONS (fpp=0.1, numItems=50000000));
4. Query Optimization & CBO (Cost-Based Optimizer)
If the user provides a slow Spark SQL query:
- Check for
SortMergeJoinvsBroadcastHashJoin. Suggest/*+ BROADCAST(table) */for small dimension tables. - Suggest running
ANALYZE TABLE my_table COMPUTE STATISTICSso the engine can utilize the Cost-Based Optimizer (CBO).
Output Format: Performance Report
### 🚀 Enterprise Performance Report: `[Table Name]`
**Health Score:** [e.g., 65/100]
#### ⚠️ Issues Detected
1. **Small File Problem:** Average file size is 12 MB (Target: 128 MB).
2. **Missing Statistics:** CBO cannot optimize joins because table stats are missing.
#### 🛠️ Recommended Actions
- [ ] **Liquid Clustering:** Migrate from Z-Ordering to Liquid Clustering for better write concurrency. `ALTER TABLE [table] CLUSTER BY (...)`
- [ ] **Compute Stats:** Execute `ANALYZE TABLE [table] COMPUTE STATISTICS`.