---
# System prepended metadata

title: TDSQL 3.0 development

---

# TDSQL 3.0 development

## SQLEngine开发路径

源代码目录：/data1/home/axingguchen/TDSQL3-TOOLS/tdsql3/src/SQLEngin
tdsql-cnt目录：/data1/home/axingguchen/TDSQL3-TOOLS/bin
客户端登陆：/data1/home/axingguchen/tdsql3_installs/9527/SQLEngine/install ./jmysql.sh 9527


## 集群搭建和重建tdsql-cntl常用命令
``
./tdsql-cntl --config ../config/cluster-config_9527.toml  --module all --option rebuild
``
## Debug 方法

通过port抓取process：lsof -i:[port]
通过gdb连上process: gdb attach [pid]

#### Example:

lsof -i:9527
gdb attach 39851

## 代码重编译
```
    cd /data1/home/axingguchen/TDSQL3-TOOLS/tdsql3/src/SQLEngine
    ./make.sh -d 1
    rm -rf /data1/home/axingguchen/TDSQL3-TOOLS/tdsql3/release/SQLEngine
    rm -rf /data1/home/axingguchen/TDSQL3-TOOLS/tdsql3/release/TDStore
    rm -rf  /data1/home/axingguchen/tdsql3_installs/9527/SQLEngine
    rm -rf  /data1/home/axingguchen/tdsql3_installs/9527/TDStore
    cd /data1/home/axingguchen/TDSQL3-TOOLS/tdsql3/src/SQLEngine/mysql_install
    cp  -rf ./*  /data1/home/axingguchen/TDSQL3-TOOLS/tdsql3/release/
    cp  -rf ./* ../../../release/  # same as above
    cp -rf ./* /data1/home/axingguchen/tdsql3_installs/9527/
    sudo rm -rf *
```

```
# 更新包且重启，而且保留数据
cd /data1/home/axingguchen/TDSQL3-TOOLS/tdsql3/src/SQLEngine
./make.sh -d 1
rm -rf ../../release/SQLEngine
cd mysql_install/
cp  -rf ./* ../../../release/  
./tdsql-cntl --config ../config/cluster-config_9527_1.toml --module all --option update 
```


## IMDB 数据导入
```
SOURCE /data1/home/axingguchen/imdb_data/ft_local/sql_scripts/imdb-create-tables.sql
SOURCE /data1/home/axingguchen/imdb_data/ft_local/sql_scripts/test-imdb-load-data-1_100.sql
SOURCE /data1/home/axingguchen/imdb_data/ft_local/sql_scripts/imdb-index-tables.sql

```
## 一些关键目录：

Update Cardinality:
sql/dd/info_schema/table_stats.cc:363

set global rocksdb_force_compute_memtable_stats_cachetime=0;

CREATE TABLE Test (
  a INT PRIMARY KEY,
  b INT
)ENGINE=ROCKSDB;

INSERT INTO Test (a, b) VALUES (3, 4);


CREATE TABLE Test1 (
  a INT PRIMARY KEY,
  b INT,
  c INT
)ENGINE=ROCKSDB;

CREATE INDEX index1 ON Test1(a);
CREATE INDEX index2 ON Test1(a,b);
CREATE INDEX index3 ON Test1(a,b,c);

INSERT INTO Test1 (a, b, c) VALUES (1,1,1);
INSERT INTO Test1 (a, b, c) VALUES (2,2,2);
INSERT INTO Test1 (a, b, c) VALUES (3,3,3),(4,4,4),(5,5,5),(6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10);


## 一些更改的地方

/data1/home/axingguchen/TDSQL3.0-test/TDSQL3-TOOLS/tdsql3/src/SQLEngine/sql/tdsql/estimated_info_thread.cc

```
# memtable里统计的行数
memtableCount = index_range_info.data_rows;
```

/data1/home/axingguchen/TDSQL3.0-test/TDSQL3-TOOLS/tdsql3/src/SQLEngine/storage/rocksdb/ha_rocksdb.cc

```
# check share pointer data
p ((Rdb_key_def*)m_key_descr_arr)->m_stats

# key infomation
p *table->key_info
p *(table->key_info+1)

# distinct value of key
k->rec_per_key[j] = x;
```