Commit ddc9a195 authored by Alexey Botchkov's avatar Alexey Botchkov

merging

parents 620fb880 d445b215
...@@ -250,7 +250,11 @@ static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, ...@@ -250,7 +250,11 @@ static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo,
if (info->ft1_to_ft2) if (info->ft1_to_ft2)
{ {
/* we're in ft1->ft2 conversion mode. Saving key data */ /* we're in ft1->ft2 conversion mode. Saving key data */
insert_dynamic(info->ft1_to_ft2, (char*) (lastkey+off)); if (insert_dynamic(info->ft1_to_ft2, (char*) (lastkey+off)))
{
DBUG_PRINT("error",("Out of memory"));
DBUG_RETURN(-1);
}
} }
else else
{ {
......
...@@ -550,7 +550,14 @@ int _mi_insert(register MI_INFO *info, register MI_KEYDEF *keyinfo, ...@@ -550,7 +550,14 @@ int _mi_insert(register MI_INFO *info, register MI_KEYDEF *keyinfo,
we cannot easily dispatch an empty page here */ we cannot easily dispatch an empty page here */
b+=blen+ft2len+2; b+=blen+ft2len+2;
for (a=anc_buff+a_length ; b < a ; b+=ft2len+2) for (a=anc_buff+a_length ; b < a ; b+=ft2len+2)
insert_dynamic(info->ft1_to_ft2, (char*) b); {
if (insert_dynamic(info->ft1_to_ft2, (char*) b))
{
mi_print_error(info->s, HA_ERR_OUT_OF_MEM);
my_errno= HA_ERR_OUT_OF_MEM;
DBUG_RETURN(-1);
}
}
/* fixing the page's length - it contains only one key now */ /* fixing the page's length - it contains only one key now */
mi_putint(anc_buff,2+blen+ft2len+2,0); mi_putint(anc_buff,2+blen+ft2len+2,0);
......
...@@ -522,8 +522,7 @@ int Instance_options::add_option(const char* option) ...@@ -522,8 +522,7 @@ int Instance_options::add_option(const char* option)
switch (selected_options->type) { switch (selected_options->type) {
case SAVE_WHOLE_AND_ADD: case SAVE_WHOLE_AND_ADD:
*(selected_options->value)= tmp; *(selected_options->value)= tmp;
insert_dynamic(&options_array,(gptr) &tmp); return insert_dynamic(&options_array,(gptr) &tmp);
return 0;
case SAVE_VALUE: case SAVE_VALUE:
*(selected_options->value)= strchr(tmp, '=') + 1; *(selected_options->value)= strchr(tmp, '=') + 1;
return 0; return 0;
......
...@@ -1053,8 +1053,7 @@ int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec) ...@@ -1053,8 +1053,7 @@ int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec)
e->tbl_name = e->db + (dot - table_spec) + 1; e->tbl_name = e->db + (dot - table_spec) + 1;
e->key_len = len; e->key_len = len;
memcpy(e->db, table_spec, len); memcpy(e->db, table_spec, len);
insert_dynamic(a, (gptr)&e); return insert_dynamic(a, (gptr)&e);
return 0;
} }
......
...@@ -1929,17 +1929,16 @@ sp_head::restore_lex(THD *thd) ...@@ -1929,17 +1929,16 @@ sp_head::restore_lex(THD *thd)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
void int
sp_head::push_backpatch(sp_instr *i, sp_label_t *lab) sp_head::push_backpatch(sp_instr *i, sp_label_t *lab)
{ {
bp_t *bp= (bp_t *)sql_alloc(sizeof(bp_t)); bp_t *bp= (bp_t *)sql_alloc(sizeof(bp_t));
if (bp) if (!bp)
{ return 1;
bp->lab= lab; bp->lab= lab;
bp->instr= i; bp->instr= i;
(void)m_backpatch.push_front(bp); return m_backpatch.push_front(bp);
}
} }
void void
...@@ -2014,7 +2013,7 @@ sp_head::fill_field_definition(THD *thd, LEX *lex, ...@@ -2014,7 +2013,7 @@ sp_head::fill_field_definition(THD *thd, LEX *lex,
} }
void int
sp_head::new_cont_backpatch(sp_instr_opt_meta *i) sp_head::new_cont_backpatch(sp_instr_opt_meta *i)
{ {
m_cont_level+= 1; m_cont_level+= 1;
...@@ -2022,15 +2021,17 @@ sp_head::new_cont_backpatch(sp_instr_opt_meta *i) ...@@ -2022,15 +2021,17 @@ sp_head::new_cont_backpatch(sp_instr_opt_meta *i)
{ {
/* Use the cont. destination slot to store the level */ /* Use the cont. destination slot to store the level */
i->m_cont_dest= m_cont_level; i->m_cont_dest= m_cont_level;
(void)m_cont_backpatch.push_front(i); if (m_cont_backpatch.push_front(i))
return 1;
} }
return 0;
} }
void int
sp_head::add_cont_backpatch(sp_instr_opt_meta *i) sp_head::add_cont_backpatch(sp_instr_opt_meta *i)
{ {
i->m_cont_dest= m_cont_level; i->m_cont_dest= m_cont_level;
(void)m_cont_backpatch.push_front(i); return m_cont_backpatch.push_front(i);
} }
void void
...@@ -2212,7 +2213,7 @@ sp_head::show_create_procedure(THD *thd) ...@@ -2212,7 +2213,7 @@ sp_head::show_create_procedure(THD *thd)
instr Instruction instr Instruction
*/ */
void sp_head::add_instr(sp_instr *instr) int sp_head::add_instr(sp_instr *instr)
{ {
instr->free_list= m_thd->free_list; instr->free_list= m_thd->free_list;
m_thd->free_list= 0; m_thd->free_list= 0;
...@@ -2223,7 +2224,7 @@ void sp_head::add_instr(sp_instr *instr) ...@@ -2223,7 +2224,7 @@ void sp_head::add_instr(sp_instr *instr)
entire stored procedure, as their life span is equal. entire stored procedure, as their life span is equal.
*/ */
instr->mem_root= &main_mem_root; instr->mem_root= &main_mem_root;
insert_dynamic(&m_instr, (gptr)&instr); return insert_dynamic(&m_instr, (gptr)&instr);
} }
......
...@@ -226,7 +226,7 @@ public: ...@@ -226,7 +226,7 @@ public:
int int
show_create_function(THD *thd); show_create_function(THD *thd);
void int
add_instr(sp_instr *instr); add_instr(sp_instr *instr);
inline uint inline uint
...@@ -254,7 +254,7 @@ public: ...@@ -254,7 +254,7 @@ public:
restore_lex(THD *thd); restore_lex(THD *thd);
// Put the instruction on the backpatch list, associated with the label. // Put the instruction on the backpatch list, associated with the label.
void int
push_backpatch(sp_instr *, struct sp_label *); push_backpatch(sp_instr *, struct sp_label *);
// Update all instruction with this label in the backpatch list to // Update all instruction with this label in the backpatch list to
...@@ -263,11 +263,11 @@ public: ...@@ -263,11 +263,11 @@ public:
backpatch(struct sp_label *); backpatch(struct sp_label *);
// Start a new cont. backpatch level. If 'i' is NULL, the level is just incr. // Start a new cont. backpatch level. If 'i' is NULL, the level is just incr.
void int
new_cont_backpatch(sp_instr_opt_meta *i); new_cont_backpatch(sp_instr_opt_meta *i);
// Add an instruction to the current level // Add an instruction to the current level
void int
add_cont_backpatch(sp_instr_opt_meta *i); add_cont_backpatch(sp_instr_opt_meta *i);
// Backpatch (and pop) the current level to the current position. // Backpatch (and pop) the current level to the current position.
......
...@@ -263,7 +263,8 @@ sp_pcontext::push_variable(LEX_STRING *name, enum enum_field_types type, ...@@ -263,7 +263,8 @@ sp_pcontext::push_variable(LEX_STRING *name, enum enum_field_types type,
p->mode= mode; p->mode= mode;
p->offset= current_var_count(); p->offset= current_var_count();
p->dflt= NULL; p->dflt= NULL;
insert_dynamic(&m_vars, (gptr)&p); if (insert_dynamic(&m_vars, (gptr)&p))
return NULL;
return p; return p;
} }
...@@ -308,18 +309,17 @@ sp_pcontext::find_label(char *name) ...@@ -308,18 +309,17 @@ sp_pcontext::find_label(char *name)
return NULL; return NULL;
} }
void int
sp_pcontext::push_cond(LEX_STRING *name, sp_cond_type_t *val) sp_pcontext::push_cond(LEX_STRING *name, sp_cond_type_t *val)
{ {
sp_cond_t *p= (sp_cond_t *)sql_alloc(sizeof(sp_cond_t)); sp_cond_t *p= (sp_cond_t *)sql_alloc(sizeof(sp_cond_t));
if (p) if (p == NULL)
{ return 1;
p->name.str= name->str; p->name.str= name->str;
p->name.length= name->length; p->name.length= name->length;
p->val= val; p->val= val;
insert_dynamic(&m_conds, (gptr)&p); return insert_dynamic(&m_conds, (gptr)&p);
}
} }
/* /*
...@@ -382,7 +382,7 @@ sp_pcontext::find_handler(sp_cond_type_t *cond) ...@@ -382,7 +382,7 @@ sp_pcontext::find_handler(sp_cond_type_t *cond)
return FALSE; return FALSE;
} }
void int
sp_pcontext::push_cursor(LEX_STRING *name) sp_pcontext::push_cursor(LEX_STRING *name)
{ {
LEX_STRING n; LEX_STRING n;
...@@ -391,7 +391,7 @@ sp_pcontext::push_cursor(LEX_STRING *name) ...@@ -391,7 +391,7 @@ sp_pcontext::push_cursor(LEX_STRING *name)
m_max_cursor_index+= 1; m_max_cursor_index+= 1;
n.str= name->str; n.str= name->str;
n.length= name->length; n.length= name->length;
insert_dynamic(&m_cursors, (gptr)&n); return insert_dynamic(&m_cursors, (gptr)&n);
} }
/* /*
......
...@@ -323,7 +323,7 @@ public: ...@@ -323,7 +323,7 @@ public:
// Conditions // Conditions
// //
void int
push_cond(LEX_STRING *name, sp_cond_type_t *val); push_cond(LEX_STRING *name, sp_cond_type_t *val);
inline void inline void
...@@ -365,7 +365,7 @@ public: ...@@ -365,7 +365,7 @@ public:
// Cursors // Cursors
// //
void int
push_cursor(LEX_STRING *name); push_cursor(LEX_STRING *name);
my_bool my_bool
......
...@@ -3371,10 +3371,6 @@ add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level, ...@@ -3371,10 +3371,6 @@ add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level,
} }
} }
/*
Add all keys with uses 'field' for some keypart
If field->and_level != and_level then only mark key_part as const_part
*/
static uint static uint
max_part_bit(key_part_map bits) max_part_bit(key_part_map bits)
...@@ -3384,7 +3380,16 @@ max_part_bit(key_part_map bits) ...@@ -3384,7 +3380,16 @@ max_part_bit(key_part_map bits)
return found; return found;
} }
static void /*
Add all keys with uses 'field' for some keypart
If field->and_level != and_level then only mark key_part as const_part
RETURN
0 - OK
1 - Out of memory.
*/
static bool
add_key_part(DYNAMIC_ARRAY *keyuse_array,KEY_FIELD *key_field) add_key_part(DYNAMIC_ARRAY *keyuse_array,KEY_FIELD *key_field)
{ {
Field *field=key_field->field; Field *field=key_field->field;
...@@ -3414,24 +3419,26 @@ add_key_part(DYNAMIC_ARRAY *keyuse_array,KEY_FIELD *key_field) ...@@ -3414,24 +3419,26 @@ add_key_part(DYNAMIC_ARRAY *keyuse_array,KEY_FIELD *key_field)
keyuse.optimize= key_field->optimize & KEY_OPTIMIZE_REF_OR_NULL; keyuse.optimize= key_field->optimize & KEY_OPTIMIZE_REF_OR_NULL;
keyuse.null_rejecting= key_field->null_rejecting; keyuse.null_rejecting= key_field->null_rejecting;
keyuse.cond_guard= key_field->cond_guard; keyuse.cond_guard= key_field->cond_guard;
VOID(insert_dynamic(keyuse_array,(gptr) &keyuse)); if (insert_dynamic(keyuse_array,(gptr) &keyuse))
return TRUE;
} }
} }
} }
} }
return FALSE;
} }
#define FT_KEYPART (MAX_REF_PARTS+10) #define FT_KEYPART (MAX_REF_PARTS+10)
static void static bool
add_ft_keys(DYNAMIC_ARRAY *keyuse_array, add_ft_keys(DYNAMIC_ARRAY *keyuse_array,
JOIN_TAB *stat,COND *cond,table_map usable_tables) JOIN_TAB *stat,COND *cond,table_map usable_tables)
{ {
Item_func_match *cond_func=NULL; Item_func_match *cond_func=NULL;
if (!cond) if (!cond)
return; return FALSE;
if (cond->type() == Item::FUNC_ITEM) if (cond->type() == Item::FUNC_ITEM)
{ {
...@@ -3465,13 +3472,16 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array, ...@@ -3465,13 +3472,16 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array,
{ {
Item *item; Item *item;
while ((item=li++)) while ((item=li++))
add_ft_keys(keyuse_array,stat,item,usable_tables); {
if (add_ft_keys(keyuse_array,stat,item,usable_tables))
return TRUE;
}
} }
} }
if (!cond_func || cond_func->key == NO_SUCH_KEY || if (!cond_func || cond_func->key == NO_SUCH_KEY ||
!(usable_tables & cond_func->table->map)) !(usable_tables & cond_func->table->map))
return; return FALSE;
KEYUSE keyuse; KEYUSE keyuse;
keyuse.table= cond_func->table; keyuse.table= cond_func->table;
...@@ -3481,7 +3491,7 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array, ...@@ -3481,7 +3491,7 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array,
keyuse.used_tables=cond_func->key_item()->used_tables(); keyuse.used_tables=cond_func->key_item()->used_tables();
keyuse.optimize= 0; keyuse.optimize= 0;
keyuse.keypart_map= 0; keyuse.keypart_map= 0;
VOID(insert_dynamic(keyuse_array,(gptr) &keyuse)); return insert_dynamic(keyuse_array,(gptr) &keyuse);
} }
...@@ -3631,7 +3641,8 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, ...@@ -3631,7 +3641,8 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
sargables); sargables);
for (; field != end ; field++) for (; field != end ; field++)
{ {
add_key_part(keyuse,field); if (add_key_part(keyuse,field))
return TRUE;
/* Mark that we can optimize LEFT JOIN */ /* Mark that we can optimize LEFT JOIN */
if (field->val->type() == Item::NULL_ITEM && if (field->val->type() == Item::NULL_ITEM &&
!field->field->real_maybe_null()) !field->field->real_maybe_null())
...@@ -3669,11 +3680,15 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, ...@@ -3669,11 +3680,15 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
/* fill keyuse with found key parts */ /* fill keyuse with found key parts */
for ( ; field != end ; field++) for ( ; field != end ; field++)
add_key_part(keyuse,field); {
if (add_key_part(keyuse,field))
return TRUE;
}
if (select_lex->ftfunc_list->elements) if (select_lex->ftfunc_list->elements)
{ {
add_ft_keys(keyuse,join_tab,cond,normal_tables); if (add_ft_keys(keyuse,join_tab,cond,normal_tables))
return TRUE;
} }
/* /*
...@@ -3694,7 +3709,8 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, ...@@ -3694,7 +3709,8 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
(qsort_cmp) sort_keyuse); (qsort_cmp) sort_keyuse);
bzero((char*) &key_end,sizeof(key_end)); /* Add for easy testing */ bzero((char*) &key_end,sizeof(key_end)); /* Add for easy testing */
VOID(insert_dynamic(keyuse,(gptr) &key_end)); if (insert_dynamic(keyuse,(gptr) &key_end))
return TRUE;
use=save_pos=dynamic_element(keyuse,0,KEYUSE*); use=save_pos=dynamic_element(keyuse,0,KEYUSE*);
prev= &key_end; prev= &key_end;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment