Skip to content

Commit

Permalink
Improve output of plan
Browse files Browse the repository at this point in the history
  • Loading branch information
mamcx committed Dec 24, 2024
1 parent d34889f commit 81adebc
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 79 deletions.
134 changes: 82 additions & 52 deletions crates/physical-plan/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,15 +1287,17 @@ mod tests {
self.optimize = true;
self
}
fn show_source(mut self) -> Self {
fn with_source(mut self) -> Self {
self.show_source = true;
self
}
fn show_schema(mut self) -> Self {
fn with_schema(mut self) -> Self {
self.show_schema = true;
self
}
fn show_timings(mut self) -> Self {
// TODO: Remove when we integrate it.
#[allow(dead_code)]
fn with_timings(mut self) -> Self {
self.show_timings = true;
self
}
Expand Down Expand Up @@ -1363,6 +1365,8 @@ mod tests {
)
}

//TODO: This test are not ported until we integrate the changes that allow correctly report the labels.

/// No rewrites applied to a simple table scan
#[test]
fn table_scan_noop() {
Expand Down Expand Up @@ -1496,7 +1500,7 @@ mod tests {
Some(0),
));

let db = SchemaViewer::new(vec![u.clone(), l.clone(), b.clone()]);
let db = SchemaViewer::new(vec![u.clone(), l.clone(), b.clone()]).optimize();

let sql = "
select b.*
Expand Down Expand Up @@ -1917,28 +1921,27 @@ mod tests {

#[test]
fn plan_metadata() {
let db = data().show_schema().show_source().optimize();
let db = data().with_schema().with_source().optimize();
check_query(
&db,
"SELECT m.* FROM m CROSS JOIN p WHERE m.employee = 1",
expect![
r#"
Query: SELECT m.* FROM m CROSS JOIN p WHERE m.employee = 1
Nested Loop
-> Index Scan using Index id 0: (employee) on m
-> Index Scan using Index id 0: (employee) on m:1
-> Index Cond: (m.employee = U64(1))
-> Seq Scan on p:2
Output: id, name
-------
Schema:
Label 1: m
Label m: 1
Columns: employee, manager
Indexes: Unique(m.employee)
Label 2: p
Label p: 2
Columns: id, name
Indexes: Unique(p.id)
"#
Indexes: Unique(p.id)"#
],
);
}
Expand All @@ -1951,11 +1954,36 @@ mod tests {
"SELECT * FROM p",
expect![
r#"
Seq Scan on p
Output: id, name
"#
Seq Scan on p:1
Output: id, name"#
],
);
}

#[test]
fn table_alias() {
let db = data();
check_sub(
&db,
"SELECT * FROM p as b",
expect![
r#"
Seq Scan on p:1
Output: id, name"#
],
);
// TODO: Look like need pr #2074 to correctly report the labels and fields
// check_sub(
// &db,
// "select b.*
// from u
// join l as p",
// expect![
// r#"
// Seq Scan on p:1
// Output: id, name"#
// ],
// );
}

#[test]
Expand All @@ -1966,9 +1994,8 @@ mod tests {
"SELECT id FROM p",
expect![
r#"
Seq Scan on p
Output: p.id
"#
Seq Scan on p:1
Output: p.id"#
],
);

Expand All @@ -1978,10 +2005,9 @@ mod tests {
expect![
r#"
Nested Loop
-> Seq Scan on m
-> Seq Scan on p
Output: p.id, m.employee
"#
-> Seq Scan on m:1
-> Seq Scan on p:2
Output: p.id, m.employee"#
],
);
}
Expand All @@ -1993,11 +2019,19 @@ mod tests {
check_sub(
&db,
"SELECT * FROM p WHERE id = 1",
expect![["
Seq Scan on p
Filter: (p.id = U64(1))
Output: id, name
"]],
expect![[r#"
Seq Scan on p:1
Filter: (p.id = U64(1))
Output: id, name"#]],
);

check_query(
&db,
"SELECT * FROM p WHERE id = 1 AND id =2 OR name = 'jhon'",
expect![[r#"
Seq Scan on p:1
Filter: (p.id = U64(1) AND p.id = U64(2) OR p.name = String("jhon"))
Output: id, name"#]],
);
}

Expand All @@ -2008,11 +2042,10 @@ mod tests {
check_sub(
&db,
"SELECT m.* FROM m WHERE employee = 1",
expect![["
Index Scan using Index id 0[employee] on m
Index Cond: (m.employee = U64(1))
Output: employee, manager
"]],
expect![[r#"
Index Scan using Index id 0: (employee) on m:1
Index Cond: (m.employee = U64(1))
Output: employee, manager"#]],
);
}

Expand All @@ -2023,12 +2056,11 @@ mod tests {
check_sub(
&db,
"SELECT p.* FROM m JOIN p",
expect![["
Nested Loop
-> Seq Scan on m
-> Seq Scan on p
Output: id, name
"]],
expect![[r#"
Nested Loop
-> Seq Scan on m:1
-> Seq Scan on p:2
Output: id, name"#]],
);
}

Expand All @@ -2039,15 +2071,14 @@ mod tests {
check_sub(
&db,
"SELECT p.* FROM m JOIN p ON m.employee = p.id where m.employee = 1",
expect![["
Hash Join: All
-> Seq Scan on m
-> Seq Scan on p
Inner Unique: false
Hash Cond: (m.employee = p.id)
Filter: (m.employee = U64(1))
Output: id, name
"]],
expect![[r#"
Hash Join: All
-> Seq Scan on m:1
-> Seq Scan on p:2
Inner Unique: false
Hash Cond: (m.employee = p.id)
Filter: (m.employee = U64(1))
Output: id, name"#]],
);
}

Expand All @@ -2058,13 +2089,12 @@ mod tests {
check_sub(
&db,
"SELECT p.* FROM m JOIN p ON m.employee = p.id",
expect![["
Index Join: Rhs
-> Seq Scan on m
Inner Unique: true
Index Cond: (m.employee = p.id)
Output: employee, manager
"]],
expect![[r#"
Index Join: Rhs
-> Seq Scan on m:1
Inner Unique: true
Index Cond: (m.employee = p.id)
Output: employee, manager"#]],
);
}
}
Loading

0 comments on commit 81adebc

Please sign in to comment.