From d16aa23ea27a3bcc8e788c07036be81794d332af Mon Sep 17 00:00:00 2001 From: lyang24 Date: Sat, 14 Dec 2024 21:11:59 -0800 Subject: [PATCH] fix: display inverted and fulltext index in show index --- .../information_schema/key_column_usage.rs | 28 +++++++++++++++ src/datatypes/src/schema/column_schema.rs | 4 +++ .../standalone/common/show/show_index.result | 35 +++++++++++-------- .../standalone/common/show/show_index.sql | 3 ++ 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/src/catalog/src/system_schema/information_schema/key_column_usage.rs b/src/catalog/src/system_schema/information_schema/key_column_usage.rs index 56713dabba28..8326f98a7ca7 100644 --- a/src/catalog/src/system_schema/information_schema/key_column_usage.rs +++ b/src/catalog/src/system_schema/information_schema/key_column_usage.rs @@ -54,6 +54,10 @@ const INIT_CAPACITY: usize = 42; pub(crate) const PRI_CONSTRAINT_NAME: &str = "PRIMARY"; /// Time index constraint name pub(crate) const TIME_INDEX_CONSTRAINT_NAME: &str = "TIME INDEX"; +/// Inverted index constraint name +pub(crate) const INVERTED_INDEX_CONSTRAINT_NAME: &str = "INVERTED INDEX"; +/// Fulltext index constraint name +pub(crate) const FULLTEXT_INDEX_CONSTRAINT_NAME: &str = "FULLTEXT INDEX"; /// The virtual table implementation for `information_schema.KEY_COLUMN_USAGE`. pub(super) struct InformationSchemaKeyColumnUsage { @@ -236,6 +240,30 @@ impl InformationSchemaKeyColumnUsageBuilder { 1, //always 1 for time index ); } + if column.is_inverted_indexed() { + self.add_key_column_usage( + &predicates, + &schema_name, + INVERTED_INDEX_CONSTRAINT_NAME, + &catalog_name, + &schema_name, + table_name, + &column.name, + idx as u32 + 1, + ); + } + if column.is_fulltext_indexed() { + self.add_key_column_usage( + &predicates, + &schema_name, + FULLTEXT_INDEX_CONSTRAINT_NAME, + &catalog_name, + &schema_name, + table_name, + &column.name, + idx as u32 + 1, + ); + } if keys.contains(&idx) { primary_constraints.push(( catalog_name.clone(), diff --git a/src/datatypes/src/schema/column_schema.rs b/src/datatypes/src/schema/column_schema.rs index c1e2df846918..9afd40aab645 100644 --- a/src/datatypes/src/schema/column_schema.rs +++ b/src/datatypes/src/schema/column_schema.rs @@ -156,6 +156,10 @@ impl ColumnSchema { .unwrap_or(false) } + pub fn is_fulltext_indexed(&self) -> bool { + self.metadata.contains_key(FULLTEXT_KEY) + } + pub fn has_inverted_index_key(&self) -> bool { self.metadata.contains_key(INVERTED_INDEX_KEY) } diff --git a/tests/cases/standalone/common/show/show_index.result b/tests/cases/standalone/common/show/show_index.result index 995da87c133d..bb092b8c22fd 100644 --- a/tests/cases/standalone/common/show/show_index.result +++ b/tests/cases/standalone/common/show/show_index.result @@ -4,8 +4,11 @@ CREATE TABLE IF NOT EXISTS system_metrics ( cpu_util DOUBLE, memory_util DOUBLE, disk_util DOUBLE, + desc1 STRING, + desc2 VARCHAR FULLTEXT, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(host, idc), + INVERTED INDEX(desc1), TIME INDEX(ts) ); @@ -38,23 +41,27 @@ SHOW INDEX FROM test; SHOW INDEX FROM system_metrics; -+----------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ -| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | -+----------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ -| system_metrics | 1 | PRIMARY | 1 | host | A | | | | YES | greptime-inverted-index-v1 | | | YES | | -| system_metrics | 1 | PRIMARY | 2 | idc | A | | | | YES | greptime-inverted-index-v1 | | | YES | | -| system_metrics | 1 | TIME INDEX | 1 | ts | A | | | | NO | greptime-inverted-index-v1 | | | YES | | -+----------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ ++----------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ +| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | ++----------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ +| system_metrics | 1 | INVERTED INDEX | 6 | desc1 | A | | | | YES | greptime-inverted-index-v1 | | | YES | | +| system_metrics | 1 | FULLTEXT INDEX | 7 | desc2 | A | | | | YES | greptime-inverted-index-v1 | | | YES | | +| system_metrics | 1 | PRIMARY | 1 | host | A | | | | YES | greptime-inverted-index-v1 | | | YES | | +| system_metrics | 1 | PRIMARY | 2 | idc | A | | | | YES | greptime-inverted-index-v1 | | | YES | | +| system_metrics | 1 | TIME INDEX | 1 | ts | A | | | | NO | greptime-inverted-index-v1 | | | YES | | ++----------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ SHOW INDEX FROM system_metrics in public; -+----------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ -| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | -+----------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ -| system_metrics | 1 | PRIMARY | 1 | host | A | | | | YES | greptime-inverted-index-v1 | | | YES | | -| system_metrics | 1 | PRIMARY | 2 | idc | A | | | | YES | greptime-inverted-index-v1 | | | YES | | -| system_metrics | 1 | TIME INDEX | 1 | ts | A | | | | NO | greptime-inverted-index-v1 | | | YES | | -+----------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ ++----------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ +| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | ++----------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ +| system_metrics | 1 | INVERTED INDEX | 6 | desc1 | A | | | | YES | greptime-inverted-index-v1 | | | YES | | +| system_metrics | 1 | FULLTEXT INDEX | 7 | desc2 | A | | | | YES | greptime-inverted-index-v1 | | | YES | | +| system_metrics | 1 | PRIMARY | 1 | host | A | | | | YES | greptime-inverted-index-v1 | | | YES | | +| system_metrics | 1 | PRIMARY | 2 | idc | A | | | | YES | greptime-inverted-index-v1 | | | YES | | +| system_metrics | 1 | TIME INDEX | 1 | ts | A | | | | NO | greptime-inverted-index-v1 | | | YES | | ++----------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+ SHOW INDEX FROM system_metrics like '%util%'; diff --git a/tests/cases/standalone/common/show/show_index.sql b/tests/cases/standalone/common/show/show_index.sql index 3f804db3845f..b0a9d84c8d57 100644 --- a/tests/cases/standalone/common/show/show_index.sql +++ b/tests/cases/standalone/common/show/show_index.sql @@ -4,8 +4,11 @@ CREATE TABLE IF NOT EXISTS system_metrics ( cpu_util DOUBLE, memory_util DOUBLE, disk_util DOUBLE, + desc1 STRING, + desc2 VARCHAR FULLTEXT, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(host, idc), + INVERTED INDEX(desc1), TIME INDEX(ts) );