Skip to content

Commit

Permalink
feat(frontend): describe stmt shows index ordering (#8073)
Browse files Browse the repository at this point in the history
- As title.

Approved-By: yezizp2012
Approved-By: cyliu0

Co-Authored-By: Dylan Chen <zilin@singularity-data.com>
Co-Authored-By: Dylan <chenzl25@mail2.sysu.edu.cn>
  • Loading branch information
chenzl25 and chenzl25 authored Feb 22, 2023
1 parent b429e9c commit e16e26d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/frontend/src/handler/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::binder::{Binder, Relation};
use crate::catalog::{CatalogError, IndexCatalog};
use crate::handler::util::col_descs_to_rows;
use crate::handler::HandlerArgs;
use crate::optimizer::property::Direction;

pub fn handle_describe(handler_args: HandlerArgs, table_name: ObjectName) -> Result<RwPgResponse> {
let session = handler_args.session;
Expand Down Expand Up @@ -113,11 +114,18 @@ pub fn handle_describe(handler_args: HandlerArgs, table_name: ObjectName) -> Res
rows.extend(indices.iter().map(|index| {
let index_table = index.index_table.clone();

let index_columns = index_table
let index_columns_with_ordering = index_table
.pk
.iter()
.filter(|x| !index_table.columns[x.index].is_hidden)
.map(|x| index_table.columns[x.index].name().to_string())
.map(|x| {
let index_column_name = index_table.columns[x.index].name().to_string();
if Direction::Desc == x.direct {
index_column_name + " DESC"
} else {
index_column_name
}
})
.collect_vec();

let pk_column_index_set = index_table
Expand Down Expand Up @@ -147,7 +155,7 @@ pub fn handle_describe(handler_args: HandlerArgs, table_name: ObjectName) -> Res
Some(
format!(
"index({}) distributed by({})",
display_comma_separated(&index_columns),
display_comma_separated(&index_columns_with_ordering),
display_comma_separated(&distributed_by_columns),
)
.into(),
Expand All @@ -156,7 +164,7 @@ pub fn handle_describe(handler_args: HandlerArgs, table_name: ObjectName) -> Res
Some(
format!(
"index({}) include({}) distributed by({})",
display_comma_separated(&index_columns),
display_comma_separated(&index_columns_with_ordering),
display_comma_separated(&include_columns),
display_comma_separated(&distributed_by_columns),
)
Expand Down Expand Up @@ -204,7 +212,7 @@ mod tests {
.unwrap();

frontend
.run_sql("create index idx1 on t (v1,v2);")
.run_sql("create index idx1 on t (v1 DESC, v2);")
.await
.unwrap();

Expand Down Expand Up @@ -233,7 +241,7 @@ mod tests {
"v3".into() => "Int32".into(),
"v4".into() => "Int32".into(),
"primary key".into() => "v3".into(),
"idx1".into() => "index(v1, v2, v3) include(v4) distributed by(v1, v2)".into(),
"idx1".into() => "index(v1 DESC, v2, v3) include(v4) distributed by(v1, v2)".into(),
};

assert_eq!(columns, expected_columns);
Expand Down

0 comments on commit e16e26d

Please sign in to comment.