Skip to content
  • Roy Lyseng's avatar
    7b118bc7
    Bug#32288089: Tighten the use of member TABLE::in_use for temporary tables · 7b118bc7
    Roy Lyseng authored
    The problem with this member is that it can have the same value as
    the current session's THD, it can have the value of another session's
    THD, or it can be NULL, in various stages of execution.
    For internal temporary tables, the problem is that for temporary tables
    associated with triggers, the trigger may be passed on from one
    session to another, and there is no well defined point where this
    transition happens.
    To tighten the use, we will instead set the in_use member to NULL
    when the internal temporary table is closed and assign the current
    session's THD pointer to it when the temporary table is used by
    another session.
    This is all well, but there is also much use of the in_use throughout
    server code, because it is a convenient way of accessing the THD
    pointer when it is not passed as a function argument, or by other
    other means. We will therefore start recommending against this
    practice and substitute old use by either a passed THD argument
    or the thread-local variable current_thd.
    
    Storage engines still need in_use, so no change is made here.
    We also use in_use to check for MDL lock waits, so this use stays.
    
    For storage engines, it might be an idea to pass the THD pointer
    though the HANDLER object instead. It should make a more stable
    interface than TABLE::in_use.
    
    The THD argument to close_tmp_table() has also been eliminated.
    This also implicated removing server stage: deleting temporary table.
    
    Reviewed by: Catalin Besleaga <catalin.besleaga@oracle.com>
    7b118bc7
    Bug#32288089: Tighten the use of member TABLE::in_use for temporary tables
    Roy Lyseng authored
    The problem with this member is that it can have the same value as
    the current session's THD, it can have the value of another session's
    THD, or it can be NULL, in various stages of execution.
    For internal temporary tables, the problem is that for temporary tables
    associated with triggers, the trigger may be passed on from one
    session to another, and there is no well defined point where this
    transition happens.
    To tighten the use, we will instead set the in_use member to NULL
    when the internal temporary table is closed and assign the current
    session's THD pointer to it when the temporary table is used by
    another session.
    This is all well, but there is also much use of the in_use throughout
    server code, because it is a convenient way of accessing the THD
    pointer when it is not passed as a function argument, or by other
    other means. We will therefore start recommending against this
    practice and substitute old use by either a passed THD argument
    or the thread-local variable current_thd.
    
    Storage engines still need in_use, so no change is made here.
    We also use in_use to check for MDL lock waits, so this use stays.
    
    For storage engines, it might be an idea to pass the THD pointer
    though the HANDLER object instead. It should make a more stable
    interface than TABLE::in_use.
    
    The THD argument to close_tmp_table() has also been eliminated.
    This also implicated removing server stage: deleting temporary table.
    
    Reviewed by: Catalin Besleaga <catalin.besleaga@oracle.com>
Loading