summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <magnus@neptunus.(none)>2004-05-17 09:57:02 +0200
committerunknown <magnus@neptunus.(none)>2004-05-17 09:57:02 +0200
commit4d3f8f210a27e6294be450e48419fa6c68a83490 (patch)
tree6c93441c16c48609ee517800ad11dcd287aff83e /sql
parent2ddc1888267d14707771fe8309627de7e354a42e (diff)
parent8ef62cc1ef3e2b16795fa5fbbc45bcdf422f344c (diff)
downloadmariadb-git-4d3f8f210a27e6294be450e48419fa6c68a83490.tar.gz
Merge
sql/ha_ndbcluster.cc: Auto merged sql/handler.cc: Auto merged sql/handler.h: Auto merged sql/sql_table.cc: Auto merged sql/ha_ndbcluster.h: SCCS merged
Diffstat (limited to 'sql')
-rw-r--r--sql/examples/ha_example.cc11
-rw-r--r--sql/field.cc9
-rw-r--r--sql/ha_berkeley.cc29
-rw-r--r--sql/ha_berkeley.h7
-rw-r--r--sql/ha_heap.cc34
-rw-r--r--sql/ha_heap.h5
-rw-r--r--sql/ha_innodb.cc41
-rw-r--r--sql/ha_innodb.h6
-rw-r--r--sql/ha_isam.cc23
-rw-r--r--sql/ha_isam.h6
-rw-r--r--sql/ha_myisam.cc26
-rw-r--r--sql/ha_myisam.h6
-rw-r--r--sql/ha_myisammrg.cc16
-rw-r--r--sql/ha_myisammrg.h6
-rw-r--r--sql/ha_ndbcluster.cc25
-rw-r--r--sql/ha_ndbcluster.h7
-rw-r--r--sql/handler.cc66
-rw-r--r--sql/handler.h25
-rw-r--r--sql/item_subselect.cc107
-rw-r--r--sql/item_subselect.h4
-rw-r--r--sql/item_sum.cc8
-rw-r--r--sql/item_sum.h8
-rw-r--r--sql/key.cc76
-rw-r--r--sql/mysql_priv.h5
-rw-r--r--sql/opt_range.cc81
-rw-r--r--sql/opt_range.h7
-rw-r--r--sql/opt_sum.cc2
-rw-r--r--sql/sql_acl.cc22
-rw-r--r--sql/sql_base.cc9
-rw-r--r--sql/sql_class.cc2
-rw-r--r--sql/sql_lex.cc3
-rw-r--r--sql/sql_lex.h1
-rw-r--r--sql/sql_select.cc52
-rw-r--r--sql/sql_select.h1
-rw-r--r--sql/sql_table.cc12
-rw-r--r--sql/sql_union.cc29
-rw-r--r--sql/sql_yacc.yy4
37 files changed, 454 insertions, 327 deletions
diff --git a/sql/examples/ha_example.cc b/sql/examples/ha_example.cc
index b8ae5967475..2d17caf1a83 100644
--- a/sql/examples/ha_example.cc
+++ b/sql/examples/ha_example.cc
@@ -625,14 +625,11 @@ int ha_example::rename_table(const char * from, const char * to)
Called from opt_range.cc by check_quick_keys().
*/
-ha_rows ha_example::records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag)
+ha_rows ha_example::records_in_range(uint inx, key_range *min_key,
+ key_range *max_key)
{
- DBUG_ENTER("ha_example::records_in_range ");
- DBUG_RETURN(records);
+ DBUG_ENTER("ha_example::records_in_range");
+ DBUG_RETURN(10); // low number to force index usage
}
diff --git a/sql/field.cc b/sql/field.cc
index edaa29dbaa0..1ad7e039363 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -4252,12 +4252,13 @@ int Field_string::cmp(const char *a_ptr, const char *b_ptr)
like in latin_de 'ae' and 0xe4
*/
return field_charset->coll->strnncollsp(field_charset,
- (const uchar*) a_ptr, field_length,
- (const uchar*) b_ptr, field_length);
+ (const uchar*) a_ptr, field_length,
+ (const uchar*) b_ptr,
+ field_length);
}
return field_charset->coll->strnncoll(field_charset,
- (const uchar*) a_ptr, field_length,
- (const uchar*) b_ptr, field_length);
+ (const uchar*) a_ptr, field_length,
+ (const uchar*) b_ptr, field_length);
}
void Field_string::sort_string(char *to,uint length)
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc
index 593b9575fb6..4dde893116f 100644
--- a/sql/ha_berkeley.cc
+++ b/sql/ha_berkeley.cc
@@ -1542,7 +1542,7 @@ int ha_berkeley::index_next_same(byte * buf, const byte *key, uint keylen)
{
error=read_row(cursor->c_get(cursor, &last_key, &row, DB_NEXT),
(char*) buf, active_index, &row, &last_key, 1);
- if (!error && ::key_cmp(table, key, active_index, keylen))
+ if (!error && ::key_cmp_if_same(table, key, active_index, keylen))
error=HA_ERR_END_OF_FILE;
}
DBUG_RETURN(error);
@@ -1987,11 +1987,8 @@ double ha_berkeley::scan_time()
return rows2double(records/3);
}
-ha_rows ha_berkeley::records_in_range(int keynr,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag)
+ha_rows ha_berkeley::records_in_range(uint keynr, key_range *start_key,
+ key_range *end_key)
{
DBT key;
DB_KEY_RANGE start_range, end_range;
@@ -2000,25 +1997,27 @@ ha_rows ha_berkeley::records_in_range(int keynr,
DBUG_ENTER("records_in_range");
if ((start_key && kfile->key_range(kfile,transaction,
- pack_key(&key, keynr, key_buff, start_key,
- start_key_len),
- &start_range,0)) ||
+ pack_key(&key, keynr, key_buff,
+ start_key->key,
+ start_key->length),
+ &start_range,0)) ||
(end_key && kfile->key_range(kfile,transaction,
- pack_key(&key, keynr, key_buff, end_key,
- end_key_len),
+ pack_key(&key, keynr, key_buff,
+ end_key->key,
+ end_key->length),
&end_range,0)))
DBUG_RETURN(HA_BERKELEY_RANGE_COUNT); // Better than returning an error /* purecov: inspected */
if (!start_key)
- start_pos=0.0;
- else if (start_search_flag == HA_READ_KEY_EXACT)
+ start_pos= 0.0;
+ else if (start_key->flag == HA_READ_KEY_EXACT)
start_pos=start_range.less;
else
start_pos=start_range.less+start_range.equal;
if (!end_key)
- end_pos=1.0;
- else if (end_search_flag == HA_READ_BEFORE_KEY)
+ end_pos= 1.0;
+ else if (end_key->flag == HA_READ_BEFORE_KEY)
end_pos=end_range.less;
else
end_pos=end_range.less+end_range.equal;
diff --git a/sql/ha_berkeley.h b/sql/ha_berkeley.h
index 88af2326eac..4bc8e3a5777 100644
--- a/sql/ha_berkeley.h
+++ b/sql/ha_berkeley.h
@@ -143,12 +143,7 @@ class ha_berkeley: public handler
int optimize(THD* thd, HA_CHECK_OPT* check_opt);
int check(THD* thd, HA_CHECK_OPT* check_opt);
- ha_rows records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag);
-
+ ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
int create(const char *name, register TABLE *form,
HA_CREATE_INFO *create_info);
int delete_table(const char *name);
diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc
index 12b922e6fc0..9915dc90dc1 100644
--- a/sql/ha_heap.cc
+++ b/sql/ha_heap.cc
@@ -363,28 +363,20 @@ int ha_heap::rename_table(const char * from, const char * to)
return heap_rename(from,to);
}
-ha_rows ha_heap::records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag)
+
+ha_rows ha_heap::records_in_range(uint inx, key_range *min_key,
+ key_range *max_key)
{
- KEY *pos=table->key_info+inx;
- if (pos->algorithm == HA_KEY_ALG_BTREE)
- {
- return hp_rb_records_in_range(file, inx, start_key, start_key_len,
- start_search_flag, end_key, end_key_len,
- end_search_flag);
- }
- else
- {
- if (start_key_len != end_key_len ||
- start_key_len != pos->key_length ||
- start_search_flag != HA_READ_KEY_EXACT ||
- end_search_flag != HA_READ_AFTER_KEY)
- return HA_POS_ERROR; // Can't only use exact keys
- return 10; // Good guess
- }
+ KEY *key=table->key_info+inx;
+ if (key->algorithm == HA_KEY_ALG_BTREE)
+ return hp_rb_records_in_range(file, inx, min_key, max_key);
+
+ if (min_key->length != max_key->length ||
+ min_key->length != key->key_length ||
+ min_key->flag != HA_READ_KEY_EXACT ||
+ max_key->flag != HA_READ_AFTER_KEY)
+ return HA_POS_ERROR; // Can't only use exact keys
+ return 10; // Good guess
}
diff --git a/sql/ha_heap.h b/sql/ha_heap.h
index 2f849d2574b..f55eda91149 100644
--- a/sql/ha_heap.h
+++ b/sql/ha_heap.h
@@ -86,10 +86,7 @@ class ha_heap: public handler
int disable_indexes(uint mode);
int enable_indexes(uint mode);
int indexes_are_disabled(void);
- ha_rows records_in_range(int inx, const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag);
+ ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
int delete_table(const char *from);
int rename_table(const char * from, const char * to);
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 201ec8f183f..ff491a95043 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -3925,18 +3925,11 @@ ha_innobase::records_in_range(
/*==========================*/
/* out: estimated number of
rows */
- int keynr, /* in: index number */
- const mysql_byte* start_key, /* in: start key value of the
- range, may also be empty */
- uint start_key_len, /* in: start key val len, may
- also be 0 */
- enum ha_rkey_function start_search_flag,/* in: start search condition
- e.g., 'greater than' */
- const mysql_byte* end_key, /* in: range end key val, may
- also be empty */
- uint end_key_len, /* in: range end key val len,
- may also be 0 */
- enum ha_rkey_function end_search_flag)/* in: range end search cond */
+ uint keynr, /* in: index number */
+ key_range *min_key, /* in: start key value of the
+ range, may also be 0 */
+ key_range *max_key) /* in: range end key val, may
+ also be 0 */
{
row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt;
KEY* key;
@@ -3957,12 +3950,6 @@ ha_innobase::records_in_range(
DBUG_ENTER("records_in_range");
- /* We do not know if MySQL can call this function before calling
- external_lock(). To be safe, update the thd of the current table
- handle. */
-
- update_thd(current_thd);
-
prebuilt->trx->op_info = (char*)"estimating records in index range";
/* In case MySQL calls this in the middle of a SELECT query, release
@@ -3986,17 +3973,21 @@ ha_innobase::records_in_range(
range_start, (byte*) key_val_buff,
(ulint)upd_and_key_val_buff_len,
index,
- (byte*) start_key,
- (ulint) start_key_len);
+ (byte*) (min_key ? min_key->key :
+ (const mysql_byte*) 0),
+ (ulint) (min_key ? min_key->length : 0));
row_sel_convert_mysql_key_to_innobase(
range_end, (byte*) key_val_buff2,
buff2_len, index,
- (byte*) end_key,
- (ulint) end_key_len);
-
- mode1 = convert_search_mode_to_innobase(start_search_flag);
- mode2 = convert_search_mode_to_innobase(end_search_flag);
+ (byte*) (max_key ? max_key->key :
+ (const mysql_byte*) 0),
+ (ulint) (max_key ? max_key->length : 0));
+
+ mode1 = convert_search_mode_to_innobase(min_key ? min_key->flag :
+ HA_READ_KEY_EXACT);
+ mode2 = convert_search_mode_to_innobase(max_key ? max_key->flag :
+ HA_READ_KEY_EXACT);
n_rows = btr_estimate_n_rows_in_range(index, range_start,
mode1, range_end, mode2);
diff --git a/sql/ha_innodb.h b/sql/ha_innodb.h
index 83a3edc4126..c585fd9c463 100644
--- a/sql/ha_innodb.h
+++ b/sql/ha_innodb.h
@@ -166,11 +166,7 @@ class ha_innobase: public handler
int start_stmt(THD *thd);
void position(byte *record);
- ha_rows records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag);
+ ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
ha_rows estimate_number_of_rows();
int create(const char *name, register TABLE *form,
diff --git a/sql/ha_isam.cc b/sql/ha_isam.cc
index 09c2aeceafc..85ab25a31d9 100644
--- a/sql/ha_isam.cc
+++ b/sql/ha_isam.cc
@@ -382,18 +382,21 @@ int ha_isam::create(const char *name, register TABLE *form,
}
+static key_range no_range= { (byte*) 0, 0, HA_READ_KEY_EXACT };
-ha_rows ha_isam::records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag)
+ha_rows ha_isam::records_in_range(uint inx, key_range *min_key,
+ key_range *max_key)
{
+ /* ISAM checks if 'key' pointer <> 0 to know if there is no range */
+ if (!min_key)
+ min_key= &no_range;
+ if (!max_key)
+ max_key= &no_range;
return (ha_rows) nisam_records_in_range(file,
- inx,
- start_key,start_key_len,
- start_search_flag,
- end_key,end_key_len,
- end_search_flag);
+ (int) inx,
+ min_key->key, min_key->length,
+ min_key->flag,
+ max_key->key, max_key->length,
+ max_key->flag);
}
#endif /* HAVE_ISAM */
diff --git a/sql/ha_isam.h b/sql/ha_isam.h
index 2c8ec274145..8a887ababde 100644
--- a/sql/ha_isam.h
+++ b/sql/ha_isam.h
@@ -70,11 +70,7 @@ class ha_isam: public handler
void info(uint);
int extra(enum ha_extra_function operation);
int external_lock(THD *thd, int lock_type);
- ha_rows records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag);
+ ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 1b24633953d..feac5c51dce 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -1515,19 +1515,15 @@ longlong ha_myisam::get_auto_increment()
SYNOPSIS
records_in_range()
inx Index to use
- start_key Start of range. Null pointer if from first key
- start_key_len Length of start key
- start_search_flag Flag if start key should be included or not
- end_key End of range. Null pointer if to last key
- end_key_len Length of end key
- end_search_flag Flag if start key should be included or not
+ min_key Start of range. Null pointer if from first key
+ max_key End of range. Null pointer if to last key
NOTES
- start_search_flag can have one of the following values:
+ min_key.flag can have one of the following values:
HA_READ_KEY_EXACT Include the key in the range
HA_READ_AFTER_KEY Don't include key in range
- end_search_flag can have one of the following values:
+ max_key.flag can have one of the following values:
HA_READ_BEFORE_KEY Don't include key in range
HA_READ_AFTER_KEY Include all 'end_key' values in the range
@@ -1538,18 +1534,10 @@ longlong ha_myisam::get_auto_increment()
the range.
*/
-ha_rows ha_myisam::records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag)
+ha_rows ha_myisam::records_in_range(uint inx, key_range *min_key,
+ key_range *max_key)
{
- return (ha_rows) mi_records_in_range(file,
- inx,
- start_key,start_key_len,
- start_search_flag,
- end_key,end_key_len,
- end_search_flag);
+ return (ha_rows) mi_records_in_range(file, (int) inx, min_key, max_key);
}
diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h
index 206a1c62a2f..77887220903 100644
--- a/sql/ha_myisam.h
+++ b/sql/ha_myisam.h
@@ -110,11 +110,7 @@ class ha_myisam: public handler
int indexes_are_disabled(void);
void start_bulk_insert(ha_rows rows);
int end_bulk_insert();
- ha_rows records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag);
+ ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
void update_create_info(HA_CREATE_INFO *create_info);
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc
index 041d9eaead3..9aa6d039efb 100644
--- a/sql/ha_myisammrg.cc
+++ b/sql/ha_myisammrg.cc
@@ -199,20 +199,14 @@ void ha_myisammrg::position(const byte *record)
ha_store_ptr(ref, ref_length, (my_off_t) position);
}
-ha_rows ha_myisammrg::records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag)
+
+ha_rows ha_myisammrg::records_in_range(uint inx, key_range *min_key,
+ key_range *max_key)
{
- return (ha_rows) myrg_records_in_range(file,
- inx,
- start_key,start_key_len,
- start_search_flag,
- end_key,end_key_len,
- end_search_flag);
+ return (ha_rows) myrg_records_in_range(file, (int) inx, min_key, max_key);
}
+
void ha_myisammrg::info(uint flag)
{
MYMERGE_INFO info;
diff --git a/sql/ha_myisammrg.h b/sql/ha_myisammrg.h
index c0f81a77a1e..fd36c78202d 100644
--- a/sql/ha_myisammrg.h
+++ b/sql/ha_myisammrg.h
@@ -70,11 +70,7 @@ class ha_myisammrg: public handler
int rnd_next(byte *buf);
int rnd_pos(byte * buf, byte *pos);
void position(const byte *record);
- ha_rows records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag);
+ ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
my_off_t row_position() { return myrg_position(file); }
void info(uint);
int extra(enum ha_extra_function operation);
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index a2dad79dab7..98ddf07b654 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -3048,22 +3048,19 @@ void ha_ndbcluster::set_dbname(const char *path_name)
ha_rows
-ha_ndbcluster::records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag)
-{
- ha_rows records= 10;
- KEY* key_info= table->key_info + inx;
+ha_ndbcluster::records_in_range(uint inx, key_range *min_key,
+ key_range *max_key)
+{
+ ha_rows records= 10; /* Good guess when you don't know anything */
+ KEY *key_info= table->key_info + inx;
uint key_length= key_info->key_length;
DBUG_ENTER("records_in_range");
- DBUG_PRINT("enter", ("inx: %d", inx));
- DBUG_PRINT("enter", ("start_key: %x, start_key_len: %d", start_key, start_key_len));
- DBUG_PRINT("enter", ("start_search_flag: %d", start_search_flag));
- DBUG_PRINT("enter", ("end_key: %x, end_key_len: %d", end_key, end_key_len));
- DBUG_PRINT("enter", ("end_search_flag: %d", end_search_flag));
+ DBUG_PRINT("enter", ("inx: %u", inx));
+ DBUG_DUMP("start_key", min_key->key, min_key->length);
+ DBUG_DUMP("end_key", max_key->key, max_key->length);
+ DBUG_PRINT("enter", ("start_search_flag: %u end_search_flag: %u",
+ min_key->flag, max_key->flag));
#ifndef USE_EXTRA_ORDERED_INDEX
/*
@@ -3073,7 +3070,7 @@ ha_ndbcluster::records_in_range(int inx,
*/
NDB_INDEX_TYPE idx_type= get_index_type(inx);
if ((idx_type == UNIQUE_INDEX || idx_type == PRIMARY_KEY_INDEX) &&
- start_key_len < key_length)
+ min_key->length < key_length)
{
DBUG_PRINT("warning", ("Tried to use index which required"
"full key length: %d, HA_POS_ERROR",
diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h
index b18f81dbf7e..7b182d81ff5 100644
--- a/sql/ha_ndbcluster.h
+++ b/sql/ha_ndbcluster.h
@@ -126,12 +126,7 @@ class ha_ndbcluster: public handler
}
double scan_time();
- ha_rows records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag);
-
+ ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
void start_bulk_insert(ha_rows rows);
int end_bulk_insert();
diff --git a/sql/handler.cc b/sql/handler.cc
index 5a7f9e8fc28..3301dd7c04e 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -1213,7 +1213,7 @@ int handler::index_next_same(byte *buf, const byte *key, uint keylen)
int error;
if (!(error=index_next(buf)))
{
- if (key_cmp(table, key, active_index, keylen))
+ if (key_cmp_if_same(table, key, active_index, keylen))
{
table->status=STATUS_NOT_FOUND;
error=HA_ERR_END_OF_FILE;
@@ -1417,6 +1417,7 @@ int ha_discover(const char* dbname, const char* name,
read_range_first()
start_key Start key. Is 0 if no min range
end_key End key. Is 0 if no max range
+ eq_range_arg Set to 1 if start_key == end_key
sorted Set to 1 if result should be sorted per key
NOTES
@@ -1430,11 +1431,12 @@ int ha_discover(const char* dbname, const char* name,
int handler::read_range_first(const key_range *start_key,
const key_range *end_key,
- bool sorted)
+ bool eq_range_arg, bool sorted)
{
int result;
DBUG_ENTER("handler::read_range_first");
+ eq_range= eq_range_arg;
end_range= 0;
if (end_key)
{
@@ -1445,7 +1447,6 @@ int handler::read_range_first(const key_range *start_key,
}
range_key_part= table->key_info[active_index].key_part;
-
if (!start_key) // Read first record
result= index_first(table->record[0]);
else
@@ -1467,7 +1468,6 @@ int handler::read_range_first(const key_range *start_key,
SYNOPSIS
read_range_next()
- eq_range Set to 1 if start_key == end_key
NOTES
Record is read into table->record[0]
@@ -1478,17 +1478,19 @@ int handler::read_range_first(const key_range *start_key,
# Error code
*/
-int handler::read_range_next(bool eq_range)
+int handler::read_range_next()
{
int result;
DBUG_ENTER("handler::read_range_next");
if (eq_range)
- result= index_next_same(table->record[0],
- end_range->key,
- end_range->length);
- else
- result= index_next(table->record[0]);
+ {
+ /* We trust that index_next_same always gives a row in range */
+ DBUG_RETURN(index_next_same(table->record[0],
+ end_range->key,
+ end_range->length));
+ }
+ result= index_next(table->record[0]);
if (result)
DBUG_RETURN(result);
DBUG_RETURN(compare_key(end_range) <= 0 ? 0 : HA_ERR_END_OF_FILE);
@@ -1496,16 +1498,18 @@ int handler::read_range_next(bool eq_range)
/*
- Compare if found key is over max-value
+ Compare if found key (in row) is over max-value
SYNOPSIS
compare_key
- range key to compare to row
+ range range to compare to row. May be 0 for no range
NOTES
- For this to work, the row must be stored in table->record[0]
+ See key.cc::key_cmp() for details
RETURN
+ The return value is SIGN(key_in_row - range_key):
+
0 Key is equal to range or 'range' == 0 (no range)
-1 Key is less than range
1 Key is larger than range
@@ -1513,37 +1517,11 @@ int handler::read_range_next(bool eq_range)
int handler::compare_key(key_range *range)
{
- KEY_PART_INFO *key_part= range_key_part;
- uint store_length;
-
+ int cmp;
if (!range)
return 0; // No max range
-
- for (const char *key= (const char*) range->key, *end=key+range->length;
- key < end;
- key+= store_length, key_part++)
- {
- int cmp;
- store_length= key_part->store_length;
- if (key_part->null_bit)
- {
- if (*key)
- {
- if (!key_part->field->is_null())
- return 1;
- continue;
- }
- else if (key_part->field->is_null())
- return 0;
- key++; // Skip null byte
- store_length--;
- }
- if ((cmp=key_part->field->key_cmp((byte*) key, key_part->length)) < 0)
- return -1;
- if (cmp > 0)
- return 1;
- }
- return key_compare_result_on_equal;
+ cmp= key_cmp(range_key_part, range->key, range->length);
+ if (!cmp)
+ cmp= key_compare_result_on_equal;
+ return cmp;
}
-
-
diff --git a/sql/handler.h b/sql/handler.h
index ddf7d94c547..17151877286 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -234,14 +234,6 @@ typedef struct st_ha_check_opt
} HA_CHECK_OPT;
-typedef struct st_key_range
-{
- const byte *key;
- uint length;
- enum ha_rkey_function flag;
-} key_range;
-
-
class handler :public Sql_alloc
{
protected:
@@ -268,6 +260,7 @@ public:
key_range save_end_range, *end_range;
KEY_PART_INFO *range_key_part;
int key_compare_result_on_equal;
+ bool eq_range;
uint errkey; /* Last dup key */
uint sortkey, key_used_on_scan;
@@ -331,13 +324,14 @@ public:
return (my_errno=HA_ERR_WRONG_COMMAND);
}
virtual int read_range_first(const key_range *start_key,
- const key_range *end_key,
- bool sorted);
- virtual int read_range_next(bool eq_range);
+ const key_range *end_key,
+ bool eq_range, bool sorted);
+ virtual int read_range_next();
int compare_key(key_range *range);
virtual int ft_init()
{ return -1; }
- virtual FT_INFO *ft_init_ext(uint flags,uint inx,const byte *key, uint keylen)
+ virtual FT_INFO *ft_init_ext(uint flags,uint inx,const byte *key,
+ uint keylen)
{ return NULL; }
virtual int ft_read(byte *buf) { return -1; }
virtual int rnd_init(bool scan=1)=0;
@@ -346,11 +340,8 @@ public:
virtual int rnd_pos(byte * buf, byte *pos)=0;
virtual int read_first_row(byte *buf, uint primary_key);
virtual int restart_rnd_next(byte *buf, byte *pos);
- virtual ha_rows records_in_range(int inx,
- const byte *start_key,uint start_key_len,
- enum ha_rkey_function start_search_flag,
- const byte *end_key,uint end_key_len,
- enum ha_rkey_function end_search_flag)
+ virtual ha_rows records_in_range(uint inx, key_range *min_key,
+ key_range *max_key)
{ return (ha_rows) 10; }
virtual void position(const byte *record)=0;
virtual my_off_t row_position() { return HA_OFFSET_ERROR; }
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 2d10be62d53..4503c1b63a9 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -56,10 +56,24 @@ void Item_subselect::init(st_select_lex *select_lex,
DBUG_PRINT("subs", ("select_lex 0x%xl", (ulong) select_lex));
unit= select_lex->master_unit();
- if (select_lex->next_select())
- engine= new subselect_union_engine(unit, result, this);
+ if (unit->item)
+ {
+ /*
+ Item can be changed in JOIN::prepare while engine in JOIN::optimize
+ => we do not copy old_engine here
+ */
+ engine= unit->item->engine;
+ unit->item->engine= 0;
+ unit->item= this;
+ engine->change_item(this, result);
+ }
else
- engine= new subselect_single_select_engine(select_lex, result, this);
+ {
+ if (select_lex->next_select())
+ engine= new subselect_union_engine(unit, result, this);
+ else
+ engine= new subselect_single_select_engine(select_lex, result, this);
+ }
DBUG_VOID_RETURN;
}
@@ -69,11 +83,13 @@ void Item_subselect::cleanup()
Item_result_field::cleanup();
if (old_engine)
{
- engine->cleanup();
+ if (engine)
+ engine->cleanup();
engine= old_engine;
old_engine= 0;
}
- engine->cleanup();
+ if (engine)
+ engine->cleanup();
reset();
value_assigned= 0;
DBUG_VOID_RETURN;
@@ -127,7 +143,6 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref)
if (have_to_be_excluded)
engine->exclude();
substitution= 0;
- fixed= 1;
thd->where= "checking transformed subquery";
if (!(*ref)->fixed)
ret= (*ref)->fix_fields(thd, tables, ref);
@@ -660,10 +675,20 @@ Item_in_subselect::single_value_transformer(JOIN *join,
item= new Item_sum_min(*select_lex->ref_pointer_array);
}
*select_lex->ref_pointer_array= item;
- select_lex->item_list.empty();
- select_lex->item_list.push_back(item);
+ {
+ List_iterator<Item> it(select_lex->item_list);
+ it++;
+ it.replace(item);
+ }
- // fix_fields call for 'item' will be made during new subquery fix_fields
+ /*
+ Item_sum_(max|min) can't substitute other item => we can use 0 as
+ reference
+ */
+ if (item->fix_fields(thd, join->tables_list, 0))
+ goto err;
+ /* we added aggregate function => we have to change statistic */
+ count_field_types(&join->tmp_table_param, join->all_fields, 0);
subs= new Item_singlerow_subselect(select_lex);
}
@@ -1428,3 +1453,67 @@ void subselect_indexsubquery_engine::print(String *str)
}
str->append(')');
}
+
+/*
+ change select_result object of engine
+
+ SINOPSYS
+ subselect_single_select_engine::change_result()
+ si new subselect Item
+ res new select_result object
+
+ RETURN
+ 0 OK
+ -1 error
+*/
+
+int subselect_single_select_engine::change_item(Item_subselect *si,
+ select_subselect *res)
+{
+ item= si;
+ result= res;
+ return select_lex->join->change_result(result);
+}
+
+
+/*
+ change select_result object of engine
+
+ SINOPSYS
+ subselect_single_select_engine::change_result()
+ si new subselect Item
+ res new select_result object
+
+ RETURN
+ 0 OK
+ -1 error
+*/
+
+int subselect_union_engine::change_item(Item_subselect *si,
+ select_subselect *res)
+{
+ item= si;
+ int rc= unit->change_result(res, result);
+ result= res;
+ return rc;
+}
+
+
+/*
+ change select_result emulation, never should be called
+
+ SINOPSYS
+ subselect_single_select_engine::change_result()
+ si new subselect Item
+ res new select_result object
+
+ RETURN
+ -1 error
+*/
+
+int subselect_uniquesubquery_engine::change_item(Item_subselect *si,
+ select_subselect *res)
+{
+ DBUG_ASSERT(0);
+ return -1;
+}
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 6d8f5353695..364781de362 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -290,6 +290,7 @@ public:
virtual table_map upper_select_const_tables()= 0;
static table_map calc_const_tables(TABLE_LIST *);
virtual void print(String *str)= 0;
+ virtual int change_item(Item_subselect *si, select_subselect *result)= 0;
};
@@ -313,6 +314,7 @@ public:
void exclude();
table_map upper_select_const_tables();
void print (String *str);
+ int change_item(Item_subselect *si, select_subselect *result);
};
@@ -332,6 +334,7 @@ public:
void exclude();
table_map upper_select_const_tables();
void print (String *str);
+ int change_item(Item_subselect *si, select_subselect *result);
};
@@ -360,6 +363,7 @@ public:
void exclude();
table_map upper_select_const_tables() { return 0; }
void print (String *str);
+ int change_item(Item_subselect *si, select_subselect *result);
};
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index eac8d31b256..0c5b29fc069 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -502,6 +502,14 @@ void Item_sum_variance::update_field()
/* min & max */
+void Item_sum_hybrid::clear()
+{
+ sum= 0.0;
+ sum_int= 0;
+ value.length(0);
+ null_value= 1;
+}
+
double Item_sum_hybrid::val()
{
DBUG_ASSERT(fixed == 1);
diff --git a/sql/item_sum.h b/sql/item_sum.h
index 4cded41a9f6..ef947900fd2 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -415,13 +415,7 @@ class Item_sum_hybrid :public Item_sum
table_map used_tables() const { return used_table_cache; }
bool const_item() const { return !used_table_cache; }
- void clear()
- {
- sum=0.0;
- sum_int=0;
- value.length(0);
- null_value=1;
- }
+ void clear();
double val();
longlong val_int();
void reset_field();
diff --git a/sql/key.cc b/sql/key.cc
index a2c3b2c8989..9425a368669 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -156,9 +156,28 @@ void key_restore(TABLE *table,byte *key,uint idx,uint key_length)
} /* key_restore */
- /* Compare if a key has changed */
+/*
+ Compare if a key has changed
+
+ SYNOPSIS
+ key_cmp_if_same()
+ table TABLE
+ key key to compare to row
+ idx Index used
+ key_length Length of key
+
+ NOTES
+ In theory we could just call field->cmp() for all field types,
+ but as we are only interested if a key has changed (not if the key is
+ larger or smaller than the previous value) we can do things a bit
+ faster by using memcmp() instead.
+
+ RETURN
+ 0 If key is equal
+ 1 Key has changed
+*/
-int key_cmp(TABLE *table,const byte *key,uint idx,uint key_length)
+bool key_cmp_if_same(TABLE *table,const byte *key,uint idx,uint key_length)
{
uint length;
KEY_PART_INFO *key_part;
@@ -281,3 +300,56 @@ bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields)
return check_if_key_used(table, table->primary_key, fields);
return 0;
}
+
+
+/*
+ Compare key in row to a given key
+
+ SYNOPSIS
+ key_cmp()
+ key_part Key part handler
+ key Key to compare to value in table->record[0]
+ key_length length of 'key'
+
+ RETURN
+ The return value is SIGN(key_in_row - range_key):
+
+ 0 Key is equal to range or 'range' == 0 (no range)
+ -1 Key is less than range
+ 1 Key is larger than range
+*/
+
+int key_cmp(KEY_PART_INFO *key_part, const byte *key, uint key_length)
+{
+ uint store_length;
+
+ for (const byte *end=key + key_length;
+ key < end;
+ key+= store_length, key_part++)
+ {
+ int cmp;
+ store_length= key_part->store_length;
+ if (key_part->null_bit)
+ {
+ /* This key part allows null values; NULL is lower than everything */
+ register bool field_is_null= key_part->field->is_null();
+ if (*key) // If range key is null
+ {
+ /* the range is expecting a null value */
+ if (!field_is_null)
+ return 1; // Found key is > range
+ /* null -- exact match, go to next key part */
+ continue;
+ }
+ else if (field_is_null)
+ return -1; // NULL is less than any value
+ key++; // Skip null byte
+ store_length--;
+ }
+ if ((cmp=key_part->field->key_cmp((byte*) key, key_part->length)) < 0)
+ return -1;
+ if (cmp > 0)
+ return 1;
+ }
+ return 0; // Keys are equal
+}
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 8cae95e5070..14bd16332ef 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -754,11 +754,12 @@ void mysql_print_status(THD *thd);
int find_ref_key(TABLE *form,Field *field, uint *offset);
void key_copy(byte *key,TABLE *form,uint index,uint key_length);
void key_restore(TABLE *form,byte *key,uint index,uint key_length);
-int key_cmp(TABLE *form,const byte *key,uint index,uint key_length);
+bool key_cmp_if_same(TABLE *form,const byte *key,uint index,uint key_length);
void key_unpack(String *to,TABLE *form,uint index);
bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields);
-bool init_errmessage(void);
+int key_cmp(KEY_PART_INFO *key_part, const byte *key, uint key_length);
+bool init_errmessage(void);
void sql_perror(const char *message);
void sql_print_error(const char *format,...)
__attribute__ ((format (printf, 1, 2)));
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 1e7bf90738c..3cc64c35223 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -1800,8 +1800,8 @@ SEL_ARG *
SEL_ARG::insert(SEL_ARG *key)
{
SEL_ARG *element,**par,*last_element;
-
LINT_INIT(par); LINT_INIT(last_element);
+
for (element= this; element != &null_element ; )
{
last_element=element;
@@ -2296,26 +2296,32 @@ check_quick_keys(PARAM *param,uint idx,SEL_ARG *key_tree,
{
if (tmp_min_flag & GEOM_FLAG)
{
- tmp= param->table->file->
- records_in_range((int) keynr, (byte*)(param->min_key),
- min_key_length,
- (ha_rkey_function)(tmp_min_flag ^ GEOM_FLAG),
- (byte *)NullS, 0, HA_READ_KEY_EXACT);
+ key_range min_range;
+ min_range.key= (byte*) param->min_key;
+ min_range.length= min_key_length;
+ /* In this case tmp_min_flag contains the handler-read-function */
+ min_range.flag= (ha_rkey_function) (tmp_min_flag ^ GEOM_FLAG);
+
+ tmp= param->table->file->records_in_range(keynr, &min_range,
+ (key_range*) 0);
}
else
{
- tmp=param->table->file->
- records_in_range((int) keynr,
- (byte*) (!min_key_length ? NullS :
- param->min_key),
- min_key_length,
- tmp_min_flag & NEAR_MIN ?
- HA_READ_AFTER_KEY : HA_READ_KEY_EXACT,
- (byte*) (!max_key_length ? NullS :
- param->max_key),
- max_key_length,
- (tmp_max_flag & NEAR_MAX ?
- HA_READ_BEFORE_KEY : HA_READ_AFTER_KEY));
+ key_range min_range, max_range;
+
+ min_range.key= (byte*) param->min_key;
+ min_range.length= min_key_length;
+ min_range.flag= (tmp_min_flag & NEAR_MIN ? HA_READ_AFTER_KEY :
+ HA_READ_KEY_EXACT);
+ max_range.key= param->max_key;
+ max_range.length= max_key_length;
+ max_range.flag= (tmp_max_flag & NEAR_MAX ?
+ HA_READ_BEFORE_KEY : HA_READ_AFTER_KEY);
+ tmp=param->table->file->records_in_range(keynr,
+ (min_key_length ? &min_range :
+ (key_range*) 0),
+ (max_key_length ? &max_range :
+ (key_range*) 0));
}
}
end:
@@ -2604,7 +2610,7 @@ int QUICK_SELECT::get_next()
if (range)
{
// Already read through key
- result= file->read_range_next(test(range->flag & EQ_RANGE));
+ result= file->read_range_next();
if (result != HA_ERR_END_OF_FILE)
DBUG_RETURN(result);
}
@@ -2628,6 +2634,7 @@ int QUICK_SELECT::get_next()
result= file->read_range_first(range->min_length ? &start_key : 0,
range->max_length ? &end_key : 0,
+ test(range->flag & EQ_RANGE),
sorted);
if (range->flag == (UNIQUE_RANGE | EQ_RANGE))
range=0; // Stop searching
@@ -2815,40 +2822,14 @@ int QUICK_SELECT_DESC::get_next()
int QUICK_SELECT_DESC::cmp_prev(QUICK_RANGE *range_arg)
{
+ int cmp;
if (range_arg->flag & NO_MIN_RANGE)
return 0; /* key can't be to small */
- KEY_PART *key_part = key_parts;
- uint store_length;
-
- for (char *key = range_arg->min_key, *end = key + range_arg->min_length;
- key < end;
- key += store_length, key_part++)
- {
- int cmp;
- store_length= key_part->store_length;
- if (key_part->null_bit)
- {
- // this key part allows null values; NULL is lower than everything else
- if (*key)
- {
- // the range is expecting a null value
- if (!key_part->field->is_null())
- return 0; // not null -- still inside the range
- continue; // null -- exact match, go to next key part
- }
- else if (key_part->field->is_null())
- return 1; // null -- outside the range
- key++;
- store_length--;
- }
- if ((cmp = key_part->field->key_cmp((byte*) key,
- key_part->length)) > 0)
- return 0;
- if (cmp < 0)
- return 1;
- }
- return (range_arg->flag & NEAR_MIN) ? 1 : 0; // Exact match
+ cmp= key_cmp(key_part_info, range_arg->min_key, range_arg->min_length);
+ if (cmp > 0 || cmp == 0 && !(range_arg->flag & NEAR_MIN))
+ return 0;
+ return 1; // outside of range
}
diff --git a/sql/opt_range.h b/sql/opt_range.h
index 2df9d93e1ef..2072ded15d1 100644
--- a/sql/opt_range.h
+++ b/sql/opt_range.h
@@ -80,13 +80,18 @@ public:
MEM_ROOT alloc;
KEY_PART *key_parts;
+ KEY_PART_INFO *key_part_info;
ha_rows records;
double read_time;
QUICK_SELECT(THD *thd, TABLE *table,uint index_arg,bool no_alloc=0);
virtual ~QUICK_SELECT();
void reset(void) { next=0; it.rewind(); }
- int init() { return error=file->index_init(index); }
+ int init()
+ {
+ key_part_info= head->key_info[index].key_part;
+ return error=file->index_init(index);
+ }
virtual int get_next();
virtual bool reverse_sorted() { return 0; }
bool unique_key_range();
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index 4fdcd093132..8c1cd9ce1cb 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -716,7 +716,7 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref,
static int reckey_in_range(bool max_fl, TABLE_REF *ref, Field* field,
COND *cond, uint range_fl, uint prefix_len)
{
- if (key_cmp(field->table, ref->key_buff, ref->key, prefix_len))
+ if (key_cmp_if_same(field->table, ref->key_buff, ref->key, prefix_len))
return 1;
if (!cond || (range_fl & (max_fl ? NO_MIN_RANGE : NO_MAX_RANGE)))
return 0;
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 9c7fe3e2993..fbd47d4954d 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -1820,7 +1820,7 @@ GRANT_TABLE::GRANT_TABLE(TABLE *form, TABLE *col_privs)
}
my_hash_insert(&hash_columns, (byte *) mem_check);
} while (!col_privs->file->index_next(col_privs->record[0]) &&
- !key_cmp(col_privs,key,0,key_len));
+ !key_cmp_if_same(col_privs,key,0,key_len));
}
}
@@ -2043,7 +2043,7 @@ static int replace_column_table(GRANT_TABLE *g_t,
}
}
} while (!table->file->index_next(table->record[0]) &&
- !key_cmp(table,key,0,key_length));
+ !key_cmp_if_same(table,key,0,key_length));
}
end:
@@ -3064,7 +3064,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
/* Add first global access grants */
{
- String global(buff,sizeof(buff),&my_charset_latin1);
+ String global(buff,sizeof(buff),system_charset_info);
global.length(0);
global.append("GRANT ",6);
@@ -3089,7 +3089,8 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
}
}
global.append (" ON *.* TO '",12);
- global.append(lex_user->user.str,lex_user->user.length);
+ global.append(lex_user->user.str, lex_user->user.length,
+ system_charset_info);
global.append ("'@'",3);
global.append(lex_user->host.str,lex_user->host.length);
global.append ('\'');
@@ -3177,7 +3178,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
want_access=acl_db->access;
if (want_access)
{
- String db(buff,sizeof(buff),&my_charset_latin1);
+ String db(buff,sizeof(buff),system_charset_info);
db.length(0);
db.append("GRANT ",6);
@@ -3203,7 +3204,8 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
db.append (" ON ",4);
append_identifier(thd, &db, acl_db->db, strlen(acl_db->db));
db.append (".* TO '",7);
- db.append(lex_user->user.str,lex_user->user.length);
+ db.append(lex_user->user.str, lex_user->user.length,
+ system_charset_info);
db.append ("'@'",3);
db.append(lex_user->host.str, lex_user->host.length);
db.append ('\'');
@@ -3237,7 +3239,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
ulong table_access= grant_table->privs;
if ((table_access | grant_table->cols) != 0)
{
- String global(buff,sizeof(buff),&my_charset_latin1);
+ String global(buff, sizeof(buff), system_charset_info);
ulong test_access= (table_access | grant_table->cols) & ~GRANT_ACL;
global.length(0);
@@ -3291,7 +3293,8 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
else
global.append(", ",2);
global.append(grant_column->column,
- grant_column->key_length);
+ grant_column->key_length,
+ system_charset_info);
}
}
if (found_col)
@@ -3307,7 +3310,8 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
append_identifier(thd, &global, grant_table->tname,
strlen(grant_table->tname));
global.append(" TO '",5);
- global.append(lex_user->user.str,lex_user->user.length);
+ global.append(lex_user->user.str, lex_user->user.length,
+ system_charset_info);
global.append("'@'",3);
global.append(lex_user->host.str,lex_user->host.length);
global.append('\'');
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 3a18b7eaabc..14a54a410a2 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -2096,7 +2096,14 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
if (field_name && item->type() == Item::FIELD_ITEM)
{
Item_field *item_field= (Item_field*) item;
- if (!my_strcasecmp(system_charset_info, item_field->name, field_name))
+ /*
+ In case of group_concat() with ORDER BY condition in the QUERY
+ item_field can be field of temporary table without item name
+ (if this field created from expression argument of group_concat()),
+ => we have to check presence of name before compare
+ */
+ if (item_field->name &&
+ !my_strcasecmp(system_charset_info, item_field->name, field_name))
{
if (!table_name)
{
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 03d67c4f300..f7992c3db9e 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -86,7 +86,7 @@ bool key_part_spec::operator==(const key_part_spec& other) const
/*
- Test if a foreign key is a prefix of the given key
+ Test if a foreign key (= generated key) is a prefix of the given key
(ignoring key name, key type and order of columns)
NOTES:
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 5fa8b37285e..1038066f6ef 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -1710,6 +1710,7 @@ TABLE_LIST *st_lex::link_first_table_back(TABLE_LIST *tables,
st_select_lex::print is in sql_select.h
st_select_lex_unit::prepare, st_select_lex_unit::exec,
- st_select_lex_unit::cleanup, st_select_lex_unit::reinit_exec_mechanism
+ st_select_lex_unit::cleanup, st_select_lex_unit::reinit_exec_mechanism,
+ st_select_lex_unit::change_result
are in sql_union.cc
*/
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index aa3e81fd9c9..557c037c799 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -371,6 +371,7 @@ public:
void print(String *str);
ulong init_prepare_fake_select_lex(THD *thd);
+ int change_result(select_subselect *result, select_subselect *old_result);
friend void mysql_init_query(THD *thd);
friend int subselect_union_engine::exec();
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index c330d1e6b54..4325edc3502 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -665,7 +665,6 @@ JOIN::optimize()
if (!order && org_order)
skip_sort_order= 1;
}
- order= remove_const(this, order, conds, &simple_order);
if (group_list || tmp_table_param.sum_func_count)
{
if (! hidden_group_fields)
@@ -1585,8 +1584,7 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
if (select_lex->linkage != GLOBAL_OPTIONS_TYPE)
{
//here is EXPLAIN of subselect or derived table
- join->result= result;
- if (!join->procedure && result->prepare(join->fields_list, unit))
+ if (join->change_result(result))
{
DBUG_RETURN(-1);
}
@@ -6162,8 +6160,8 @@ join_read_prev_same(READ_RECORD *info)
if ((error=table->file->index_prev(table->record[0])))
return report_error(table, error);
- if (key_cmp(table, tab->ref.key_buff, tab->ref.key,
- tab->ref.key_length))
+ if (key_cmp_if_same(table, tab->ref.key_buff, tab->ref.key,
+ tab->ref.key_length))
{
table->status=STATUS_NOT_FOUND;
error= -1;
@@ -9123,7 +9121,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
THD *thd=join->thd;
select_result *result=join->result;
Item *item_null= new Item_null();
- CHARSET_INFO *cs= &my_charset_latin1;
+ CHARSET_INFO *cs= system_charset_info;
DBUG_ENTER("select_describe");
DBUG_PRINT("info", ("Select 0x%lx, type %s, message %s",
(ulong)join->select_lex, join->select_lex->type,
@@ -9190,7 +9188,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
{
if (tmp1.length())
tmp1.append(',');
- tmp1.append(table->key_info[j].name);
+ tmp1.append(table->key_info[j].name, 0, system_charset_info);
}
}
}
@@ -9209,7 +9207,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
{
if (tmp2.length())
tmp2.append(',');
- tmp2.append((*ref)->name());
+ tmp2.append((*ref)->name(), 0, system_charset_info);
}
item_list.push_back(new Item_string(tmp2.ptr(),tmp2.length(),cs));
}
@@ -9370,23 +9368,23 @@ void st_select_lex::print(THD *thd, String *str)
//options
if (options & SELECT_STRAIGHT_JOIN)
str->append("straight_join ", 14);
- if ((thd->lex->lock_option & TL_READ_HIGH_PRIORITY) &&
+ if ((thd->lex->lock_option == TL_READ_HIGH_PRIORITY) &&
(this == &thd->lex->select_lex))
str->append("high_priority ", 14);
if (options & SELECT_DISTINCT)
str->append("distinct ", 9);
if (options & SELECT_SMALL_RESULT)
- str->append("small_result ", 13);
+ str->append("sql_small_result ", 17);
if (options & SELECT_BIG_RESULT)
- str->append("big_result ", 11);
+ str->append("sql_big_result ", 15);
if (options & OPTION_BUFFER_RESULT)
- str->append("buffer_result ", 14);
+ str->append("sql_buffer_result ", 18);
if (options & OPTION_FOUND_ROWS)
- str->append("calc_found_rows ", 16);
+ str->append("sql_calc_found_rows ", 20);
if (!thd->lex->safe_to_cache_query)
- str->append("no_cache ", 9);
+ str->append("sql_no_cache ", 13);
if (options & OPTION_TO_QUERY_CACHE)
- str->append("cache ", 6);
+ str->append("sql_cache ", 10);
//Item List
bool first= 1;
@@ -9514,3 +9512,27 @@ void st_select_lex::print(THD *thd, String *str)
// PROCEDURE unsupported here
}
+
+
+/*
+ change select_result object of JOIN
+
+ SYNOPSIS
+ JOIN::change_result()
+ res new select_result object
+
+ RETURN
+ 0 - OK
+ -1 - error
+*/
+
+int JOIN::change_result(select_result *res)
+{
+ DBUG_ENTER("JOIN::change_result");
+ result= res;
+ if (!procedure && result->prepare(fields_list, select_lex->master_unit()))
+ {
+ DBUG_RETURN(-1);
+ }
+ DBUG_RETURN(0);
+}
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 5a246a477cf..8aca43484d2 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -304,6 +304,7 @@ class JOIN :public Sql_alloc
return (do_send_rows && tmp_table_param.sum_func_count != 0 &&
!group_list);
}
+ int change_result(select_result *result);
};
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index edcc77d11f4..b54c223d35a 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -683,9 +683,16 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
{
while ((key2 = key_iterator2++) != key)
{
- if ((key2->type != Key::FOREIGN_KEY && !foreign_key_prefix(key, key2)))
+ /*
+ foreign_key_prefix(key, key2) returns 0 if key or key2, or both, is
+ 'generated', and a generated key is a prefix of the other key.
+ Then we do not need the generated shorter key.
+ */
+ if ((key2->type != Key::FOREIGN_KEY &&
+ key2->name != ignore_key &&
+ !foreign_key_prefix(key, key2)))
{
- /* TO DO: issue warning message */
+ /* TODO: issue warning message */
/* mark that the generated key should be ignored */
if (!key2->generated ||
(key->generated && key->columns.elements <
@@ -693,7 +700,6 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
key->name= ignore_key;
else
{
- /* Remove the previous, generated key */
key2->name= ignore_key;
key_parts-= key2->columns.elements;
(*key_count)--;
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 63638b618d9..de3eeec0db0 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -555,3 +555,32 @@ void st_select_lex_unit::reinit_exec_mechanism()
}
#endif
}
+
+
+/*
+ change select_result object of unit
+
+ SYNOPSIS
+ st_select_lex_unit::change_result()
+ result new select_result object
+ old_result old select_result object
+
+ RETURN
+ 0 - OK
+ -1 - error
+*/
+
+int st_select_lex_unit::change_result(select_subselect *result,
+ select_subselect *old_result)
+{
+ int res= 0;
+ for (SELECT_LEX *sl= first_select_in_union(); sl; sl= sl->next_select())
+ {
+ if (sl->join && sl->join->result == old_result)
+ if ((res= sl->join->change_result(result)))
+ return (res);
+ }
+ if (fake_select_lex && fake_select_lex->join)
+ res= fake_select_lex->join->change_result(result);
+ return (res);
+}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 0f29289ac25..d7ef1fc8d7f 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -4683,8 +4683,8 @@ literal:
| TIMESTAMP text_literal { $$ = $2; };
NUM_literal:
- NUM { $$ = new Item_int($1.str, (longlong) strtol($1.str, NULL, 10),$1.length); }
- | LONG_NUM { $$ = new Item_int($1.str, (longlong) strtoll($1.str,NULL,10), $1.length); }
+ NUM { int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); }
+ | LONG_NUM { int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); }
| ULONGLONG_NUM { $$ = new Item_uint($1.str, $1.length); }
| REAL_NUM { $$ = new Item_real($1.str, $1.length); }
| FLOAT_NUM { $$ = new Item_float($1.str, $1.length); }