diff --git a/heap/hp_create.c b/heap/hp_create.c index 40b8202d94f..5265607ce53 100644 --- a/heap/hp_create.c +++ b/heap/hp_create.c @@ -140,6 +140,7 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, share->auto_key= create_info->auto_key; share->auto_key_type= create_info->auto_key_type; share->auto_increment= create_info->auto_increment; + /* Must be allocated separately for rename to work */ if (!(share->name= my_strdup(name,MYF(0)))) { my_free((gptr) share,MYF(0)); diff --git a/heap/hp_update.c b/heap/hp_update.c index dd7374f506c..b789ab82b84 100644 --- a/heap/hp_update.c +++ b/heap/hp_update.c @@ -62,7 +62,8 @@ int heap_update(HP_INFO *info, const byte *old, const byte *heap_new) /* we don't need to delete non-inserted key from rb-tree */ if ((*keydef->write_key)(info, keydef, old, pos)) { - if (++(share->records) == share->blength) share->blength+= share->blength; + if (++(share->records) == share->blength) + share->blength+= share->blength; DBUG_RETURN(my_errno); } keydef--; @@ -78,6 +79,7 @@ int heap_update(HP_INFO *info, const byte *old, const byte *heap_new) keydef--; } } - if (++(share->records) == share->blength) share->blength+= share->blength; + if (++(share->records) == share->blength) + share->blength+= share->blength; DBUG_RETURN(my_errno); } /* heap_update */ diff --git a/heap/hp_write.c b/heap/hp_write.c index 9edd897eb34..87211d4c224 100644 --- a/heap/hp_write.c +++ b/heap/hp_write.c @@ -155,7 +155,7 @@ static byte *next_free_record_pos(HP_SHARE *info) /* Write a hash-key to the hash-index */ int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, - const byte *record, byte *recpos) + const byte *record, byte *recpos) { HP_SHARE *share = info->s; int flag; diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index d585243c6bc..745cde325f9 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -19,7 +19,7 @@ TZ=GMT-3; export TZ # for UNIX_TIMESTAMP tests to work # Program Definitions #-- -PATH=/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin:/usr/openwin/bin:/usr/bin/X11 +PATH=/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin:/usr/openwin/bin:/usr/bin/X11:$PATH MASTER_40_ARGS="--rpl-recovery-rank=1 --init-rpl-role=master" # Standard functions @@ -319,8 +319,8 @@ while test $# -gt 0; do VALGRIND="valgrind --alignment=8 --leak-check=yes" EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-safemalloc" EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-safemalloc" - SLEEP_TIME_AFTER_RESTART=120 - SLEEP_TIME_FOR_DELETE=120 + SLEEP_TIME_AFTER_RESTART=60 + SLEEP_TIME_FOR_DELETE=60 ;; --valgrind-options=*) TMP=`$ECHO "$1" | $SED -e "s;--valgrind-options=;;"` diff --git a/mysql-test/r/row_test.result b/mysql-test/r/row_test.result index f5bf9856a60..f6e989789c7 100644 --- a/mysql-test/r/row_test.result +++ b/mysql-test/r/row_test.result @@ -1,60 +1,60 @@ -SELECT (1,2,3)=(1,2,3); -(1,2,3)=(1,2,3) +SELECT ROW(1,2,3)=ROW(1,2,3); +ROW(1,2,3)=ROW(1,2,3) 1 -SELECT (2,2,3)=(1+1,2,3); -(2,2,3)=(1+1,2,3) +SELECT ROW(2,2,3)=ROW(1+1,2,3); +ROW(2,2,3)=ROW(1+1,2,3) 1 -SELECT (1,2,3)=(1+1,2,3); -(1,2,3)=(1+1,2,3) +SELECT ROW(1,2,3)=ROW(1+1,2,3); +ROW(1,2,3)=ROW(1+1,2,3) 0 -SELECT (1,2,3)<(1+1,2,3); -(1,2,3)<(1+1,2,3) +SELECT ROW(1,2,3)(1+1,2,3); -(1,2,3)>(1+1,2,3) +SELECT ROW(1,2,3)>ROW(1+1,2,3); +ROW(1,2,3)>ROW(1+1,2,3) 0 -SELECT (1,2,3)<=(1+1,2,3); -(1,2,3)<=(1+1,2,3) +SELECT ROW(1,2,3)<=ROW(1+1,2,3); +ROW(1,2,3)<=ROW(1+1,2,3) 1 -SELECT (1,2,3)>=(1+1,2,3); -(1,2,3)>=(1+1,2,3) +SELECT ROW(1,2,3)>=ROW(1+1,2,3); +ROW(1,2,3)>=ROW(1+1,2,3) 0 -SELECT (1,2,3)<>(1+1,2,3); -(1,2,3)<>(1+1,2,3) +SELECT ROW(1,2,3)<>ROW(1+1,2,3); +ROW(1,2,3)<>ROW(1+1,2,3) 1 -SELECT (NULL,2,3)=(NULL,2,3); -(NULL,2,3)=(NULL,2,3) +SELECT ROW(NULL,2,3)=ROW(NULL,2,3); +ROW(NULL,2,3)=ROW(NULL,2,3) NULL -SELECT (NULL,2,3)<=>(NULL,2,3); -(NULL,2,3)<=>(NULL,2,3) +SELECT ROW(NULL,2,3)<=>ROW(NULL,2,3); +ROW(NULL,2,3)<=>ROW(NULL,2,3) 1 -SELECT (1,2,(3,4,5))=(1,2,(3,4,5)); -(1,2,(3,4,5))=(1,2,(3,4,5)) +SELECT ROW(1,2,ROW(3,4,5))=ROW(1,2,ROW(3,4,5)); +ROW(1,2,ROW(3,4,5))=ROW(1,2,ROW(3,4,5)) 1 -SELECT ('test',2,3.33)=('test',2,3.33); -('test',2,3.33)=('test',2,3.33) +SELECT ROW('test',2,3.33)=ROW('test',2,3.33); +ROW('test',2,3.33)=ROW('test',2,3.33) 1 -SELECT ('test',2,3.33)=('test',2,3.33,4); +SELECT ROW('test',2,3.33)=ROW('test',2,3.33,4); Cardinality error (more/less than 3 columns) drop table if exists t1; create table t1 ( a int, b int, c int); insert into t1 values (1,2,3), (2,3,1), (3,2,1); -select * from t1 where (1,2,3)=(a,b,c); +select * from t1 where ROW(1,2,3)=ROW(a,b,c); a b c 1 2 3 -select * from t1 where (0,2,3)=(a,b,c); +select * from t1 where ROW(0,2,3)=ROW(a,b,c); a b c -select * from t1 where (1,2,3)<(a,b,c); +select * from t1 where ROW(1,2,3)(1+1,2,3); -SELECT (1,2,3)<=(1+1,2,3); -SELECT (1,2,3)>=(1+1,2,3); -SELECT (1,2,3)<>(1+1,2,3); -SELECT (NULL,2,3)=(NULL,2,3); -SELECT (NULL,2,3)<=>(NULL,2,3); -SELECT (1,2,(3,4,5))=(1,2,(3,4,5)); -SELECT ('test',2,3.33)=('test',2,3.33); +SELECT ROW(1,2,3)=ROW(1,2,3); +SELECT ROW(2,2,3)=ROW(1+1,2,3); +SELECT ROW(1,2,3)=ROW(1+1,2,3); +SELECT ROW(1,2,3)ROW(1+1,2,3); +SELECT ROW(1,2,3)<=ROW(1+1,2,3); +SELECT ROW(1,2,3)>=ROW(1+1,2,3); +SELECT ROW(1,2,3)<>ROW(1+1,2,3); +SELECT ROW(NULL,2,3)=ROW(NULL,2,3); +SELECT ROW(NULL,2,3)<=>ROW(NULL,2,3); +SELECT ROW(1,2,ROW(3,4,5))=ROW(1,2,ROW(3,4,5)); +SELECT ROW('test',2,3.33)=ROW('test',2,3.33); -- error 1239 -SELECT ('test',2,3.33)=('test',2,3.33,4); +SELECT ROW('test',2,3.33)=ROW('test',2,3.33,4); drop table if exists t1; create table t1 ( a int, b int, c int); insert into t1 values (1,2,3), (2,3,1), (3,2,1); -select * from t1 where (1,2,3)=(a,b,c); -select * from t1 where (0,2,3)=(a,b,c); -select * from t1 where (1,2,3)<(a,b,c); +select * from t1 where ROW(1,2,3)=ROW(a,b,c); +select * from t1 where ROW(0,2,3)=ROW(a,b,c); +select * from t1 where ROW(1,2,3) &list) list.empty(); // Fields are used } -inline void Item_sum::mark_as_sum_func() +void Item_sum::mark_as_sum_func() { current_thd->lex.current_select->with_sum_func= with_sum_func= 1; } diff --git a/sql/item_sum.h b/sql/item_sum.h index 56b36b615f4..23b8482d41a 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -34,7 +34,7 @@ public: uint arg_count; bool quick_group; /* If incremental update of fields */ - inline void mark_as_sum_func(); + void mark_as_sum_func(); Item_sum() : arg_count(0),quick_group(1) { mark_as_sum_func(); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 9bca7245cba..57cd0e7a13d 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -142,8 +142,6 @@ THD::THD():user_time(0), fatal_error(0), bzero((char*) &con_root,sizeof(con_root)); bzero((char*) &warn_root,sizeof(warn_root)); init_alloc_root(&warn_root, 1024, 0); - bzero((char*) warn_count, sizeof(warn_count)); - warn_list.empty(); user_connect=(USER_CONN *)0; hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0, (hash_get_key) get_var_key, @@ -187,17 +185,20 @@ THD::THD():user_time(0), fatal_error(0), void THD::init(void) { - server_status= SERVER_STATUS_AUTOCOMMIT; - update_lock_default= (variables.low_priority_updates ? - TL_WRITE_LOW_PRIORITY : - TL_WRITE); - options= thd_startup_options; - sql_mode=(uint) opt_sql_mode; - open_options=ha_open_options; pthread_mutex_lock(&LOCK_global_system_variables); variables= global_system_variables; pthread_mutex_unlock(&LOCK_global_system_variables); + server_status= SERVER_STATUS_AUTOCOMMIT; + options= thd_startup_options; + sql_mode=(uint) opt_sql_mode; + open_options=ha_open_options; + update_lock_default= (variables.low_priority_updates ? + TL_WRITE_LOW_PRIORITY : + TL_WRITE); session_tx_isolation= (enum_tx_isolation) variables.tx_isolation; + warn_list.empty(); + bzero((char*) warn_count, sizeof(warn_count)); + total_warn_count= 0; } /* @@ -228,6 +229,7 @@ void THD::cleanup(void) { DBUG_ENTER("THD::cleanup"); ha_rollback(this); + delete_tree(&prepared_statements); if (locked_tables) { lock=locked_tables; locked_tables=0; @@ -289,7 +291,6 @@ THD::~THD() free_root(&con_root,MYF(0)); free_root(&warn_root,MYF(0)); free_root(&transaction.mem_root,MYF(0)); - delete_tree(&prepared_statements); mysys_var=0; // Safety (shouldn't be needed) pthread_mutex_destroy(&LOCK_delete); #ifndef DBUG_OFF diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index fe1a967f936..d35790da1b0 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -140,9 +140,11 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order, deleted=0L; init_ftfuncs(thd, &thd->lex.select_lex, 1); thd->proc_info="updating"; - while (!(error=info.read_record(&info)) && !thd->killed) + while (!(error=info.read_record(&info)) && !thd->killed && + !thd->net.report_error) { - if (!(select && select->skipp_record())) + // thd->net.report_error is tested to disallow delete row on error + if (!(select && select->skipp_record())&& !thd->net.report_error ) { if (!(error=table->file->delete_row(table->record[0]))) { @@ -205,7 +207,7 @@ cleanup: thd->lock=0; } delete select; - if (error >= 0) // Fatal error + if (error >= 0 || thd->net.report_error) send_error(thd,thd->killed ? ER_SERVER_SHUTDOWN: 0); else { diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 83b125ee630..9ee824d0e2c 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -235,9 +235,10 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List &fields, if (fields.elements || !value_count) { restore_record(table,2); // Get empty record - if (fill_record(fields,*values) || check_null_fields(thd,table)) + if (fill_record(fields,*values)|| thd->net.report_error || + check_null_fields(thd,table)) { - if (values_list.elements != 1) + if (values_list.elements != 1 && !thd->net.report_error) { info.records++; continue; @@ -252,9 +253,9 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List &fields, restore_record(table,2); // Get empty record else table->record[0][0]=table->record[2][0]; // Fix delete marker - if (fill_record(table->field,*values)) + if (fill_record(table->field,*values) || thd->net.report_error) { - if (values_list.elements != 1) + if (values_list.elements != 1 && ! thd->net.report_error) { info.records++; continue; @@ -1349,7 +1350,7 @@ bool select_insert::send_data(List &values) fill_record(*fields,values); else fill_record(table->field,values); - if (write_record(table,&info)) + if (thd->net.report_error || write_record(table,&info)) return 1; if (table->next_number_field) // Clear for next record { @@ -1463,7 +1464,7 @@ bool select_create::send_data(List &values) return 0; } fill_record(field,values); - if (write_record(table,&info)) + if (thd->net.report_error ||write_record(table,&info)) return 1; if (table->next_number_field) // Clear for next record { diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index d765c741932..54f28668644 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -458,7 +458,7 @@ int yylex(void *arg, void *yythd) LINT_INIT(c); for (;;) { - switch(state) { + switch (state) { case STATE_OPERATOR_OR_IDENT: // Next is operator or keyword case STATE_START: // Start of token // Skip startspace @@ -900,7 +900,8 @@ int yylex(void *arg, void *yythd) return((int) '@'); case STATE_HOSTNAME: // end '@' of user@hostname for (c=yyGet() ; - my_isalnum(system_charset_info,c) || c == '.' || c == '_' || c == '$'; + my_isalnum(system_charset_info,c) || c == '.' || c == '_' || + c == '$'; c= yyGet()) ; yylval->lex_str=get_token(lex,yyLength()); return(LEX_HOSTNAME); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d60542528d2..bb12e4c585d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1900,6 +1900,8 @@ mysql_execute_command(THD *thd) (ORDER *) select_lex->order_list.first, select_lex->select_limit, lex->duplicates); + if (thd->net.report_error) + res= -1; break; case SQLCOM_UPDATE_MULTI: if (check_access(thd,UPDATE_ACL,tables->db,&tables->grant.privilege)) @@ -1959,6 +1961,8 @@ mysql_execute_command(THD *thd) SELECT_NO_JOIN_CACHE, result, unit, select_lex, 0); delete result; + if (thd->net.report_error) + res= -1; } else res= -1; // Error is not sent @@ -1976,6 +1980,8 @@ mysql_execute_command(THD *thd) goto error; res = mysql_insert(thd,tables,lex->field_list,lex->many_values, lex->duplicates); + if (thd->net.report_error) + res= -1; break; } case SQLCOM_REPLACE_SELECT: @@ -2020,6 +2026,8 @@ mysql_execute_command(THD *thd) if ((result=new select_insert(tables->table,&lex->field_list, lex->duplicates))) res=handle_select(thd,lex,result); + if (thd->net.report_error) + res= -1; } else res= -1; @@ -2050,6 +2058,8 @@ mysql_execute_command(THD *thd) res = mysql_delete(thd,tables, select_lex->where, (ORDER*) select_lex->order_list.first, select_lex->select_limit, select_lex->options); + if (thd->net.report_error) + res= -1; break; } case SQLCOM_DELETE_MULTI: @@ -2122,6 +2132,8 @@ mysql_execute_command(THD *thd) select_lex->options | thd->options | SELECT_NO_JOIN_CACHE, result, unit, select_lex, 0); + if (thd->net.report_error) + res= -1; delete result; } else diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c1f7e8272bc..50820b931b6 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4115,6 +4115,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, keyinfo->usable_key_parts=keyinfo->key_parts= param->group_parts; keyinfo->key_length=0; keyinfo->rec_per_key=0; + keyinfo->algorithm= HA_KEY_ALG_UNDEF; for (; group ; group=group->next,key_part_info++) { Field *field=(*group->item)->tmp_table_field(); @@ -4191,6 +4192,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, keyinfo->flags=HA_NOSAME | HA_NULL_ARE_EQUAL; keyinfo->key_length=(uint16) reclength; keyinfo->name=(char*) "tmp"; + keyinfo->algorithm= HA_KEY_ALG_UNDEF; if (null_pack_length) { key_part_info->null_bit=0; diff --git a/sql/sql_union.cc b/sql/sql_union.cc index d448a5204e2..e170f6c040e 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -76,7 +76,7 @@ bool select_union::send_data(List &values) return 0; } fill_record(table->field,values); - if ((write_record(table,&info))) + if (thd->net.report_error || write_record(table,&info)) { if (thd->net.last_errno == ER_RECORD_FILE_FULL) { diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 4e15011c254..c3ae435d851 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -281,7 +281,7 @@ int mysql_update(THD *thd, if (!(select && select->skipp_record())) { store_record(table,1); - if (fill_record(fields,values)) + if (fill_record(fields,values) || thd->net.report_error) break; /* purecov: inspected */ found++; if (compare_record(table, query_id)) @@ -605,7 +605,7 @@ bool multi_update::send_data(List &values) // Only one table being updated receives a completely different treatment table->status|= STATUS_UPDATED; store_record(table,1); - if (fill_record(fields,real_values)) + if (fill_record(fields,real_values) || thd->net.report_error) return 1; found++; if (/* compare_record(table, query_id) && */ @@ -644,7 +644,8 @@ bool multi_update::send_data(List &values) { table->status|= STATUS_UPDATED; store_record(table,1); - if (fill_record(*fields_by_tables[0],values_by_table)) + if (fill_record(*fields_by_tables[0], values_by_table) || + thd->net.report_error) return 1; found++; if (/*compare_record(table, query_id) && */ @@ -667,8 +668,8 @@ bool multi_update::send_data(List &values) table->file->ref_length, system_charset_info)); fill_record(tmp_tables[secure_counter]->field,values_by_table); - error= write_record(tmp_tables[secure_counter], - &(infos[secure_counter])); + error= thd->net.report_error || + write_record(tmp_tables[secure_counter], &(infos[secure_counter])); if (error) { error=-1; @@ -774,8 +775,10 @@ int multi_update::do_updates (bool from_send_error) table->status|= STATUS_UPDATED; store_record(table,1); local_error= (fill_record(*fields_by_tables[counter + 1],list) || + thd->net.report_error || /* compare_record(table, query_id) || */ - table->file->update_row(table->record[1],table->record[0])); + table->file->update_row(table->record[1], + table->record[0])); if (local_error) { table->file->print_error(local_error,MYF(0)); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index ed17053910c..4cdb608d700 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1979,10 +1979,12 @@ simple_expr: | NOT expr %prec NEG { $$= new Item_func_not($2); } | '!' expr %prec NEG { $$= new Item_func_not($2); } | '(' expr ')' { $$= $2; } - | '(' expr ',' expr_list ')' + /* Note: In SQL-99 "ROW" is optional, but not having it mandatory + causes conflicts with the INTERVAL syntax. */ + | ROW_SYM '(' expr ',' expr_list ')' { - $4->push_front($2); - $$= new Item_row(*$4); + $5->push_front($3); + $$= new Item_row(*$5); } | EXISTS exists_subselect { $$= $2; } | singleval_subselect { $$= $1; } @@ -2680,7 +2682,11 @@ order_dir: opt_limit_clause: /* empty */ {} - | LIMIT + | limit_clause {} + ; + +limit_clause: + LIMIT { LEX *lex= Lex; if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE && @@ -4378,10 +4384,7 @@ union_opt: ; optional_order_or_limit: - /* empty - intentional reduce/reduce conflict here !!! - { code } below should not be executed - when neither ORDER BY nor LIMIT are used */ {} + /* Empty */ {} | { LEX *lex=Lex; @@ -4397,7 +4400,13 @@ optional_order_or_limit: lex->current_select->select_limit= lex->thd->variables.select_limit; } - opt_order_clause opt_limit_clause + order_or_limit + ; + +order_or_limit: + order_clause opt_limit_clause + | + limit_clause ; union_option: