diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item.cc | 5 | ||||
-rw-r--r-- | sql/item_subselect.cc | 28 | ||||
-rw-r--r-- | sql/item_subselect.h | 3 | ||||
-rw-r--r-- | sql/lock.cc | 17 | ||||
-rw-r--r-- | sql/sql_lex.h | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 33 | ||||
-rw-r--r-- | sql/sql_show.cc | 10 | ||||
-rw-r--r-- | sql/sql_statistics.cc | 107 | ||||
-rw-r--r-- | sql/sql_statistics.h | 11 | ||||
-rw-r--r-- | sql/sql_tvc.cc | 27 | ||||
-rw-r--r-- | sql/structs.h | 2 | ||||
-rw-r--r-- | sql/table.cc | 4 | ||||
-rw-r--r-- | sql/table.h | 2 | ||||
-rw-r--r-- | sql/wsrep_sst.cc | 62 |
14 files changed, 211 insertions, 102 deletions
diff --git a/sql/item.cc b/sql/item.cc index 19918361dd7..a658b105217 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -9295,8 +9295,9 @@ bool Item_default_value::fix_fields(THD *thd, Item **items) memcpy((void *)def_field, (void *)field_arg->field, field_arg->field->size_of()); def_field->reset_fields(); - // If non-constant default value expression - if (def_field->default_value && def_field->default_value->flags) + // If non-constant default value expression or a blob + if (def_field->default_value && + (def_field->default_value->flags || def_field->flags & BLOB_FLAG)) { uchar *newptr= (uchar*) thd->alloc(1+def_field->pack_length()); if (!newptr) diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index e2058475d0e..ad6dba01ad6 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -276,7 +276,11 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref) { if (sl->tvc) { - wrap_tvc_into_select(thd, sl); + if (!(sl= wrap_tvc_into_select(thd, sl))) + { + res= TRUE; + goto end; + } } } @@ -380,7 +384,7 @@ bool Item_subselect::mark_as_eliminated_processor(void *arg) bool Item_subselect::eliminate_subselect_processor(void *arg) { unit->item= NULL; - unit->exclude_from_tree(); + unit->exclude(); eliminated= TRUE; return FALSE; } @@ -449,6 +453,26 @@ bool Item_subselect::mark_as_dependent(THD *thd, st_select_lex *select, /* + @brief + Update the table bitmaps for the outer references used within a subquery +*/ + +bool Item_subselect::update_table_bitmaps_processor(void *arg) +{ + List_iterator<Ref_to_outside> it(upper_refs); + Ref_to_outside *upper; + + while ((upper= it++)) + { + if (upper->item && + upper->item->walk(&Item::update_table_bitmaps_processor, FALSE, arg)) + return TRUE; + } + return FALSE; +} + + +/* Adjust attributes after our parent select has been merged into grandparent DESCRIPTION diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 16a4735359b..015b32ae6d6 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -256,6 +256,7 @@ public: @retval FALSE otherwise */ bool is_expensive_processor(void *arg) { return is_expensive(); } + bool update_table_bitmaps_processor(void *arg); /** Get the SELECT_LEX structure associated with this Item. @@ -277,7 +278,7 @@ public: Item* build_clone(THD *thd) { return 0; } Item* get_copy(THD *thd) { return 0; } - bool wrap_tvc_into_select(THD *thd, st_select_lex *tvc_sl); + st_select_lex *wrap_tvc_into_select(THD *thd, st_select_lex *tvc_sl); friend class select_result_interceptor; friend class Item_in_optimizer; diff --git a/sql/lock.cc b/sql/lock.cc index a3744d7f000..3a2001fbc34 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -729,6 +729,9 @@ static int unlock_external(THD *thd, TABLE **table,uint count) - GET_LOCK_STORE_LOCKS : Store lock info in TABLE - GET_LOCK_SKIP_SEQUENCES : Ignore sequences (for temporary unlock) - GET_LOCK_ON_THD : Store lock in thd->mem_root + + Temporary tables are not locked (as these are single user), except for + TRANSACTIONAL_TMP_TABLES as locking is needed to handle transactions. */ MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, uint flags) @@ -745,8 +748,8 @@ MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, uint flags) { TABLE *t= table_ptr[i]; - if (t->s->tmp_table != NON_TRANSACTIONAL_TMP_TABLE && - t->s->tmp_table != INTERNAL_TMP_TABLE && + if ((likely(!t->s->tmp_table) || + (t->s->tmp_table == TRANSACTIONAL_TMP_TABLE)) && (!(flags & GET_LOCK_SKIP_SEQUENCES) || t->s->sequence == 0)) { lock_count+= t->file->lock_count(); @@ -774,13 +777,13 @@ MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, uint flags) for (i=0 ; i < count ; i++) { - TABLE *table; + TABLE *table= table_ptr[i]; enum thr_lock_type lock_type; THR_LOCK_DATA **locks_start; - table= table_ptr[i]; - if (table->s->tmp_table == NON_TRANSACTIONAL_TMP_TABLE || - table->s->tmp_table == INTERNAL_TMP_TABLE || - ((flags & GET_LOCK_SKIP_SEQUENCES) && table->s->sequence)) + + if (!((likely(!table->s->tmp_table) || + (table->s->tmp_table == TRANSACTIONAL_TMP_TABLE)) && + (!(flags & GET_LOCK_SKIP_SEQUENCES) || table->s->sequence == 0))) continue; lock_type= table->reginfo.lock_type; DBUG_ASSERT(lock_type != TL_WRITE_DEFAULT && lock_type != TL_READ_DEFAULT); diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 66c44f2d901..7dce0bf6016 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -501,7 +501,7 @@ struct LEX_MASTER_INFO } host= user= password= log_file_name= ssl_key= ssl_cert= ssl_ca= - ssl_capath= ssl_cipher= relay_log_name= 0; + ssl_capath= ssl_cipher= ssl_crl= ssl_crlpath= relay_log_name= NULL; pos= relay_log_pos= server_id= port= connect_retry= 0; heartbeat_period= 0; ssl= ssl_verify_server_cert= heartbeat_opt= diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 7d9517ff1f2..e62da0ef782 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1166,22 +1166,6 @@ JOIN::prepare(TABLE_LIST *tables_init, FALSE, SELECT_ACL, SELECT_ACL, FALSE)) DBUG_RETURN(-1); - /* - Permanently remove redundant parts from the query if - 1) This is a subquery - 2) This is the first time this query is optimized (since the - transformation is permanent - 3) Not normalizing a view. Removal should take place when a - query involving a view is optimized, not when the view - is created - */ - if (select_lex->master_unit()->item && // 1) - select_lex->first_cond_optimization && // 2) - !thd->lex->is_view_context_analysis()) // 3) - { - remove_redundant_subquery_clauses(select_lex); - } - /* System Versioning: handle FOR SYSTEM_TIME clause. */ if (select_lex->vers_setup_conds(thd, tables_list) < 0) DBUG_RETURN(-1); @@ -1264,6 +1248,23 @@ JOIN::prepare(TABLE_LIST *tables_init, &hidden_group_fields, &select_lex->select_n_reserved)) DBUG_RETURN(-1); + + /* + Permanently remove redundant parts from the query if + 1) This is a subquery + 2) This is the first time this query is optimized (since the + transformation is permanent + 3) Not normalizing a view. Removal should take place when a + query involving a view is optimized, not when the view + is created + */ + if (select_lex->master_unit()->item && // 1) + select_lex->first_cond_optimization && // 2) + !thd->lex->is_view_context_analysis()) // 3) + { + remove_redundant_subquery_clauses(select_lex); + } + /* Resolve the ORDER BY that was skipped, then remove it. */ if (skip_order_by && select_lex != select_lex->master_unit()->global_parameters()) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index eac4af52ef4..c6be14540f3 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -8885,6 +8885,16 @@ bool get_schema_tables_result(JOIN *join, if (table_list->schema_table->fill_table == 0) continue; + /* + Do not fill in tables thare are marked as JT_CONST as these will never + be read and they also don't have a tab->read_record.table set! + This can happen with queries like + SELECT * FROM t1 LEFT JOIN (t1 AS t1b JOIN INFORMATION_SCHEMA.ROUTINES) + ON (t1b.a IS NULL); + */ + if (tab->type == JT_CONST) + continue; + /* skip I_S optimizations specific to get_all_tables */ if (lex->describe && (table_list->schema_table->fill_table != get_all_tables)) diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index e7d380ebb2d..042e86fbd86 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -1022,14 +1022,14 @@ public: void store_stat_fields() { - char buff[MAX_FIELD_WIDTH]; - String val(buff, sizeof(buff), &my_charset_bin); + StringBuffer<MAX_FIELD_WIDTH> val; MY_BITMAP *old_map= dbug_tmp_use_all_columns(stat_table, &stat_table->read_set); for (uint i= COLUMN_STAT_MIN_VALUE; i <= COLUMN_STAT_HISTOGRAM; i++) { Field *stat_field= stat_table->field[i]; - if (table_field->collected_stats->is_null(i)) + Column_statistics *stats= table_field->collected_stats; + if (stats->is_null(i)) stat_field->set_null(); else { @@ -1037,10 +1037,10 @@ public: switch (i) { case COLUMN_STAT_MIN_VALUE: if (table_field->type() == MYSQL_TYPE_BIT) - stat_field->store(table_field->collected_stats->min_value->val_int(),true); + stat_field->store(stats->min_value->val_int(),true); else { - table_field->collected_stats->min_value->val_str(&val); + stats->min_value->val_str(&val); size_t length= Well_formed_prefix(val.charset(), val.ptr(), MY_MIN(val.length(), stat_field->field_length)).length(); stat_field->store(val.ptr(), length, &my_charset_bin); @@ -1048,37 +1048,33 @@ public: break; case COLUMN_STAT_MAX_VALUE: if (table_field->type() == MYSQL_TYPE_BIT) - stat_field->store(table_field->collected_stats->max_value->val_int(),true); + stat_field->store(stats->max_value->val_int(),true); else { - table_field->collected_stats->max_value->val_str(&val); + stats->max_value->val_str(&val); size_t length= Well_formed_prefix(val.charset(), val.ptr(), MY_MIN(val.length(), stat_field->field_length)).length(); stat_field->store(val.ptr(), length, &my_charset_bin); } break; case COLUMN_STAT_NULLS_RATIO: - stat_field->store(table_field->collected_stats->get_nulls_ratio()); + stat_field->store(stats->get_nulls_ratio()); break; case COLUMN_STAT_AVG_LENGTH: - stat_field->store(table_field->collected_stats->get_avg_length()); + stat_field->store(stats->get_avg_length()); break; case COLUMN_STAT_AVG_FREQUENCY: - stat_field->store(table_field->collected_stats->get_avg_frequency()); + stat_field->store(stats->get_avg_frequency()); break; case COLUMN_STAT_HIST_SIZE: - stat_field->store(table_field->collected_stats->histogram.get_size()); + stat_field->store(stats->histogram.get_size()); break; case COLUMN_STAT_HIST_TYPE: - stat_field->store(table_field->collected_stats->histogram.get_type() + - 1); + stat_field->store(stats->histogram.get_type() + 1); break; case COLUMN_STAT_HISTOGRAM: - const char * col_histogram= - (const char *) (table_field->collected_stats->histogram.get_values()); - stat_field->store(col_histogram, - table_field->collected_stats->histogram.get_size(), - &my_charset_bin); + stat_field->store((char *)stats->histogram.get_values(), + stats->histogram.get_size(), &my_charset_bin); break; } } @@ -1133,16 +1129,30 @@ public: switch (i) { case COLUMN_STAT_MIN_VALUE: - table_field->read_stats->min_value->set_notnull(); - stat_field->val_str(&val); - table_field->read_stats->min_value->store(val.ptr(), val.length(), - &my_charset_bin); + table_field->read_stats->min_value->set_notnull(); + if (table_field->type() == MYSQL_TYPE_BIT) + table_field->read_stats->min_value->store(stat_field->val_int(), + true); + else + { + stat_field->val_str(&val); + table_field->read_stats->min_value->store(val.ptr(), + val.length(), + &my_charset_bin); + } break; case COLUMN_STAT_MAX_VALUE: - table_field->read_stats->max_value->set_notnull(); - stat_field->val_str(&val); - table_field->read_stats->max_value->store(val.ptr(), val.length(), - &my_charset_bin); + table_field->read_stats->max_value->set_notnull(); + if (table_field->type() == MYSQL_TYPE_BIT) + table_field->read_stats->max_value->store(stat_field->val_int(), + true); + else + { + stat_field->val_str(&val); + table_field->read_stats->max_value->store(val.ptr(), + val.length(), + &my_charset_bin); + } break; case COLUMN_STAT_NULLS_RATIO: table_field->read_stats->set_nulls_ratio(stat_field->val_real()); @@ -2096,20 +2106,24 @@ void create_min_max_statistical_fields_for_table_share(THD *thd, int alloc_statistics_for_table(THD* thd, TABLE *table) { Field **field_ptr; - uint fields; DBUG_ENTER("alloc_statistics_for_table"); + uint columns= 0; + for (field_ptr= table->field; *field_ptr; field_ptr++) + { + if (bitmap_is_set(table->read_set, (*field_ptr)->field_index)) + columns++; + } Table_statistics *table_stats= (Table_statistics *) alloc_root(&table->mem_root, sizeof(Table_statistics)); - fields= table->s->fields ; Column_statistics_collected *column_stats= (Column_statistics_collected *) alloc_root(&table->mem_root, sizeof(Column_statistics_collected) * - (fields+1)); + columns); uint keys= table->s->keys; Index_statistics *index_stats= @@ -2120,16 +2134,6 @@ int alloc_statistics_for_table(THD* thd, TABLE *table) ulonglong *idx_avg_frequency= (ulonglong*) alloc_root(&table->mem_root, sizeof(ulonglong) * key_parts); - if (table->file->ha_rnd_init(TRUE)) - DBUG_RETURN(1); - table->file->ha_rnd_end(); - - uint columns= 0; - for (field_ptr= table->field; *field_ptr; field_ptr++) - { - if (bitmap_is_set(table->read_set, (*field_ptr)->field_index)) - columns++; - } uint hist_size= thd->variables.histogram_size; Histogram_type hist_type= (Histogram_type) (thd->variables.histogram_type); uchar *histogram= NULL; @@ -2151,19 +2155,17 @@ int alloc_statistics_for_table(THD* thd, TABLE *table) table_stats->idx_avg_frequency= idx_avg_frequency; table_stats->histograms= histogram; - memset(column_stats, 0, sizeof(Column_statistics) * (fields+1)); + memset(column_stats, 0, sizeof(Column_statistics) * columns); - for (field_ptr= table->field; *field_ptr; field_ptr++, column_stats++) + for (field_ptr= table->field; *field_ptr; field_ptr++) { - (*field_ptr)->collected_stats= column_stats; - (*field_ptr)->collected_stats->max_value= NULL; - (*field_ptr)->collected_stats->min_value= NULL; if (bitmap_is_set(table->read_set, (*field_ptr)->field_index)) { column_stats->histogram.set_size(hist_size); column_stats->histogram.set_type(hist_type); column_stats->histogram.set_values(histogram); histogram+= hist_size; + (*field_ptr)->collected_stats= column_stats++; } } @@ -2658,7 +2660,7 @@ int collect_statistics_for_table(THD *thd, TABLE *table) for (field_ptr= table->field; *field_ptr; field_ptr++) { table_field= *field_ptr; - if (!bitmap_is_set(table->read_set, table_field->field_index)) + if (!table_field->collected_stats) continue; table_field->collected_stats->init(thd, table_field); } @@ -2683,7 +2685,7 @@ int collect_statistics_for_table(THD *thd, TABLE *table) for (field_ptr= table->field; *field_ptr; field_ptr++) { table_field= *field_ptr; - if (!bitmap_is_set(table->read_set, table_field->field_index)) + if (!table_field->collected_stats) continue; if ((rc= table_field->collected_stats->add())) break; @@ -2713,7 +2715,7 @@ int collect_statistics_for_table(THD *thd, TABLE *table) for (field_ptr= table->field; *field_ptr; field_ptr++) { table_field= *field_ptr; - if (!bitmap_is_set(table->read_set, table_field->field_index)) + if (!table_field->collected_stats) continue; bitmap_set_bit(table->write_set, table_field->field_index); if (!rc) @@ -2817,7 +2819,7 @@ int update_statistics_for_table(THD *thd, TABLE *table) for (Field **field_ptr= table->field; *field_ptr; field_ptr++) { Field *table_field= *field_ptr; - if (!bitmap_is_set(table->read_set, table_field->field_index)) + if (!table_field->collected_stats) continue; restore_record(stat_table, s->default_values); column_stat.set_key_fields(table_field); @@ -3744,6 +3746,7 @@ double get_column_range_cardinality(Field *field, if (!table->stats_is_read) return tab_records; + THD *thd= table->in_use; double col_nulls= tab_records * col_stats->get_nulls_ratio(); double col_non_nulls= tab_records - col_nulls; @@ -3774,7 +3777,7 @@ double get_column_range_cardinality(Field *field, col_stats->min_max_values_are_provided()) { Histogram *hist= &col_stats->histogram; - if (hist->is_available()) + if (hist->is_usable(thd)) { store_key_image_to_rec(field, (uchar *) min_endp->key, field->key_length()); @@ -3818,10 +3821,10 @@ double get_column_range_cardinality(Field *field, max_mp_pos= 1.0; Histogram *hist= &col_stats->histogram; - if (!hist->is_available()) - sel= (max_mp_pos - min_mp_pos); - else + if (hist->is_usable(thd)) sel= hist->range_selectivity(min_mp_pos, max_mp_pos); + else + sel= (max_mp_pos - min_mp_pos); res= col_non_nulls * sel; set_if_bigger(res, col_stats->get_avg_frequency()); } diff --git a/sql/sql_statistics.h b/sql/sql_statistics.h index 20ecf06bfee..35b3aa33acc 100644 --- a/sql/sql_statistics.h +++ b/sql/sql_statistics.h @@ -239,6 +239,17 @@ public: bool is_available() { return get_size() > 0 && get_values(); } + /* + This function checks that histograms should be usable only when + 1) the level of optimizer_use_condition_selectivity > 3 + 2) histograms have been collected + */ + bool is_usable(THD *thd) + { + return thd->variables.optimizer_use_condition_selectivity > 3 && + is_available(); + } + void set_value(uint i, double val) { switch (type) { diff --git a/sql/sql_tvc.cc b/sql/sql_tvc.cc index 33ee2dd381c..4b10ef4ecb4 100644 --- a/sql/sql_tvc.cc +++ b/sql/sql_tvc.cc @@ -341,6 +341,13 @@ int table_value_constr::save_explain_data_intern(THD *thd, if (select_lex->master_unit()->derived) explain->connection_type= Explain_node::EXPLAIN_NODE_DERIVED; + for (SELECT_LEX_UNIT *unit= select_lex->first_inner_unit(); + unit; + unit= unit->next_unit()) + { + explain->add_child(unit->first_select()->select_number); + } + output->add_node(explain); if (select_lex->is_top_level_node()) @@ -365,9 +372,14 @@ bool table_value_constr::optimize(THD *thd) thd->lex->explain && // for "SET" command in SPs. (!thd->lex->explain->get_select(select_lex->select_number))) { - return save_explain_data_intern(thd, thd->lex->explain); + if (save_explain_data_intern(thd, thd->lex->explain)) + return true; } - return 0; + + if (select_lex->optimize_unflattened_subqueries(true)) + return true; + + return false; } @@ -778,11 +790,12 @@ st_select_lex *wrap_tvc_with_tail(THD *thd, st_select_lex *tvc_sl) SELECT * FROM (VALUES (v1), ... (vn)) tvc_x and replaces the subselect with the result of the transformation. - @retval false if successfull - true otherwise + @retval wrapping select if successful + 0 otherwise */ -bool Item_subselect::wrap_tvc_into_select(THD *thd, st_select_lex *tvc_sl) +st_select_lex * +Item_subselect::wrap_tvc_into_select(THD *thd, st_select_lex *tvc_sl) { LEX *lex= thd->lex; /* SELECT_LEX object where the transformation is performed */ @@ -793,12 +806,12 @@ bool Item_subselect::wrap_tvc_into_select(THD *thd, st_select_lex *tvc_sl) if (engine->engine_type() == subselect_engine::SINGLE_SELECT_ENGINE) ((subselect_single_select_engine *) engine)->change_select(wrapper_sl); lex->current_select= wrapper_sl; - return false; + return wrapper_sl; } else { lex->current_select= parent_select; - return true; + return 0; } } diff --git a/sql/structs.h b/sql/structs.h index 28c0cb6e1a2..215fe7b60ea 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -92,7 +92,7 @@ class engine_option_value; struct ha_index_option_struct; typedef struct st_key { - uint key_length; /* Tot length of key */ + uint key_length; /* total length of user defined key parts */ ulong flags; /* dupp key and pack flags */ uint user_defined_key_parts; /* How many key_parts */ uint usable_key_parts; /* Should normally be = user_defined_key_parts */ diff --git a/sql/table.cc b/sql/table.cc index 4be8f8c91bb..b7c3a33aa40 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -2730,7 +2730,8 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, else key_part->key_part_flag|= HA_VAR_LENGTH_PART; key_part->store_length+=HA_KEY_BLOB_LENGTH; - keyinfo->key_length+= HA_KEY_BLOB_LENGTH; + if (i < keyinfo->user_defined_key_parts) + keyinfo->key_length+= HA_KEY_BLOB_LENGTH; } if (field->type() == MYSQL_TYPE_BIT) key_part->key_part_flag|= HA_BIT_PART; @@ -2827,7 +2828,6 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, set_if_bigger(share->max_key_length,keyinfo->key_length+ keyinfo->user_defined_key_parts); - share->total_key_length+= keyinfo->key_length; /* MERGE tables do not have unique indexes. But every key could be an unique index on the underlying MyISAM table. (Bug #10400) diff --git a/sql/table.h b/sql/table.h index bb0e087bacb..0237a3fe6cf 100644 --- a/sql/table.h +++ b/sql/table.h @@ -806,7 +806,7 @@ struct TABLE_SHARE uint rec_buff_length; /* Size of table->record[] buffer */ uint keys, key_parts; uint ext_key_parts; /* Total number of key parts in extended keys */ - uint max_key_length, max_unique_length, total_key_length; + uint max_key_length, max_unique_length; uint uniques; /* Number of UNIQUE index */ uint db_create_options; /* Create options from database */ uint db_options_in_use; /* Options in use */ diff --git a/sql/wsrep_sst.cc b/sql/wsrep_sst.cc index 23de4d7f7c1..d2a3369be72 100644 --- a/sql/wsrep_sst.cc +++ b/sql/wsrep_sst.cc @@ -770,8 +770,20 @@ static size_t estimate_cmd_len (bool* extra_args) char c; while ((c = *arg++) != 0) { - /* A whitespace or a single quote requires double quotation marks: */ - if (isspace(c) || c == '\'') + /* + Space, single quote, ampersand, and I/O redirection characters + require text to be enclosed in double quotes: + */ + if (isspace(c) || c == '\'' || c == '&' || c == '|' || +#ifdef __WIN__ + c == '>' || c == '<') +#else + /* + The semicolon is used to separate shell commands, so it must be + enclosed in double quotes as well: + */ + c == '>' || c == '<' || c == ';') +#endif { quotation= true; } @@ -794,10 +806,19 @@ static size_t estimate_cmd_len (bool* extra_args) while ((c = *arg++) != 0) { /* - A whitespace or a single quote requires double - quotation marks: + Space, single quote, ampersand, and I/O redirection characters + require text to be enclosed in double quotes: + */ + if (isspace(c) || c == '\'' || c == '&' || c == '|' || +#ifdef __WIN__ + c == '>' || c == '<') +#else + /* + The semicolon is used to separate shell commands, so it must be + enclosed in double quotes as well: */ - if (isspace(c) || c == '\'') + c == '>' || c == '<' || c == ';') +#endif { quotation= true; } @@ -878,8 +899,20 @@ static void copy_orig_argv (char* cmd_str) char c; while ((c = *arg_scan++) != 0) { - /* A whitespace or a single quote requires double quotation marks: */ - if (isspace(c) || c == '\'') + /* + Space, single quote, ampersand, and I/O redirection characters + require text to be enclosed in double quotes: + */ + if (isspace(c) || c == '\'' || c == '&' || c == '|' || +#ifdef __WIN__ + c == '>' || c == '<') +#else + /* + The semicolon is used to separate shell commands, so it must be + enclosed in double quotes as well: + */ + c == '>' || c == '<' || c == ';') +#endif { quotation= true; } @@ -953,10 +986,19 @@ static void copy_orig_argv (char* cmd_str) while ((c = *arg_scan++) != 0) { /* - A whitespace or a single quote requires double - quotation marks: + Space, single quote, ampersand, and I/O redirection characters + require text to be enclosed in double quotes: + */ + if (isspace(c) || c == '\'' || c == '&' || c == '|' || +#ifdef __WIN__ + c == '>' || c == '<') +#else + /* + The semicolon is used to separate shell commands, so it must be + enclosed in double quotes as well: */ - if (isspace(c) || c == '\'') + c == '>' || c == '<' || c == ';') +#endif { quotation= true; } |