diff options
author | unknown <monty@mysql.com> | 2005-07-04 03:50:04 +0300 |
---|---|---|
committer | unknown <monty@mysql.com> | 2005-07-04 03:50:04 +0300 |
commit | 3c82f72091d2c21519540ee5bcc3b2acadfbf198 (patch) | |
tree | 8d29892167ff9d836d0992c219bf4307f1c03b75 /sql | |
parent | 428830c50024475e85e12f6b188879c2de536529 (diff) | |
parent | 306ebf7b1c1b26b45e93fbcbbf248b3479142c41 (diff) | |
download | mariadb-git-3c82f72091d2c21519540ee5bcc3b2acadfbf198.tar.gz |
manual merge
sql/field.cc:
Auto merged
sql/item.cc:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_cmpfunc.h:
Auto merged
sql/item_func.cc:
Auto merged
sql/mysqld.cc:
Auto merged
sql/opt_range.cc:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_view.cc:
Auto merged
strings/ctype-utf8.c:
Auto merged
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.cc | 9 | ||||
-rw-r--r-- | sql/ha_federated.cc | 24 | ||||
-rw-r--r-- | sql/ha_ndbcluster.cc | 377 | ||||
-rw-r--r-- | sql/item.cc | 15 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 17 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 1 | ||||
-rw-r--r-- | sql/item_func.cc | 23 | ||||
-rw-r--r-- | sql/mysqld.cc | 11 | ||||
-rw-r--r-- | sql/opt_range.cc | 27 | ||||
-rw-r--r-- | sql/sql_class.h | 12 | ||||
-rw-r--r-- | sql/sql_parse.cc | 4 | ||||
-rw-r--r-- | sql/sql_select.cc | 65 | ||||
-rw-r--r-- | sql/sql_union.cc | 4 | ||||
-rw-r--r-- | sql/sql_view.cc | 23 |
14 files changed, 336 insertions, 276 deletions
diff --git a/sql/field.cc b/sql/field.cc index 56bb40e0f8f..925fca8ac43 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -2486,7 +2486,7 @@ int Field_new_decimal::store(longlong nr) int err; if ((err= int2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, - nr, false, &decimal_value))) + nr, FALSE, &decimal_value))) { if (check_overflow(err)) set_value_on_overflow(&decimal_value, decimal_value.sign()); @@ -6829,7 +6829,12 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs) ¬_used))) { uint conv_errors; - tmpstr.copy(from, length, cs, field_charset, &conv_errors); + if (tmpstr.copy(from, length, cs, field_charset, &conv_errors)) + { + /* Fatal OOM error */ + bzero(ptr,Field_blob::pack_length()); + return -1; + } from= tmpstr.ptr(); length= tmpstr.length(); if (conv_errors) diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc index 77db17608bc..6754a1a8707 100644 --- a/sql/ha_federated.cc +++ b/sql/ha_federated.cc @@ -1399,27 +1399,25 @@ int ha_federated::update_row(const byte *old_data, byte *new_data) int ha_federated::delete_row(const byte *buf) { - uint x= 0; char delete_buffer[IO_SIZE]; char data_buffer[IO_SIZE]; - String delete_string(delete_buffer, sizeof(delete_buffer), &my_charset_bin); - delete_string.length(0); String data_string(data_buffer, sizeof(data_buffer), &my_charset_bin); - data_string.length(0); - DBUG_ENTER("ha_federated::delete_row"); + delete_string.length(0); delete_string.append("DELETE FROM `"); delete_string.append(share->table_base_name); delete_string.append("`"); delete_string.append(" WHERE "); - for (Field **field= table->field; *field; field++, x++) + for (Field **field= table->field; *field; field++) { - delete_string.append((*field)->field_name); + Field *cur_field= *field; + data_string.length(0); + delete_string.append(cur_field->field_name); - if ((*field)->is_null()) + if (cur_field->is_null_in_record((const uchar*) buf)) { delete_string.append(" IS "); data_string.append("NULL"); @@ -1427,17 +1425,15 @@ int ha_federated::delete_row(const byte *buf) else { delete_string.append("="); - (*field)->val_str(&data_string); - (*field)->quote_data(&data_string); + cur_field->val_str(&data_string, (char*) buf+ cur_field->offset()); + cur_field->quote_data(&data_string); } delete_string.append(data_string); - data_string.length(0); - - if (x + 1 < table->s->fields) - delete_string.append(" AND "); + delete_string.append(" AND "); } + delete_string.length(delete_string.length()-5); // Remove AND delete_string.append(" LIMIT 1"); DBUG_PRINT("info", ("Delete sql: %s", delete_string.c_ptr_quick())); diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 89b81f684a3..def99b51f95 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -341,7 +341,7 @@ void ha_ndbcluster::records_update() { Ndb *ndb= get_ndb(); struct Ndb_statistics stat; - if(ndb_get_table_statistics(ndb, m_tabname, &stat) == 0){ + if (ndb_get_table_statistics(ndb, m_tabname, &stat) == 0){ mean_rec_length= stat.row_size; data_file_length= stat.fragment_memory; info->records= stat.row_count; @@ -448,27 +448,27 @@ void ha_ndbcluster::invalidate_dictionary_cache(bool global) NDBINDEX *unique_index = (NDBINDEX *) m_index[i].unique_index; NDB_INDEX_TYPE idx_type= m_index[i].type; - switch(idx_type) { - case(PRIMARY_KEY_ORDERED_INDEX): - case(ORDERED_INDEX): + switch (idx_type) { + case PRIMARY_KEY_ORDERED_INDEX: + case ORDERED_INDEX: if (global) dict->invalidateIndex(index->getName(), m_tabname); else dict->removeCachedIndex(index->getName(), m_tabname); break; - case(UNIQUE_ORDERED_INDEX): + case UNIQUE_ORDERED_INDEX: if (global) dict->invalidateIndex(index->getName(), m_tabname); else dict->removeCachedIndex(index->getName(), m_tabname); - case(UNIQUE_INDEX): + case UNIQUE_INDEX: if (global) dict->invalidateIndex(unique_index->getName(), m_tabname); else dict->removeCachedIndex(unique_index->getName(), m_tabname); break; - case(PRIMARY_KEY_INDEX): - case(UNDEFINED_INDEX): + case PRIMARY_KEY_INDEX: + case UNDEFINED_INDEX: break; } } @@ -1387,7 +1387,7 @@ int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf) return res; } - if((res= define_read_attrs(buf, op))) + if ((res= define_read_attrs(buf, op))) DBUG_RETURN(res); if (execute_no_commit_ie(this,trans) != 0) @@ -1517,10 +1517,10 @@ int ha_ndbcluster::unique_index_read(const byte *key, ERR_RETURN(trans->getNdbError()); // Set secondary index key(s) - if((res= set_index_key(op, table->key_info + active_index, key))) + if ((res= set_index_key(op, table->key_info + active_index, key))) DBUG_RETURN(res); - if((res= define_read_attrs(buf, op))) + if ((res= define_read_attrs(buf, op))) DBUG_RETURN(res); if (execute_no_commit_ie(this,trans) != 0) @@ -1580,7 +1580,7 @@ inline int ha_ndbcluster::fetch_next(NdbScanOperation* cursor) { if (execute_commit(this,trans) != 0) DBUG_RETURN(-1); - if(trans->restart() != 0) + if (trans->restart() != 0) { DBUG_ASSERT(0); DBUG_RETURN(-1); @@ -1618,7 +1618,7 @@ inline int ha_ndbcluster::next_result(byte *buf) if (!m_active_cursor) DBUG_RETURN(HA_ERR_END_OF_FILE); - if((res= fetch_next(m_active_cursor)) == 0) + if ((res= fetch_next(m_active_cursor)) == 0) { DBUG_PRINT("info", ("One more record found")); @@ -1626,7 +1626,7 @@ inline int ha_ndbcluster::next_result(byte *buf) table->status= 0; DBUG_RETURN(0); } - else if(res == 1) + else if (res == 1) { // No more records table->status= STATUS_NOT_FOUND; @@ -1857,7 +1857,7 @@ int ha_ndbcluster::ordered_index_scan(const key_range *start_key, DBUG_ASSERT(op->getSorted() == sorted); DBUG_ASSERT(op->getLockMode() == (NdbOperation::LockMode)get_ndb_lock_type(m_lock.type)); - if(op->reset_bounds(m_force_send)) + if (op->reset_bounds(m_force_send)) DBUG_RETURN(ndb_err(m_active_trans)); } @@ -1903,7 +1903,7 @@ int ha_ndbcluster::full_table_scan(byte *buf) m_active_cursor= op; if (generate_scan_filter(m_cond_stack, op)) DBUG_RETURN(ndb_err(trans)); - if((res= define_read_attrs(buf, op))) + if ((res= define_read_attrs(buf, op))) DBUG_RETURN(res); if (execute_no_commit(this,trans) != 0) @@ -2041,7 +2041,7 @@ int ha_ndbcluster::write_row(byte *record) no_uncommitted_rows_execute_failure(); DBUG_RETURN(ndb_err(trans)); } - if(trans->restart() != 0) + if (trans->restart() != 0) { DBUG_ASSERT(0); DBUG_RETURN(-1); @@ -2420,7 +2420,7 @@ void ha_ndbcluster::print_results() field= table->field[f]; if (!(value= m_value[f]).ptr) { - my_snprintf(buf, sizeof(buf), "not read"); + strmov(buf, "not read"); goto print_value; } @@ -2430,7 +2430,7 @@ void ha_ndbcluster::print_results() { if (value.rec->isNULL()) { - my_snprintf(buf, sizeof(buf), "NULL"); + strmov(buf, "NULL"); goto print_value; } type.length(0); @@ -2444,10 +2444,8 @@ void ha_ndbcluster::print_results() NdbBlob *ndb_blob= value.blob; bool isNull= TRUE; ndb_blob->getNull(isNull); - if (isNull) { - my_snprintf(buf, sizeof(buf), "NULL"); - goto print_value; - } + if (isNull) + strmov(buf, "NULL"); } print_value: @@ -2487,7 +2485,7 @@ check_null_in_key(const KEY* key_info, const byte *key, uint key_len) for (; curr_part != end_part && key < end_ptr; curr_part++) { - if(curr_part->null_bit && *key) + if (curr_part->null_bit && *key) return 1; key += curr_part->store_length; @@ -2511,7 +2509,7 @@ int ha_ndbcluster::index_read(byte *buf, case PRIMARY_KEY_INDEX: if (find_flag == HA_READ_KEY_EXACT && key_info->key_length == key_len) { - if(m_active_cursor && (error= close_scan())) + if (m_active_cursor && (error= close_scan())) DBUG_RETURN(error); DBUG_RETURN(pk_read(key, key_len, buf)); } @@ -2525,7 +2523,7 @@ int ha_ndbcluster::index_read(byte *buf, if (find_flag == HA_READ_KEY_EXACT && key_info->key_length == key_len && !check_null_in_key(key_info, key, key_len)) { - if(m_active_cursor && (error= close_scan())) + if (m_active_cursor && (error= close_scan())) DBUG_RETURN(error); DBUG_RETURN(unique_index_read(key, key_len, buf)); } @@ -2637,7 +2635,7 @@ int ha_ndbcluster::read_range_first_to_buf(const key_range *start_key, start_key->length == key_info->key_length && start_key->flag == HA_READ_KEY_EXACT) { - if(m_active_cursor && (error= close_scan())) + if (m_active_cursor && (error= close_scan())) DBUG_RETURN(error); error= pk_read(start_key->key, start_key->length, buf); DBUG_RETURN(error == HA_ERR_KEY_NOT_FOUND ? HA_ERR_END_OF_FILE : error); @@ -2650,7 +2648,7 @@ int ha_ndbcluster::read_range_first_to_buf(const key_range *start_key, start_key->flag == HA_READ_KEY_EXACT && !check_null_in_key(key_info, start_key->key, start_key->length)) { - if(m_active_cursor && (error= close_scan())) + if (m_active_cursor && (error= close_scan())) DBUG_RETURN(error); error= unique_index_read(start_key->key, start_key->length, buf); DBUG_RETURN(error == HA_ERR_KEY_NOT_FOUND ? HA_ERR_END_OF_FILE : error); @@ -2697,7 +2695,7 @@ int ha_ndbcluster::rnd_init(bool scan) { if (!scan) DBUG_RETURN(1); - if(cursor->restart(m_force_send) != 0) + if (cursor->restart(m_force_send) != 0) { DBUG_ASSERT(0); DBUG_RETURN(-1); @@ -3467,7 +3465,7 @@ int ndbcluster_commit(THD *thd, bool all) } ndb->closeTransaction(trans); - if(all) + if (all) thd_ndb->all= NULL; else thd_ndb->stmt= NULL; @@ -3517,7 +3515,7 @@ int ndbcluster_rollback(THD *thd, bool all) } ndb->closeTransaction(trans); - if(all) + if (all) thd_ndb->all= NULL; else thd_ndb->stmt= NULL; @@ -3773,7 +3771,8 @@ static int create_ndb_column(NDBCOL &col, col.setType(NDBCOL::Char); col.setLength(field->pack_length()); break; - case MYSQL_TYPE_BIT: { + case MYSQL_TYPE_BIT: + { int no_of_bits= field->field_length*8 + ((Field_bit *) field)->bit_len; col.setType(NDBCOL::Bit); if (!no_of_bits) @@ -3908,7 +3907,7 @@ int ha_ndbcluster::create(const char *name, if ((my_errno= create_ndb_column(col, field, info))) DBUG_RETURN(my_errno); tab.addColumn(col); - if(col.getPrimaryKey()) + if (col.getPrimaryKey()) pk_length += (field->pack_length() + 3) / 4; } @@ -3941,7 +3940,7 @@ int ha_ndbcluster::create(const char *name, { NdbDictionary::Column * col= tab.getColumn(i); int size= pk_length + (col->getPartSize()+3)/4 + 7; - if(size > NDB_MAX_TUPLE_SIZE_IN_WORDS && + if (size > NDB_MAX_TUPLE_SIZE_IN_WORDS && (pk_length+7) < NDB_MAX_TUPLE_SIZE_IN_WORDS) { size= NDB_MAX_TUPLE_SIZE_IN_WORDS - pk_length - 7; @@ -4169,12 +4168,10 @@ ulonglong ha_ndbcluster::get_auto_increment() m_rows_to_insert+= m_autoincrement_prefetch; } cache_size= - (int) - (m_rows_to_insert - m_rows_inserted < m_autoincrement_prefetch) ? - m_rows_to_insert - m_rows_inserted - : (m_rows_to_insert > m_autoincrement_prefetch) ? - m_rows_to_insert - : m_autoincrement_prefetch; + (int) ((m_rows_to_insert - m_rows_inserted < m_autoincrement_prefetch) ? + m_rows_to_insert - m_rows_inserted : + ((m_rows_to_insert > m_autoincrement_prefetch) ? + m_rows_to_insert : m_autoincrement_prefetch)); auto_value= NDB_FAILED_AUTO_INCREMENT; uint retries= NDB_AUTO_INCREMENT_RETRIES; do { @@ -4778,7 +4775,7 @@ ndbcluster_init() g_ndb_cluster_connection->get_connected_port())); g_ndb_cluster_connection->wait_until_ready(10,3); } - else if(res == 1) + else if (res == 1) { if (g_ndb_cluster_connection->start_connect_thread(connect_callback)) { @@ -4826,7 +4823,7 @@ ndbcluster_init() DBUG_RETURN(&ndbcluster_hton); ndbcluster_init_error: - if(g_ndb) + if (g_ndb) delete g_ndb; g_ndb= NULL; if (g_ndb_cluster_connection) @@ -4855,7 +4852,7 @@ bool ndbcluster_end() (void) pthread_cond_signal(&COND_ndb_util_thread); (void) pthread_mutex_unlock(&LOCK_ndb_util_thread); - if(g_ndb) + if (g_ndb) delete g_ndb; g_ndb= NULL; if (g_ndb_cluster_connection) @@ -5105,7 +5102,7 @@ uint ndb_get_commitcount(THD *thd, char *dbname, char *tabname, } pthread_mutex_lock(&share->mutex); - if(share->commit_count_lock == lock) + if (share->commit_count_lock == lock) { DBUG_PRINT("info", ("Setting commit_count to %llu", stat.commit_count)); share->commit_count= stat.commit_count; @@ -5596,9 +5593,13 @@ ha_ndbcluster::read_multi_range_first(KEY_MULTI_RANGE **found_range_p, for (; multi_range_curr<multi_range_end && curr+reclength <= end_of_buffer; multi_range_curr++) { - switch(index_type){ + switch (index_type){ + case PRIMARY_KEY_ORDERED_INDEX: + if (!(multi_range_curr->start_key.length == key_info->key_length && + multi_range_curr->start_key.flag == HA_READ_KEY_EXACT)) + goto range; + /* fall through */ case PRIMARY_KEY_INDEX: - pk: { multi_range_curr->range_flag |= UNIQUE_RANGE; if ((op= m_active_trans->getNdbOperation(tab)) && @@ -5612,8 +5613,14 @@ ha_ndbcluster::read_multi_range_first(KEY_MULTI_RANGE **found_range_p, break; } break; + case UNIQUE_ORDERED_INDEX: + if (!(multi_range_curr->start_key.length == key_info->key_length && + multi_range_curr->start_key.flag == HA_READ_KEY_EXACT && + !check_null_in_key(key_info, multi_range_curr->start_key.key, + multi_range_curr->start_key.length))) + goto range; + /* fall through */ case UNIQUE_INDEX: - sk: { multi_range_curr->range_flag |= UNIQUE_RANGE; if ((op= m_active_trans->getNdbIndexOperation(unique_idx, tab)) && @@ -5626,19 +5633,8 @@ ha_ndbcluster::read_multi_range_first(KEY_MULTI_RANGE **found_range_p, ERR_RETURN(op ? op->getNdbError() : m_active_trans->getNdbError()); break; } - case PRIMARY_KEY_ORDERED_INDEX: - if (multi_range_curr->start_key.length == key_info->key_length && - multi_range_curr->start_key.flag == HA_READ_KEY_EXACT) - goto pk; - goto range; - case UNIQUE_ORDERED_INDEX: - if (multi_range_curr->start_key.length == key_info->key_length && - multi_range_curr->start_key.flag == HA_READ_KEY_EXACT && - !check_null_in_key(key_info, multi_range_curr->start_key.key, - multi_range_curr->start_key.length)) - goto sk; - goto range; - case ORDERED_INDEX: { + case ORDERED_INDEX: + { range: multi_range_curr->range_flag &= ~(uint)UNIQUE_RANGE; if (scanOp == 0) @@ -5649,7 +5645,7 @@ ha_ndbcluster::read_multi_range_first(KEY_MULTI_RANGE **found_range_p, DBUG_ASSERT(scanOp->getSorted() == sorted); DBUG_ASSERT(scanOp->getLockMode() == (NdbOperation::LockMode)get_ndb_lock_type(m_lock.type)); - if(scanOp->reset_bounds(m_force_send)) + if (scanOp->reset_bounds(m_force_send)) DBUG_RETURN(ndb_err(m_active_trans)); end_of_buffer -= reclength; @@ -5675,7 +5671,7 @@ ha_ndbcluster::read_multi_range_first(KEY_MULTI_RANGE **found_range_p, DBUG_RETURN(res); break; } - case(UNDEFINED_INDEX): + case UNDEFINED_INDEX: DBUG_ASSERT(FALSE); DBUG_RETURN(1); break; @@ -5784,7 +5780,7 @@ ha_ndbcluster::read_multi_range_next(KEY_MULTI_RANGE ** multi_range_found_p) DBUG_MULTI_RANGE(6); // First fetch from cursor DBUG_ASSERT(range_no == -1); - if((res= m_multi_cursor->nextResult(true))) + if ((res= m_multi_cursor->nextResult(true))) { goto close_scan; } @@ -5887,7 +5883,7 @@ ha_ndbcluster::update_table_comment( const char* comment)/* in: table comment defined by user */ { uint length= strlen(comment); - if(length > 64000 - 3) + if (length > 64000 - 3) { return((char*)comment); /* string too long */ } @@ -5914,9 +5910,9 @@ ha_ndbcluster::update_table_comment( return (char*)comment; } - snprintf(str,fmt_len_plus_extra,fmt,comment, - length > 0 ? " ":"", - tab->getReplicaCount()); + my_snprintf(str,fmt_len_plus_extra,fmt,comment, + length > 0 ? " ":"", + tab->getReplicaCount()); return str; } @@ -6015,7 +6011,7 @@ extern "C" pthread_handler_decl(ndb_util_thread_func, lock= share->commit_count_lock; pthread_mutex_unlock(&share->mutex); - if(ndb_get_table_statistics(ndb, tabname, &stat) == 0) + if (ndb_get_table_statistics(ndb, tabname, &stat) == 0) { DBUG_PRINT("ndb_util_thread", ("Table: %s, commit_count: %llu, rows: %llu", @@ -6050,7 +6046,7 @@ extern "C" pthread_handler_decl(ndb_util_thread_func, abstime.tv_sec= tick_time.tv_sec; abstime.tv_nsec= tick_time.tv_usec * 1000; - if(msecs >= 1000){ + if (msecs >= 1000){ secs= msecs / 1000; msecs= msecs % 1000; } @@ -6159,17 +6155,18 @@ void ndb_serialize_cond(const Item *item, void *arg) { DBUG_PRINT("info", ("Skiping argument %d", context->skip)); context->skip--; - switch(item->type()) { - case (Item::FUNC_ITEM): { + switch (item->type()) { + case Item::FUNC_ITEM: + { Item_func *func_item= (Item_func *) item; context->skip+= func_item->argument_count(); break; } - case(Item::INT_ITEM): - case(Item::REAL_ITEM): - case(Item::STRING_ITEM): - case(Item::VARBIN_ITEM): - case(Item::DECIMAL_ITEM): + case Item::INT_ITEM: + case Item::REAL_ITEM: + case Item::STRING_ITEM: + case Item::VARBIN_ITEM: + case Item::DECIMAL_ITEM: break; default: context->supported= FALSE; @@ -6188,8 +6185,8 @@ void ndb_serialize_cond(const Item *item, void *arg) (func_item= rewrite_context->func_item) && rewrite_context->count++ == 0) { - switch(func_item->functype()) { - case(Item_func::BETWEEN): + switch (func_item->functype()) { + case Item_func::BETWEEN: /* Rewrite <field>|<const> BETWEEN <const1>|<field1> AND <const2>|<field2> @@ -6199,7 +6196,8 @@ void ndb_serialize_cond(const Item *item, void *arg) BEGIN(AND) GT(<field>|<const>, <const1>|<field1>), LT(<field>|<const>, <const2>|<field2>), END() */ - case(Item_func::IN_FUNC): { + case Item_func::IN_FUNC: + { /* Rewrite <field>|<const> IN(<const1>|<field1>, <const2>|<field2>,..) to <field>|<const> = <const1>|<field1> OR @@ -6264,17 +6262,18 @@ void ndb_serialize_cond(const Item *item, void *arg) { Ndb_rewrite_context *rewrite_context= context->rewrite_stack; const Item_func *func_item= rewrite_context->func_item; - switch(func_item->functype()) { - case(Item_func::BETWEEN): { - /* - Rewrite - <field>|<const> BETWEEN <const1>|<field1> AND <const2>|<field2> - to <field>|<const> > <const1>|<field1> AND - <field>|<const> < <const2>|<field2> - or actually in prefix format - BEGIN(AND) GT(<field>|<const>, <const1>|<field1>), - LT(<field>|<const>, <const2>|<field2>), END() - */ + switch (func_item->functype()) { + case Item_func::BETWEEN: + { + /* + Rewrite + <field>|<const> BETWEEN <const1>|<field1> AND <const2>|<field2> + to <field>|<const> > <const1>|<field1> AND + <field>|<const> < <const2>|<field2> + or actually in prefix format + BEGIN(AND) GT(<field>|<const>, <const1>|<field1>), + LT(<field>|<const>, <const2>|<field2>), END() + */ if (rewrite_context->count == 2) { // Lower limit of BETWEEN @@ -6296,7 +6295,8 @@ void ndb_serialize_cond(const Item *item, void *arg) } break; } - case(Item_func::IN_FUNC): { + case Item_func::IN_FUNC: + { /* Rewrite <field>|<const> IN(<const1>|<field1>, <const2>|<field2>,..) to <field>|<const> = <const1>|<field1> OR @@ -6345,8 +6345,10 @@ void ndb_serialize_cond(const Item *item, void *arg) curr_cond->ndb_item= new Ndb_item(NDB_END_COND); } else - switch(item->type()) { - case(Item::FIELD_ITEM): { + { + switch (item->type()) { + case Item::FIELD_ITEM: + { Item_field *field_item= (Item_field *) item; Field *field= field_item->field; enum_field_types type= field->type(); @@ -6392,23 +6394,23 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect(Item::INT_ITEM); } else - switch(field->result_type()) { - case(STRING_RESULT): + switch (field->result_type()) { + case STRING_RESULT: // Expect char string or binary string context->expect_only(Item::STRING_ITEM); context->expect(Item::VARBIN_ITEM); context->expect_collation(field_item->collation.collation); break; - case(REAL_RESULT): + case REAL_RESULT: context->expect_only(Item::REAL_ITEM); context->expect(Item::DECIMAL_ITEM); context->expect(Item::INT_ITEM); break; - case(INT_RESULT): + case INT_RESULT: context->expect_only(Item::INT_ITEM); context->expect(Item::VARBIN_ITEM); break; - case(DECIMAL_RESULT): + case DECIMAL_RESULT: context->expect_only(Item::DECIMAL_ITEM); context->expect(Item::REAL_ITEM); context->expect(Item::INT_ITEM); @@ -6453,7 +6455,8 @@ void ndb_serialize_cond(const Item *item, void *arg) } break; } - case(Item::FUNC_ITEM): { + case Item::FUNC_ITEM: + { Item_func *func_item= (Item_func *) item; // Check that we expect a function or functional expression here if (context->expecting(Item::FUNC_ITEM) || @@ -6466,8 +6469,9 @@ void ndb_serialize_cond(const Item *item, void *arg) break; } - switch(func_item->functype()) { - case(Item_func::EQ_FUNC): { + switch (func_item->functype()) { + case Item_func::EQ_FUNC: + { DBUG_PRINT("info", ("EQ_FUNC")); curr_cond->ndb_item= new Ndb_item(func_item->functype(), func_item); @@ -6483,7 +6487,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect_field_result(DECIMAL_RESULT); break; } - case(Item_func::NE_FUNC): { + case Item_func::NE_FUNC: + { DBUG_PRINT("info", ("NE_FUNC")); curr_cond->ndb_item= new Ndb_item(func_item->functype(), func_item); @@ -6499,7 +6504,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect_field_result(DECIMAL_RESULT); break; } - case(Item_func::LT_FUNC): { + case Item_func::LT_FUNC: + { DBUG_PRINT("info", ("LT_FUNC")); curr_cond->ndb_item= new Ndb_item(func_item->functype(), func_item); @@ -6515,7 +6521,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect_field_result(DECIMAL_RESULT); break; } - case(Item_func::LE_FUNC): { + case Item_func::LE_FUNC: + { DBUG_PRINT("info", ("LE_FUNC")); curr_cond->ndb_item= new Ndb_item(func_item->functype(), func_item); @@ -6531,7 +6538,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect_field_result(DECIMAL_RESULT); break; } - case(Item_func::GE_FUNC): { + case Item_func::GE_FUNC: + { DBUG_PRINT("info", ("GE_FUNC")); curr_cond->ndb_item= new Ndb_item(func_item->functype(), func_item); @@ -6547,7 +6555,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect_field_result(DECIMAL_RESULT); break; } - case(Item_func::GT_FUNC): { + case Item_func::GT_FUNC: + { DBUG_PRINT("info", ("GT_FUNC")); curr_cond->ndb_item= new Ndb_item(func_item->functype(), func_item); @@ -6563,7 +6572,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect_field_result(DECIMAL_RESULT); break; } - case(Item_func::LIKE_FUNC): { + case Item_func::LIKE_FUNC: + { DBUG_PRINT("info", ("LIKE_FUNC")); curr_cond->ndb_item= new Ndb_item(func_item->functype(), func_item); @@ -6573,7 +6583,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect(Item::FUNC_ITEM); break; } - case(Item_func::NOTLIKE_FUNC): { + case Item_func::NOTLIKE_FUNC: + { DBUG_PRINT("info", ("NOTLIKE_FUNC")); curr_cond->ndb_item= new Ndb_item(func_item->functype(), func_item); @@ -6583,7 +6594,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect(Item::FUNC_ITEM); break; } - case(Item_func::ISNULL_FUNC): { + case Item_func::ISNULL_FUNC: + { DBUG_PRINT("info", ("ISNULL_FUNC")); curr_cond->ndb_item= new Ndb_item(func_item->functype(), func_item); @@ -6594,7 +6606,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect_field_result(DECIMAL_RESULT); break; } - case(Item_func::ISNOTNULL_FUNC): { + case Item_func::ISNOTNULL_FUNC: + { DBUG_PRINT("info", ("ISNOTNULL_FUNC")); curr_cond->ndb_item= new Ndb_item(func_item->functype(), func_item); @@ -6605,7 +6618,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect_field_result(DECIMAL_RESULT); break; } - case(Item_func::NOT_FUNC): { + case Item_func::NOT_FUNC: + { DBUG_PRINT("info", ("NOT_FUNC")); curr_cond->ndb_item= new Ndb_item(func_item->functype(), func_item); @@ -6613,7 +6627,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect(Item::COND_ITEM); break; } - case(Item_func::BETWEEN) : { + case Item_func::BETWEEN: + { DBUG_PRINT("info", ("BETWEEN, rewriting using AND")); Ndb_rewrite_context *rewrite_context= new Ndb_rewrite_context(func_item); @@ -6629,7 +6644,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect(Item::FUNC_ITEM); break; } - case(Item_func::IN_FUNC) : { + case Item_func::IN_FUNC: + { DBUG_PRINT("info", ("IN_FUNC, rewriting using OR")); Ndb_rewrite_context *rewrite_context= new Ndb_rewrite_context(func_item); @@ -6645,13 +6661,16 @@ void ndb_serialize_cond(const Item *item, void *arg) context->expect(Item::FUNC_ITEM); break; } - case(Item_func::UNKNOWN_FUNC): { + case Item_func::UNKNOWN_FUNC: + { DBUG_PRINT("info", ("UNKNOWN_FUNC %s", func_item->const_item()?"const":"")); DBUG_PRINT("info", ("result type %d", func_item->result_type())); if (func_item->const_item()) - switch(func_item->result_type()) { - case(STRING_RESULT): { + { + switch (func_item->result_type()) { + case STRING_RESULT: + { NDB_ITEM_QUALIFICATION q; q.value_type= Item::STRING_ITEM; curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item); @@ -6680,7 +6699,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->skip= func_item->argument_count(); break; } - case(REAL_RESULT): { + case REAL_RESULT: + { NDB_ITEM_QUALIFICATION q; q.value_type= Item::REAL_ITEM; curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item); @@ -6702,7 +6722,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->skip= func_item->argument_count(); break; } - case(INT_RESULT): { + case INT_RESULT: + { NDB_ITEM_QUALIFICATION q; q.value_type= Item::INT_ITEM; curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item); @@ -6724,7 +6745,8 @@ void ndb_serialize_cond(const Item *item, void *arg) context->skip= func_item->argument_count(); break; } - case(DECIMAL_RESULT): { + case DECIMAL_RESULT: + { NDB_ITEM_QUALIFICATION q; q.value_type= Item::DECIMAL_ITEM; curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item); @@ -6748,12 +6770,14 @@ void ndb_serialize_cond(const Item *item, void *arg) default: break; } + } else // Function does not return constant expression context->supported= FALSE; break; } - default: { + default: + { DBUG_PRINT("info", ("Found func_item of type %d", func_item->functype())); context->supported= FALSE; @@ -6761,7 +6785,7 @@ void ndb_serialize_cond(const Item *item, void *arg) } break; } - case(Item::STRING_ITEM): + case Item::STRING_ITEM: DBUG_PRINT("info", ("STRING_ITEM")); if (context->expecting(Item::STRING_ITEM)) { @@ -6800,7 +6824,7 @@ void ndb_serialize_cond(const Item *item, void *arg) else context->supported= FALSE; break; - case(Item::INT_ITEM): + case Item::INT_ITEM: DBUG_PRINT("info", ("INT_ITEM")); if (context->expecting(Item::INT_ITEM)) { @@ -6827,7 +6851,7 @@ void ndb_serialize_cond(const Item *item, void *arg) else context->supported= FALSE; break; - case(Item::REAL_ITEM): + case Item::REAL_ITEM: DBUG_PRINT("info", ("REAL_ITEM %s")); if (context->expecting(Item::REAL_ITEM)) { @@ -6852,7 +6876,7 @@ void ndb_serialize_cond(const Item *item, void *arg) else context->supported= FALSE; break; - case(Item::VARBIN_ITEM): + case Item::VARBIN_ITEM: DBUG_PRINT("info", ("VARBIN_ITEM")); if (context->expecting(Item::VARBIN_ITEM)) { @@ -6875,7 +6899,7 @@ void ndb_serialize_cond(const Item *item, void *arg) else context->supported= FALSE; break; - case(Item::DECIMAL_ITEM): + case Item::DECIMAL_ITEM: DBUG_PRINT("info", ("DECIMAL_ITEM %s")); if (context->expecting(Item::DECIMAL_ITEM)) { @@ -6901,17 +6925,19 @@ void ndb_serialize_cond(const Item *item, void *arg) else context->supported= FALSE; break; - case(Item::COND_ITEM): { + case Item::COND_ITEM: + { Item_cond *cond_item= (Item_cond *) item; if (context->expecting(Item::COND_ITEM)) - switch(cond_item->functype()) { - case(Item_func::COND_AND_FUNC): + { + switch (cond_item->functype()) { + case Item_func::COND_AND_FUNC: DBUG_PRINT("info", ("COND_AND_FUNC")); curr_cond->ndb_item= new Ndb_item(cond_item->functype(), cond_item); break; - case(Item_func::COND_OR_FUNC): + case Item_func::COND_OR_FUNC: DBUG_PRINT("info", ("COND_OR_FUNC")); curr_cond->ndb_item= new Ndb_item(cond_item->functype(), cond_item); @@ -6921,17 +6947,21 @@ void ndb_serialize_cond(const Item *item, void *arg) context->supported= FALSE; break; } + } else - // Did not expect condition + { + /* Did not expect condition */ context->supported= FALSE; + } break; } - default: { + default: + { DBUG_PRINT("info", ("Found item of type %d", item->type())); context->supported= FALSE; } } - + } if (context->supported && context->rewrite_stack) { Ndb_rewrite_context *rewrite_context= context->rewrite_stack; @@ -6975,18 +7005,19 @@ ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond, bool negated) { DBUG_ENTER("build_scan_filter_predicate"); - switch(cond->ndb_item->type) { - case(NDB_FUNCTION): { + switch (cond->ndb_item->type) { + case NDB_FUNCTION: + { if (!cond->next) break; Ndb_item *a= cond->next->ndb_item; Ndb_item *b, *field, *value= NULL; - switch(cond->ndb_item->argument_count()) { - case(1): + switch (cond->ndb_item->argument_count()) { + case 1: field= (a->type == NDB_FIELD)? a : NULL; break; - case(2): + case 2: if (!cond->next->next) break; b= cond->next->next->ndb_item; @@ -7002,11 +7033,11 @@ ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond, default: break; } - switch((negated) ? - Ndb_item::negate(cond->ndb_item->qualification.function_type) - : cond->ndb_item->qualification.function_type) + switch ((negated) ? + Ndb_item::negate(cond->ndb_item->qualification.function_type) + : cond->ndb_item->qualification.function_type) { + case Item_func::EQ_FUNC: { - case(Item_func::EQ_FUNC): { if (!value || !field) break; // Save value in right format for the field type value->save_in_field(field); @@ -7019,7 +7050,8 @@ ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond, cond= cond->next->next->next; DBUG_RETURN(0); } - case(Item_func::NE_FUNC): { + case Item_func::NE_FUNC: + { if (!value || !field) break; // Save value in right format for the field type value->save_in_field(field); @@ -7032,7 +7064,8 @@ ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond, cond= cond->next->next->next; DBUG_RETURN(0); } - case(Item_func::LT_FUNC): { + case Item_func::LT_FUNC: + { if (!value || !field) break; // Save value in right format for the field type value->save_in_field(field); @@ -7057,7 +7090,8 @@ ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond, cond= cond->next->next->next; DBUG_RETURN(0); } - case(Item_func::LE_FUNC): { + case Item_func::LE_FUNC: + { if (!value || !field) break; // Save value in right format for the field type value->save_in_field(field); @@ -7082,7 +7116,8 @@ ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond, cond= cond->next->next->next; DBUG_RETURN(0); } - case(Item_func::GE_FUNC): { + case Item_func::GE_FUNC: + { if (!value || !field) break; // Save value in right format for the field type value->save_in_field(field); @@ -7107,7 +7142,8 @@ ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond, cond= cond->next->next->next; DBUG_RETURN(0); } - case(Item_func::GT_FUNC): { + case Item_func::GT_FUNC: + { if (!value || !field) break; // Save value in right format for the field type value->save_in_field(field); @@ -7132,7 +7168,8 @@ ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond, cond= cond->next->next->next; DBUG_RETURN(0); } - case(Item_func::LIKE_FUNC): { + case Item_func::LIKE_FUNC: + { if (!value || !field) break; if ((value->qualification.value_type != Item::STRING_ITEM) && (value->qualification.value_type != Item::VARBIN_ITEM)) @@ -7150,7 +7187,8 @@ ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond, cond= cond->next->next->next; DBUG_RETURN(0); } - case(Item_func::NOTLIKE_FUNC): { + case Item_func::NOTLIKE_FUNC: + { if (!value || !field) break; if ((value->qualification.value_type != Item::STRING_ITEM) && (value->qualification.value_type != Item::VARBIN_ITEM)) @@ -7168,7 +7206,7 @@ ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond, cond= cond->next->next->next; DBUG_RETURN(0); } - case(Item_func::ISNULL_FUNC): + case Item_func::ISNULL_FUNC: if (!field) break; DBUG_PRINT("info", ("Generating ISNULL filter")); @@ -7176,7 +7214,8 @@ ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond, DBUG_RETURN(1); cond= cond->next->next; DBUG_RETURN(0); - case(Item_func::ISNOTNULL_FUNC): { + case Item_func::ISNOTNULL_FUNC: + { if (!field) break; DBUG_PRINT("info", ("Generating ISNOTNULL filter")); @@ -7202,15 +7241,18 @@ ha_ndbcluster::build_scan_filter_group(Ndb_cond* &cond, NdbScanFilter *filter) { uint level=0; bool negated= FALSE; - DBUG_ENTER("build_scan_filter_group"); + do { - if (!cond) DBUG_RETURN(1); - switch(cond->ndb_item->type) { - case(NDB_FUNCTION): - switch(cond->ndb_item->qualification.function_type) { - case(Item_func::COND_AND_FUNC): { + if (!cond) + DBUG_RETURN(1); + switch (cond->ndb_item->type) { + case NDB_FUNCTION: + { + switch (cond->ndb_item->qualification.function_type) { + case Item_func::COND_AND_FUNC: + { level++; DBUG_PRINT("info", ("Generating %s group %u", (negated)?"NAND":"AND", level)); @@ -7221,7 +7263,8 @@ ha_ndbcluster::build_scan_filter_group(Ndb_cond* &cond, NdbScanFilter *filter) cond= cond->next; break; } - case(Item_func::COND_OR_FUNC): { + case Item_func::COND_OR_FUNC: + { level++; DBUG_PRINT("info", ("Generating %s group %u", (negated)?"NOR":"OR", level)); @@ -7232,11 +7275,11 @@ ha_ndbcluster::build_scan_filter_group(Ndb_cond* &cond, NdbScanFilter *filter) cond= cond->next; break; } - case(Item_func::NOT_FUNC): { + case Item_func::NOT_FUNC: + { DBUG_PRINT("info", ("Generating negated query")); cond= cond->next; negated= TRUE; - break; } default: @@ -7246,7 +7289,8 @@ ha_ndbcluster::build_scan_filter_group(Ndb_cond* &cond, NdbScanFilter *filter) break; } break; - case(NDB_END_COND): + } + case NDB_END_COND: DBUG_PRINT("info", ("End of group %u", level)); level--; if (cond) cond= cond->next; @@ -7255,7 +7299,8 @@ ha_ndbcluster::build_scan_filter_group(Ndb_cond* &cond, NdbScanFilter *filter) if (!negated) break; // else fall through (NOT END is an illegal condition) - default: { + default: + { DBUG_PRINT("info", ("Illegal scan filter")); } } @@ -7270,11 +7315,11 @@ ha_ndbcluster::build_scan_filter(Ndb_cond * &cond, NdbScanFilter *filter) bool simple_cond= TRUE; DBUG_ENTER("build_scan_filter"); - switch(cond->ndb_item->type) { - case(NDB_FUNCTION): - switch(cond->ndb_item->qualification.function_type) { - case(Item_func::COND_AND_FUNC): - case(Item_func::COND_OR_FUNC): + switch (cond->ndb_item->type) { + case NDB_FUNCTION: + switch (cond->ndb_item->qualification.function_type) { + case Item_func::COND_AND_FUNC: + case Item_func::COND_OR_FUNC: simple_cond= FALSE; break; default: diff --git a/sql/item.cc b/sql/item.cc index 8bc71ae5693..e53c1ebf734 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4381,18 +4381,16 @@ my_decimal *Item_ref::val_decimal(my_decimal *decimal_value) int Item_ref::save_in_field(Field *to, bool no_conversions) { int res; - if(result_field){ + if (result_field) + { if (result_field->is_null()) { null_value= 1; return set_field_to_null_with_conversions(to, no_conversions); } - else - { - to->set_notnull(); - field_conv(to, result_field); - null_value= 0; - } + to->set_notnull(); + field_conv(to, result_field); + null_value= 0; return 0; } res= (*ref)->save_in_field(to, no_conversions); @@ -5221,8 +5219,7 @@ enum_field_types Item_type_holder::get_real_type(Item *item) acceptable information for client in send_field, so we make field type from expression type. */ - switch (item->result_type()) - { + switch (item->result_type()) { case STRING_RESULT: return MYSQL_TYPE_VAR_STRING; case INT_RESULT: diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 5e08c9f9cb7..bce6a58330f 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -275,7 +275,7 @@ int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type) owner= item; func= comparator_matrix[type] [test(owner->functype() == Item_func::EQUAL_FUNC)]; - switch(type) { + switch (type) { case ROW_RESULT: { uint n= (*a)->cols(); @@ -1578,6 +1578,21 @@ my_decimal *Item_func_case::val_decimal(my_decimal *decimal_value) } +bool Item_func_case::fix_fields(THD *thd, struct st_table_list *tables, + Item **ref) +{ + /* + buff should match stack usage from + Item_func_case::val_int() -> Item_func_case::find_item() + */ + char buff[MAX_FIELD_WIDTH*2+sizeof(String)*2+sizeof(String*)*2+sizeof(double)*2+sizeof(longlong)*2]; + if (check_stack_overrun(thd, STACK_MIN_SIZE, buff)) + return TRUE; // Fatal error flag is set! + return Item_func::fix_fields(thd, tables, ref); +} + + + void Item_func_case::fix_length_and_dec() { Item **agg; diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 4ed04e89ce3..c21e9ba4925 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -566,6 +566,7 @@ public: longlong val_int(); String *val_str(String *); my_decimal *val_decimal(my_decimal *); + bool fix_fields(THD *thd,struct st_table_list *tlist, Item **ref); void fix_length_and_dec(); uint decimal_precision() const; table_map not_null_tables() const { return 0; } diff --git a/sql/item_func.cc b/sql/item_func.cc index b29074a9504..16296266234 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1880,8 +1880,7 @@ void Item_func_round::fix_length_and_dec() return; } - switch (args[0]->result_type()) - { + switch (args[0]->result_type()) { case REAL_RESULT: case STRING_RESULT: hybrid_type= REAL_RESULT; @@ -1889,16 +1888,17 @@ void Item_func_round::fix_length_and_dec() max_length= float_length(decimals); break; case INT_RESULT: - if ((decimals_to_set==0) && + if (!decimals_to_set && (truncate || (args[0]->decimal_precision() < DECIMAL_LONGLONG_DIGITS))) { + int length_can_increase= test(!truncate && (args[1]->val_int() < 0)); + max_length= args[0]->max_length + length_can_increase; /* Here we can keep INT_RESULT */ hybrid_type= INT_RESULT; - int length_can_increase= !truncate && (args[1]->val_int() < 0); - max_length= args[0]->max_length + length_can_increase; decimals= 0; break; } + /* fall through */ case DECIMAL_RESULT: { hybrid_type= DECIMAL_RESULT; @@ -4446,7 +4446,8 @@ err: bool Item_func_match::eq(const Item *item, bool binary_cmp) const { - if (item->type() != FUNC_ITEM || ((Item_func*)item)->functype() != FT_FUNC || + if (item->type() != FUNC_ITEM || + ((Item_func*)item)->functype() != FT_FUNC || flags != ((Item_func_match*)item)->flags) return 0; @@ -4807,7 +4808,7 @@ Item_func_sp::execute(Item **itp) ulong old_client_capabilites; int res= -1; bool save_in_sub_stmt= thd->transaction.in_sub_stmt; - my_bool nsok; + my_bool save_no_send_ok; #ifndef NO_EMBEDDED_ACCESS_CHECKS st_sp_security_context save_ctx; #endif @@ -4822,7 +4823,7 @@ Item_func_sp::execute(Item **itp) thd->client_capabilities &= ~CLIENT_MULTI_RESULTS; #ifndef EMBEDDED_LIBRARY - nsok= thd->net.no_send_ok; + save_no_send_ok= thd->net.no_send_ok; thd->net.no_send_ok= TRUE; #endif @@ -4834,7 +4835,7 @@ Item_func_sp::execute(Item **itp) if (save_ctx.changed && check_routine_access(thd, EXECUTE_ACL, m_sp->m_db.str, m_sp->m_name.str, 0, 0)) - goto error_check; + goto error_check_ctx; #endif /* Like for SPs, we don't binlog the substatements. If the statement which @@ -4857,8 +4858,8 @@ Item_func_sp::execute(Item **itp) ER_FAILED_ROUTINE_BREAK_BINLOG, ER(ER_FAILED_ROUTINE_BREAK_BINLOG)); -error_check_ctx: #ifndef NO_EMBEDDED_ACCESS_CHECKS +error_check_ctx: sp_restore_security_context(thd, m_sp, &save_ctx); #endif @@ -4866,7 +4867,7 @@ error_check_ctx: error_check: #ifndef EMBEDDED_LIBRARY - thd->net.no_send_ok= nsok; + thd->net.no_send_ok= save_no_send_ok; #endif thd->client_capabilities|= old_client_capabilites & CLIENT_MULTI_RESULTS; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index b24d42cbcfd..78d9af387da 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2992,9 +2992,7 @@ int win_main(int argc, char **argv) int main(int argc, char **argv) #endif { - DEBUGGER_OFF; - MY_INIT(argv[0]); // init my_sys library & pthreads #ifdef _CUSTOMSTARTUPCONFIG_ @@ -3006,14 +3004,15 @@ int main(int argc, char **argv) #endif #ifdef __WIN__ -/* Before performing any socket operation (like retrieving hostname */ -/* in init_common_variables we have to call WSAStartup */ - if (!opt_disable_networking) + /* + Before performing any socket operation (like retrieving hostname + in init_common_variables we have to call WSAStartup + */ { WSADATA WsaData; if (SOCKET_ERROR == WSAStartup (0x0101, &WsaData)) { - /* errors are not read yet, so we use test here */ + /* errors are not read yet, so we use english text here */ my_message(ER_WSAS_FAILED, "WSAStartup Failed", MYF(0)); unireg_abort(1); } diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 3226dc9607b..c2760b08b6e 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -3528,15 +3528,12 @@ static SEL_TREE *get_mm_tree(PARAM *param,COND *cond) { /* Optimize NOT BETWEEN and NOT IN */ Item *arg= cond_func->arguments()[0]; - if (arg->type() == Item::FUNC_ITEM) - { - cond_func= (Item_func*) arg; - if (cond_func->select_optimize() == Item_func::OPTIMIZE_NONE) - DBUG_RETURN(0); - inv= TRUE; - } - else + if (arg->type() != Item::FUNC_ITEM) + DBUG_RETURN(0); + cond_func= (Item_func*) arg; + if (cond_func->select_optimize() == Item_func::OPTIMIZE_NONE) DBUG_RETURN(0); + inv= TRUE; } else if (cond_func->select_optimize() == Item_func::OPTIMIZE_NONE) DBUG_RETURN(0); @@ -8178,7 +8175,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::get_next() (have_max && have_min && (max_res == 0))); } /* - If this is a just a GROUP BY or DISTINCT without MIN or MAX and there + If this is just a GROUP BY or DISTINCT without MIN or MAX and there are equality predicates for the key parts after the group, find the first sub-group with the extended prefix. */ @@ -8581,23 +8578,21 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_max_in_range() if ((result == HA_ERR_KEY_NOT_FOUND) && (cur_range->flag & EQ_RANGE)) continue; /* Check the next range. */ - else if (result) + if (result) + { /* In no key was found with this upper bound, there certainly are no keys in the ranges to the left. */ return result; - + } /* A key was found. */ if (cur_range->flag & EQ_RANGE) - return result; /* No need to perform the checks below for equal keys. */ + return 0; /* No need to perform the checks below for equal keys. */ /* Check if record belongs to the current group. */ if (key_cmp(index_info->key_part, group_prefix, real_prefix_len)) - { - result = HA_ERR_KEY_NOT_FOUND; - continue; - } + continue; // Row not found /* If there is a lower limit, check if the found key is in the range. */ if ( !(cur_range->flag & NO_MIN_RANGE) ) diff --git a/sql/sql_class.h b/sql/sql_class.h index 1f232b9ca21..5642fa0d6af 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -653,6 +653,14 @@ typedef struct system_status_var void free_tmp_table(THD *thd, TABLE *entry); +/* The following macro is to make init of Query_arena simpler */ +#ifndef DBUG_OFF +#define INIT_ARENA_DBUG_INFO is_backup_arena= 0 +#else +#define INIT_ARENA_DBUG_INFO +#endif + + class Query_arena { public: @@ -664,9 +672,6 @@ public: MEM_ROOT *mem_root; // Pointer to current memroot #ifndef DBUG_OFF bool is_backup_arena; /* True if this arena is used for backup. */ -#define INIT_ARENA_DBUG_INFO is_backup_arena= 0 -#else -#define INIT_ARENA_DBUG_INFO #endif enum enum_state { @@ -691,7 +696,6 @@ public: */ Query_arena() { INIT_ARENA_DBUG_INFO; } -#undef INIT_ARENA_DBUG_INFO virtual Type type() const; virtual ~Query_arena() {}; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d9e50cba9e4..a57ad84da5b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2355,10 +2355,6 @@ mysql_execute_command(THD *thd) } #endif /* !HAVE_REPLICATION */ - - - - /* When option readonly is set deny operations which change tables. Except for the replication thread and the 'super' users. diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2e6794dd983..66e783a2103 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7987,9 +7987,11 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, convert_blob_length); } case Item::REF_ITEM: - if ( item->real_item()->type() == Item::FIELD_ITEM) + { + Item *tmp_item; + if ((tmp_item= item->real_item())->type() == Item::FIELD_ITEM) { - Item_field *field= (Item_field*) *((Item_ref*)item)->ref; + Item_field *field= (Item_field*) tmp_item; Field *new_field= create_tmp_field_from_field(thd, (*from_field= field->field), item->name, table, @@ -7999,6 +8001,7 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, item->set_result_field(new_field); return new_field; } + } case Item::FUNC_ITEM: case Item::COND_ITEM: case Item::FIELD_AVG_ITEM: @@ -11807,14 +11810,13 @@ cp_buffer_from_ref(THD *thd, TABLE_REF *ref) SYNOPSIS find_order_in_list() - thd [in] Pointer to current thread structure - ref_pointer_array [in/out] All select, group and order by fields - tables [in] List of tables to search in (usually FROM clause) - order [in] Column reference to be resolved - fields [in] List of fields to search in (usually SELECT list) - all_fields [in/out] All select, group and order by fields - is_group_field [in] True if order is a GROUP field, false if - ORDER by field + thd Pointer to current thread structure + ref_pointer_array All select, group and order by fields + tables List of tables to search in (usually FROM clause) + order Column reference to be resolved + fields List of fields to search in (usually SELECT list) + all_fields All select, group and order by fields + is_group_field True if order is a GROUP field, false if ORDER by field DESCRIPTION Given a column reference (represented by 'order') from a GROUP BY or ORDER @@ -11831,6 +11833,8 @@ cp_buffer_from_ref(THD *thd, TABLE_REF *ref) RETURN FALSE if OK TRUE if error occurred + + ref_pointer_array and all_fields are updated */ static bool @@ -11882,6 +11886,7 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, /* Lookup the current GROUP field in the FROM clause. */ order_item_type= order_item->type(); + from_field= (Field*) not_found_field; if (is_group_field && order_item_type == Item::FIELD_ITEM || order_item_type == Item::REF_ITEM) @@ -11889,14 +11894,11 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, from_field= find_field_in_tables(thd, (Item_ident*) order_item, tables, &view_ref, IGNORE_ERRORS, TRUE, FALSE); - if(!from_field) - from_field= (Field*) not_found_field; + if (!from_field) + from_field= (Field*) not_found_field; } - else - from_field= (Field*) not_found_field; if (from_field == not_found_field || - from_field && (from_field != view_ref_found ? /* it is field of base table => check that fields are same */ ((*select_item)->type() == Item::FIELD_ITEM && @@ -11909,37 +11911,40 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, view_ref->type() == Item::REF_ITEM && ((Item_ref *) (*select_item))->ref == ((Item_ref *) view_ref)->ref))) + { /* - If there is no such field in the FROM clause, or it is the same field as - the one found in the SELECT clause, then use the Item created for the - SELECT field. As a result if there was a derived field that 'shadowed' - a table field with the same name, the table field will be chosen over - the derived field. + If there is no such field in the FROM clause, or it is the same field + as the one found in the SELECT clause, then use the Item created for + the SELECT field. As a result if there was a derived field that + 'shadowed' a table field with the same name, the table field will be + chosen over the derived field. */ - { order->item= ref_pointer_array + counter; order->in_field_list=1; return FALSE; } else + { /* - There is a field with the same name in the FROM clause. This is the field - that will be chosen. In this case we issue a warning so the user knows - that the field from the FROM clause overshadows the column reference from - the SELECT list. + There is a field with the same name in the FROM clause. This + is the field that will be chosen. In this case we issue a + warning so the user knows that the field from the FROM clause + overshadows the column reference from the SELECT list. */ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR, ER(ER_NON_UNIQ_ERROR), from_field->field_name, current_thd->where); + } } order->in_field_list=0; /* - The call to order_item->fix_fields() means that here we resolve 'order_item' - to a column from a table in the list 'tables', or to a column in some outer - query. Exactly because of the second case we come to this point even if - (select_item == not_found_item), inspite of that fix_fields() calls - find_item_in_list() one more time. + The call to order_item->fix_fields() means that here we resolve + 'order_item' to a column from a table in the list 'tables', or to + a column in some outer query. Exactly because of the second case + we come to this point even if (select_item == not_found_item), + inspite of that fix_fields() calls find_item_in_list() one more + time. We check order_item->fixed because Item_func_group_concat can put arguments for which fix_fields already was called. diff --git a/sql/sql_union.cc b/sql/sql_union.cc index c32c557a45e..c23f14e980b 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -656,14 +656,14 @@ bool st_select_lex::cleanup() if (join) { DBUG_ASSERT((st_select_lex*)join->select_lex == this); - error|= join->destroy(); + error= join->destroy(); delete join; join= 0; } for (SELECT_LEX_UNIT *lex_unit= first_inner_unit(); lex_unit ; lex_unit= lex_unit->next_unit()) { - error|= lex_unit->cleanup(); + error= (bool) ((uint) error | (uint) lex_unit->cleanup()); } DBUG_RETURN(error); } diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 0a4d26c3a95..c8abee1e7dc 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -58,13 +58,13 @@ static void make_unique_view_field_name(Item *target, char *name= (target->orig_name ? target->orig_name : target->name); - uint name_len; - uint attempt= 0; + uint name_len, attempt; char buff[NAME_LEN+1]; - for (;; attempt++) + List_iterator_fast<Item> itc(item_list); + + for (attempt= 0;; attempt++) { Item *check; - List_iterator_fast<Item> itc(item_list); bool ok= TRUE; if (attempt) @@ -84,6 +84,7 @@ static void make_unique_view_field_name(Item *target, } while (check != last_element); if (ok) break; + itc.rewind(); } target->orig_name= target->name; @@ -305,13 +306,14 @@ bool mysql_create_view(THD *thd, { Item *item; List_iterator_fast<Item> it(select_lex->item_list); + List_iterator_fast<Item> itc(select_lex->item_list); while ((item= it++)) { Item *check; - List_iterator_fast<Item> itc(select_lex->item_list); /* treat underlying fields like set by user names */ if (item->real_item()->type() == Item::FIELD_ITEM) item->is_autogenerated_name= FALSE; + itc.rewind(); while ((check= itc++) && check != item) { if (my_strcasecmp(system_charset_info, item->name, check->name) == 0) @@ -822,6 +824,7 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table) old_lex->can_use_merged()) && !old_lex->can_not_use_merged()) { + List_iterator_fast<TABLE_LIST> ti(view_select->top_join_list); /* lex should contain at least one table */ DBUG_ASSERT(view_tables != 0); @@ -865,13 +868,11 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table) nested_join->join_list= view_select->top_join_list; /* re-nest tables of VIEW */ + ti.rewind(); + while ((tbl= ti++)) { - List_iterator_fast<TABLE_LIST> ti(nested_join->join_list); - while ((tbl= ti++)) - { - tbl->join_list= &nested_join->join_list; - tbl->embedding= table; - } + tbl->join_list= &nested_join->join_list; + tbl->embedding= table; } } |