Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve some descriptions about optimizer (#7261) #7296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion information-schema/information-schema-statistics.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ DESC statistics;
* `SEQ_IN_INDEX`:索引中的列序号,从 `1` 开始。
* `COLUMN_NAME`:列名。请参见表达式列的说明。
* `COLLATION`:列在索引中的排序方式。取值可以是 `A`(升序)、`D`(降序)或 `NULL`(未排序)。
* `CARDINALITY`:索引中唯一值的数量的估计。要更新这个数字,执行 `ANALYZE TABLE`。
* `CARDINALITY`:TiDB 未使用该字段。该字段的值总是 `0`。
* `SUB_PART`:索引的前缀。如果只对列的部分前缀进行索引,则为索引字符的数量;如果对整个列进行索引,则为 `NULL`。
* `PACKED`:TiDB 未使用该字段。这个值总是 `NULL`。
* `NULLABLE`:如果列可能包含 `NULL` 值,则值为 `YES`;如果不包含,则值为 `''`。
Expand Down
22 changes: 21 additions & 1 deletion sql-plan-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,30 @@ using

```sql
select * from t where a > 1
-- 标准化后
-- 以上语句标准化后如下
select * from test . t where a > ?
```

> **注意:**
>
> 在进行标准化的时候,被逗号 `,` 连接起来的多个常量会被标准化为 `...` 而不是 `?`。
>
> 例如:
>
> ```sql
> select * from t limit 10
> select * from t limit 10, 20
> select * from t where a in (1)
> select * from t where a in (1,2,3)
> -- 以上语句标准化后如下:
> select * from test . t limit ?
> select * from test . t limit ...
> select * from test . t where a in ( ? )
> select * from test . t where a in ( ... )
> ```
>
> 因此包含单个常量的 SQL 语句和包含被逗号连接起来多个常量的 SQL 语句,在被绑定时会被 TiDB 视作不同的 SQL 语句,需要分别创建绑定。

值得注意的是,如果一条 SQL 语句在 GLOBAL 和 SESSION 作用域内都有与之绑定的执行计划,因为优化器在遇到 SESSION 绑定时会忽略 GLOBAL 绑定的执行计划,该语句在 SESSION 作用域内绑定的执行计划会屏蔽掉语句在 GLOBAL 作用域内绑定的执行计划。

例如:
Expand Down
2 changes: 1 addition & 1 deletion sql-statements/sql-statement-show-indexes.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ SHOW KEYS FROM t1;

## MySQL 兼容性

`SHOW INDEXES [FROM|IN]` 语句与 MySQL 完全兼容。如发现任何兼容性差异,请在 GitHub 上提交 [issue](https://github.com/pingcap/tidb/issues/new/choose)
MySQL 中的 `Cardinality` 列返回该索引上不同值的个数,而 TiDB 中的 `Cardinality` 列始终返回 `0`

## 另请参阅

Expand Down