From 6cfaf04e4d81e0a30cf096b67064841dc938c07e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 12 Feb 2003 16:17:03 +0100 Subject: [PATCH] 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.) --- sql/sp.cc | 16 +++++++++++----- sql/sp_head.cc | 29 +++++++++++++++++++++-------- sql/sql_parse.cc | 12 ++++++------ sql/sql_yacc.yy | 14 +++++++++++--- 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/sql/sp.cc b/sql/sp.cc index a4fd239b513..42b7248aa80 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -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); } diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 286a009b38e..ff487429ec7 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -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, - name->c_ptr(), name->length(), - def->c_ptr(), def->length()); + 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())); } 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); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d1d6f63694e..8b5d315aac9 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -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); } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index aec286fb655..b15612070a3 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1049,10 +1049,18 @@ sp_proc_stmt: } else { - sp_instr_stmt *i= new sp_instr_stmt(lex->sphead->instructions()); + /* 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); + i->set_lex(lex); + lex->sphead->add_instr(i); + } lex->sphead->restore_lex(YYTHD); } }