Commit 6cfaf04e authored by unknown's avatar unknown

Fixed some DBUGing, and optimized SET slightly.


sql/sp.cc:
  Added DBUG statements.
sql/sp_head.cc:
  Added DBUG statements.
sql/sql_parse.cc:
  Changed returns into DBUG_RETURNs in mysql_execute_command().
sql/sql_yacc.yy:
  Small optimization: Don't generate sp_instr_stmt instructions for empty
  SET_OPTIONs. (Which happened if there were only local variables in the SET
  statement.)
parent 565d9895
......@@ -26,6 +26,7 @@
sp_head *
sp_find_procedure(THD *thd, Item_string *iname)
{
DBUG_ENTER("sp_find_procedure");
extern int yyparse(void *thd);
LEX *tmplex;
TABLE *table;
......@@ -35,11 +36,12 @@ sp_find_procedure(THD *thd, Item_string *iname)
sp_head *sp = NULL;
name = iname->const_string();
DBUG_PRINT("enter", ("name: %*s", name->length(), name->c_ptr()));
memset(&tables, 0, sizeof(tables));
tables.db= (char*)"mysql";
tables.real_name= tables.alias= (char*)"proc";
if (! (table= open_ltable(thd, &tables, TL_READ)))
return NULL;
DBUG_RETURN(NULL);
if (table->file->index_read_idx(table->record[0], 0,
(byte*)name->c_ptr(), name->length(),
......@@ -59,12 +61,14 @@ sp_find_procedure(THD *thd, Item_string *iname)
done:
if (table)
close_thread_tables(thd);
return sp;
DBUG_RETURN(sp);
}
int
sp_create_procedure(THD *thd, char *name, uint namelen, char *def, uint deflen)
{
DBUG_ENTER("sp_create_procedure");
DBUG_PRINT("enter", ("name: %*s def: %*s", namelen, name, deflen, def));
int ret= 0;
TABLE *table;
TABLE_LIST tables;
......@@ -88,12 +92,14 @@ sp_create_procedure(THD *thd, char *name, uint namelen, char *def, uint deflen)
done:
close_thread_tables(thd);
return ret;
DBUG_RETURN(ret);
}
int
sp_drop_procedure(THD *thd, char *name, uint namelen)
{
DBUG_ENTER("sp_drop_procedure");
DBUG_PRINT("enter", ("name: %*s", namelen, name));
TABLE *table;
TABLE_LIST tables;
......@@ -111,9 +117,9 @@ sp_drop_procedure(THD *thd, char *name, uint namelen)
table->file->print_error(error, MYF(0));
}
close_thread_tables(thd);
return 0;
DBUG_RETURN(0);
err:
close_thread_tables(thd);
return -1;
DBUG_RETURN(-1);
}
......@@ -99,17 +99,21 @@ sp_head::sp_head(LEX_STRING *name, LEX *lex)
int
sp_head::create(THD *thd)
{
DBUG_ENTER("sp_head::create");
String *name= m_name->const_string();
String *def= m_defstr->const_string();
return sp_create_procedure(thd,
DBUG_PRINT("info", ("name: %s def: %s", name->c_ptr(), def->c_ptr()));
DBUG_RETURN(sp_create_procedure(thd,
name->c_ptr(), name->length(),
def->c_ptr(), def->length());
def->c_ptr(), def->length()));
}
int
sp_head::execute(THD *thd)
{
DBUG_ENTER("sp_head::execute");
DBUG_PRINT("executing", ("procedure %s", ((String *)m_name->const_string())->c_ptr()));
int ret= 0;
sp_instr *p;
sp_pcontext *pctx = m_call_lex->spcont;
......@@ -171,6 +175,7 @@ sp_head::execute(THD *thd)
i = get_instr(ip); // Returns NULL when we're done.
if (i == NULL)
break;
DBUG_PRINT("execute", ("Instruction %u", ip));
ret= i->execute(thd, &ip);
}
}
......@@ -218,7 +223,7 @@ sp_head::execute(THD *thd)
thd->spcont= octx;
}
return ret;
DBUG_RETURN(ret);
}
......@@ -351,6 +356,8 @@ sp_head::backpatch(sp_label_t *lab)
int
sp_instr_stmt::execute(THD *thd, uint *nextp)
{
DBUG_ENTER("sp_instr_stmt::execute");
DBUG_PRINT("info", ("command: %d", m_lex.sql_command));
LEX olex; // The other lex
int res;
......@@ -364,7 +371,7 @@ sp_instr_stmt::execute(THD *thd, uint *nextp)
memcpy(&thd->lex, &olex, sizeof(LEX)); // Restore the other lex
*nextp = m_ip+1;
return res;
DBUG_RETURN(res);
}
//
......@@ -373,9 +380,11 @@ sp_instr_stmt::execute(THD *thd, uint *nextp)
int
sp_instr_set::execute(THD *thd, uint *nextp)
{
DBUG_ENTER("sp_instr_set::execute");
DBUG_PRINT("info", ("offset: %u", m_offset));
thd->spcont->set_item(m_offset, eval_func_item(thd, m_value, m_type));
*nextp = m_ip+1;
return 0;
DBUG_RETURN(0);
}
//
......@@ -384,13 +393,15 @@ sp_instr_set::execute(THD *thd, uint *nextp)
int
sp_instr_jump_if::execute(THD *thd, uint *nextp)
{
DBUG_ENTER("sp_instr_jump_if::execute");
DBUG_PRINT("info", ("destination: %u", m_dest));
Item *it= eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
if (it->val_int())
*nextp = m_dest;
else
*nextp = m_ip+1;
return 0;
DBUG_RETURN(0);
}
//
......@@ -399,11 +410,13 @@ sp_instr_jump_if::execute(THD *thd, uint *nextp)
int
sp_instr_jump_if_not::execute(THD *thd, uint *nextp)
{
DBUG_ENTER("sp_instr_jump_if_not::execute");
DBUG_PRINT("info", ("destination: %u", m_dest));
Item *it= eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
if (! it->val_int())
*nextp = m_dest;
else
*nextp = m_ip+1;
return 0;
DBUG_RETURN(0);
}
......@@ -1513,7 +1513,7 @@ mysql_execute_command(THD *thd)
given and the table list says the query should not be replicated
*/
if (table_rules_on && tables && !tables_ok(thd,tables))
return 0;
DBUG_RETURN(0);
#ifndef TO_BE_DELETED
/*
This is a workaround to deal with the shortcoming in 3.23.44-3.23.46
......@@ -1549,7 +1549,7 @@ mysql_execute_command(THD *thd)
{
if (res < 0 || thd->net.report_error)
send_error(thd,thd->killed ? ER_SERVER_SHUTDOWN : 0);
return res;
DBUG_RETURN(res);
}
}
}
......@@ -1558,7 +1558,7 @@ mysql_execute_command(THD *thd)
lex->unit.create_total_list(thd, lex, &tables)) ||
(table_rules_on && tables && thd->slave_thread &&
!tables_ok(thd,tables)))
return 0;
DBUG_RETURN(0);
statistic_increment(com_stat[lex->sql_command],&LOCK_status);
switch (lex->sql_command) {
......@@ -1838,7 +1838,7 @@ mysql_execute_command(THD *thd)
find_real_table_in_list(tables->next, tables->db, tables->real_name))
{
net_printf(thd,ER_UPDATE_TABLE_USED,tables->real_name);
return -1;
DBUG_RETURN(-1);
}
if (tables->next)
{
......@@ -2912,11 +2912,11 @@ mysql_execute_command(THD *thd)
// or res != 0 and no send_error() has yet been done.
if (res < 0)
send_error(thd,thd->killed ? ER_SERVER_SHUTDOWN : 0);
return res;
DBUG_RETURN(res);
error:
// We end up here if send_error() has already been done.
return -1;
DBUG_RETURN(-1);
}
......
......@@ -1048,11 +1048,19 @@ sp_proc_stmt:
YYABORT;
}
else
{
/* Don't add an instruction for empty SET statements.
** (This happens if the SET only contained local variables,
** which get their set instructions generated separately.)
*/
if (lex->sql_command != SQLCOM_SET_OPTION ||
!lex->var_list.is_empty())
{
sp_instr_stmt *i= new sp_instr_stmt(lex->sphead->instructions());
i->set_lex(lex);
lex->sphead->add_instr(i);
}
lex->sphead->restore_lex(YYTHD);
}
}
......
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