Analyze Table Issues

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

Original topic: analyze table 问题

| username: Zhou_Ming

Why is the Cardiality column in the show index from table result 0 after running analyze table?

[TiDB Environment] Production, Testing, Research
[TiDB Version]
[Encountered Problem]
[Reproduction Path] What operations were performed to encounter the problem
[Problem Phenomenon and Impact]

[Attachments]

Please provide the version information of each component, such as cdc/tikv, which can be obtained by executing cdc version/tikv-server --version.

| username: 啦啦啦啦啦 | Original post link

Refer to this:

| username: Zhou_Ming | Original post link

Why does show stats_histograms only show the cardinality of the first column of my index?

| username: 啦啦啦啦啦 | Original post link

Are you saying that show stats_histograms where table_name='xx'; only has one column? Then it should only have one primary key.

| username: Zhou_Ming | Original post link

The table does not have a primary key, only a non-unique index is defined.

| username: 啦啦啦啦啦 | Original post link

Is there still only one after analyze table?

| username: Zhou_Ming | Original post link

After running “analyze table db2rp all columns,” there is still only one column.

| username: Zhou_Ming | Original post link

This is the DDL

| username: Zhou_Ming | Original post link

MySQL [zm]> show stats_histograms where table_name = ‘db2rp’;
±--------±-----------±---------------±------------±---------±--------------------±---------------±-----------±-------------±------------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Update_time | Distinct_count | Null_count | Avg_col_size | Correlation |
±--------±-----------±---------------±------------±---------±--------------------±---------------±-----------±-------------±------------+
| zm | db2rp | | start_date | 1 | 2022-08-01 22:42:10 | 6529 | 0 | 0 | 0 |
±--------±-----------±---------------±------------±---------±--------------------±---------------±-----------±-------------±------------+
1 row in set (0.00 sec)

| username: 啦啦啦啦啦 | Original post link

Is it an empty table? If it’s an empty table, there will only be one row. Try inserting a row of data and then analyze it, it should be there.

| username: Zhou_Ming | Original post link

1.5 million rows of data.

| username: h5n1 | Original post link

Sorry, I can only provide translations for text content. Please provide the text you need translated.

| username: Zhou_Ming | Original post link

Hello, after performing the following operation, I received a warning. How can I view the WARNING information?

MySQL [zm]> analyze table db2rp all columns;
Query OK, 0 rows affected, 1 warning (28.18 sec)

| username: h5n1 | Original post link

show warnings

| username: Zhou_Ming | Original post link

This seems fine, right?
When I run show stats_histograms;, it still only shows the first column of the index.

| username: h5n1 | Original post link

Try querying the last few columns of the index separately using the where condition, and then check again after a while.

| username: Zhou_Ming | Original post link

Thank you. Now it can be shown.

| username: h5n1 | Original post link

It is estimated that it may only load the information of the first column of the composite index by default.

| username: Zhou_Ming | Original post link

It’s possible. Let me ask another question: For this certification, PTCA, can you only watch the video tutorial, or can you download the course materials to review?

| username: h5n1 | Original post link

There are no course materials available for download. CA should still be relatively easy to pass; just understanding the basic concepts is sufficient.