risingwave_frontend/catalog/system_catalog/rw_catalog/
rw_indexes.rs1use risingwave_common::types::{Fields, Timestamptz};
16use risingwave_frontend_macro::system_catalog;
17
18use crate::catalog::system_catalog::SysCatalogReaderImpl;
19use crate::error::Result;
20
21#[derive(Fields)]
22struct RwIndex {
23 #[primary_key]
24 id: i32,
25 name: String,
26 primary_table_id: i32,
27 key_columns: Vec<i16>,
28 include_columns: Vec<i16>,
29 schema_id: i32,
30 owner: i32,
31 definition: String,
32 acl: Vec<String>,
33 initialized_at: Option<Timestamptz>,
34 created_at: Option<Timestamptz>,
35 initialized_at_cluster_version: Option<String>,
36 created_at_cluster_version: Option<String>,
37}
38
39#[system_catalog(table, "rw_catalog.rw_indexes")]
40fn read_rw_indexes(reader: &SysCatalogReaderImpl) -> Result<Vec<RwIndex>> {
41 let catalog_reader = reader.catalog_reader.read_guard();
42 let schemas = catalog_reader.iter_schemas(&reader.auth_context.database)?;
43 let user_reader = reader.user_info_reader.read_guard();
44 let current_user = user_reader
45 .get_user_by_name(&reader.auth_context.user_name)
46 .expect("user not found");
47
48 Ok(schemas
49 .flat_map(|schema| {
50 schema
51 .iter_index_with_acl(current_user)
52 .map(|index| RwIndex {
53 id: index.id.index_id as i32,
54 name: index.name.clone(),
55 primary_table_id: index.primary_table.id().table_id as i32,
56 key_columns: index
57 .index_item
58 .iter()
59 .take(index.index_columns_len as usize)
60 .map(|index| {
61 let ind = if let Some(input_ref) = index.as_input_ref() {
62 input_ref.index() + 1
63 } else {
64 0
65 };
66 ind as i16
67 })
68 .collect(),
69 include_columns: index
70 .index_item
71 .iter()
72 .skip(index.index_columns_len as usize)
73 .map(|index| {
74 let ind = if let Some(input_ref) = index.as_input_ref() {
75 input_ref.index() + 1
76 } else {
77 0
78 };
79 ind as i16
80 })
81 .collect(),
82 schema_id: schema.id() as i32,
83 owner: index.index_table.owner as i32,
84 definition: index.index_table.create_sql(),
85 acl: vec![],
86 initialized_at: index.initialized_at_epoch.map(|e| e.as_timestamptz()),
87 created_at: index.created_at_epoch.map(|e| e.as_timestamptz()),
88 initialized_at_cluster_version: index.initialized_at_cluster_version.clone(),
89 created_at_cluster_version: index.created_at_cluster_version.clone(),
90 })
91 })
92 .collect())
93}