What are the potential performance issues when using SQL ROLLUP in PHP and how can they be mitigated?

Potential performance issues when using SQL ROLLUP in PHP include increased processing time and memory usage due to the aggregation of multiple rows into a single result set. To mitigate these issues, consider limiting the number of rows being aggregated or optimizing the SQL query to reduce the amount of data being processed.

// Example of limiting the number of rows being aggregated
$query = "SELECT column1, SUM(column2) FROM table GROUP BY column1 WITH ROLLUP LIMIT 100";
$result = mysqli_query($connection, $query);
while ($row = mysqli_fetch_assoc($result)) {
    // Process the aggregated data
}