risingwave_frontend/expr/function_impl/
pg_relation_size.rs1use risingwave_expr::{ExprError, Result, capture_context, function};
16
17use super::context::CATALOG_READER;
18use crate::catalog::CatalogReader;
19
20#[function("pg_relation_size(int4) -> int8")]
22fn pg_relation_size(oid: i32) -> Result<i64> {
23 pg_relation_size_impl_captured(oid, "main")
24}
25
26#[function("pg_relation_size(int4, varchar) -> int8")]
27fn pg_relation_size_fork(oid: i32, fork: &str) -> Result<i64> {
28 pg_relation_size_impl_captured(oid, fork)
29}
30
31#[capture_context(CATALOG_READER)]
32fn pg_relation_size_impl(catalog: &CatalogReader, oid: i32, fork: &str) -> Result<i64> {
33 match fork {
34 "main" => {}
35 "fsm" | "vm" | "init" => return Ok(0),
37 _ => return Err(ExprError::InvalidParam {
38 name: "fork",
39 reason:
40 "invalid fork name. Valid fork names are \"main\", \"fsm\", \"vm\", and \"init\""
41 .into(),
42 }),
43 }
44 let catalog = catalog.read_guard();
45 if let Some(stats) = catalog.table_stats().table_stats.get(&(oid as u32)) {
46 Ok(stats.total_key_size + stats.total_value_size)
47 } else {
48 Ok(0)
49 }
50}