Skip to content

Commit

Permalink
MDEV-17676: Assertion `inited==NONE || (inited==RND && scan)' failed …
Browse files Browse the repository at this point in the history
…in handler::ha_rnd_init

While calculating distinct with the function remove_dup_with_compare, we don't have rnd_end calls
when we have completed the scan over the temporary table.
Added ha_rnd_end calls when we are done with the scan of the table.
  • Loading branch information
Varun Gupta committed Dec 16, 2018
1 parent 20011c8 commit 32eeed2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mysql-test/r/win.result
Expand Up @@ -3457,3 +3457,16 @@ i row_number() over (partition by i order by i)
deallocate prepare stmt;
drop table t1;
drop view v1;
#
# MDEV-17676: Assertion `inited==NONE || (inited==RND && scan)' failed in handler::ha_rnd_init
#
CREATE TABLE t1 (b1 text NOT NULL);
INSERT INTO t1 VALUES ('2'),('1');
EXPLAIN
SELECT DISTINCT MIN(b1) OVER () FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary
SELECT DISTINCT MIN(b1) OVER () FROM t1;
MIN(b1) OVER ()
1
drop table t1;
11 changes: 11 additions & 0 deletions mysql-test/t/win.test
Expand Up @@ -2216,3 +2216,14 @@ execute stmt;
deallocate prepare stmt;
drop table t1;
drop view v1;

--echo #
--echo # MDEV-17676: Assertion `inited==NONE || (inited==RND && scan)' failed in handler::ha_rnd_init
--echo #

CREATE TABLE t1 (b1 text NOT NULL);
INSERT INTO t1 VALUES ('2'),('1');
EXPLAIN
SELECT DISTINCT MIN(b1) OVER () FROM t1;
SELECT DISTINCT MIN(b1) OVER () FROM t1;
drop table t1;
2 changes: 2 additions & 0 deletions sql/sql_select.cc
Expand Up @@ -22138,9 +22138,11 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field,
}

file->extra(HA_EXTRA_NO_CACHE);
(void) file->ha_rnd_end();
DBUG_RETURN(0);
err:
file->extra(HA_EXTRA_NO_CACHE);
(void) file->ha_rnd_end();
if (error)
file->print_error(error,MYF(0));
DBUG_RETURN(1);
Expand Down

0 comments on commit 32eeed2

Please sign in to comment.