Repository: risingwavelabs/risingwave
File: src/frontend/src/handler/alter_streaming_rate_limit.rs (Rust)

Code before:
        (PbThrottleTarget::Source, PbThrottleType::Source) => {
            let reader = session.env().catalog_reader().read_guard();
            let (source, schema_name) =
                reader.get_source_by_name(db_name, schema_path, &real_table_name)?;
            session.check_privilege_for_drop_alter(schema_name, &**source)?;
            (StatementType::ALTER_SOURCE, source.id.as_raw_id())
        }
        (PbThrottleTarget::Table, PbThrottleType::Dml) => {
            let reader = session.env().catalog_reader().read_guard();
            let (table, schema_name) =
                reader.get_created_table_by_name(db_name, schema_path, &real_table_name)?;
            session.check_privilege_for_drop_alter(schema_name, &**table)?;
            if table.table_type != TableType::Table {
                return Err(ErrorCode::InvalidInputSyntax(format!(
                    "\"{table_name}\" is not a table",
                ))
                .into());
            }
            (StatementType::ALTER_TABLE, table.id.as_raw_id())
        }
        (PbThrottleTarget::Table, PbThrottleType::Source) => {
            let reader = session.env().catalog_reader().read_guard();
            let (table, schema_name) =
                reader.get_created_table_by_name(db_name, schema_path, &real_table_name)?;
            session.check_privilege_for_drop_alter(schema_name, &**table)?;
            if table.table_type != TableType::Table {
                return Err(ErrorCode::InvalidInputSyntax(format!(
                    "\"{table_name}\" is not a table",
                ))
                .into());
            }
            let source_id = if let Some(id) = table.associated_source_id {
                id.as_raw_id()
            } else {
                bail!("ALTER SOURCE_RATE_LIMIT is not for table without source")
            };
            (StatementType::ALTER_TABLE, source_id)
        }
        (PbThrottleTarget::Table, PbThrottleType::Backfill) => {
            let reader = session.env().catalog_reader().read_guard();
            let (table, schema_name) =
                reader.get_created_table_by_name(db_name, schema_path, &real_table_name)?;
            session.check_privilege_for_drop_alter(schema_name, &**table)?;
            if table.table_type != TableType::Table || table.cdc_table_type.is_none() {
                return Err(ErrorCode::InvalidInputSyntax(format!(
                    "\"{table_name}\" is not a CDC table",
                ))
                .into());
            }
            (StatementType::ALTER_TABLE, table.id.as_raw_id())
        }

Review comment (security):
Shall we merge some code for checking the privilege of table? Like
```
(PbThrottleTarget::Table, PbThrottleType::Dml|PbThrottleType::Source|PbThrottleType::Backfill) => {
        let reader = session.env().catalog_reader().read_guard();
        let (table, schema_name) =
            reader.get_created_table_by_name(db_name, schema_path, &real_table_name)?;
        session.check_privilege_for_drop_alter(schema_name, &**table)?;
        if table.table_type != TableType::Table {
            return Err(ErrorCode::InvalidInputSyntax(format!(
                "\"{table_name}\" is not a table",
            ))
            .into());
        }
        if let PbThrottleType::Source = throttle_type {
            let source_id = if let Some(id) = table.associated_source_id {
                id.as_raw_id()
            } else {
                bail!("ALTER SOURCE_RATE_LIMIT is not for table without source")
            };
        }
}
```

Code after:
    let user_name = &session.user_name();

    let schema_path = SchemaPath::new(schema_name.as_deref(), &search_path, user_name);

    let (stmt_type, id) = match (throttle_target, throttle_type) {
        (PbThrottleTarget::Mv, PbThrottleType::Backfill) => {
            let reader = session.env().catalog_reader().read_guard();
            let (table, schema_name) =
                reader.get_any_table_by_name(db_name, schema_path, &real_table_name)?;
            if table.table_type != TableType::MaterializedView {
                return Err(ErrorCode::InvalidInputSyntax(format!(
                    "\"{table_name}\" is not a materialized view",
                ))
                .into());
            }
            session.check_privilege_for_drop_alter(schema_name, &**table)?;
            (StatementType::ALTER_MATERIALIZED_VIEW, table.id.as_raw_id())
        }
        (PbThrottleTarget::Source, PbThrottleType::Source) => {
            let reader = session.env().catalog_reader().read_guard();
            let (source, schema_name) =
                reader.get_source_by_name(db_name, schema_path, &real_table_name)?;
            session.check_privilege_for_drop_alter(schema_name, &**source)?;
            (StatementType::ALTER_SOURCE, source.id.as_raw_id())
        }
        (PbThrottleTarget::Table, PbThrottleType::Dml) => {
            let reader = session.env().catalog_reader().read_guard();
            let table =
                check_table_mismatch(&reader, &session, db_name, schema_path, &real_table_name)?;
            (StatementType::ALTER_TABLE, table.id.as_raw_id())
        }
        (PbThrottleTarget::Table, PbThrottleType::Source) => {
            let reader = session.env().catalog_reader().read_guard();
            let table =
                check_table_mismatch(&reader, &session, db_name, schema_path, &real_table_name)?;
            let source_id = if let Some(id) = table.associated_source_id {
                id.as_raw_id()
            } else {
                bail!("ALTER SOURCE_RATE_LIMIT is not for table without source")
            };
            (StatementType::ALTER_TABLE, source_id)
        }
        (PbThrottleTarget::Table, PbThrottleType::Backfill) => {
            let reader = session.env().catalog_reader().read_guard();
            let table =
                check_table_mismatch(&reader, &session, db_name, schema_path, &real_table_name)?;
            if table.cdc_table_type.is_none() {
                return Err(ErrorCode::InvalidInputSyntax(format!(
                    "\"{table_name}\" is not a CDC table",
                ))
                .into());