Skip to content

Commit

Permalink
fix the statement to update statistics of partitioned tables (#14471)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiancai authored Aug 9, 2023
1 parent 50175c2 commit fb11436
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions partitioned-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -1973,12 +1973,14 @@ Currently, neither `static` nor `dynamic` pruning mode supports prepared stateme
2. Generate the statements for updating the statistics of all partitioned tables:
{{< copyable "sql" >}}
```sql
select distinct concat('ANALYZE TABLE ',TABLE_SCHEMA,'.',TABLE_NAME,' ALL COLUMNS;')
from information_schema.PARTITIONS
where TABLE_SCHEMA not in ('INFORMATION_SCHEMA','mysql','sys','PERFORMANCE_SCHEMA','METRICS_SCHEMA');
SELECT DISTINCT CONCAT('ANALYZE TABLE ',TABLE_SCHEMA,'.',TABLE_NAME,' ALL COLUMNS;')
FROM information_schema.PARTITIONS
WHERE TIDB_PARTITION_ID IS NOT NULL
AND TABLE_SCHEMA NOT IN ('INFORMATION_SCHEMA','mysql','sys','PERFORMANCE_SCHEMA','METRICS_SCHEMA');
```
```
+----------------------------------------------------------------------+
| concat('ANALYZE TABLE ',TABLE_SCHEMA,'.',TABLE_NAME,' ALL COLUMNS;') |
+----------------------------------------------------------------------+
Expand All @@ -1991,12 +1993,11 @@ Currently, neither `static` nor `dynamic` pruning mode supports prepared stateme
3. Export the batch update statements to a file:
{{< copyable "sql" >}}
```sql
mysql --host xxxx --port xxxx -u root -p -e "select distinct concat('ANALYZE TABLE ',TABLE_SCHEMA,'.',TABLE_NAME,' ALL COLUMNS;') \
from information_schema.PARTITIONS \
where TABLE_SCHEMA not in ('INFORMATION_SCHEMA','mysql','sys','PERFORMANCE_SCHEMA','METRICS_SCHEMA');" | tee gatherGlobalStats.sql
```shell
mysql --host xxxx --port xxxx -u root -p -e "SELECT DISTINCT CONCAT('ANALYZE TABLE ',TABLE_SCHEMA,'.',TABLE_NAME,' ALL COLUMNS;') \
FROM information_schema.PARTITIONS \
WHERE TIDB_PARTITION_ID IS NOT NULL \
AND TABLE_SCHEMA NOT IN ('INFORMATION_SCHEMA','mysql','sys','PERFORMANCE_SCHEMA','METRICS_SCHEMA');" | tee gatherGlobalStats.sql
```
4. Execute a batch update:
Expand Down

0 comments on commit fb11436

Please sign in to comment.