Too many rows or bytes troubleshooting¶
Common issues and solutions for TOO_MANY_ROWS_OR_BYTES errors in ClickHouse and Tinybird.
Common causes¶
Large result sets¶
Issue: Queries returning more data than allowed
Solution: Use LIMIT and proper filtering
-- Add limits to prevent large results SELECT * FROM events WHERE date >= today() - 7 LIMIT 10000
Missing WHERE clauses¶
Issue: Queries without proper filters
Solution: Add selective filters
-- Add specific filters SELECT * FROM events WHERE user_id = 123 AND date >= '2023-01-01'
Memory management¶
Streaming queries¶
Issue: Large datasets consuming too much memory
Solution: Use streaming and smaller block sizes
-- Use streaming for large datasets SELECT * FROM events WHERE date >= today() - 30 SETTINGS max_block_size = 10000
Chunked processing¶
Issue: Processing entire datasets at once
Solution: Process data in chunks
-- Process by date ranges SELECT * FROM events WHERE date BETWEEN '2023-01-01' AND '2023-01-07'
Query optimization¶
Using aggregations¶
Issue: Returning raw data instead of summaries
Solution: Use aggregations to reduce result size
-- Aggregate instead of returning raw data SELECT user_id, count() as event_count, sum(value) as total_value FROM events GROUP BY user_id
Column selection¶
Issue: Selecting unnecessary columns
Solution: Select only needed columns
-- Select specific columns only SELECT user_id, event_type, timestamp FROM events WHERE date = today()
Configuration solutions¶
Adjusting limits¶
Issue: Default limits too restrictive
Solution: Configure appropriate limits
-- Set higher limits when needed SET max_result_rows = 1000000 SET max_result_bytes = 1000000000
Using sampling¶
Issue: Need to analyze large datasets
Solution: Use sampling for analysis
-- Use sampling for large datasets SELECT * FROM events SAMPLE 0.1 WHERE date >= today() - 30
Best practices¶
- Always use LIMIT - Prevent unexpectedly large results
- Add selective filters - Filter data early in queries
- Use aggregations - Summarize data instead of returning raw rows
- Select specific columns - Avoid SELECT * on large tables
- Use streaming - For large datasets, use streaming queries