-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4757 from TCeason/ISSUE-4698/support_show_table_s…
…tatus support query: show table status
- Loading branch information
Showing
31 changed files
with
694 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2021 Datafuse Labs. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use crate::PlanShowKind; | ||
|
||
#[derive(serde::Serialize, serde::Deserialize, PartialEq, Clone, Debug)] | ||
pub struct ShowTabStatPlan { | ||
pub kind: PlanShowKind, | ||
// show tables from db1 [or in db1] | ||
pub fromdb: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
docs/doc/30-reference/30-sql/40-show/show-table-status.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
--- | ||
title: SHOW TABLE STATUS | ||
--- | ||
|
||
Shows the list of table status in the currently selected database. | ||
|
||
## Syntax | ||
|
||
``` | ||
SHOW TABLE STATUS | ||
[{FROM | IN} db_name] | ||
[LIKE 'pattern' | WHERE expr] | ||
``` | ||
|
||
## Examples | ||
|
||
```sql | ||
mysql> CREATE TABLE t(id int); | ||
mysql> SHOW TABLE STATUS\G | ||
*************************** 1. row *************************** | ||
Name: t | ||
Engine: FUSE | ||
Version: 0 | ||
Row_format: NULL | ||
Rows: NULL | ||
Avg_row_length: NULL | ||
Data_length: NULL | ||
Max_data_length: NULL | ||
Index_length: NULL | ||
Data_free: NULL | ||
Auto_increment: NULL | ||
Create_time: 2022-04-08 04:13:48.988 +0000 | ||
Update_time: NULL | ||
Check_time: NULL | ||
Collation: NULL | ||
Checksum: NULL | ||
Comment: | ||
``` | ||
|
||
Showing the tables with table name `"t"`: | ||
```sql | ||
mysql> SHOW TABLE STATUS LIKE 't'\G | ||
*************************** 1. row *************************** | ||
Name: t | ||
Engine: FUSE | ||
Version: 0 | ||
Row_format: NULL | ||
Rows: NULL | ||
Avg_row_length: NULL | ||
Data_length: NULL | ||
Max_data_length: NULL | ||
Index_length: NULL | ||
Data_free: NULL | ||
Auto_increment: NULL | ||
Create_time: 2022-04-08 04:13:48.988 +0000 | ||
Update_time: NULL | ||
Check_time: NULL | ||
Collation: NULL | ||
Checksum: NULL | ||
Comment: | ||
``` | ||
|
||
Showing the tables begin with `"t"`: | ||
```sql | ||
mysql> SHOW TABLE STATUS LIKE 't%'\G | ||
*************************** 1. row *************************** | ||
Name: t | ||
Engine: FUSE | ||
Version: 0 | ||
Row_format: NULL | ||
Rows: NULL | ||
Avg_row_length: NULL | ||
Data_length: NULL | ||
Max_data_length: NULL | ||
Index_length: NULL | ||
Data_free: NULL | ||
Auto_increment: NULL | ||
Create_time: 2022-04-08 04:13:48.988 +0000 | ||
Update_time: NULL | ||
Check_time: NULL | ||
Collation: NULL | ||
Checksum: NULL | ||
Comment: | ||
``` | ||
|
||
Showing the tables begin with `"t"` with `WHERE`: | ||
```sql | ||
mysql> SHOW TABLE STATUS WHERE table_name LIKE 't%'\G | ||
*************************** 1. row *************************** | ||
Name: t | ||
Engine: FUSE | ||
Version: 0 | ||
Row_format: NULL | ||
Rows: NULL | ||
Avg_row_length: NULL | ||
Data_length: NULL | ||
Max_data_length: NULL | ||
Index_length: NULL | ||
Data_free: NULL | ||
Auto_increment: NULL | ||
Create_time: 2022-04-08 04:13:48.988 +0000 | ||
Update_time: NULL | ||
Check_time: NULL | ||
Collation: NULL | ||
Checksum: NULL | ||
Comment: | ||
``` | ||
|
||
Showing the tables are inside `"default"`: | ||
```sql | ||
mysql> SHOW TABLE STATUS FROM 'default'\G | ||
*************************** 1. row *************************** | ||
Name: t | ||
Engine: FUSE | ||
Version: 0 | ||
Row_format: NULL | ||
Rows: NULL | ||
Avg_row_length: NULL | ||
Data_length: NULL | ||
Max_data_length: NULL | ||
Index_length: NULL | ||
Data_free: NULL | ||
Auto_increment: NULL | ||
Create_time: 2022-04-08 04:13:48.988 +0000 | ||
Update_time: NULL | ||
Check_time: NULL | ||
Collation: NULL | ||
Checksum: NULL | ||
Comment: | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright 2022 Datafuse Labs. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::sync::Arc; | ||
|
||
use common_exception::ErrorCode; | ||
use common_exception::Result; | ||
use common_planners::PlanNode; | ||
use common_planners::PlanShowKind; | ||
use common_planners::ShowTabStatPlan; | ||
use common_streams::SendableDataBlockStream; | ||
|
||
use crate::interpreters::Interpreter; | ||
use crate::interpreters::InterpreterPtr; | ||
use crate::interpreters::SelectInterpreter; | ||
use crate::optimizers::Optimizers; | ||
use crate::sessions::QueryContext; | ||
use crate::sql::PlanParser; | ||
|
||
pub struct ShowTabStatInterpreter { | ||
ctx: Arc<QueryContext>, | ||
plan: ShowTabStatPlan, | ||
} | ||
|
||
impl ShowTabStatInterpreter { | ||
pub fn try_create(ctx: Arc<QueryContext>, plan: ShowTabStatPlan) -> Result<InterpreterPtr> { | ||
Ok(Arc::new(ShowTabStatInterpreter { ctx, plan })) | ||
} | ||
|
||
fn build_query(&self) -> Result<String> { | ||
let mut database = self.ctx.get_current_database(); | ||
if let Some(v) = &self.plan.fromdb { | ||
database = v.to_string(); | ||
} | ||
let select_cols = "table_name AS Name, engine AS Engine, 0 AS Version, \ | ||
NULL AS Row_format, NULL AS Rows, NULL AS Avg_row_length, NULL AS Data_length, \ | ||
NULL AS Max_data_length, NULL AS Index_length, NULL AS Data_free, NULL AS Auto_increment, \ | ||
create_time AS Create_time, NULL AS Update_time, NULL AS Check_time, NULL AS Collation, \ | ||
NULL AS Checksum, '' AS Comment" | ||
.to_string(); | ||
return match &self.plan.kind { | ||
PlanShowKind::All => Ok(format!( | ||
"SELECT {} FROM information_schema.TABLES WHERE table_schema = '{}' \ | ||
ORDER BY table_schema, table_name", | ||
select_cols, database | ||
)), | ||
PlanShowKind::Like(v) => Ok(format!( | ||
"SELECT {} FROM information_schema.TABLES WHERE table_schema = '{}' \ | ||
AND table_name LIKE {} ORDER BY table_schema, table_name", | ||
select_cols, database, v | ||
)), | ||
PlanShowKind::Where(v) => Ok(format!( | ||
"SELECT {} FROM information_schema.TABLES WHERE table_schema = '{}' \ | ||
AND ({}) ORDER BY table_schema, table_name", | ||
select_cols, database, v | ||
)), | ||
}; | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Interpreter for ShowTabStatInterpreter { | ||
fn name(&self) -> &str { | ||
"ShowTabStatInterpreter" | ||
} | ||
|
||
async fn execute( | ||
&self, | ||
input_stream: Option<SendableDataBlockStream>, | ||
) -> Result<SendableDataBlockStream> { | ||
let query = self.build_query()?; | ||
let plan = PlanParser::parse(self.ctx.clone(), &query).await?; | ||
let optimized = Optimizers::create(self.ctx.clone()).optimize(&plan)?; | ||
|
||
if let PlanNode::Select(plan) = optimized { | ||
let interpreter = SelectInterpreter::try_create(self.ctx.clone(), plan)?; | ||
interpreter.execute(input_stream).await | ||
} else { | ||
return Err(ErrorCode::LogicalError( | ||
"Show table status build query error", | ||
)); | ||
} | ||
} | ||
} |
Oops, something went wrong.
4bfa099
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
databend – ./
databend-databend.vercel.app
databend-git-main-databend.vercel.app
databend.rs
databend.vercel.app