Feb 24, 2011

Com_flush vs Flush_commands

MySQL status variables has two variables with similar name (and description), but quite different meaning.

Flush_commands - internal version of tables (incremented when tables are actually flushed, i.e. in SQL command FLUSH TABLES or in COM_REFRESH packet).
Com_flush - incremented on each FLUSH command and in each COM_REFRESH packet.

Difference 1: at startup Flush_commands has initial value 1. So name of variable is somewhat wrong, because "1" means no commands were executed yet.

Difference 2: Both FLUSH command and COM_REFRESH packet internally call reload_acl_and_cache() function, but not every call will actually flush tables (e.g. it may flush only privileges or only hosts).
So following condition is always true on GLOBAL level of MySQL:

Com_flush >= (Flush_commands -1)


Difference 3: logical conclusion is that Flush_commands is only GLOBAL variable, while Com_flush has both SESSION and GLOBAL values.


This looks quite complex, but looking into history will explain wrong name of "Flash_commands" variable. Initially there was no SQL command FLUSH in MySQL and COM_REFRESH packet had no parameters - so every COM_REFRESH did increment this variable.

No comments:

Post a Comment