mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Subquery code cleanups:
- Make functions that operate on SJ_TMP_TABLE be member functions - Make Loose_scan_opt data members private
This commit is contained in:
@ -3472,12 +3472,8 @@ static bool is_cond_sj_in_equality(Item *item)
|
|||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
|
|
||||||
create_duplicate_weedout_tmp_table()
|
create_sj_weedout_tmp_table()
|
||||||
thd Thread handle
|
thd Thread handle
|
||||||
uniq_tuple_length_arg Length of the table's column
|
|
||||||
sjtbl Update sjtbl->[start_]recinfo values which
|
|
||||||
will be needed if we'll need to convert the
|
|
||||||
created temptable from HEAP to MyISAM/Maria.
|
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
Create a temporary table to weed out duplicate rowid combinations. The
|
Create a temporary table to weed out duplicate rowid combinations. The
|
||||||
@ -3502,9 +3498,8 @@ static bool is_cond_sj_in_equality(Item *item)
|
|||||||
NULL on error
|
NULL on error
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TABLE *create_duplicate_weedout_tmp_table(THD *thd,
|
bool
|
||||||
uint uniq_tuple_length_arg,
|
SJ_TMP_TABLE::create_sj_weedout_tmp_table(THD *thd)
|
||||||
SJ_TMP_TABLE *sjtbl)
|
|
||||||
{
|
{
|
||||||
MEM_ROOT *mem_root_save, own_root;
|
MEM_ROOT *mem_root_save, own_root;
|
||||||
TABLE *table;
|
TABLE *table;
|
||||||
@ -3517,15 +3512,17 @@ TABLE *create_duplicate_weedout_tmp_table(THD *thd,
|
|||||||
uchar *group_buff;
|
uchar *group_buff;
|
||||||
uchar *bitmaps;
|
uchar *bitmaps;
|
||||||
uint *blob_field;
|
uint *blob_field;
|
||||||
ENGINE_COLUMNDEF *recinfo, *start_recinfo;
|
|
||||||
bool using_unique_constraint=FALSE;
|
bool using_unique_constraint=FALSE;
|
||||||
bool use_packed_rows= FALSE;
|
bool use_packed_rows= FALSE;
|
||||||
Field *field, *key_field;
|
Field *field, *key_field;
|
||||||
uint null_pack_length, null_count;
|
uint null_pack_length, null_count;
|
||||||
uchar *null_flags;
|
uchar *null_flags;
|
||||||
uchar *pos;
|
uchar *pos;
|
||||||
DBUG_ENTER("create_duplicate_weedout_tmp_table");
|
DBUG_ENTER("create_sj_weedout_tmp_table");
|
||||||
DBUG_ASSERT(!sjtbl->is_degenerate);
|
DBUG_ASSERT(!is_degenerate);
|
||||||
|
|
||||||
|
tmp_table= NULL;
|
||||||
|
uint uniq_tuple_length_arg= rowid_len + null_bytes;
|
||||||
/*
|
/*
|
||||||
STEP 1: Get temporary table name
|
STEP 1: Get temporary table name
|
||||||
*/
|
*/
|
||||||
@ -3567,7 +3564,7 @@ TABLE *create_duplicate_weedout_tmp_table(THD *thd,
|
|||||||
{
|
{
|
||||||
if (temp_pool_slot != MY_BIT_NONE)
|
if (temp_pool_slot != MY_BIT_NONE)
|
||||||
bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
|
bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
|
||||||
DBUG_RETURN(NULL);
|
DBUG_RETURN(TRUE);
|
||||||
}
|
}
|
||||||
strmov(tmpname,path);
|
strmov(tmpname,path);
|
||||||
|
|
||||||
@ -3771,20 +3768,19 @@ TABLE *create_duplicate_weedout_tmp_table(THD *thd,
|
|||||||
if (create_internal_tmp_table(table, keyinfo, start_recinfo, &recinfo, 0))
|
if (create_internal_tmp_table(table, keyinfo, start_recinfo, &recinfo, 0))
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
sjtbl->start_recinfo= start_recinfo;
|
|
||||||
sjtbl->recinfo= recinfo;
|
|
||||||
if (open_tmp_table(table))
|
if (open_tmp_table(table))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
thd->mem_root= mem_root_save;
|
thd->mem_root= mem_root_save;
|
||||||
DBUG_RETURN(table);
|
tmp_table= table;
|
||||||
|
DBUG_RETURN(FALSE);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
thd->mem_root= mem_root_save;
|
thd->mem_root= mem_root_save;
|
||||||
free_tmp_table(thd,table); /* purecov: inspected */
|
free_tmp_table(thd,table); /* purecov: inspected */
|
||||||
if (temp_pool_slot != MY_BIT_NONE)
|
if (temp_pool_slot != MY_BIT_NONE)
|
||||||
bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
|
bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
|
||||||
DBUG_RETURN(NULL); /* purecov: inspected */
|
DBUG_RETURN(TRUE); /* purecov: inspected */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -3792,25 +3788,25 @@ err:
|
|||||||
SemiJoinDuplicateElimination: Reset the temporary table
|
SemiJoinDuplicateElimination: Reset the temporary table
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int do_sj_reset(SJ_TMP_TABLE *sj_tbl)
|
int SJ_TMP_TABLE::sj_weedout_delete_rows()
|
||||||
{
|
{
|
||||||
DBUG_ENTER("do_sj_reset");
|
DBUG_ENTER("SJ_TMP_TABLE::sj_weedout_delete_rows");
|
||||||
if (sj_tbl->tmp_table)
|
if (tmp_table)
|
||||||
{
|
{
|
||||||
int rc= sj_tbl->tmp_table->file->ha_delete_all_rows();
|
int rc= tmp_table->file->ha_delete_all_rows();
|
||||||
DBUG_RETURN(rc);
|
DBUG_RETURN(rc);
|
||||||
}
|
}
|
||||||
sj_tbl->have_degenerate_row= FALSE;
|
have_degenerate_row= FALSE;
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
SemiJoinDuplicateElimination: Weed out duplicate row combinations
|
SemiJoinDuplicateElimination: Weed out duplicate row combinations
|
||||||
|
|
||||||
SYNPOSIS
|
SYNPOSIS
|
||||||
do_sj_dups_weedout()
|
sj_weedout_check_row()
|
||||||
thd Thread handle
|
thd Thread handle
|
||||||
sjtbl Duplicate weedout table
|
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
Try storing current record combination of outer tables (i.e. their
|
Try storing current record combination of outer tables (i.e. their
|
||||||
@ -3823,47 +3819,47 @@ int do_sj_reset(SJ_TMP_TABLE *sj_tbl)
|
|||||||
0 The row combination is not a duplicate (continue)
|
0 The row combination is not a duplicate (continue)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int do_sj_dups_weedout(THD *thd, SJ_TMP_TABLE *sjtbl)
|
int SJ_TMP_TABLE::sj_weedout_check_row(THD *thd)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
SJ_TMP_TABLE::TAB *tab= sjtbl->tabs;
|
SJ_TMP_TABLE::TAB *tab= tabs;
|
||||||
SJ_TMP_TABLE::TAB *tab_end= sjtbl->tabs_end;
|
SJ_TMP_TABLE::TAB *tab_end= tabs_end;
|
||||||
uchar *ptr;
|
uchar *ptr;
|
||||||
uchar *nulls_ptr;
|
uchar *nulls_ptr;
|
||||||
|
|
||||||
DBUG_ENTER("do_sj_dups_weedout");
|
DBUG_ENTER("SJ_TMP_TABLE::sj_weedout_check_row");
|
||||||
|
|
||||||
if (sjtbl->is_degenerate)
|
if (is_degenerate)
|
||||||
{
|
{
|
||||||
if (sjtbl->have_degenerate_row)
|
if (have_degenerate_row)
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
|
|
||||||
sjtbl->have_degenerate_row= TRUE;
|
have_degenerate_row= TRUE;
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr= sjtbl->tmp_table->record[0] + 1;
|
ptr= tmp_table->record[0] + 1;
|
||||||
|
|
||||||
/* Put the the rowids tuple into table->record[0]: */
|
/* Put the the rowids tuple into table->record[0]: */
|
||||||
|
|
||||||
// 1. Store the length
|
// 1. Store the length
|
||||||
if (((Field_varstring*)(sjtbl->tmp_table->field[0]))->length_bytes == 1)
|
if (((Field_varstring*)(tmp_table->field[0]))->length_bytes == 1)
|
||||||
{
|
{
|
||||||
*ptr= (uchar)(sjtbl->rowid_len + sjtbl->null_bytes);
|
*ptr= (uchar)(rowid_len + null_bytes);
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int2store(ptr, sjtbl->rowid_len + sjtbl->null_bytes);
|
int2store(ptr, rowid_len + null_bytes);
|
||||||
ptr += 2;
|
ptr += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
nulls_ptr= ptr;
|
nulls_ptr= ptr;
|
||||||
// 2. Zero the null bytes
|
// 2. Zero the null bytes
|
||||||
if (sjtbl->null_bytes)
|
if (null_bytes)
|
||||||
{
|
{
|
||||||
bzero(ptr, sjtbl->null_bytes);
|
bzero(ptr, null_bytes);
|
||||||
ptr += sjtbl->null_bytes;
|
ptr += null_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Put the rowids
|
// 3. Put the rowids
|
||||||
@ -3883,15 +3879,14 @@ int do_sj_dups_weedout(THD *thd, SJ_TMP_TABLE *sjtbl)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error= sjtbl->tmp_table->file->ha_write_tmp_row(sjtbl->tmp_table->record[0]);
|
error= tmp_table->file->ha_write_tmp_row(tmp_table->record[0]);
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
/* create_internal_tmp_table_from_heap will generate error if needed */
|
/* create_internal_tmp_table_from_heap will generate error if needed */
|
||||||
if (!sjtbl->tmp_table->file->is_fatal_error(error, HA_CHECK_DUP))
|
if (!tmp_table->file->is_fatal_error(error, HA_CHECK_DUP))
|
||||||
DBUG_RETURN(1); /* Duplicate */
|
DBUG_RETURN(1); /* Duplicate */
|
||||||
if (create_internal_tmp_table_from_heap(thd, sjtbl->tmp_table,
|
if (create_internal_tmp_table_from_heap(thd, tmp_table, start_recinfo,
|
||||||
sjtbl->start_recinfo,
|
&recinfo, error, 1))
|
||||||
&sjtbl->recinfo, error, 1))
|
|
||||||
DBUG_RETURN(-1);
|
DBUG_RETURN(-1);
|
||||||
}
|
}
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
@ -3943,11 +3938,8 @@ int init_dups_weedout(JOIN *join, uint first_table, int first_fanout_table, uint
|
|||||||
sjtbl->rowid_len= jt_rowid_offset;
|
sjtbl->rowid_len= jt_rowid_offset;
|
||||||
sjtbl->null_bits= jt_null_bits;
|
sjtbl->null_bits= jt_null_bits;
|
||||||
sjtbl->null_bytes= (jt_null_bits + 7)/8;
|
sjtbl->null_bytes= (jt_null_bits + 7)/8;
|
||||||
sjtbl->tmp_table=
|
if (sjtbl->create_sj_weedout_tmp_table(thd))
|
||||||
create_duplicate_weedout_tmp_table(thd,
|
DBUG_RETURN(TRUE);
|
||||||
sjtbl->rowid_len +
|
|
||||||
sjtbl->null_bytes,
|
|
||||||
sjtbl);
|
|
||||||
join->sj_tmp_tables.push_back(sjtbl->tmp_table);
|
join->sj_tmp_tables.push_back(sjtbl->tmp_table);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -40,7 +40,6 @@ ulonglong get_bound_sj_equalities(TABLE_LIST *sj_nest,
|
|||||||
|
|
||||||
class Loose_scan_opt
|
class Loose_scan_opt
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
/* All methods must check this before doing anything else */
|
/* All methods must check this before doing anything else */
|
||||||
bool try_loosescan;
|
bool try_loosescan;
|
||||||
|
|
||||||
@ -71,6 +70,7 @@ public:
|
|||||||
|
|
||||||
uint best_max_loose_keypart;
|
uint best_max_loose_keypart;
|
||||||
|
|
||||||
|
public:
|
||||||
Loose_scan_opt():
|
Loose_scan_opt():
|
||||||
try_loosescan(FALSE),
|
try_loosescan(FALSE),
|
||||||
bound_sj_equalities(0),
|
bound_sj_equalities(0),
|
||||||
@ -288,10 +288,6 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join);
|
|||||||
bool setup_sj_materialization_part1(JOIN_TAB *sjm_tab);
|
bool setup_sj_materialization_part1(JOIN_TAB *sjm_tab);
|
||||||
bool setup_sj_materialization_part2(JOIN_TAB *sjm_tab);
|
bool setup_sj_materialization_part2(JOIN_TAB *sjm_tab);
|
||||||
|
|
||||||
TABLE *create_duplicate_weedout_tmp_table(THD *thd, uint uniq_tuple_length_arg,
|
|
||||||
SJ_TMP_TABLE *sjtbl);
|
|
||||||
int do_sj_reset(SJ_TMP_TABLE *sj_tbl);
|
|
||||||
int do_sj_dups_weedout(THD *thd, SJ_TMP_TABLE *sjtbl);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Temporary table used by semi-join DuplicateElimination strategy
|
Temporary table used by semi-join DuplicateElimination strategy
|
||||||
@ -359,6 +355,10 @@ public:
|
|||||||
ENGINE_COLUMNDEF *recinfo;
|
ENGINE_COLUMNDEF *recinfo;
|
||||||
|
|
||||||
SJ_TMP_TABLE *next_flush_table;
|
SJ_TMP_TABLE *next_flush_table;
|
||||||
|
|
||||||
|
int sj_weedout_delete_rows();
|
||||||
|
int sj_weedout_check_row(THD *thd);
|
||||||
|
bool create_sj_weedout_tmp_table(THD *thd);
|
||||||
};
|
};
|
||||||
|
|
||||||
int setup_semijoin_dups_elimination(JOIN *join, ulonglong options,
|
int setup_semijoin_dups_elimination(JOIN *join, ulonglong options,
|
||||||
|
@ -2367,7 +2367,7 @@ enum_nested_loop_state JOIN_CACHE::generate_full_extensions(uchar *rec_ptr)
|
|||||||
int res= 0;
|
int res= 0;
|
||||||
|
|
||||||
if (!join_tab->check_weed_out_table ||
|
if (!join_tab->check_weed_out_table ||
|
||||||
!(res= do_sj_dups_weedout(join->thd, join_tab->check_weed_out_table)))
|
!(res= join_tab->check_weed_out_table->sj_weedout_check_row(join->thd)))
|
||||||
{
|
{
|
||||||
set_curr_rec_link(rec_ptr);
|
set_curr_rec_link(rec_ptr);
|
||||||
rc= (join_tab->next_select)(join, join_tab+1, 0);
|
rc= (join_tab->next_select)(join, join_tab+1, 0);
|
||||||
|
@ -15105,7 +15105,7 @@ sub_select(JOIN *join,JOIN_TAB *join_tab,bool end_of_records)
|
|||||||
flush_dups_table;
|
flush_dups_table;
|
||||||
flush_dups_table= flush_dups_table->next_flush_table)
|
flush_dups_table= flush_dups_table->next_flush_table)
|
||||||
{
|
{
|
||||||
do_sj_reset(flush_dups_table);
|
flush_dups_table->sj_weedout_delete_rows();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!join_tab->preread_init_done && join_tab->preread_init())
|
if (!join_tab->preread_init_done && join_tab->preread_init())
|
||||||
@ -15321,7 +15321,7 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
|
|||||||
|
|
||||||
if (join_tab->check_weed_out_table && found)
|
if (join_tab->check_weed_out_table && found)
|
||||||
{
|
{
|
||||||
int res= do_sj_dups_weedout(join->thd, join_tab->check_weed_out_table);
|
int res= join_tab->check_weed_out_table->sj_weedout_check_row(join->thd);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
DBUG_RETURN(NESTED_LOOP_ERROR);
|
DBUG_RETURN(NESTED_LOOP_ERROR);
|
||||||
else if (res == 1)
|
else if (res == 1)
|
||||||
@ -15445,7 +15445,7 @@ evaluate_null_complemented_join_record(JOIN *join, JOIN_TAB *join_tab)
|
|||||||
*/
|
*/
|
||||||
if (join_tab->check_weed_out_table)
|
if (join_tab->check_weed_out_table)
|
||||||
{
|
{
|
||||||
int res= do_sj_dups_weedout(join->thd, join_tab->check_weed_out_table);
|
int res= join_tab->check_weed_out_table->sj_weedout_check_row(join->thd);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return NESTED_LOOP_ERROR;
|
return NESTED_LOOP_ERROR;
|
||||||
else if (res == 1)
|
else if (res == 1)
|
||||||
|
Reference in New Issue
Block a user