summaryrefslogtreecommitdiff
path: root/sql/sql_join_cache.cc
diff options
context:
space:
mode:
authorSergey Petrunya <psergey@askmonty.org>2010-06-05 12:37:16 +0400
committerSergey Petrunya <psergey@askmonty.org>2010-06-05 12:37:16 +0400
commit49568aefe7a9d95e303ccfe40614fd3d1ee5b12f (patch)
tree19fba606d12dd350791517cd798d9b04ec30e4bd /sql/sql_join_cache.cc
parentdad93f2c822f174f4674c4a04c2382c18a262e36 (diff)
downloadmariadb-git-49568aefe7a9d95e303ccfe40614fd3d1ee5b12f.tar.gz
MWL#90: Code cleanup: Unification of merged and non-merged SJM nests processing
- Make join buffering code to take into account that JOIN_TABs are not a linear array anymore.
Diffstat (limited to 'sql/sql_join_cache.cc')
-rw-r--r--sql/sql_join_cache.cc76
1 files changed, 68 insertions, 8 deletions
diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc
index 13c5e5c8ee3..bf77239ce74 100644
--- a/sql/sql_join_cache.cc
+++ b/sql/sql_join_cache.cc
@@ -137,6 +137,7 @@ uint add_table_data_fields_to_join_cache(JOIN_TAB *tab,
return len;
}
+JOIN_TAB *next_linear_tab(JOIN* join, JOIN_TAB* tab, bool include_bush_roots);
/*
Determine different counters of fields associated with a record in the cache
@@ -157,10 +158,61 @@ uint add_table_data_fields_to_join_cache(JOIN_TAB *tab,
void JOIN_CACHE::calc_record_fields()
{
- JOIN_TAB *tab = prev_cache ? prev_cache->join_tab :
+ //psergey4-todo: prev_cache, or
+ // - first non-const table if on top level
+ // - first table inside SJM nest if within sjm nest
+ // this->join_tab is 'our' join_tab
+
+ // No. the right idea: start from ... and walk to the current join_tab
+ /// with an iterator, skipping
+ // join nests (can do so for now)
+
+ /*
+ The above sucks, too.
+ The right idea:
+ - for SJM-inner tables, walk only within the nest
+ - for SJM-outer tables, use all preceding tables, including inner ones.
+ eof
+ */
+
+/* JOIN_TAB *tab = prev_cache ? prev_cache->join_tab :
join->join_tab+join->const_tables;
- tables= join_tab-tab;
+*/
+/* JOIN_TAB *tab;
+ if (prev_cache)
+ tab= prev_cache->join_tab;
+ else
+ {
+ if (tab->bush_root_tab)
+ {
+ ;
+ }
+ else
+ {
+ / * top-level * /
+ tab= join->join_tab+join->const_tables;
+ }
+ }*/
+ JOIN_TAB *tab;
+ if (prev_cache)
+ tab= prev_cache->join_tab;
+ else
+ {
+ if (join_tab->bush_root_tab)
+ {
+ // inside SJM-Mat nest: pick first one
+ tab= join_tab->bush_root_tab->bush_children->start;
+ }
+ else
+ {
+ // outside SJM-Mat nest: start from first non-const table
+ tab= join->join_tab + join->const_tables;
+ }
+ }
+ start_tab= tab;
+ //tables= join_tab-tab;
+ //tables= 0;
fields= 0;
blobs= 0;
flag_fields= 0;
@@ -168,7 +220,7 @@ void JOIN_CACHE::calc_record_fields()
data_field_ptr_count= 0;
referenced_fields= 0;
- for ( ; tab < join_tab ; tab++)
+ for ( ; tab != join_tab ; tab= next_linear_tab(join, tab, TRUE))
{
calc_used_field_length(join->thd, tab);
flag_fields+= test(tab->used_null_fields || tab->used_uneven_bit_fields);
@@ -177,6 +229,7 @@ void JOIN_CACHE::calc_record_fields()
blobs+= tab->used_blobs;
fields+= tab->check_rowid_field();
+ //tables++;
}
if ((with_match_flag= join_tab->use_match_flag()))
flag_fields++;
@@ -271,7 +324,8 @@ void JOIN_CACHE::create_flag_fields()
&copy);
/* Create fields for all null bitmaps and null row flags that are needed */
- for (tab= join_tab-tables; tab < join_tab; tab++)
+ //for (tab= join_tab-tables; tab < join_tab; tab++)
+ for (tab= start_tab; tab != join_tab; tab= next_linear_tab(join, tab, TRUE))
{
TABLE *table= tab->table;
@@ -336,7 +390,8 @@ void JOIN_CACHE:: create_remaining_fields(bool all_read_fields)
CACHE_FIELD *copy= field_descr+flag_fields+data_field_count;
CACHE_FIELD **copy_ptr= blob_ptr+data_field_ptr_count;
- for (tab= join_tab-tables; tab < join_tab; tab++)
+ for (tab= start_tab; tab != join_tab; tab= next_linear_tab(join, tab, TRUE))
+ //for (tab= join_tab-tables; tab < join_tab; tab++)
{
MY_BITMAP *rem_field_set;
TABLE *table= tab->table;
@@ -557,7 +612,9 @@ int JOIN_CACHE_BKA::init()
of the counting 'in local_key_arg_fields' and 'external_key_arg_fields'
respectively.
*/
- for (tab= cache->join_tab-cache->tables; tab < cache->join_tab ; tab++)
+ // for (tab= cache->join_tab-cache->tables; tab < cache->join_tab ; tab++)
+ for (tab= cache->start_tab; tab != cache->join_tab; tab=
+ next_linear_tab(cache->join, tab, TRUE))
{
uint key_args;
bitmap_clear_all(&tab->table->tmp_set);
@@ -597,7 +654,9 @@ int JOIN_CACHE_BKA::init()
while (ext_key_arg_cnt)
{
cache= cache->prev_cache;
- for (tab= cache->join_tab-cache->tables; tab < cache->join_tab ; tab++)
+ for (tab= cache->start_tab; tab != cache->join_tab; tab=
+ next_linear_tab(cache->join, tab, TRUE))
+ //for (tab= cache->join_tab-cache->tables; tab < cache->join_tab ; tab++)
{
CACHE_FIELD *copy_end;
MY_BITMAP *key_read_set= &tab->table->tmp_set;
@@ -640,7 +699,8 @@ int JOIN_CACHE_BKA::init()
/* Now create local fields that are used to build ref for this key access */
copy= field_descr+flag_fields;
- for (tab= join_tab-tables; tab < join_tab ; tab++)
+ //for (tab= join_tab-tables; tab < join_tab ; tab++)
+ for (tab= start_tab; tab != join_tab; tab= next_linear_tab(join, tab, TRUE))
{
length+= add_table_data_fields_to_join_cache(tab, &tab->table->tmp_set,
&data_field_count, &copy,