Skip to content

Commit

Permalink
fix: display inverted and fulltext index in show index
Browse files Browse the repository at this point in the history
  • Loading branch information
lyang24 committed Dec 15, 2024
1 parent 2137c53 commit d16aa23
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions src/datatypes/src/schema/column_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
35 changes: 21 additions & 14 deletions tests/cases/standalone/common/show/show_index.result
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

Expand Down Expand Up @@ -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%';

Expand Down
3 changes: 3 additions & 0 deletions tests/cases/standalone/common/show/show_index.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

Expand Down

0 comments on commit d16aa23

Please sign in to comment.