Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(planner): refine project set cardinality #16944

Merged
merged 4 commits into from
Nov 26, 2024
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
2 changes: 2 additions & 0 deletions src/query/sql/src/planner/plans/project_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ impl ProjectSet {
pub fn derive_project_set_stats(&self, input_stat: &mut StatInfo) -> Result<Arc<StatInfo>> {
// ProjectSet is set-returning functions, precise_cardinality set None
input_stat.statistics.precise_cardinality = None;
// We assume that the SRF function will expand by at least x3 per row.
input_stat.cardinality *= 3.0;
Ok(Arc::new(input_stat.clone()))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ AggregateFinal
├── estimated rows: 1.00
└── ProjectSet
├── output columns: [unnest(fold_count.id (#0)) (#2)]
├── estimated rows: 1.00
├── estimated rows: 3.00
├── set returning functions: unnest(fold_count.id (#0))
└── TableScan
├── table: default.default.fold_count
Expand Down Expand Up @@ -54,7 +54,7 @@ explain select number from (select unnest([1,2,3]), number from numbers(10)) t
----
ProjectSet
├── output columns: [numbers.number (#0), unnest([1, 2, 3]) (#1)]
├── estimated rows: 10.00
├── estimated rows: 30.00
├── set returning functions: unnest([1, 2, 3])
└── TableScan
├── table: default.system.numbers
Expand All @@ -71,7 +71,7 @@ explain select number from (select unnest([1,2,3,number]), number from numbers(1
----
ProjectSet
├── output columns: [numbers.number (#0), unnest(array(1, 2, 3, numbers.number (#0))) (#1)]
├── estimated rows: 10.00
├── estimated rows: 30.00
├── set returning functions: unnest(CAST(array(1, 2, 3, numbers.number (#0)) AS Array(UInt64 NULL)))
└── TableScan
├── table: default.system.numbers
Expand Down Expand Up @@ -131,5 +131,42 @@ EvalScalar
├── push downs: [filters: [], limit: NONE]
└── estimated rows: 0.00

query T
explain select * from (select unnest([1,2,3]), number from numbers(10)) t1(a) inner join (select * from numbers(15)) t2(a) on t1.a = t2.a;
----
HashJoin
├── output columns: [numbers.number (#0), a (#2), numbers.number (#3)]
├── join type: INNER
├── build keys: [CAST(t2.a (#3) AS UInt64 NULL)]
├── probe keys: [CAST(t1.a (#2) AS UInt64 NULL)]
├── filters: []
├── estimated rows: 450.00
├── TableScan(Build)
│ ├── table: default.system.numbers
│ ├── output columns: [number (#3)]
│ ├── read rows: 15
│ ├── read size: < 1 KiB
│ ├── partitions total: 1
│ ├── partitions scanned: 1
│ ├── push downs: [filters: [], limit: NONE]
│ └── estimated rows: 15.00
└── EvalScalar(Probe)
├── output columns: [numbers.number (#0), a (#2)]
├── expressions: [get(1)(unnest([1, 2, 3]) (#1))]
├── estimated rows: 30.00
└── ProjectSet
├── output columns: [numbers.number (#0), unnest([1, 2, 3]) (#1)]
├── estimated rows: 30.00
├── set returning functions: unnest([1, 2, 3])
└── TableScan
├── table: default.system.numbers
├── output columns: [number (#0)]
├── read rows: 10
├── read size: < 1 KiB
├── partitions total: 1
├── partitions scanned: 1
├── push downs: [filters: [], limit: NONE]
└── estimated rows: 10.00

statement ok
drop database project_set
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ explain select name, json_path_query(details, '$.features.*') as all_features, j
EvalScalar
├── output columns: [products.name (#0), all_features (#3), first_feature (#4)]
├── expressions: [get(1)(json_path_query(products.details (#1), '$.features.*') (#2)), json_path_query_first(products.details (#1), '$.features.*')]
├── estimated rows: 0.12
├── estimated rows: 0.36
└── Filter
├── output columns: [products.name (#0), products.details (#1), json_path_query(products.details (#1), '$.features.*') (#2)]
├── filters: [is_true(TRY_CAST(get(1)(json_path_query(products.details (#1), '$.features.*') (#2)) AS String NULL) = '512GB')]
├── estimated rows: 0.12
├── estimated rows: 0.36
└── ProjectSet
├── output columns: [products.name (#0), products.details (#1), json_path_query(products.details (#1), '$.features.*') (#2)]
├── estimated rows: 0.60
├── estimated rows: 1.80
├── set returning functions: json_path_query(products.details (#1), '$.features.*')
└── Filter
├── output columns: [products.name (#0), products.details (#1)]
Expand Down Expand Up @@ -49,10 +49,10 @@ explain select name, json_path_query(details, '$.features.*') as all_features, j
EvalScalar
├── output columns: [products.name (#0), all_features (#3), first_feature (#4)]
├── expressions: [get(1)(json_path_query(products.details (#1), '$.features.*') (#2)), json_path_query_first(products.details (#1), '$.features.*')]
├── estimated rows: 0.60
├── estimated rows: 1.80
└── ProjectSet
├── output columns: [products.name (#0), products.details (#1), json_path_query(products.details (#1), '$.features.*') (#2)]
├── estimated rows: 0.60
├── estimated rows: 1.80
├── set returning functions: json_path_query(products.details (#1), '$.features.*')
└── Filter
├── output columns: [products.name (#0), products.details (#1)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ AggregateFinal
├── estimated rows: 1.00
└── ProjectSet
├── output columns: [unnest(fold_count.id (#0)) (#2)]
├── estimated rows: 1.00
├── estimated rows: 3.00
├── set returning functions: unnest(fold_count.id (#0))
└── TableScan
├── table: default.default.fold_count
Expand Down Expand Up @@ -54,7 +54,7 @@ explain select number from (select unnest([1,2,3]), number from numbers(10)) t
----
ProjectSet
├── output columns: [numbers.number (#0), unnest([1, 2, 3]) (#1)]
├── estimated rows: 10.00
├── estimated rows: 30.00
├── set returning functions: unnest([1, 2, 3])
└── TableScan
├── table: default.system.numbers
Expand All @@ -71,7 +71,7 @@ explain select number from (select unnest([1,2,3,number]), number from numbers(1
----
ProjectSet
├── output columns: [numbers.number (#0), unnest(array(1, 2, 3, numbers.number (#0))) (#1)]
├── estimated rows: 10.00
├── estimated rows: 30.00
├── set returning functions: unnest(CAST(array(1, 2, 3, numbers.number (#0)) AS Array(UInt64 NULL)))
└── TableScan
├── table: default.system.numbers
Expand All @@ -83,5 +83,42 @@ ProjectSet
├── push downs: [filters: [], limit: NONE]
└── estimated rows: 10.00

query T
explain select * from (select unnest([1,2,3]), number from numbers(10)) t1(a) inner join (select * from numbers(15)) t2(a) on t1.a = t2.a;
----
HashJoin
├── output columns: [numbers.number (#0), a (#2), numbers.number (#3)]
├── join type: INNER
├── build keys: [CAST(t2.a (#3) AS UInt64 NULL)]
├── probe keys: [CAST(t1.a (#2) AS UInt64 NULL)]
├── filters: []
├── estimated rows: 450.00
├── TableScan(Build)
│ ├── table: default.system.numbers
│ ├── output columns: [number (#3)]
│ ├── read rows: 15
│ ├── read size: < 1 KiB
│ ├── partitions total: 1
│ ├── partitions scanned: 1
│ ├── push downs: [filters: [], limit: NONE]
│ └── estimated rows: 15.00
└── EvalScalar(Probe)
├── output columns: [numbers.number (#0), a (#2)]
├── expressions: [get(1)(unnest([1, 2, 3]) (#1))]
├── estimated rows: 30.00
└── ProjectSet
├── output columns: [numbers.number (#0), unnest([1, 2, 3]) (#1)]
├── estimated rows: 30.00
├── set returning functions: unnest([1, 2, 3])
└── TableScan
├── table: default.system.numbers
├── output columns: [number (#0)]
├── read rows: 10
├── read size: < 1 KiB
├── partitions total: 1
├── partitions scanned: 1
├── push downs: [filters: [], limit: NONE]
└── estimated rows: 10.00

statement ok
drop database project_set
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ explain select name, json_path_query(details, '$.features.*') as all_features, j
EvalScalar
├── output columns: [products.name (#0), all_features (#3), first_feature (#4)]
├── expressions: [get(1)(json_path_query(products.details (#1), '$.features.*') (#2)), json_path_query_first(products.details (#1), '$.features.*')]
├── estimated rows: 0.12
├── estimated rows: 0.36
└── Filter
├── output columns: [products.name (#0), products.details (#1), json_path_query(products.details (#1), '$.features.*') (#2)]
├── filters: [is_true(TRY_CAST(get(1)(json_path_query(products.details (#1), '$.features.*') (#2)) AS String NULL) = '512GB')]
├── estimated rows: 0.12
├── estimated rows: 0.36
└── ProjectSet
├── output columns: [products.name (#0), products.details (#1), json_path_query(products.details (#1), '$.features.*') (#2)]
├── estimated rows: 0.60
├── estimated rows: 1.80
├── set returning functions: json_path_query(products.details (#1), '$.features.*')
└── TableScan
├── table: default.default.products
Expand All @@ -45,10 +45,10 @@ explain select name, json_path_query(details, '$.features.*') as all_features, j
EvalScalar
├── output columns: [products.name (#0), all_features (#3), first_feature (#4)]
├── expressions: [get(1)(json_path_query(products.details (#1), '$.features.*') (#2)), json_path_query_first(products.details (#1), '$.features.*')]
├── estimated rows: 0.60
├── estimated rows: 1.80
└── ProjectSet
├── output columns: [products.name (#0), products.details (#1), json_path_query(products.details (#1), '$.features.*') (#2)]
├── estimated rows: 0.60
├── estimated rows: 1.80
├── set returning functions: json_path_query(products.details (#1), '$.features.*')
└── TableScan
├── table: default.default.products
Expand Down