class OptimizeStatementPlanner

Plans OPTIMIZE as one statement per bounded group of partitions, so no single query ever opens more writers than Trino’s Iceberg connector default (iceberg.max-partitions-per-writer = 100) allows.

A table that is badly behind on maintenance can accumulate far more identity partitions than any static limit - a table that missed 100 daily partitions could just as easily miss 1000. Batching sidesteps the ceiling entirely: each statement touches only a bounded subset of the partition column, so it always completes instead of failing outright on the tables that need the maintenance most.

Batching only applies when it is safe to scope by partition: * the step is an OPTIMIZE * the operator did not already set a WHERE predicate (that would conflict) * the table has a single identity-transformed partition column In every other case the planner returns the single, unbatched statement, so behaviour is unchanged.