advanced
High-Volume SQL Query Optimization
Optimize a complex SQL query for a dataset with billions of rows.
📝 প্রম্পট বিষয়বস্তু
Given a PostgreSQL schema with tables 'events' (10 billion rows), 'users' (50 million rows), and 'products' (1 million rows), optimize the following hypothetical slow query: 'SELECT u.name, COUNT(e.id) FROM users u JOIN events e ON u.id = e.user_id WHERE e.timestamp > NOW() - INTERVAL '1 year' GROUP BY u.name HAVING COUNT(e.id) > 1000'. Explain your indexing strategy, potential partitioning approach, and rewrite the query if necessary to minimize execution time and resource consumption.