Hi Jørgen,
Thanks for your comments. I have committed an updated version of the
patch based on my "alternative 2" version of the assert. This includes
as you suggested the state of the h2 handler object.
I have also added some extra asserts for the case where the h2 handler
object already exists that verify the consistency between the two
handler object with regards to the active index and information about ICP.
The updated patch is available here:
http://lists.mysql.com/commits/136663
Olav
On 03/05/2011 08:37, Jorgen Loland wrote:
> Hi Olav,
>
> I feel strongly that we should have these asserts so thank you for
> this alternate patch.
>
> If I understand the code/your comments/gdb correctly, DsMRR uses two
> handlers: one for positioning in the index (h2) and one for reading
> from the table based on the position (h_arg).
>
> I think the DBUG_ASSERT can be improved a bit by taking h2 into account:
>
> Alternative 1:
> --------------
> DBUG_ASSERT(h->active_index == MAX_KEY && h2 ||
> !h->pushed_idx_cond ||
> h->pushed_idx_cond_keyno == h->active_index ||
> h->pushed_idx_cond_keyno != table->s->primary_key);
>
> Alternative 2:
> --------------
> handler *hfi= h2 ? h2 : h; // handler for index
> DBUG_ASSERT(hfi->active_index == MAX_KEY ||
> !hfi->pushed_idx_cond ||
> hfi->pushed_idx_cond_keyno == hfi->active_index ||
> hfi->pushed_idx_cond_keyno != table->s->primary_key);
>
>
> Also, I think the documentation for this DBUG_ASSERT should be
> improved. Currently it states e.g. that it's OK that the handler does
> not have an active index but not why this is OK (which is because h2
> is the one used to dive into the index)
>
> On 04/13/2011 03:11 PM, Olav Sandstaa wrote:
>> #At file:///export/home/tmp/olav/mrr-init-bug/ based on
>> revid:olav.sandstaa@stripped
>>
>> 3362 Olav Sandstaa 2011-04-13
>> Fix for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT
>> STRAIGHT_JOIN
>>
>> This crash is caused by a too strict assert that was added in the
>> patch for Bug#58463. The purpose of this assert was to detect
>> situations where the optimizer pushes an index condition (ICP)
>> on the
>> primary index and then later during execution "changes its
>> mind" and
>> uses a different index. This assert failed to take into
>> account that
>> the handler might be scanned multiple times during execution
>> of query
>> and that if MRR is used only on the first initialization of
>> the MRR
>> scan it will be initialized to use an index. On the second
>> initialization of the MRR scan it will not have an active
>> index open on
>> the handler.
>>
>> Detailed explanation of how this situation occurs:
>>
>> The optimizer has decided to scan the second table as a range
>> scan and
>> pushed an index condition to the handler on the primary key.
>> The range
>> scan will be done using an DS-MRR scan to read the second table
>> multiple times (due to join buffering is disabled). This scan is
>> initialized from QUICK_RANGE_SELECT::reset().
>>
>> The first time QUICK_RANGE_SELECT::reset() is called it will
>> initialize the handler to use the primary index. Then it will
>> call
>> handler::multi_range_read_init() which will set up DS-MRR for
>> this
>> scan. This is done in DsMrr_impl::dsmrr_init(). The
>> problematic assert
>> will be evaluated and at this point it passes (since the
>> pushed index
>> condition is on the same active index as
>> QUICK_RANGE_SELECT::reset()
>> initialized). The main thing the initialization of the DS-MRR
>> scan
>> does is to create a "clone" of the handler object that will be
>> used
>> for some part of the DS-MRR scan. In this cloning process it will
>> "copy" the pushed index condition from the main handler object
>> to the
>> clone handler object and set up the clone to do the index scan
>> on the
>> same index as the main handler was set up to use. Then it will
>> "close"
>> the active index on the main handler object since this will be
>> used
>> for reading the records from the base table.
>>
>> Then a second scan of the table needs to be done and this
>> causes a
>> second call to
>> QUICK_RANGE_SELECT::reset(). QUICK_RANGE_SELECT::reset()
>> checks if the
>> handler has been initialized, and since it has it does not
>> initialize
>> the index. Then it calls handler::multi_range_read_init()
>> which calls
>> DsMrr_impl::dsmrr_init(). In DsMrr_impl::dsmrr_init() the
>> problematic
>> assert will be evaluated. And this time it fails due to the
>> handler
>> have no active index (since this was "transferred" to the clone
>> handler object during the first initialization). Thus the
>> assert fails
>> even though we have a valid state of the handler object.
>>
>> The fix for this problem is to make the assert less strict by
>> adding
>> the case where the handler does not have an active index as a
>> legal
>> state.
>> @ mysql-test/include/mrr_tests.inc
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/innodb_mrr.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/innodb_mrr_all.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/innodb_mrr_cost.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/innodb_mrr_cost_all.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/innodb_mrr_cost_icp.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/innodb_mrr_icp.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/innodb_mrr_none.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/myisam_mrr.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/myisam_mrr_all.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/myisam_mrr_cost.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/myisam_mrr_cost_all.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/myisam_mrr_cost_icp.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/myisam_mrr_icp.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ mysql-test/r/myisam_mrr_none.result
>> Test case for Bug#12321461 CRASH IN DSMRR_IMPL::DSMRR_INIT
>> ON SELECT STRAIGHT_JOIN
>> @ sql/handler.cc
>> Extend an assert in DsMrr_impl::dsmrr_init() to also pass
>> when the
>> handler object does not have an active index.
>>
>> modified:
>> mysql-test/include/mrr_tests.inc
>> mysql-test/r/innodb_mrr.result
>> mysql-test/r/innodb_mrr_all.result
>> mysql-test/r/innodb_mrr_cost.result
>> mysql-test/r/innodb_mrr_cost_all.result
>> mysql-test/r/innodb_mrr_cost_icp.result
>> mysql-test/r/innodb_mrr_icp.result
>> mysql-test/r/innodb_mrr_none.result
>> mysql-test/r/myisam_mrr.result
>> mysql-test/r/myisam_mrr_all.result
>> mysql-test/r/myisam_mrr_cost.result
>> mysql-test/r/myisam_mrr_cost_all.result
>> mysql-test/r/myisam_mrr_cost_icp.result
>> mysql-test/r/myisam_mrr_icp.result
>> mysql-test/r/myisam_mrr_none.result
>> sql/handler.cc
>> === modified file 'mysql-test/include/mrr_tests.inc'
>> --- a/mysql-test/include/mrr_tests.inc 2011-01-07 08:38:31 +0000
>> +++ b/mysql-test/include/mrr_tests.inc 2011-04-13 13:11:15 +0000
>> @@ -377,3 +377,36 @@ eval EXPLAIN $query;
>> eval $query;
>>
>> DROP TABLE t1, t2;
>> +
>> +--echo #
>> +--echo # Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT
>> STRAIGHT_JOIN
>> +--echo #
>> +
>> +# This test should run with join cache level 0
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +
>> +CREATE TABLE t1 (
>> + pk INTEGER,
>> + c1 VARCHAR(1) NOT NULL,
>> + PRIMARY KEY (pk)
>> +);
>> +
>> +CREATE TABLE t2 (
>> + c1 VARCHAR(1) NOT NULL
>> +);
>> +
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +
>> +let query=
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +
>> +eval EXPLAIN $query;
>> +eval $query;
>> +
>> +DROP TABLE t1,t2;
>> +
>> +# Restore join cache level to its original value
>> +set optimizer_join_cache_level= @save_join_cache_level;
>>
>> === modified file 'mysql-test/r/innodb_mrr.result'
>> --- a/mysql-test/r/innodb_mrr.result 2011-01-07 08:38:31 +0000
>> +++ b/mysql-test/r/innodb_mrr.result 2011-04-13 13:11:15 +0000
>> @@ -543,6 +543,32 @@ ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> #
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using where
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> +#
>> # Bug#41029 "MRR: SELECT FOR UPDATE fails to lock gaps (InnoDB table)"
>> #
>> SET AUTOCOMMIT=0;
>>
>> === modified file 'mysql-test/r/innodb_mrr_all.result'
>> --- a/mysql-test/r/innodb_mrr_all.result 2011-01-07 08:38:31 +0000
>> +++ b/mysql-test/r/innodb_mrr_all.result 2011-04-13 13:11:15 +0000
>> @@ -543,6 +543,32 @@ ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> #
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using index condition; Using where
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> +#
>> # Bug#41029 "MRR: SELECT FOR UPDATE fails to lock gaps (InnoDB table)"
>> #
>> SET AUTOCOMMIT=0;
>>
>> === modified file 'mysql-test/r/innodb_mrr_cost.result'
>> --- a/mysql-test/r/innodb_mrr_cost.result 2011-01-07 08:38:31 +0000
>> +++ b/mysql-test/r/innodb_mrr_cost.result 2011-04-13 13:11:15 +0000
>> @@ -543,6 +543,32 @@ ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> #
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using where
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> +#
>> # Bug#41029 "MRR: SELECT FOR UPDATE fails to lock gaps (InnoDB table)"
>> #
>> SET AUTOCOMMIT=0;
>>
>> === modified file 'mysql-test/r/innodb_mrr_cost_all.result'
>> --- a/mysql-test/r/innodb_mrr_cost_all.result 2011-01-07 08:38:31
>> +0000
>> +++ b/mysql-test/r/innodb_mrr_cost_all.result 2011-04-13 13:11:15
>> +0000
>> @@ -543,6 +543,32 @@ ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> #
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using index condition; Using where
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> +#
>> # Bug#41029 "MRR: SELECT FOR UPDATE fails to lock gaps (InnoDB table)"
>> #
>> SET AUTOCOMMIT=0;
>>
>> === modified file 'mysql-test/r/innodb_mrr_cost_icp.result'
>> --- a/mysql-test/r/innodb_mrr_cost_icp.result 2011-01-07 08:38:31
>> +0000
>> +++ b/mysql-test/r/innodb_mrr_cost_icp.result 2011-04-13 13:11:15
>> +0000
>> @@ -543,6 +543,32 @@ ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> #
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using index condition; Using where
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> +#
>> # Bug#41029 "MRR: SELECT FOR UPDATE fails to lock gaps (InnoDB table)"
>> #
>> SET AUTOCOMMIT=0;
>>
>> === modified file 'mysql-test/r/innodb_mrr_icp.result'
>> --- a/mysql-test/r/innodb_mrr_icp.result 2011-01-07 08:38:31 +0000
>> +++ b/mysql-test/r/innodb_mrr_icp.result 2011-04-13 13:11:15 +0000
>> @@ -543,6 +543,32 @@ ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> #
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using index condition; Using where
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> +#
>> # Bug#41029 "MRR: SELECT FOR UPDATE fails to lock gaps (InnoDB table)"
>> #
>> SET AUTOCOMMIT=0;
>>
>> === modified file 'mysql-test/r/innodb_mrr_none.result'
>> --- a/mysql-test/r/innodb_mrr_none.result 2011-01-07 08:38:31 +0000
>> +++ b/mysql-test/r/innodb_mrr_none.result 2011-04-13 13:11:15 +0000
>> @@ -542,6 +542,32 @@ ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> #
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using where
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> +#
>> # Bug#41029 "MRR: SELECT FOR UPDATE fails to lock gaps (InnoDB table)"
>> #
>> SET AUTOCOMMIT=0;
>>
>> === modified file 'mysql-test/r/myisam_mrr.result'
>> --- a/mysql-test/r/myisam_mrr.result 2011-01-07 08:38:31 +0000
>> +++ b/mysql-test/r/myisam_mrr.result 2011-04-13 13:11:15 +0000
>> @@ -544,5 +544,31 @@ AND t2.pk IS NULL
>> ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> +#
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using where; Using MRR
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
>> set optimizer_switch=default;
>>
>> === modified file 'mysql-test/r/myisam_mrr_all.result'
>> --- a/mysql-test/r/myisam_mrr_all.result 2011-01-07 08:38:31 +0000
>> +++ b/mysql-test/r/myisam_mrr_all.result 2011-04-13 13:11:15 +0000
>> @@ -544,5 +544,31 @@ AND t2.pk IS NULL
>> ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> +#
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using index condition; Using where; Using MRR
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
>> set optimizer_switch=default;
>>
>> === modified file 'mysql-test/r/myisam_mrr_cost.result'
>> --- a/mysql-test/r/myisam_mrr_cost.result 2011-01-07 08:38:31 +0000
>> +++ b/mysql-test/r/myisam_mrr_cost.result 2011-04-13 13:11:15 +0000
>> @@ -544,5 +544,31 @@ AND t2.pk IS NULL
>> ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> +#
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using where
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
>> set optimizer_switch=default;
>>
>> === modified file 'mysql-test/r/myisam_mrr_cost_all.result'
>> --- a/mysql-test/r/myisam_mrr_cost_all.result 2011-01-07 08:38:31
>> +0000
>> +++ b/mysql-test/r/myisam_mrr_cost_all.result 2011-04-13 13:11:15
>> +0000
>> @@ -544,5 +544,31 @@ AND t2.pk IS NULL
>> ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> +#
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using index condition; Using where
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
>> set optimizer_switch=default;
>>
>> === modified file 'mysql-test/r/myisam_mrr_cost_icp.result'
>> --- a/mysql-test/r/myisam_mrr_cost_icp.result 2011-01-07 08:38:31
>> +0000
>> +++ b/mysql-test/r/myisam_mrr_cost_icp.result 2011-04-13 13:11:15
>> +0000
>> @@ -544,5 +544,31 @@ AND t2.pk IS NULL
>> ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> +#
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using index condition; Using where
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
>> set optimizer_switch=default;
>>
>> === modified file 'mysql-test/r/myisam_mrr_icp.result'
>> --- a/mysql-test/r/myisam_mrr_icp.result 2011-01-07 08:38:31 +0000
>> +++ b/mysql-test/r/myisam_mrr_icp.result 2011-04-13 13:11:15 +0000
>> @@ -544,5 +544,31 @@ AND t2.pk IS NULL
>> ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> +#
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using index condition; Using where; Using MRR
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
>> set optimizer_switch=default;
>>
>> === modified file 'mysql-test/r/myisam_mrr_none.result'
>> --- a/mysql-test/r/myisam_mrr_none.result 2011-01-07 08:38:31 +0000
>> +++ b/mysql-test/r/myisam_mrr_none.result 2011-04-13 13:11:15 +0000
>> @@ -543,5 +543,31 @@ AND t2.pk IS NULL
>> ORDER BY i1;
>> i1
>> DROP TABLE t1, t2;
>> +#
>> +# Bug#12321461: CRASH IN DSMRR_IMPL::DSMRR_INIT ON SELECT STRAIGHT_JOIN
>> +#
>> +set @save_join_cache_level= @@optimizer_join_cache_level;
>> +set optimizer_join_cache_level=0;
>> +CREATE TABLE t1 (
>> +pk INTEGER,
>> +c1 VARCHAR(1) NOT NULL,
>> +PRIMARY KEY (pk)
>> +);
>> +CREATE TABLE t2 (
>> +c1 VARCHAR(1) NOT NULL
>> +);
>> +INSERT INTO t2 VALUES ('v'), ('c');
>> +EXPLAIN SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +id select_type table type possible_keys key
>> key_len ref rows Extra
>> +1 SIMPLE t2 ALL NULL NULL NULL NULL 2
>> +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL
>> 1 Using where
>> +SELECT STRAIGHT_JOIN t1.c1
>> +FROM t1 RIGHT OUTER JOIN t2 ON t1.c1 = t2.c1
>> +WHERE t1.pk> 176;
>> +c1
>> +DROP TABLE t1,t2;
>> +set optimizer_join_cache_level= @save_join_cache_level;
>> set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
>> set optimizer_switch=default;
>>
>> === modified file 'sql/handler.cc'
>> --- a/sql/handler.cc 2011-04-11 09:35:34 +0000
>> +++ b/sql/handler.cc 2011-04-13 13:11:15 +0000
>> @@ -4777,19 +4777,19 @@ int DsMrr_impl::dsmrr_init(handler *h_ar
>> /*
>> This assert will hit if we have pushed an index condition to the
>> primary key index and then "change our mind" and use a different
>> - index for retrieving data with MRR.
>> -
>> - This assert is too strict for the existing code. If an index
>> - condition has been pushed on the primary index the existing code
>> - does not clean up information about the pushed index condition when
>> - the index scan is completed. Disables the assert until we have
>> - a fix for better cleaning up after a pushed index condition.
>> + index for retrieving data with MRR. One of the following criteria
>> + must be true:
>> + 1. This handler object does not have an active index.
>> + 2. We have not pushed an index conditon on this handler.
>> + 3. We have pushed and index condition and this is on the
>> + currently used index.
>> + 4. We have pushed and index condition but this is not for the
>> + primary key.
>> */
>> - /*
>> - DBUG_ASSERT(!h->pushed_idx_cond ||
>> + DBUG_ASSERT(h->active_index == MAX_KEY ||
>> + !h->pushed_idx_cond ||
>> h->pushed_idx_cond_keyno == h->active_index ||
>> h->pushed_idx_cond_keyno != table->s->primary_key);
>> - */
>>
>> rowids_buf= buf->buffer;
>>
>>
>>
>>
>>
>>
>