From 6905d7963edc07f0c69b38b2ae14d3e014f7f322 Mon Sep 17 00:00:00 2001 From: "monty@narttu.mysql.fi" <> Date: Mon, 29 Sep 2003 12:39:38 +0300 Subject: [PATCH 1/3] Don't print warnings about 'setrlimit' if --warnings is not given Code review/cleanup of sub subselect_uniquesubquery_engine --- sql/ha_myisam.cc | 4 +-- sql/item_subselect.cc | 81 +++++++++++++++++++++---------------------- sql/item_subselect.h | 11 ++++-- sql/mysqld.cc | 8 +++-- 4 files changed, 55 insertions(+), 49 deletions(-) diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index cec1aefa2d5..864ee55a85f 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -898,7 +898,7 @@ int ha_myisam::index_read(byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag) { statistic_increment(ha_read_key_count,&LOCK_status); - int error=mi_rkey(file,buf,active_index, key, key_len, (enum ha_rkey_function)find_flag); + int error=mi_rkey(file,buf,active_index, key, key_len, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return error; } @@ -907,7 +907,7 @@ int ha_myisam::index_read_idx(byte * buf, uint index, const byte * key, uint key_len, enum ha_rkey_function find_flag) { statistic_increment(ha_read_key_count,&LOCK_status); - int error=mi_rkey(file,buf,index, key, key_len, (enum ha_rkey_function)find_flag); + int error=mi_rkey(file,buf,index, key, key_len, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return error; } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 7c4fe8621a7..cf79ba1fcc1 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -36,7 +36,7 @@ inline Item * and_items(Item* cond, Item *item) Item_subselect::Item_subselect(): Item_result_field(), engine_owner(1), value_assigned(0), substitution(0), - have_to_be_excluded(0), engine_changed(0) + engine(0), have_to_be_excluded(0), engine_changed(0) { reset(); /* @@ -46,6 +46,7 @@ Item_subselect::Item_subselect(): null_value= 1; } + void Item_subselect::init(THD *thd, st_select_lex *select_lex, select_subselect *result) { @@ -62,6 +63,7 @@ void Item_subselect::init(THD *thd, st_select_lex *select_lex, DBUG_VOID_RETURN; } + Item_subselect::~Item_subselect() { if (engine_owner) @@ -693,6 +695,7 @@ Item_in_subselect::row_value_transformer(JOIN *join, DBUG_RETURN(RES_OK); } + Item_subselect::trans_res Item_in_subselect::select_transformer(JOIN *join) { @@ -702,18 +705,21 @@ Item_in_subselect::select_transformer(JOIN *join) return row_value_transformer(join, left_expr); } + Item_subselect::trans_res Item_allany_subselect::select_transformer(JOIN *join) { return single_value_transformer(join, left_expr, func); } -subselect_single_select_engine::subselect_single_select_engine(THD *thd, - st_select_lex *select, - select_subselect *result, - Item_subselect *item): - subselect_engine(thd, item, result), - prepared(0), optimized(0), executed(0) + +subselect_single_select_engine:: +subselect_single_select_engine(THD *thd, + st_select_lex *select, + select_subselect *result, + Item_subselect *item) + :subselect_engine(thd, item, result), + prepared(0), optimized(0), executed(0) { select_lex= select; SELECT_LEX_UNIT *unit= select_lex->master_unit(); @@ -732,11 +738,12 @@ subselect_single_select_engine::subselect_single_select_engine(THD *thd, this->select_lex= select_lex; } + subselect_union_engine::subselect_union_engine(THD *thd, st_select_lex_unit *u, select_subselect *result, - Item_subselect *item): - subselect_engine(thd, item, result) + Item_subselect *item) + :subselect_engine(thd, item, result) { unit= u; if (!result) @@ -919,6 +926,7 @@ int subselect_union_engine::exec() return res; } + int subselect_uniquesubquery_engine::exec() { DBUG_ENTER("subselect_uniquesubquery_engine::exec"); @@ -940,34 +948,22 @@ int subselect_uniquesubquery_engine::exec() { error= 0; table->null_row= 0; - if (table->status) - ((Item_in_subselect *) item)->value= 0; - else - ((Item_in_subselect *) item)->value= (!cond || cond->val_int()?1:0); + ((Item_in_subselect *) item)->value= (!table->status && + (!cond || cond->val_int()) ? 1 : + 0); } } - DBUG_RETURN(end_exec(table) || (error != 0)); -} - -int subselect_uniquesubquery_engine::end_exec(TABLE *table) -{ - DBUG_ENTER("subselect_uniquesubquery_engine::end_exec"); - int error=0, tmp; - if ((tmp= table->file->extra(HA_EXTRA_NO_CACHE))) - { - DBUG_PRINT("error", ("extra(HA_EXTRA_NO_CACHE) failed")); - error= 1; - } - if ((tmp= table->file->index_end())) - { - DBUG_PRINT("error", ("index_end() failed")); - error= 1; - } - if (error == 1) - table->file->print_error(tmp, MYF(0)); DBUG_RETURN(error != 0); } + +subselect_uniquesubquery_engine::~subselect_uniquesubquery_engine() +{ + /* Tell handler we don't need the index anymore */ + tab->table->file->index_end(); +} + + int subselect_indexsubquery_engine::exec() { DBUG_ENTER("subselect_indexsubselect_engine::exec"); @@ -976,9 +972,11 @@ int subselect_indexsubquery_engine::exec() TABLE *table= tab->table; ((Item_in_subselect *) item)->value= 0; + if (check_null) { - *tab->null_ref_key= 0; + /* We need to check for NULL if there wasn't a matching value */ + *tab->null_ref_key= 0; // Search first for not null ((Item_in_subselect *) item)->was_null= 0; } @@ -996,7 +994,7 @@ int subselect_indexsubquery_engine::exec() error= report_error(table, error); else { - for(;;) + for (;;) { error= 0; table->null_row= 0; @@ -1008,7 +1006,7 @@ int subselect_indexsubquery_engine::exec() ((Item_in_subselect *) item)->was_null= 1; else ((Item_in_subselect *) item)->value= 1; - goto finish; + break; } error= table->file->index_next_same(table->record[0], tab->ref.key_buff, @@ -1016,25 +1014,26 @@ int subselect_indexsubquery_engine::exec() if (error && error != HA_ERR_END_OF_FILE) { error= report_error(table, error); - goto finish; + break; } } else { if (!check_null || null_finding) - goto finish; + break; /* We don't need to check nulls */ *tab->null_ref_key= 1; null_finding= 1; - if (safe_index_read(tab)) - goto finish; + /* Check if there exists a row with a null value in the index */ + if ((error= safe_index_read(tab))) + break; } } } } -finish: - DBUG_RETURN(end_exec(table) || (error != 0)); + DBUG_RETURN(error != 0); } + uint subselect_single_select_engine::cols() { return select_lex->item_list.elements; diff --git a/sql/item_subselect.h b/sql/item_subselect.h index a17715c57c1..dc4ac8435f4 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -230,6 +230,7 @@ public: friend class subselect_indexsubquery_engine; }; + /* ALL/ANY/SOME subselect */ class Item_allany_subselect :public Item_in_subselect { @@ -244,6 +245,7 @@ public: trans_res select_transformer(JOIN *join); }; + class subselect_engine: public Sql_alloc { protected: @@ -275,6 +277,7 @@ public: bool may_be_null() { return maybe_null; }; }; + class subselect_single_select_engine: public subselect_engine { my_bool prepared; /* simple subselect is prepared */ @@ -295,6 +298,7 @@ public: void exclude(); }; + class subselect_union_engine: public subselect_engine { st_select_lex_unit *unit; /* corresponding unit structure */ @@ -312,6 +316,7 @@ public: void exclude(); }; + struct st_join_table; class subselect_uniquesubquery_engine: public subselect_engine { @@ -324,17 +329,17 @@ public: Item_subselect *subs, Item *where) :subselect_engine(thd, subs, 0), tab(tab_arg), cond(where) {} - + ~subselect_uniquesubquery_engine(); int prepare(); void fix_length_and_dec(Item_cache** row); int exec(); uint cols() { return 1; } bool dependent() { return 1; } bool uncacheable() { return 1; } - void exclude(); - static int end_exec(TABLE *table); + void exclude(); }; + class subselect_indexsubquery_engine: public subselect_uniquesubquery_engine { bool check_null; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 854fae4f15f..3cad2bac4ea 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5610,14 +5610,16 @@ static uint set_maximum_open_files(uint max_file_limit) rlimit.rlim_cur=rlimit.rlim_max=max_file_limit; if (setrlimit(RLIMIT_NOFILE,&rlimit)) { - sql_print_error("Warning: setrlimit couldn't increase number of open files to more than %lu (request: %u)", - old_cur, max_file_limit); /* purecov: inspected */ + if (global_system_variables.log_warnings) + sql_print_error("Warning: setrlimit couldn't increase number of open files to more than %lu (request: %u)", + old_cur, max_file_limit); /* purecov: inspected */ max_file_limit=old_cur; } else { (void) getrlimit(RLIMIT_NOFILE,&rlimit); - if ((uint) rlimit.rlim_cur != max_file_limit) + if ((uint) rlimit.rlim_cur != max_file_limit && + global_system_variables.log_warnings) sql_print_error("Warning: setrlimit returned ok, but didn't change limits. Max open files is %ld (request: %u)", (ulong) rlimit.rlim_cur, max_file_limit); /* purecov: inspected */ From cb334d03f42b30e25274167f1a5906cf1ab64093 Mon Sep 17 00:00:00 2001 From: "ram@gw.mysql.r18.ru" <> Date: Tue, 7 Oct 2003 12:05:35 +0500 Subject: [PATCH 2/3] WL #562: Change format of slow log in 4.1 --- sql/log.cc | 4 ++-- sql/mysqld.cc | 28 ++++++++++++++++++++-------- sql/sql_parse.cc | 2 +- sql/unireg.h | 3 ++- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/sql/log.cc b/sql/log.cc index 608a7e94431..41184615508 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1564,7 +1564,7 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, VOID(pthread_mutex_unlock(&LOCK_log)); return 0; } - if ((specialflag & SPECIAL_LONG_LOG_FORMAT) || query_start_arg) + if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT) || query_start_arg) { current_time=time(NULL); if (current_time != last_time) @@ -1617,7 +1617,7 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, // Save value if we do an insert. if (thd->insert_id_used) { - if (specialflag & SPECIAL_LONG_LOG_FORMAT) + if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT)) { end=strmov(end,",insert_id="); end=longlong10_to_str((longlong) thd->last_insert_id,end,-10); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 6213c43b80b..80f68388214 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -262,6 +262,8 @@ my_bool opt_log_slave_updates= 0; my_bool opt_console= 0, opt_bdb, opt_innodb, opt_isam; my_bool opt_readonly, use_temp_pool, relay_log_purge; my_bool opt_secure_auth= 0; +my_bool opt_short_log_format= 0; +my_bool opt_log_queries_not_using_indexes= 0; volatile bool mqh_used = 0; uint mysqld_port, test_flags, select_errors, dropping_tables, ha_open_options; @@ -3455,7 +3457,7 @@ enum options OPT_SKIP_PRIOR, OPT_BIG_TABLES, OPT_STANDALONE, OPT_ONE_THREAD, OPT_CONSOLE, OPT_LOW_PRIORITY_UPDATES, - OPT_SKIP_HOST_CACHE, OPT_LONG_FORMAT, + OPT_SKIP_HOST_CACHE, OPT_SHORT_LOG_FORMAT, OPT_FLUSH, OPT_SAFE, OPT_BOOTSTRAP, OPT_SKIP_SHOW_DB, OPT_TABLE_TYPE, OPT_INIT_FILE, @@ -3562,7 +3564,8 @@ enum options OPT_DEFAULT_WEEK_FORMAT, OPT_GROUP_CONCAT_MAX_LEN, OPT_DEFAULT_COLLATION, - OPT_SECURE_AUTH + OPT_SECURE_AUTH, + OPT_LOG_QUERIES_NOT_USING_INDEXES }; @@ -3769,9 +3772,17 @@ Disable with --skip-bdb (will save memory).", "Log slow queries to this log file. Defaults logging to hostname-slow.log file.", (gptr*) &opt_slow_logname, (gptr*) &opt_slow_logname, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, - {"log-long-format", OPT_LONG_FORMAT, - "Log some extra information to update log.", 0, 0, 0, GET_NO_ARG, NO_ARG, - 0, 0, 0, 0, 0, 0}, + {"log-long-format", '0', + "Log some extra information to update log. Please note that this option is deprecated; see --log-short-format option.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"log-short-format", OPT_SHORT_LOG_FORMAT, + "Don't log extra information to update and slow-query logs.", + (gptr*) &opt_short_log_format, (gptr*) &opt_short_log_format, + 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"log-queries-not-using-indexes", OPT_LOG_QUERIES_NOT_USING_INDEXES, + "Log queries that are executed without benefit of any index.", + (gptr*) &opt_log_queries_not_using_indexes, (gptr*) &opt_log_queries_not_using_indexes, + 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"log-slave-updates", OPT_LOG_SLAVE_UPDATES, "Tells the slave to log the updates from the slave thread to the binary log. You will need to turn it on if you plan to daisy-chain the slaves.", (gptr*) &opt_log_slave_updates, (gptr*) &opt_log_slave_updates, 0, GET_BOOL, @@ -5166,9 +5177,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case (int) OPT_SKIP_RESOLVE: opt_specialflag|=SPECIAL_NO_RESOLVE; break; - case (int) OPT_LONG_FORMAT: - opt_specialflag|=SPECIAL_LONG_LOG_FORMAT; - break; case (int) OPT_SKIP_NETWORKING: opt_disable_networking=1; mysqld_port=0; @@ -5508,6 +5516,10 @@ static void get_options(int argc,char **argv) keybuff_size= (((KEY_CACHE *) find_named(&key_caches, "default", 7, ¬_used))->size); } + if (opt_short_log_format) + opt_specialflag|= SPECIAL_SHORT_LOG_FORMAT; + if (opt_log_queries_not_using_indexes) + opt_specialflag|= SPECIAL_LOG_QUERIES_NOT_USING_INDEXES; } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 2c15362d9fa..aa91e307095 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1566,7 +1566,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->variables.long_query_time || ((thd->lex.select_lex.options & (QUERY_NO_INDEX_USED | QUERY_NO_GOOD_INDEX_USED)) && - (specialflag & SPECIAL_LONG_LOG_FORMAT))) + (specialflag & SPECIAL_LOG_QUERIES_NOT_USING_INDEXES))) { long_query_count++; mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query); diff --git a/sql/unireg.h b/sql/unireg.h index 4920d4b609a..ef6a2f44ea7 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -107,8 +107,9 @@ #define SPECIAL_NO_PRIOR 128 /* Don't prioritize threads */ #define SPECIAL_BIG_SELECTS 256 /* Don't use heap tables */ #define SPECIAL_NO_HOST_CACHE 512 /* Don't cache hosts */ -#define SPECIAL_LONG_LOG_FORMAT 1024 +#define SPECIAL_SHORT_LOG_FORMAT 1024 #define SPECIAL_SAFE_MODE 2048 +#define SPECIAL_LOG_QUERIES_NOT_USING_INDEXES 4096 /* Log q not using indexes */ /* Extern defines */ #define store_record(A,B) bmove_align((A)->B,(A)->record[0],(size_t) (A)->reclength) From 4b491cb78830d898a761e67f9cb9e1e109fb07ab Mon Sep 17 00:00:00 2001 From: "monty@narttu.mysql.fi" <> Date: Tue, 7 Oct 2003 13:26:56 +0300 Subject: [PATCH 3/3] Simple optimization --- sql/sql_select.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index ff41e9fd067..f119097edf8 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6661,7 +6661,9 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, usable_keys=0; break; } - usable_keys&=((Item_field*) (*tmp_order->item))->field->part_of_sortkey; + if (!(usable_keys&= (((Item_field*) (*tmp_order->item))->field-> + part_of_sortkey))) + break; // No usable keys } ref_key= -1;