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

feat: support pg_relation_size #11687

Merged
merged 2 commits into from
Aug 16, 2023
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
31 changes: 31 additions & 0 deletions e2e_test/batch/catalog/pg_size.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,37 @@ SELECT pg_indexes_size('t') = 0;
----
t

skipif in-memory
query T
SELECT pg_relation_size('t') != 0;
----
t

skipif in-memory
query T
SELECT pg_relation_size('t', 'main') != 0;
----
t

skipif in-memory
query T
SELECT pg_relation_size('t', 'fsm') = 0;
----
t

skipif in-memory
query T
SELECT pg_relation_size('t', 'vm') = 0;
----
t

skipif in-memory
query T
SELECT pg_relation_size('t', 'init') = 0;
----
t


statement ok
create index t_idx on t (v1);

Expand Down
56 changes: 56 additions & 0 deletions src/frontend/src/binder/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,62 @@ impl Binder {
))))
}
))),
("pg_relation_size", dispatch_by_len(vec![
(1, raw(|binder, inputs|{
let table_name = &inputs[0];
let bound_query = binder.bind_get_table_size_select("pg_relation_size", table_name)?;
Ok(ExprImpl::Subquery(Box::new(Subquery::new(
BoundQuery {
body: BoundSetExpr::Select(Box::new(bound_query)),
order: vec![],
limit: None,
offset: None,
with_ties: false,
extra_order_exprs: vec![],
},
SubqueryKind::Scalar,
))))
})),
(2, raw(|binder, inputs|{
let table_name = &inputs[0];
match inputs[1].as_literal() {
Some(literal) if literal.return_type() == DataType::Varchar => {
match literal
.get_data()
.as_ref()
.expect("ExprImpl value is a Literal but cannot get ref to data")
.as_utf8()
.as_ref() {
"main" => {
let bound_query = binder.bind_get_table_size_select("pg_relation_size", table_name)?;
Ok(ExprImpl::Subquery(Box::new(Subquery::new(
BoundQuery {
body: BoundSetExpr::Select(Box::new(bound_query)),
order: vec![],
limit: None,
offset: None,
with_ties: false,
extra_order_exprs: vec![],
},
SubqueryKind::Scalar,
))))
},
// These options are invalid in RW so we return 0 value as the result
"fsm"|"vm"|"init" => {
Ok(ExprImpl::literal_int(0))
},
_ => Err(ErrorCode::InvalidInputSyntax(
"invalid fork name. Valid fork names are \"main\", \"fsm\", \"vm\", and \"init\"".into()).into())
}
},
_ => Err(ErrorCode::ExprError(
"The 2nd argument of `pg_relation_size` must be string literal.".into(),
)
.into())
}
})),
]
)),
("pg_table_size", guard_by_len(1, raw(|binder, inputs|{
let input = &inputs[0];
let bound_query = binder.bind_get_table_size_select("pg_table_size", input)?;
Expand Down
Loading