[MDEV-30635] OPTIMIZE TABLE documentation is not mentioning ANALYZE Created: 2023-02-10  Updated: 2023-02-28  Resolved: 2023-02-28

Status: Closed
Project: MariaDB Server
Component/s: Documentation
Fix Version/s: N/A

Type: Task Priority: Major
Reporter: Oli Sennhauser Assignee: Ian Gilfillan
Resolution: Won't Fix Votes: 0
Labels: documentation, optimize_table

Issue Links:
Relates
relates to MDEV-18385 Document use cases and locking behavi... Open

 Description   

Documentation of OPTIMIZE TABLE does NOT mention that this command also does an implicit ANALYZE TABLE.

If we look at the command output this seems to be the case:

SQL> OPTIMIZE TABLE test;
+-----------+----------+----------+-------------------------------------------------------------------+
| Table     | Op       | Msg_type | Msg_text                                                          |
+-----------+----------+----------+-------------------------------------------------------------------+
| test.test | optimize | note     | Table does not support optimize, doing recreate + analyze instead |
| test.test | optimize | status   | OK                                                                |
+-----------+----------+----------+-------------------------------------------------------------------+

Also looking at the code points to this behaviour:

sql/sql_admin.cc

static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
...
    case HA_ADMIN_TRY_ALTER:
    {
      Alter_info *alter_info= &lex->alter_info;
 
      protocol->store(STRING_WITH_LEN("note"), system_charset_info);
      if (alter_info->partition_flags & ALTER_PARTITION_ADMIN)
      {
        protocol->store(STRING_WITH_LEN(
        "Table does not support optimize on partitions. All partitions "
        "will be rebuilt and analyzed."),system_charset_info);
      }
      else
      {
        protocol->store(STRING_WITH_LEN(
        "Table does not support optimize, doing recreate + analyze instead"),
        system_charset_info);
      }



 Comments   
Comment by Sergei Golubchik [ 2023-02-28 ]

As you can see, OPTIMIZE TABLE does not always includes ANALYZE, but only when the storage engine does not support OPTIMIZE internally and the server emulates it with ALTER TABLE

Generated at Thu Feb 08 10:17:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.