summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2005-07-04 03:42:33 +0300
committerunknown <monty@mysql.com>2005-07-04 03:42:33 +0300
commit306ebf7b1c1b26b45e93fbcbbf248b3479142c41 (patch)
tree502bf1c54d87aaf8e4cafea943108c20d146cacc /sql
parent1aa6343fe8d9a1d61aa7fcd4246fb5858b3dfa16 (diff)
downloadmariadb-git-306ebf7b1c1b26b45e93fbcbbf248b3479142c41.tar.gz
Fixes during review of new code
- Mostly indentation fixes - Added missing test - Ensure that Item_func_case() checks for stack overruns - Use real_item() instead of (Item_ref*) item - Fixed wrong error handling myisam/mi_unique.c: Improved comments myisam/myisampack.c: Updated version number mysql-test/r/group_by.result: Added test that was lost during earlier merge mysql-test/r/information_schema.result: Safety fix: Drop procedures before used mysql-test/t/group_by.test: Added test that was lost during earlier merge mysql-test/t/information_schema.test: Safety fix: Drop procedures before used mysys/hash.c: Updated comment sql/field.cc: false -> FALSE sql/ha_ndbcluster.cc: Fix some style issues - No () around argument to 'case' - Space before ( in switch and if - Removed 'goto' - Added {} - Added () to make expressions easier to read - my_snprintf -> strmov sql/handler.cc: if( -> if ( sql/item.cc: Indentation changes sql/item.h: false -> FALSE sql/item_cmpfunc.cc: Ensure that Item_func_case() check for stack overrun properly sql/item_cmpfunc.h: Ensure that Item_func_case() check for stack overrun properly sql/item_func.cc: Indentation fixes Fixed wrong goto label sql/mysqld.cc: Remove test for opt_disable_networking as this flag can never be set here sql/opt_range.cc: Simplify code sql/sql_class.h: Move define out from middle of class definition sql/sql_parse.cc: Remove extra empty lines sql/sql_select.cc: use real_item() instead of (Item_ref*) item Modifed function comment to be align with others Simple optimization sql/sql_union.cc: Portability fix: Don't use 'bool_variable|=...' sql/sql_view.cc: Move List_iterator_fast out from loops (rewind is faster than creating a new itearator) strings/ctype-utf8.c: if( -> if ( strings/ctype.c: Remove disabled code strings/decimal.c: Indentation fixes strings/xml.c: Indentation fixes
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc2
-rw-r--r--sql/ha_ndbcluster.cc379
-rw-r--r--sql/handler.cc2
-rw-r--r--sql/item.cc15
-rw-r--r--sql/item.h2
-rw-r--r--sql/item_cmpfunc.cc17
-rw-r--r--sql/item_cmpfunc.h1
-rw-r--r--sql/item_func.cc23
-rw-r--r--sql/mysqld.cc11
-rw-r--r--sql/opt_range.cc15
-rw-r--r--sql/sql_class.h12
-rw-r--r--sql/sql_parse.cc4
-rw-r--r--sql/sql_select.cc65
-rw-r--r--sql/sql_union.cc4
-rw-r--r--sql/sql_view.cc23
15 files changed, 319 insertions, 256 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 2cfd162899c..2ce3228be0a 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -2479,7 +2479,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());
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index 00623251c29..976a3eeead0 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;
}
}
@@ -515,8 +515,10 @@ int ha_ndbcluster::ndb_err(NdbTransaction *trans)
if (m_rows_to_insert == 1)
m_dupkey= table->s->primary_key;
else
+ {
// We are batching inserts, offending key is not available
m_dupkey= (uint) -1;
+ }
}
DBUG_RETURN(res);
}
@@ -1385,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)
@@ -1515,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)
@@ -1578,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);
@@ -1616,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"));
@@ -1624,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;
@@ -1855,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));
}
@@ -1901,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)
@@ -2039,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);
@@ -2418,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;
}
@@ -2428,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);
@@ -2442,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:
@@ -2485,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;
@@ -2509,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));
}
@@ -2523,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));
}
@@ -2635,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);
@@ -2648,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);
@@ -2695,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);
@@ -3465,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;
@@ -3515,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;
@@ -3771,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)
@@ -3906,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;
}
@@ -3939,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;
@@ -4167,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 {
@@ -4776,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))
{
@@ -4824,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)
@@ -4853,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)
@@ -5103,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;
@@ -5594,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)) &&
@@ -5610,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)) &&
@@ -5624,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)
@@ -5647,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;
@@ -5673,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;
@@ -5782,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;
}
@@ -5885,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 */
}
@@ -5912,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;
}
@@ -6013,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",
@@ -6048,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;
}
@@ -6157,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;
@@ -6186,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>
@@ -6197,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
@@ -6262,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
@@ -6294,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
@@ -6343,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();
@@ -6390,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);
@@ -6451,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) ||
@@ -6464,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);
@@ -6481,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);
@@ -6497,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);
@@ -6513,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);
@@ -6529,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);
@@ -6545,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);
@@ -6561,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);
@@ -6571,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);
@@ -6581,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);
@@ -6592,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);
@@ -6603,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);
@@ -6611,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);
@@ -6627,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);
@@ -6643,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);
@@ -6678,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);
@@ -6700,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);
@@ -6722,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);
@@ -6746,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;
@@ -6759,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))
{
@@ -6798,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))
{
@@ -6825,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))
{
@@ -6850,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))
{
@@ -6873,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))
{
@@ -6899,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);
@@ -6919,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;
@@ -6973,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;
@@ -7000,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);
@@ -7017,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);
@@ -7030,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);
@@ -7055,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);
@@ -7080,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);
@@ -7105,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);
@@ -7130,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))
@@ -7148,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))
@@ -7166,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"));
@@ -7174,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"));
@@ -7200,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));
@@ -7219,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));
@@ -7230,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:
@@ -7244,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;
@@ -7253,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"));
}
}
@@ -7268,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/handler.cc b/sql/handler.cc
index 46a80770024..4480dbf3777 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -1954,7 +1954,7 @@ int ha_create_table_from_engine(THD* thd,
bzero((char*) &create_info,sizeof(create_info));
- if(error= ha_discover(thd, db, name, &frmblob, &frmlen))
+ if ((error= ha_discover(thd, db, name, &frmblob, &frmlen)))
{
// Table could not be discovered and thus not created
DBUG_RETURN(error);
diff --git a/sql/item.cc b/sql/item.cc
index d3888cef9d5..deab704fa24 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -4366,18 +4366,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);
@@ -5153,8 +5151,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.h b/sql/item.h
index c8180b4932a..bd843add4ef 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -593,7 +593,7 @@ public:
virtual bool set_flags_processor(byte *args)
{
this->item_flags|= *((uint8*)args);
- return false;
+ return FALSE;
}
virtual bool is_splocal() { return 0; } /* Needed for error checking */
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 58a7f3316d7..a3be5ec6cd1 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();
@@ -1581,6 +1581,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 7a22e76b217..33c9e518860 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 1dbf28b67cb..c347cd2913b 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1882,8 +1882,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;
@@ -1891,16 +1890,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;
@@ -4451,7 +4451,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;
@@ -4809,7 +4810,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
@@ -4824,7 +4825,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
@@ -4836,7 +4837,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
@@ -4859,8 +4860,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
@@ -4868,7 +4869,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 2dbc8fdac96..915668aa7b1 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -2991,9 +2991,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_
@@ -3005,14 +3003,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 05028c4e2a5..65db1a290f6 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);
@@ -8153,7 +8150,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.
*/
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 d6a719e65f9..6b65f24e289 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2351,10 +2351,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 13c5c7cd716..a31e4203a93 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -7978,9 +7978,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,
@@ -7990,6 +7992,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:
@@ -11791,14 +11794,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
@@ -11815,6 +11817,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
@@ -11866,20 +11870,18 @@ 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)
{
from_field= find_field_in_tables(thd, (Item_ident*) order_item, tables,
&view_ref, IGNORE_ERRORS, TRUE);
- 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 &&
@@ -11892,37 +11894,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 87b67a5127a..bf657ce5396 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -646,14 +646,14 @@ bool st_select_lex::cleanup()
if (join)
{
- 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 0b351407c13..25610f8749b 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);
@@ -852,13 +855,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;
}
}