Bug #76007 get_default_num_partitions() called when number of partitions are known
Submitted: 23 Feb 2015 14:49 Modified: 11 Mar 2015 16:05
Reporter: Magnus Blåudd Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Partitions Severity:S2 (Serious)
Version:5.7.6 OS:Any
Assigned to: CPU Architecture:Any

[23 Feb 2015 14:49] Magnus Blåudd
Description:
MySQL Server unnecessarily asks for the default number of partitions for a table when opening a partitioned table. This is not necessary since the MySQL Server already knows how many partitions the table it want to open has. Only when the table is to be created or altered is there a need to know the default value.

open()
  part_info.num_parts = Partition_handler::get_num_parts("t1");
  default_partitions = Partition_handler::get_default_num_partitions();

How to repeat:
This was detected when merging down 5.7.6 into trunk-cluster, queries ran just after mysqld connected to the cluster failed more often. Code inspection showed that ha_ndbcluster::get_default_num_partitions() was being called before opening the table.

Suggested fix:
Don't call Partition_handler::get_default_num_partitions() when opening a table.

The function should only be used when creating a new table and the user has not specified number of partitions.

I'm quite sure the function is currently also used when altering a table, that use case seems wrong since the number of partitions in the target table should be the same as source table. Anyway, this bug is about making it not called as part of or before opening a table.

Theoretically the get_default_num_partitions() should be a handlerton function or at least a Partition_handler class function(i.e static).
[11 Mar 2015 16:05] Jon Stephens
Documented as follows in the 5.7.7 changelog:

    The MySQL Server unnecessarily requested the default number of
    partitions for a table whenever it opened a partitioned table.
    This was unnecessary since the server already has this
    information about the table to be opened. Now the server
    requests this information only when needed--that is, only
    if it is creating or altering a partitioned table.

Closed.