Skip to content

Commit c305b2b

Browse files
authored
fix: show index to display skipping index (#5297)
* fix: show index to display skipping index Signed-off-by: Zhenchi <[email protected]> * fix sqlness Signed-off-by: Zhenchi <[email protected]> * address comments Signed-off-by: Zhenchi <[email protected]> * fix sqlness Signed-off-by: Zhenchi <[email protected]> --------- Signed-off-by: Zhenchi <[email protected]>
1 parent c89ef85 commit c305b2b

File tree

8 files changed

+171
-60
lines changed

8 files changed

+171
-60
lines changed

src/catalog/src/system_schema/information_schema/key_column_usage.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pub(crate) const TIME_INDEX_CONSTRAINT_NAME: &str = "TIME INDEX";
5858
pub(crate) const INVERTED_INDEX_CONSTRAINT_NAME: &str = "INVERTED INDEX";
5959
/// Fulltext index constraint name
6060
pub(crate) const FULLTEXT_INDEX_CONSTRAINT_NAME: &str = "FULLTEXT INDEX";
61+
/// Skipping index constraint name
62+
pub(crate) const SKIPPING_INDEX_CONSTRAINT_NAME: &str = "SKIPPING INDEX";
6163

6264
/// The virtual table implementation for `information_schema.KEY_COLUMN_USAGE`.
6365
pub(super) struct InformationSchemaKeyColumnUsage {
@@ -225,6 +227,12 @@ impl InformationSchemaKeyColumnUsageBuilder {
225227
let keys = &table_info.meta.primary_key_indices;
226228
let schema = table.schema();
227229

230+
// For compatibility, use primary key columns as inverted index columns.
231+
let pk_as_inverted_index = !schema
232+
.column_schemas()
233+
.iter()
234+
.any(|c| c.has_inverted_index_key());
235+
228236
for (idx, column) in schema.column_schemas().iter().enumerate() {
229237
let mut constraints = vec![];
230238
if column.is_time_index() {
@@ -242,14 +250,20 @@ impl InformationSchemaKeyColumnUsageBuilder {
242250
// TODO(dimbtp): foreign key constraint not supported yet
243251
if keys.contains(&idx) {
244252
constraints.push(PRI_CONSTRAINT_NAME);
253+
254+
if pk_as_inverted_index {
255+
constraints.push(INVERTED_INDEX_CONSTRAINT_NAME);
256+
}
245257
}
246258
if column.is_inverted_indexed() {
247259
constraints.push(INVERTED_INDEX_CONSTRAINT_NAME);
248260
}
249-
250-
if column.has_fulltext_index_key() {
261+
if column.is_fulltext_indexed() {
251262
constraints.push(FULLTEXT_INDEX_CONSTRAINT_NAME);
252263
}
264+
if column.is_skipping_indexed() {
265+
constraints.push(SKIPPING_INDEX_CONSTRAINT_NAME);
266+
}
253267

254268
if !constraints.is_empty() {
255269
let aggregated_constraints = constraints.join(", ");

src/datatypes/src/schema/column_schema.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,15 @@ impl ColumnSchema {
164164
.unwrap_or(false)
165165
}
166166

167-
pub fn has_fulltext_index_key(&self) -> bool {
168-
self.metadata.contains_key(FULLTEXT_KEY)
167+
pub fn is_fulltext_indexed(&self) -> bool {
168+
self.fulltext_options()
169+
.unwrap_or_default()
170+
.map(|option| option.enable)
171+
.unwrap_or_default()
172+
}
173+
174+
pub fn is_skipping_indexed(&self) -> bool {
175+
self.skipping_index_options().unwrap_or_default().is_some()
169176
}
170177

171178
pub fn has_inverted_index_key(&self) -> bool {

src/query/src/sql.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -402,19 +402,22 @@ pub async fn show_index(
402402
query_ctx.current_schema()
403403
};
404404

405+
let primary_key_expr = case(col("constraint_name").like(lit("%PRIMARY%")))
406+
.when(lit(true), lit("greptime-primary-key-v1"))
407+
.otherwise(null())
408+
.context(error::PlanSqlSnafu)?;
409+
let inverted_index_expr = case(col("constraint_name").like(lit("%INVERTED INDEX%")))
410+
.when(lit(true), lit("greptime-inverted-index-v1"))
411+
.otherwise(null())
412+
.context(error::PlanSqlSnafu)?;
405413
let fulltext_index_expr = case(col("constraint_name").like(lit("%FULLTEXT INDEX%")))
406414
.when(lit(true), lit("greptime-fulltext-index-v1"))
407415
.otherwise(null())
408416
.context(error::PlanSqlSnafu)?;
409-
410-
let inverted_index_expr = case(
411-
col("constraint_name")
412-
.like(lit("%INVERTED INDEX%"))
413-
.or(col("constraint_name").like(lit("%PRIMARY%"))),
414-
)
415-
.when(lit(true), lit("greptime-inverted-index-v1"))
416-
.otherwise(null())
417-
.context(error::PlanSqlSnafu)?;
417+
let skipping_index_expr = case(col("constraint_name").like(lit("%SKIPPING INDEX%")))
418+
.when(lit(true), lit("greptime-bloom-filter-v1"))
419+
.otherwise(null())
420+
.context(error::PlanSqlSnafu)?;
418421

419422
let select = vec![
420423
// 1 as `Non_unique`: contain duplicates
@@ -435,7 +438,12 @@ pub async fn show_index(
435438
.alias(COLUMN_NULLABLE_COLUMN),
436439
concat_ws(
437440
lit(", "),
438-
vec![inverted_index_expr.clone(), fulltext_index_expr.clone()],
441+
vec![
442+
primary_key_expr,
443+
inverted_index_expr,
444+
fulltext_index_expr,
445+
skipping_index_expr,
446+
],
439447
)
440448
.alias(INDEX_INDEX_TYPE_COLUMN),
441449
lit("").alias(COLUMN_COMMENT_COLUMN),

tests/cases/standalone/common/alter/change_col_fulltext_options.result

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ SHOW CREATE TABLE test;
9494
| | ) |
9595
+-------+---------------------------------------------------------------------------------------+
9696

97+
SHOW INDEX FROM test;
98+
99+
+-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+
100+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
101+
+-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+
102+
| test | 1 | FULLTEXT INDEX | 1 | message | A | | | | YES | greptime-fulltext-index-v1 | | | YES | |
103+
| test | 1 | TIME INDEX | 1 | time | A | | | | NO | | | | YES | |
104+
+-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+
105+
97106
ALTER TABLE test MODIFY COLUMN message UNSET FULLTEXT;
98107

99108
Affected Rows: 0
@@ -115,6 +124,14 @@ SHOW CREATE TABLE test;
115124
| | ) |
116125
+-------+-------------------------------------+
117126

127+
SHOW INDEX FROM test;
128+
129+
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
130+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
131+
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
132+
| test | 1 | TIME INDEX | 1 | time | A | | | | NO | | | | YES | |
133+
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
134+
118135
ALTER TABLE test MODIFY COLUMN message SET FULLTEXT WITH(analyzer = 'Chinese', case_sensitive = 'true');
119136

120137
Affected Rows: 0
@@ -136,6 +153,15 @@ SHOW CREATE TABLE test;
136153
| | ) |
137154
+-------+---------------------------------------------------------------------------------------+
138155

156+
SHOW INDEX FROM test;
157+
158+
+-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+
159+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
160+
+-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+
161+
| test | 1 | FULLTEXT INDEX | 1 | message | A | | | | YES | greptime-fulltext-index-v1 | | | YES | |
162+
| test | 1 | TIME INDEX | 1 | time | A | | | | NO | | | | YES | |
163+
+-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+----------------------------+---------+---------------+---------+------------+
164+
139165
ALTER TABLE test MODIFY COLUMN message SET FULLTEXT WITH(analyzer = 'Chinese', case_sensitive = 'false');
140166

141167
Error: 1004(InvalidArguments), Invalid column option, column name: message, error: FULLTEXT index already enabled
@@ -161,6 +187,14 @@ SHOW CREATE TABLE test;
161187
| | ) |
162188
+-------+-------------------------------------+
163189

190+
SHOW INDEX FROM test;
191+
192+
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
193+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
194+
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
195+
| test | 1 | TIME INDEX | 1 | time | A | | | | NO | | | | YES | |
196+
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
197+
164198
ALTER TABLE test MODIFY COLUMN message SET FULLTEXT WITH(analyzer = 'Chinglish', case_sensitive = 'false');
165199

166200
Error: 1002(Unexpected), Invalid fulltext option: Chinglish, expected: 'English' | 'Chinese'

tests/cases/standalone/common/alter/change_col_fulltext_options.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,28 @@ SELECT * FROM test WHERE MATCHES(message, 'hello') ORDER BY message;
2929
-- SQLNESS ARG restart=true
3030
SHOW CREATE TABLE test;
3131

32+
SHOW INDEX FROM test;
33+
3234
ALTER TABLE test MODIFY COLUMN message UNSET FULLTEXT;
3335

3436
SHOW CREATE TABLE test;
3537

38+
SHOW INDEX FROM test;
39+
3640
ALTER TABLE test MODIFY COLUMN message SET FULLTEXT WITH(analyzer = 'Chinese', case_sensitive = 'true');
3741

3842
SHOW CREATE TABLE test;
3943

44+
SHOW INDEX FROM test;
45+
4046
ALTER TABLE test MODIFY COLUMN message SET FULLTEXT WITH(analyzer = 'Chinese', case_sensitive = 'false');
4147

4248
ALTER TABLE test MODIFY COLUMN message UNSET FULLTEXT;
4349

4450
SHOW CREATE TABLE test;
4551

52+
SHOW INDEX FROM test;
53+
4654
ALTER TABLE test MODIFY COLUMN message SET FULLTEXT WITH(analyzer = 'Chinglish', case_sensitive = 'false');
4755

4856
ALTER TABLE test MODIFY COLUMN message SET FULLTEXT WITH(analyzer = 'Chinese', case_sensitive = 'no');

0 commit comments

Comments
 (0)