Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 24 additions & 32 deletions rust/cubestore/cubestore-sql-tests/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3348,10 +3348,9 @@ async fn planning_hints(service: Box<dyn SqlClient>) {
assert_eq!(
pp_phys_plan_ext(p.worker.as_ref(), &show_hints),
"Worker, sort_order: [0, 1]\
\n CoalescePartitions, sort_order: [0, 1]\
\n Scan, index: default:1:[1], fields: [id1, id2], sort_order: [0, 1]\
\n Sort, sort_order: [0, 1]\
\n Empty"
\n Scan, index: default:1:[1], fields: [id1, id2], sort_order: [0, 1]\
\n Sort, sort_order: [0, 1]\
\n Empty"
);

let p = service
Expand All @@ -3362,10 +3361,9 @@ async fn planning_hints(service: Box<dyn SqlClient>) {
pp_phys_plan_ext(p.worker.as_ref(), &show_hints),
"Worker, sort_order: [1, 0]\
\n Projection, [id2, id1], sort_order: [1, 0]\
\n CoalescePartitions, sort_order: [0, 1]\
\n Scan, index: default:1:[1], fields: [id1, id2], sort_order: [0, 1]\
\n Sort, sort_order: [0, 1]\
\n Empty"
\n Scan, index: default:1:[1], fields: [id1, id2], sort_order: [0, 1]\
\n Sort, sort_order: [0, 1]\
\n Empty"
);

// Unsorted when skips columns from sort prefix.
Expand All @@ -3390,10 +3388,9 @@ async fn planning_hints(service: Box<dyn SqlClient>) {
assert_eq!(
pp_phys_plan_ext(p.worker.as_ref(), &show_hints),
"Worker, sort_order: [0]\
\n CoalescePartitions, sort_order: [0]\
\n Scan, index: default:1:[1], fields: [id1, id3], sort_order: [0]\
\n Sort, sort_order: [0]\
\n Empty"
\n Scan, index: default:1:[1], fields: [id1, id3], sort_order: [0]\
\n Sort, sort_order: [0]\
\n Empty"
);

// Single value hints.
Expand Down Expand Up @@ -3433,10 +3430,9 @@ async fn planning_hints(service: Box<dyn SqlClient>) {
pp_phys_plan_ext(p.worker.as_ref(), &show_hints),
"Worker, sort_order: [0, 1]\
\n Filter, sort_order: [0, 1]\
\n CoalescePartitions, sort_order: [0, 1, 2]\
\n Scan, index: default:1:[1], fields: *, sort_order: [0, 1, 2]\
\n Sort, sort_order: [0, 1, 2]\
\n Empty"
\n Scan, index: default:1:[1], fields: *, sort_order: [0, 1, 2]\
\n Sort, sort_order: [0, 1, 2]\
\n Empty"
);
}

Expand Down Expand Up @@ -3733,10 +3729,9 @@ async fn planning_simple(service: Box<dyn SqlClient>) {
assert_eq!(
pp_phys_plan(p.worker.as_ref()),
"Worker\
\n CoalescePartitions\
\n Scan, index: default:1:[1], fields: [id, amount]\
\n Sort\
\n Empty"
\n Scan, index: default:1:[1], fields: [id, amount]\
\n Sort\
\n Empty"
);

let p = service
Expand All @@ -3751,10 +3746,9 @@ async fn planning_simple(service: Box<dyn SqlClient>) {
pp_phys_plan(p.worker.as_ref()),
"Worker\
\n Filter\
\n CoalescePartitions\
\n Scan, index: default:1:[1], fields: [id, amount]\
\n Sort\
\n Empty"
\n Scan, index: default:1:[1], fields: [id, amount]\
\n Sort\
\n Empty"
);

let p = service
Expand All @@ -3776,10 +3770,9 @@ async fn planning_simple(service: Box<dyn SqlClient>) {
"Sort\
\n Worker\
\n Filter\
\n CoalescePartitions\
\n Scan, index: default:1:[1], fields: [id, amount]\
\n Sort\
\n Empty"
\n Scan, index: default:1:[1], fields: [id, amount]\
\n Sort\
\n Empty"
);

let p = service
Expand All @@ -3801,10 +3794,9 @@ async fn planning_simple(service: Box<dyn SqlClient>) {
"GlobalLimit, n: 10\
\n Worker\
\n Filter\
\n CoalescePartitions\
\n Scan, index: default:1:[1], fields: [id, amount]\
\n Sort\
\n Empty"
\n Scan, index: default:1:[1], fields: [id, amount]\
\n Sort\
\n Empty"
);

let p = service
Expand Down
12 changes: 8 additions & 4 deletions rust/cubestore/cubestore/src/queryplanner/query_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,8 @@ impl CubeTable {
let schema = table_projected_schema;
let partition_num = partition_execs.len();

let table_ordering = lex_ordering_for_index(self.index_snapshot.index.get_row(), &schema)?;

let read_data: Arc<dyn ExecutionPlan> = Arc::new(CubeTableExec {
schema: schema.clone(),
partition_execs,
Expand All @@ -891,10 +893,7 @@ impl CubeTable {
properties: PlanProperties::new(
EquivalenceProperties::new_with_orderings(
schema.clone(),
&[LexOrdering::new(lex_ordering_for_index(
self.index_snapshot.index.get_row(),
&schema,
)?)],
&[LexOrdering::new(table_ordering.clone())],
),
Partitioning::UnknownPartitioning(partition_num),
EmissionType::Incremental,
Expand Down Expand Up @@ -989,6 +988,11 @@ impl CubeTable {
LexOrdering::new(join_columns),
read_data,
))
} else if !table_ordering.is_empty() {
Arc::new(SortPreservingMergeExec::new(
LexOrdering::new(table_ordering),
read_data,
))
} else {
Arc::new(CoalescePartitionsExec::new(read_data))
};
Expand Down
Loading