summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorunknown <psergey@psergey.(none)>2003-11-13 22:14:37 +0300
committerunknown <psergey@psergey.(none)>2003-11-13 22:14:37 +0300
commit738728bd1144a29a9b8b380c6a129afc3acdcfc4 (patch)
treeee449f3b5dcb528030efbeea367fa2b4c2183c94 /sql/sql_select.cc
parent4696bb41b4cce563ffff8d7b6c32576214109113 (diff)
parent6e464cc06d8340cb5f0f26fd6894301eef55af1f (diff)
downloadmariadb-git-738728bd1144a29a9b8b380c6a129afc3acdcfc4.tar.gz
merging in index_merge (in progress, not yet working)
BitKeeper/etc/logging_ok: auto-union
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc104
1 files changed, 86 insertions, 18 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 718ba141e3d..b26be9c44d9 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -32,7 +32,8 @@
const char *join_type_str[]={ "UNKNOWN","system","const","eq_ref","ref",
"MAYBE_REF","ALL","range","index","fulltext",
- "ref_or_null","unique_subquery","index_subquery"
+ "ref_or_null","unique_subquery","index_subquery",
+ "index_merge" //!!todo: psergey: check if constant values are same
};
static void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array);
@@ -114,7 +115,6 @@ static int join_read_next_same_or_null(READ_RECORD *info);
static COND *make_cond_for_table(COND *cond,table_map table,
table_map used_table);
static Item* part_of_refkey(TABLE *form,Field *field);
-static uint find_shortest_key(TABLE *table, key_map usable_keys);
static bool test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,
ha_rows select_limit, bool no_changes);
static int create_sort_index(THD *thd, JOIN *join, ORDER *order,
@@ -3340,7 +3340,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
with key reading */
if (tab->needed_reg == 0 && tab->type != JT_EQ_REF
&& tab->type != JT_FT && (tab->type != JT_REF ||
- (uint) tab->ref.key == tab->quick->index))
+ (uint) tab->ref.key == tab->quick->index))
{
sel->quick=tab->quick; // Use value from get_quick_...
sel->quick_keys=0;
@@ -6589,7 +6589,7 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
return reverse;
}
-static uint find_shortest_key(TABLE *table, key_map usable_keys)
+uint find_shortest_key(TABLE *table, key_map usable_keys)
{
uint min_length= (uint) ~0;
uint best= MAX_KEY;
@@ -6719,6 +6719,9 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
}
else if (select && select->quick) // Range found by opt_range
{
+ /* assume results are not ordered when index merge is used */
+ if (select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE)
+ DBUG_RETURN(0);
ref_key= select->quick->index;
ref_key_parts= select->quick->used_key_parts;
}
@@ -6753,6 +6756,10 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
}
else
{
+ /*
+ We have verified above that select->quick is not
+ index_merge quick select.
+ */
select->quick->index= new_ref_key;
select->quick->init();
}
@@ -6774,10 +6781,13 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
*/
if (!select->quick->reverse_sorted())
{
- if (table->file->index_flags(ref_key) & HA_NOT_READ_PREFIX_LAST)
+ if (table->file->index_flags(ref_key) & HA_NOT_READ_PREFIX_LAST ||
+ (select->quick->get_type() ==
+ QUICK_SELECT_I::QS_TYPE_INDEX_MERGE))
DBUG_RETURN(0); // Use filesort
- // ORDER BY range_key DESC
- QUICK_SELECT_DESC *tmp=new QUICK_SELECT_DESC(select->quick,
+
+ // ORDER BY range_key DESC
+ QUICK_SELECT_DESC *tmp=new QUICK_SELECT_DESC((QUICK_RANGE_SELECT*)(select->quick),
used_key_parts);
if (!tmp || tmp->error)
{
@@ -6912,8 +6922,11 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order,
{
select->quick=tab->quick;
tab->quick=0;
- /* We can only use 'Only index' if quick key is same as ref_key */
- if (table->key_read && (uint) tab->ref.key != select->quick->index)
+ /*
+ We can only use 'Only index' if quick key is same as ref_key
+ and in index_merge 'Only index' cannot be used
+ */
+ if (table->key_read && ((uint) tab->ref.key != select->quick->index))
{
table->key_read=0;
table->file->extra(HA_EXTRA_NO_KEYREAD);
@@ -8717,12 +8730,15 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
JOIN_TAB *tab=join->join_tab+i;
TABLE *table=tab->table;
char buff[512],*buff_ptr=buff;
- char buff1[512], buff2[512];
+ char buff1[512], buff2[512], buff3[512];
+ char keylen_str_buf[64];
char derived_name[64];
String tmp1(buff1,sizeof(buff1),cs);
String tmp2(buff2,sizeof(buff2),cs);
+ String tmp3(buff3,sizeof(buff3),cs);
tmp1.length(0);
tmp2.length(0);
+ tmp3.length(0);
item_list.empty();
item_list.push_back(new Item_int((int32)
@@ -8731,7 +8747,13 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
strlen(join->select_lex->type),
cs));
if (tab->type == JT_ALL && tab->select && tab->select->quick)
- tab->type= JT_RANGE;
+ {
+ if (tab->select->quick->get_type() ==
+ QUICK_SELECT_I::QS_TYPE_INDEX_MERGE)
+ tab->type = JT_INDEX_MERGE;
+ else
+ tab->type = JT_RANGE;
+ }
if (table->derived_select_number)
{
/* Derived table name generation */
@@ -8765,10 +8787,14 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
if (tab->ref.key_parts)
{
KEY *key_info=table->key_info+ tab->ref.key;
+ register uint length;
item_list.push_back(new Item_string(key_info->name,
strlen(key_info->name),
system_charset_info));
- item_list.push_back(new Item_int((int32) tab->ref.key_length));
+ length= longlong2str(tab->ref.key_length, keylen_str_buf, 10) -
+ keylen_str_buf;
+ item_list.push_back(new Item_string(keylen_str_buf, length,
+ system_charset_info));
for (store_key **ref=tab->ref.key_copy ; *ref ; ref++)
{
if (tmp2.length())
@@ -8780,18 +8806,60 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
else if (tab->type == JT_NEXT)
{
KEY *key_info=table->key_info+ tab->index;
+ register uint length;
item_list.push_back(new Item_string(key_info->name,
strlen(key_info->name),cs));
- item_list.push_back(new Item_int((int32) key_info->key_length));
+ length= longlong2str(key_info->key_length, keylen_str_buf, 10) -
+ keylen_str_buf;
+ item_list.push_back(new Item_string(keylen_str_buf,
+ length,
+ system_charset_info));
item_list.push_back(item_null);
}
else if (tab->select && tab->select->quick)
{
- KEY *key_info=table->key_info+ tab->select->quick->index;
- item_list.push_back(new Item_string(key_info->name,
- strlen(key_info->name),cs));
- item_list.push_back(new Item_int((int32) tab->select->quick->
- max_used_key_length));
+ if (tab->select->quick->get_type() ==
+ QUICK_SELECT_I::QS_TYPE_INDEX_MERGE)
+ {
+ QUICK_INDEX_MERGE_SELECT *quick_imerge=
+ (QUICK_INDEX_MERGE_SELECT*)tab->select->quick;
+ QUICK_RANGE_SELECT *quick;
+
+ List_iterator_fast<QUICK_RANGE_SELECT> it(quick_imerge->
+ quick_selects);
+ while ((quick= it++))
+ {
+ KEY *key_info= table->key_info + quick->index;
+ register uint length;
+ if (tmp3.length())
+ tmp3.append(',');
+
+ tmp3.append(key_info->name);
+
+ if (tmp2.length())
+ tmp2.append(',');
+
+ length= longlong2str(quick->max_used_key_length, keylen_str_buf,
+ 10) -
+ keylen_str_buf;
+
+ tmp2.append(keylen_str_buf, length);
+ }
+ }
+ else
+ {
+ KEY *key_info= table->key_info + tab->select->quick->index;
+ register uint length;
+ tmp3.append(key_info->name);
+
+ length= longlong2str(tab->select->quick->max_used_key_length,
+ keylen_str_buf, 10) -
+ keylen_str_buf;
+ tmp2.append(keylen_str_buf, length);
+ }
+
+ item_list.push_back(new Item_string(tmp3.ptr(),tmp3.length(),cs));
+ item_list.push_back(new Item_string(tmp2.ptr(),tmp2.length(),cs));
item_list.push_back(item_null);
}
else