#At file:///home/mysql_src/bzrrepos/mysql-6.0-codebase-bugfixing/ based on revid:guilhem@stripped
3640 Guilhem Bichot 2009-10-02
Some debugging aids which helped debugging BUG 46743 "Azalea processing correlated, aggregate
SELECT subqueries incorrectly".
@ sql/sql_select.cc
* making use of JOIN_TAB::set_select_cond() to track changes of JOIN_TAB::select_cond when debugging
* stepping into get_best_combination() made easier (see commit comment of mi_scan.c)
* some DBUG printouts in evaluate_join_record() to track if it eliminates a record
@ sql/sql_select.h
I had to detect when JOIN_TAB::select_cond changed from non-NULL to NULL (COND elimination) so added this
inline method to always have a DBUG printout when this condition is set.
@ storage/myisam/mi_scan.c
Stepping into info->s->read_rnd() is made difficult by wrapping it directly in DBUG_RETURN
(made me step into DBUG_RETURN() dbug internal code and not manage to step into read_rnd()).
modified:
sql/sql_select.cc
sql/sql_select.h
storage/myisam/mi_scan.c
=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc 2009-10-02 13:31:12 +0000
+++ b/sql/sql_select.cc 2009-10-02 14:56:07 +0000
@@ -2784,7 +2784,7 @@ JOIN::exec()
*/
curr_table->select->cond->quick_fix_field();
}
- curr_table->select_cond= curr_table->select->cond;
+ curr_table->set_select_cond(curr_table->select->cond, __LINE__);
curr_table->select_cond->top_level_item();
DBUG_EXECUTE("where",print_where(curr_table->select->cond,
"select and having",
@@ -4471,7 +4471,8 @@ make_join_statistics(JOIN *join, TABLE_L
join->best_read=1.0;
}
/* Generate an execution plan from the found optimal join order. */
- DBUG_RETURN(join->thd->killed || get_best_combination(join));
+ error= join->thd->killed || get_best_combination(join);
+ DBUG_RETURN(error);
error:
/*
@@ -8378,7 +8379,7 @@ JOIN::make_simple_join(JOIN *parent, TAB
join_tab->cache_select= 0;
join_tab->table=tmp_table;
join_tab->select=0;
- join_tab->select_cond=0;
+ join_tab->set_select_cond(NULL, __LINE__);
join_tab->quick=0;
join_tab->type= JT_ALL; /* Map through all records */
join_tab->keys.init();
@@ -8511,7 +8512,9 @@ static void add_not_null_conds(JOIN *joi
DBUG_EXECUTE("where",print_where(notnull,
referred_tab->table->alias,
QT_ORDINARY););
- add_cond_and_fix(&referred_tab->select_cond, notnull);
+ COND *new_cond= referred_tab->select_cond;
+ add_cond_and_fix(&new_cond, notnull);
+ referred_tab->set_select_cond(new_cond, __LINE__);
}
}
}
@@ -8699,9 +8702,9 @@ static bool make_join_select(JOIN *join,
if (!tmp)
DBUG_RETURN(1);
tmp->quick_fix_field();
- cond_tab->select_cond= !cond_tab->select_cond ? tmp :
- new Item_cond_and(cond_tab->select_cond,
- tmp);
+ COND *new_cond= !cond_tab->select_cond ? tmp :
+ new Item_cond_and(cond_tab->select_cond, tmp);
+ cond_tab->set_select_cond(new_cond, __LINE__);
if (!cond_tab->select_cond)
DBUG_RETURN(1);
cond_tab->select_cond->quick_fix_field();
@@ -8825,7 +8828,8 @@ static bool make_join_select(JOIN *join,
*/
if (!(tmp= add_found_match_trig_cond(first_inner_tab, tmp, 0)))
DBUG_RETURN(1);
- tab->select_cond=sel->cond=tmp;
+ sel->cond= tmp;
+ tab->set_select_cond(tmp, __LINE__);
/* Push condition to storage engine if this is enabled
and the condition is not guarded */
tab->table->file->pushed_cond= NULL;
@@ -8842,7 +8846,10 @@ static bool make_join_select(JOIN *join,
}
}
else
- tab->select_cond= sel->cond= NULL;
+ {
+ sel->cond= NULL;
+ tab->set_select_cond(NULL, __LINE__);
+ }
sel->head=tab->table;
DBUG_EXECUTE("where",print_where(tmp,tab->table->alias, QT_ORDINARY););
@@ -8994,8 +9001,9 @@ static bool make_join_select(JOIN *join,
if (!tmp)
DBUG_RETURN(1);
tmp->quick_fix_field();
- cond_tab->select_cond= !cond_tab->select_cond ? tmp :
- new Item_cond_and(cond_tab->select_cond,tmp);
+ COND *new_cond= !cond_tab->select_cond ? tmp :
+ new Item_cond_and(cond_tab->select_cond, tmp);
+ cond_tab->set_select_cond(new_cond, __LINE__);
if (!cond_tab->select_cond)
DBUG_RETURN(1);
cond_tab->select_cond->update_used_tables();
@@ -9048,11 +9056,9 @@ static bool make_join_select(JOIN *join,
tmp_cond->quick_fix_field();
/* Add the predicate to other pushed down predicates */
DBUG_PRINT("info", ("Item_cond_and"));
- cond_tab->select_cond= !cond_tab->select_cond ? tmp_cond :
- new Item_cond_and(cond_tab->select_cond,
- tmp_cond);
- DBUG_PRINT("info", ("Item_cond_and %p",
- cond_tab->select_cond));
+ COND *new_cond= !cond_tab->select_cond ? tmp_cond :
+ new Item_cond_and(cond_tab->select_cond, tmp_cond);
+ cond_tab->set_select_cond(new_cond, __LINE__);
if (!cond_tab->select_cond)
DBUG_RETURN(1);
cond_tab->select_cond->update_used_tables();
@@ -9439,17 +9445,18 @@ static void push_index_cond(JOIN_TAB *ta
if (row_cond)
{
if (!idx_remainder_cond)
- tab->select_cond= row_cond;
+ tab->set_select_cond(row_cond, __LINE__);
else
{
- tab->select_cond= new Item_cond_and(row_cond, idx_remainder_cond);
+ COND *new_cond= new Item_cond_and(row_cond, idx_remainder_cond);
+ tab->set_select_cond(new_cond, __LINE__);
tab->select_cond->quick_fix_field();
((Item_cond_and*)tab->select_cond)->used_tables_cache=
row_cond->used_tables() | idx_remainder_cond->used_tables();
}
}
else
- tab->select_cond= idx_remainder_cond;
+ tab->set_select_cond(idx_remainder_cond, __LINE__);
if (tab->select)
{
DBUG_EXECUTE("where",
@@ -15873,7 +15880,8 @@ do_select(JOIN *join,List<Item> *fields,
DBUG_PRINT("error",("Error: do_select() failed"));
}
#endif
- DBUG_RETURN(join->thd->is_error() ? -1 : rc);
+ rc= join->thd->is_error() ? -1 : rc;
+ DBUG_RETURN(rc);
}
@@ -15991,10 +15999,10 @@ sub_select_sjm(JOIN *join, JOIN_TAB *joi
JOIN_TAB *last_tab= join_tab + (sjm->tables - 1);
Item *save_cond= last_tab->select_cond;
- last_tab->select_cond= sjm->join_cond;
+ last_tab->set_select_cond(sjm->join_cond, __LINE__);
rc= sub_select(join, last_tab, end_of_records);
- last_tab->select_cond= save_cond;
+ last_tab->set_select_cond(save_cond, __LINE__);
return rc;
}
else
@@ -16424,6 +16432,9 @@ evaluate_join_record(JOIN *join, JOIN_TA
ha_rows found_records=join->found_records;
COND *select_cond= join_tab->select_cond;
+ DBUG_PRINT("enter",
+ ("evaluate_join_record join: %p join_tab: %p"
+ " cond: %p error: %d", join, join_tab, select_cond, error));
if (error > 0 || (join->thd->is_error())) // Fatal error
return NESTED_LOOP_ERROR;
if (error < 0)
@@ -16433,7 +16444,6 @@ evaluate_join_record(JOIN *join, JOIN_TA
join->thd->send_kill_message();
return NESTED_LOOP_KILLED; /* purecov: inspected */
}
- DBUG_PRINT("info", ("select cond %p", select_cond));
if (!select_cond || select_cond->val_int())
{
/*
@@ -16515,7 +16525,7 @@ evaluate_join_record(JOIN *join, JOIN_TA
(See above join->return_tab= tab).
*/
join->examined_rows++;
- DBUG_PRINT("counts", ("join->examined_rows++: %lu",
+ DBUG_PRINT("counts", ("evaluate_join_record join->examined_rows++: %lu",
(ulong) join->examined_rows));
if (found)
@@ -16929,7 +16939,10 @@ join_read_always_key(JOIN_TAB *tab)
for (uint i= 0 ; i < tab->ref.key_parts ; i++)
{
if ((tab->ref.null_rejecting & 1 << i) && tab->ref.items[i]->is_null())
- return -1;
+ {
+ DBUG_PRINT("info", ("join_read_always_key null rejected"));
+ return -1;
+ }
}
if (cp_buffer_from_ref(tab->join->thd, table, &tab->ref))
@@ -19097,7 +19110,7 @@ create_sort_index(THD *thd, JOIN *join,
table->quick_keys.clear_all(); // as far as we cleanup select->quick
table->sort.io_cache= tablesort_result_cache;
}
- tab->select_cond=0;
+ tab->set_select_cond(NULL, __LINE__);
tab->last_inner= 0;
tab->first_unmatched= 0;
tab->type=JT_ALL; // Read with normal read_record
@@ -19138,7 +19151,7 @@ static bool fix_having(JOIN *join, Item
sort_table_cond)) ||
table->select->cond->fix_fields(join->thd, &table->select->cond))
return 1;
- table->select_cond=table->select->cond;
+ table->set_select_cond(table->select->cond, __LINE__);
table->select_cond->top_level_item();
DBUG_EXECUTE("where",print_where(table->select_cond,
"select and having",
@@ -20837,11 +20850,12 @@ static bool add_ref_to_table_cond(THD *t
if (join_tab->select)
{
error=(int) cond->add(join_tab->select->cond);
- join_tab->select_cond=join_tab->select->cond=cond;
+ join_tab->select->cond= cond;
+ join_tab->set_select_cond(cond, __LINE__);
}
else if ((join_tab->select= make_select(join_tab->table, 0, 0, cond, 0,
&error)))
- join_tab->select_cond=cond;
+ join_tab->set_select_cond(cond, __LINE__);
DBUG_RETURN(error ? TRUE : FALSE);
}
=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h 2009-10-01 16:12:23 +0000
+++ b/sql/sql_select.h 2009-10-02 14:56:07 +0000
@@ -340,10 +340,16 @@ typedef struct st_join_table
return first_inner;
return first_sj_inner_tab;
}
+ void set_select_cond(COND *to, uint line)
+ {
+ DBUG_PRINT("info", ("select_cond changes %p -> %p at line %u tab %p",
+ select_cond, to, line, this));
+ select_cond= to;
+ }
COND *set_cond(COND *new_cond)
{
COND *tmp_select_cond= select_cond;
- select_cond= new_cond;
+ set_select_cond(new_cond, __LINE__);
if (select)
select->cond= new_cond;
return tmp_select_cond;
=== modified file 'storage/myisam/mi_scan.c'
--- a/storage/myisam/mi_scan.c 2007-05-10 09:59:39 +0000
+++ b/storage/myisam/mi_scan.c 2009-10-02 14:56:07 +0000
@@ -38,8 +38,10 @@ int mi_scan_init(register MI_INFO *info)
int mi_scan(MI_INFO *info, uchar *buf)
{
+ int result;
DBUG_ENTER("mi_scan");
/* Init all but update-flag */
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
- DBUG_RETURN ((*info->s->read_rnd)(info,buf,info->nextpos,1));
+ result= (*info->s->read_rnd)(info, buf, info->nextpos, 1);
+ DBUG_RETURN(result);
}
Attachment: [text/bzr-bundle] bzr/guilhem@mysql.com-20091002145607-8r475u0f4iiucx4i.bundle
| Thread |
|---|
| • bzr commit into mysql-6.0-codebase-bugfixing branch (guilhem:3640) | Guilhem Bichot | 2 Oct |