27-index.md 2.0 KB
Newer Older
1
---
D
danielclow 已提交
2 3 4
title: Indexing
sidebar_label: Indexing
description: This document describes the SQL statements related to indexing in TDengine.
5 6
---

7
TDengine supports SMA and FULLTEXT indexing.
8

9
## Create an Index
10 11 12 13 14 15 16 17 18 19 20 21 22

```sql
CREATE FULLTEXT INDEX index_name ON tb_name (col_name [, col_name] ...)

CREATE SMA INDEX index_name ON tb_name index_option

index_option:
    FUNCTION(functions) INTERVAL(interval_val [, interval_offset]) [SLIDING(sliding_val)] [WATERMARK(watermark_val)] [MAX_DELAY(max_delay_val)]

functions:
    function [, function] ...
```

23
### SMA Indexing
24

25
Performs pre-aggregation on the specified column over the time window defined by the INTERVAL clause. The type is specified in functions_string. SMA indexing improves aggregate query performance for the specified time period. One supertable can only contain one SMA index.
26

27 28 29
- The max, min, and sum functions are supported.
- WATERMARK: Enter a value between 0ms and 900000ms. The most precise unit supported is milliseconds. The default value is 5 seconds. This option can be used only on supertables.
- MAX_DELAY: Enter a value between 1ms and 900000ms. The most precise unit supported is milliseconds. The default value is the value of interval provided that it does not exceed 900000ms. This option can be used only on supertables. Note: Retain the default value if possible. Configuring a small MAX_DELAY may cause results to be frequently pushed, affecting storage and query performance.
30

31
### FULLTEXT Indexing
32

33
Creates a text index for the specified column. FULLTEXT indexing improves performance for queries with text filtering. The index_option syntax is not supported for FULLTEXT indexing. FULLTEXT indexing is supported for JSON tag columns only. Multiple columns cannot be indexed together. However, separate indices can be created for each column.
34

35
## Delete an Index
36 37 38 39 40

```sql
DROP INDEX index_name;
```

41
## View Indices
42 43 44 45

````sql
```sql
SHOW INDEXES FROM tbl_name [FROM db_name];
G
Ganlin Zhao 已提交
46
SHOW INDEXES FROM [db_name.]tbl_name ;
47 48
````

49
Shows indices that have been created for the specified database or table.