feat: partition rule simplifier (#7622)

* basic impl

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* reuse collider

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* simplify range helpers

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* notes

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* update unit test resule

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

---------

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
Ruihang Xia
2026-01-27 22:31:20 +08:00
committed by GitHub
parent d0c610f3c7
commit c83868c4eb
5 changed files with 643 additions and 23 deletions

View File

@@ -1386,12 +1386,21 @@ impl StatementExecutor {
.map(|expr| convert_one_expr(expr, &column_name_and_type, &timezone))
.collect::<Result<Vec<_>>>()?;
let into_partition_exprs = request
let mut into_partition_exprs = request
.into_exprs
.iter()
.map(|expr| convert_one_expr(expr, &column_name_and_type, &timezone))
.collect::<Result<Vec<_>>>()?;
// `MERGE PARTITION` (and some `REPARTITION`) generates a single `OR` expression from
// multiple source partitions; try to simplify it for better readability and stability.
if from_partition_exprs.len() > 1
&& into_partition_exprs.len() == 1
&& let Some(expr) = into_partition_exprs.pop()
{
into_partition_exprs.push(partition::simplify::simplify_merged_partition_expr(expr));
}
// Parse existing partition expressions from region routes.
let mut existing_partition_exprs =
Vec::with_capacity(physical_table_route.region_routes.len());