Sergey Vojtovich wrote:
Thank you for the detailed comments Sergey!
>
>> @@ -422,6 +429,59 @@ int ha_myisammrg::open(const char *name,
>> DBUG_RETURN(0);
>> }
>>
>> +/**
>> + * Returns a cloned instance of the current handler.
>> + *
>> + * @return A cloned handler instance.
>> + */
>> +handler *ha_myisammrg::clone(MEM_ROOT *mem_root)
>> +{
>> + MYRG_TABLE *u_table,*newu_table;
>> + ha_myisammrg *new_handler=
>> + (ha_myisammrg*) get_new_handler(table->s, mem_root,
> table->s->db_type());
>> + if (!new_handler)
>> + return NULL;
>> +
>> + /* Inform ha_myisammrg::open() that it is a cloned handler */
>> + new_handler->is_cloned= TRUE;
>> + /*
>> + Allocate handler->ref here because otherwise ha_open will allocate it
>> + on this->table->mem_root and we will not be able to reclaim that
> memory
>> + when the clone handler object is destroyed.
>> + */
>> + if (!(new_handler->ref= (uchar*) alloc_root(mem_root,
> ALIGN_SIZE(ref_length)*2)))
>> + return NULL;
>> +
>> + /*
>> + Open the MySQL tables that are under the MERGE table
>> + parent
>> + */
>> + if (!(new_handler->file= myrg_open(table->s->normalized_path.str,
> table->db_stat, HA_OPEN_IGNORE_IF_LOCKED)))
>> + {
>> + return NULL;
>> + }
>> +
>> + /*
>> + Iterate through the original child tables and
>> + copy the state into the cloned child tables.
>> + We need to do this because all the child tables
>> + can be involved in delete.
>> + */
>> + newu_table= new_handler->file->open_tables;
>> + for (u_table= file->open_tables; u_table < file->end_table;
> u_table++)
>> + {
>> + newu_table->table->state= u_table->table->state;
>> + newu_table++;
>> + }
>> +
>> + file->children_attached= TRUE;
>> +
>> + if (!new_handler->ha_open(table, table->s->normalized_path.str,
> table->db_stat,
>> + HA_OPEN_IGNORE_IF_LOCKED))
>> + return new_handler;
>> + return NULL;
>> + }
>> +
>>
> I think logically it is more correct to have myrg_open() call as well as
> setting children_attached in ha_myisammrg::open() under if (is_cloned)
> branch. The loop with setting state pointers should stay here.
>
But moving
new_handler->file= myrg_open(table->s->normalized_path.str,
table->db_stat, HA_OPEN_IGNORE_IF_LOCKED
into
ha_myisammrg::open()
would cause
newu_table= new_handler->file->open_tables;
to fail?
>
> Regards,
> Sergey
>