What is the index structure of TiDB?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 请问TIDB的索引结构是什么呢

| username: TiDBer_JlY1JCJ5

Is it also a B+Tree like MySQL?

| username: TiDBer_小阿飞 | Original post link

TiDB Index Data Structure (LSM-TREE)

| username: zhanggame1 | Original post link

The underlying layer of TiDB is RocksDB, a KV database that uses the LSM-Tree data structure.

| username: Jellybean | Original post link

Both business data and index data are converted into KV key-value pairs for storage. The underlying TiKV can be roughly understood as a huge Map structure. These KV key-value pairs are stored in RocksDB, and the data structure is an LSM tree.

| username: Jolyne | Original post link

When new data is written in an LSM-Tree structure, it is first written to the in-memory Memtable. The Memtable will periodically or when it reaches a certain size, flush the data to an SSTable on the disk. When the SSTables reach a certain level, they will be compacted into a larger SSTable.

| username: dba远航 | Original post link

LSM-TREE structure

| username: TiDBer_JlY1JCJ5 | Original post link

However, when I execute “show index from customer” to look at a table, I see that the index_type shows BTREE. What’s going on?

| username: forever | Original post link

To be compatible with MySQL, it’s just a display.

| username: Jellybean | Original post link

Initially, it was probably to be compatible with the MySQL 5.7 protocol, merely for compatibility display. The underlying actual storage is not the same.

| username: zhaokede | Original post link

Tree structure, after watching the related video, it seems to be stored in a KV structure as well.

| username: 小龙虾爱大龙虾 | Original post link

Indexes are also encoded into KV and stored in TiKV. For encoding rules, see TiDB 数据库的计算 | PingCAP 文档中心
TiKV uses RocksDB as the key-value storage engine at the bottom layer, and the underlying data structure is LSM-tree.

| username: ShawnYan | Original post link

I recommend checking out the TiKV documentation:

| username: swino | Original post link

LSM-TREE

| username: oceanzhang | Original post link

It’s also a KV storage, right?

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.