#At file:///media/sdb2/hezx/work/mysql/bzrwork/merge/6.0-rpl/
2813 He Zhenxing 2009-02-10 [merge]
Auto merge 6.0 -> 6.0-rpl
modified:
mysql-test/r/subselect3.result
mysql-test/r/subselect3_jcl6.result
mysql-test/t/subselect3.test
sql/handler.cc
sql/handler.h
storage/innobase/handler/ha_innodb.cc
storage/maria/ha_maria.cc
storage/myisam/ha_myisam.cc
=== modified file 'mysql-test/r/subselect3.result'
--- a/mysql-test/r/subselect3.result 2009-01-30 14:13:39 +0000
+++ b/mysql-test/r/subselect3.result 2009-02-04 11:27:06 +0000
@@ -1219,6 +1219,21 @@ id select_type table type possible_keys
1 PRIMARY Z ALL NULL NULL NULL NULL 6 End materialize; Using join buffer
drop table t0,t1,t2;
+BUG#37842: Assertion in DsMrr_impl::dsmrr_init, at handler.cc:4307
+
+CREATE TABLE t1 (
+`pk` int(11) NOT NULL AUTO_INCREMENT,
+`int_key` int(11) DEFAULT NULL,
+PRIMARY KEY (`pk`),
+KEY `int_key` (`int_key`)
+) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1,9),(2,3),(3,8),(4,6),(5,9),(6,5),(7,5),(8,9),(9,1),(10,10);
+SELECT `pk` FROM t1 AS OUTR WHERE `int_key` = ALL (
+SELECT `int_key` FROM t1 AS INNR WHERE INNR . `pk` >= 9
+);
+pk
+DROP TABLE t1;
+
BUG#40118 Crash when running Batched Key Access and requiring one match for each key
create table t0(a int);
=== modified file 'mysql-test/r/subselect3_jcl6.result'
--- a/mysql-test/r/subselect3_jcl6.result 2009-02-03 09:16:53 +0000
+++ b/mysql-test/r/subselect3_jcl6.result 2009-02-04 11:27:06 +0000
@@ -1224,6 +1224,21 @@ id select_type table type possible_keys
1 PRIMARY Z ALL NULL NULL NULL NULL 6 End materialize; Using join buffer
drop table t0,t1,t2;
+BUG#37842: Assertion in DsMrr_impl::dsmrr_init, at handler.cc:4307
+
+CREATE TABLE t1 (
+`pk` int(11) NOT NULL AUTO_INCREMENT,
+`int_key` int(11) DEFAULT NULL,
+PRIMARY KEY (`pk`),
+KEY `int_key` (`int_key`)
+) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1,9),(2,3),(3,8),(4,6),(5,9),(6,5),(7,5),(8,9),(9,1),(10,10);
+SELECT `pk` FROM t1 AS OUTR WHERE `int_key` = ALL (
+SELECT `int_key` FROM t1 AS INNR WHERE INNR . `pk` >= 9
+);
+pk
+DROP TABLE t1;
+
BUG#40118 Crash when running Batched Key Access and requiring one match for each key
create table t0(a int);
=== modified file 'mysql-test/t/subselect3.test'
--- a/mysql-test/t/subselect3.test 2009-01-30 14:13:39 +0000
+++ b/mysql-test/t/subselect3.test 2009-02-04 11:27:06 +0000
@@ -989,6 +989,21 @@ explain select * from t1 where (a,b,c) i
drop table t0,t1,t2;
+--echo
+--echo BUG#37842: Assertion in DsMrr_impl::dsmrr_init, at handler.cc:4307
+--echo
+CREATE TABLE t1 (
+ `pk` int(11) NOT NULL AUTO_INCREMENT,
+ `int_key` int(11) DEFAULT NULL,
+ PRIMARY KEY (`pk`),
+ KEY `int_key` (`int_key`)
+) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1,9),(2,3),(3,8),(4,6),(5,9),(6,5),(7,5),(8,9),(9,1),(10,10);
+SELECT `pk` FROM t1 AS OUTR WHERE `int_key` = ALL (
+ SELECT `int_key` FROM t1 AS INNR WHERE INNR . `pk` >= 9
+);
+DROP TABLE t1;
+
--echo
--echo BUG#40118 Crash when running Batched Key Access and requiring one match for each key
--echo
=== modified file 'sql/handler.cc'
--- a/sql/handler.cc 2009-02-04 10:49:16 +0000
+++ b/sql/handler.cc 2009-02-05 08:22:22 +0000
@@ -4362,17 +4362,20 @@ scan_it_again:
@retval other Error
*/
-int DsMrr_impl::dsmrr_init(handler *h, KEY *key,
- RANGE_SEQ_IF *seq_funcs, void *seq_init_param,
- uint n_ranges, uint mode, HANDLER_BUFFER *buf)
+int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs,
+ void *seq_init_param, uint n_ranges, uint mode,
+ HANDLER_BUFFER *buf)
{
uint elem_size;
- uint keyno;
Item *pushed_cond= NULL;
handler *new_h2= 0;
DBUG_ENTER("DsMrr_impl::dsmrr_init");
- keyno= h->active_index;
+ /*
+ index_merge may invoke a scan on an object for which dsmrr_info[_const]
+ has not been called, so set the owner handler here as well.
+ */
+ h= h_arg;
if (mode & HA_MRR_USE_DEFAULT_IMPL || mode & HA_MRR_SORTED)
{
use_default_impl= TRUE;
@@ -4393,17 +4396,28 @@ int DsMrr_impl::dsmrr_init(handler *h, K
elem_size;
rowids_buf_end= rowids_buf_last;
+ /*
+ There can be two cases:
+ - This is the first call since index_init(), h2==NULL
+ Need to setup h2 then.
+ - This is not the first call, h2 is initalized and set up appropriately.
+ The caller might have called h->index_init(), need to switch h to
+ rnd_pos calls.
+ */
if (!h2)
{
/* Create a separate handler object to do rndpos() calls. */
THD *thd= current_thd;
+ /*
+ ::clone() takes up a lot of stack, especially on 64 bit platforms.
+ The constant 5 is an empiric result.
+ */
+ if (check_stack_overrun(thd, 5*STACK_MIN_SIZE, (uchar*) &new_h2))
+ DBUG_RETURN(1);
+ DBUG_ASSERT(h->active_index != MAX_KEY);
+ uint mrr_keyno= h->active_index;
- /*
- ::clone() takes up a lot of stack, especially on 64 bit platforms.
- The constant 5 is an empiric result.
- */
- if (check_stack_overrun(thd, 5*STACK_MIN_SIZE, (uchar*) &new_h2))
- DBUG_RETURN(1);
+ /* Create a separate handler object to do rndpos() calls. */
if (!(new_h2= h->clone(thd->mem_root)) ||
new_h2->ha_external_lock(thd, F_RDLCK))
{
@@ -4411,31 +4425,55 @@ int DsMrr_impl::dsmrr_init(handler *h, K
DBUG_RETURN(1);
}
- if (keyno == h->pushed_idx_cond_keyno)
+ if (mrr_keyno == h->pushed_idx_cond_keyno)
pushed_cond= h->pushed_idx_cond;
+
+ /*
+ Caution: this call will invoke this->dsmrr_close(). Do not put the
+ created secondary table handler into this->h2 or it will delete it.
+ */
if (h->ha_index_end())
{
- new_h2= h2;
+ h2=new_h2;
goto error;
}
- h2= new_h2;
+ h2= new_h2; /* Ok, now can put it into h2 */
table->prepare_for_position();
- new_h2->extra(HA_EXTRA_KEYREAD);
+ h2->extra(HA_EXTRA_KEYREAD);
- if (h2->ha_index_init(keyno, FALSE))
+ if (h2->ha_index_init(mrr_keyno, FALSE))
+ goto error;
+
+ use_default_impl= FALSE;
+ if (pushed_cond)
+ h2->idx_cond_push(mrr_keyno, pushed_cond);
+ }
+ else
+ {
+ /*
+ We get here when the access alternates betwen MRR scan(s) and non-MRR
+ scans.
+
+ Calling h->index_end() will invoke dsmrr_close() for this object,
+ which will delete h2. We need to keep it, so save put it away and dont
+ let it be deleted:
+ */
+ handler *save_h2= h2;
+ h2= NULL;
+ int res= (h->inited == handler::INDEX && h->ha_index_end());
+ h2= save_h2;
+ use_default_impl= FALSE;
+ if (res)
goto error;
}
if (h2->handler::multi_range_read_init(seq_funcs, seq_init_param, n_ranges,
- mode, buf))
- goto error;
-
- if (pushed_cond)
- h2->idx_cond_push(keyno, pushed_cond);
- if (dsmrr_fill_buffer(new_h2))
+ mode, buf) ||
+ dsmrr_fill_buffer())
+ {
goto error;
-
+ }
/*
If the above call has scanned through all intervals in *seq, then
adjust *buf to indicate that the remaining buffer space will not be used.
@@ -4504,7 +4542,7 @@ static int rowid_cmp(void *h, uchar *a,
@retval other Error
*/
-int DsMrr_impl::dsmrr_fill_buffer(handler *unused)
+int DsMrr_impl::dsmrr_fill_buffer()
{
char *range_info;
int res;
@@ -4551,7 +4589,7 @@ int DsMrr_impl::dsmrr_fill_buffer(handle
DS-MRR implementation: multi_range_read_next() function
*/
-int DsMrr_impl::dsmrr_next(handler *h, char **range_info)
+int DsMrr_impl::dsmrr_next(char **range_info)
{
int res;
uchar *cur_range_info= 0;
@@ -4569,8 +4607,7 @@ int DsMrr_impl::dsmrr_next(handler *h, c
res= HA_ERR_END_OF_FILE;
goto end;
}
-
- res= dsmrr_fill_buffer(h);
+ res= dsmrr_fill_buffer();
if (res)
goto end;
}
=== modified file 'sql/handler.h'
--- a/sql/handler.h 2009-01-29 21:17:59 +0000
+++ b/sql/handler.h 2009-02-02 14:12:27 +0000
@@ -2461,14 +2461,15 @@ public:
DsMrr_impl()
: h2(NULL) {};
-
- handler *h; /* The "owner" handler object. It is used for scanning the index */
- TABLE *table; /* Always equal to h->table */
-private:
+
/*
- Secondary handler object. It is used to retrieve full table rows by
- calling rnd_pos().
+ The "owner" handler object (the one that calls dsmrr_XXX functions.
+ It is used to retrieve full table rows by calling rnd_pos().
*/
+ handler *h;
+ TABLE *table; /* Always equal to h->table */
+private:
+ /* Secondary handler object. It is used for scanning the index */
handler *h2;
/* Buffer to store rowids, or (rowid, range_id) pairs */
@@ -2489,12 +2490,11 @@ public:
h= h_arg;
table= table_arg;
}
- int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs,
- void *seq_init_param, uint n_ranges, uint mode,
- HANDLER_BUFFER *buf);
+ int dsmrr_init(handler *h, RANGE_SEQ_IF *seq_funcs, void *seq_init_param,
+ uint n_ranges, uint mode, HANDLER_BUFFER *buf);
void dsmrr_close();
- int dsmrr_fill_buffer(handler *h);
- int dsmrr_next(handler *h, char **range_info);
+ int dsmrr_fill_buffer();
+ int dsmrr_next(char **range_info);
ha_rows dsmrr_info(uint keyno, uint n_ranges, uint keys, uint *bufsz,
uint *flags, COST_VECT *cost);
=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc 2009-01-31 16:21:19 +0000
+++ b/storage/innobase/handler/ha_innodb.cc 2009-02-05 08:22:22 +0000
@@ -3468,7 +3468,6 @@ skip_field:
prebuilt->idx_cond_func= NULL;
prebuilt->n_index_fields= n_requested_fields;
}
- // file->in_range_read= FALSE;
if (index != clust_index && prebuilt->need_to_access_clustered) {
/* Change rec_field_no's to correspond to the clustered index
@@ -6675,7 +6674,6 @@ ha_innobase::extra(
/* Reset index condition pushdown state */
pushed_idx_cond= FALSE;
pushed_idx_cond_keyno= MAX_KEY;
- //in_range_read= FALSE;
prebuilt->idx_cond_func= NULL;
break;
case HA_EXTRA_NO_KEYREAD:
@@ -8497,13 +8495,12 @@ mysql_declare_plugin_end;
int ha_innobase::multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
uint n_ranges, uint mode, HANDLER_BUFFER *buf)
{
- return ds_mrr.dsmrr_init(this, &table->key_info[active_index],
- seq, seq_init_param, n_ranges, mode, buf);
+ return ds_mrr.dsmrr_init(this, seq, seq_init_param, n_ranges, mode, buf);
}
int ha_innobase::multi_range_read_next(char **range_info)
{
- return ds_mrr.dsmrr_next(this, range_info);
+ return ds_mrr.dsmrr_next(range_info);
}
ha_rows ha_innobase::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
@@ -8539,7 +8536,7 @@ C_MODE_START
static my_bool index_cond_func_innodb(void *arg)
{
ha_innobase *h= (ha_innobase*)arg;
- if (h->end_range) //was: h->in_range_read
+ if (h->end_range)
{
if (h->compare_key2(h->end_range) > 0)
return 2; /* caller should return HA_ERR_END_OF_FILE already */
@@ -8569,11 +8566,7 @@ int ha_innobase::read_range_first(const
bool sorted /* ignored */)
{
int res;
- //if (!eq_range_arg)
- //in_range_read= TRUE;
res= handler::read_range_first(start_key, end_key, eq_range_arg, sorted);
- //if (res)
- // in_range_read= FALSE;
return res;
}
@@ -8581,8 +8574,6 @@ int ha_innobase::read_range_first(const
int ha_innobase::read_range_next()
{
int res= handler::read_range_next();
- //if (res)
- // in_range_read= FALSE;
return res;
}
=== modified file 'storage/maria/ha_maria.cc'
--- a/storage/maria/ha_maria.cc 2009-02-02 13:57:39 +0000
+++ b/storage/maria/ha_maria.cc 2009-02-05 08:22:22 +0000
@@ -3198,13 +3198,12 @@ int ha_maria::multi_range_read_init(RANG
uint n_ranges, uint mode,
HANDLER_BUFFER *buf)
{
- return ds_mrr.dsmrr_init(this, &table->key_info[active_index],
- seq, seq_init_param, n_ranges, mode, buf);
+ return ds_mrr.dsmrr_init(this, seq, seq_init_param, n_ranges, mode, buf);
}
int ha_maria::multi_range_read_next(char **range_info)
{
- return ds_mrr.dsmrr_next(this, range_info);
+ return ds_mrr.dsmrr_next(range_info);
}
ha_rows ha_maria::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
=== modified file 'storage/myisam/ha_myisam.cc'
--- a/storage/myisam/ha_myisam.cc 2009-02-04 10:49:16 +0000
+++ b/storage/myisam/ha_myisam.cc 2009-02-05 08:22:22 +0000
@@ -2013,13 +2013,12 @@ int ha_myisam::multi_range_read_init(RAN
uint n_ranges, uint mode,
HANDLER_BUFFER *buf)
{
- return ds_mrr.dsmrr_init(this, &table->key_info[active_index],
- seq, seq_init_param, n_ranges, mode, buf);
+ return ds_mrr.dsmrr_init(this, seq, seq_init_param, n_ranges, mode, buf);
}
int ha_myisam::multi_range_read_next(char **range_info)
{
- return ds_mrr.dsmrr_next(this, range_info);
+ return ds_mrr.dsmrr_next(range_info);
}
ha_rows ha_myisam::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
| Thread |
|---|
| • bzr commit into mysql-6.0-rpl branch (zhenxing.he:2813) Bug#37842 | He Zhenxing | 10 Feb |