Skip to content

Commit db10eef

Browse files
committedApr 28, 2015
BUG#20075747 RND_INIT() ON AN OPEN SCAN IS USED TO REPOSITION THE CURSOR
- rnd_init() on an open scan is used to reposition the "cursor" back to first row - Allow rnd_init() on an already open scan. Close the scan and let it reopen.
1 parent 40d805e commit db10eef

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed
 

‎mysql-test/suite/ndb/r/ndbinfo.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,3 +1328,11 @@ select count(*) from information_schema.tables
13281328
count(*)
13291329
0
13301330

1331+
set @@optimizer_switch='block_nested_loop=off';
1332+
create temporary table old_count
1333+
select counter_name, sum(val) as val
1334+
from ndbinfo.counters
1335+
where block_name='DBSPJ'
1336+
group by counter_name;
1337+
drop table old_count;
1338+
set @@optimizer_switch=default;

‎mysql-test/suite/ndb/t/ndbinfo.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,4 +705,18 @@ select type_name from ndb$dict_obj_types where type_id = 3;
705705
select count(*) from information_schema.tables
706706
where table_schema = 'ndbinfo' and engine != 'ndbinfo';
707707

708+
#
709+
# BUG#20075747 RND_INIT() ON AN OPEN SCAN IS USED TO REPOSITION THE CURSOR
710+
# - rnd_init() on an open scan is used to reposition the "cursor"
711+
# back to first row
712+
#
713+
set @@optimizer_switch='block_nested_loop=off';
714+
create temporary table old_count
715+
select counter_name, sum(val) as val
716+
from ndbinfo.counters
717+
where block_name='DBSPJ'
718+
group by counter_name;
719+
drop table old_count;
720+
set @@optimizer_switch=default;
721+
708722
--source ndbinfo_drop.inc

‎sql/ha_ndbinfo.cc

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -475,6 +475,33 @@ int ha_ndbinfo::rnd_init(bool scan)
475475
}
476476

477477
assert(is_open());
478+
479+
if (m_impl.m_scan_op)
480+
{
481+
/*
482+
It should be impossible to come here with an already open
483+
scan, assumption is that rnd_end() would be called to indicate
484+
that the previous scan should be closed or perhaps like it says
485+
in decsription of rnd_init() that it "may be called two times". Once
486+
to open the cursor and once to position te cursor at first row.
487+
488+
Unfortunately the assumption and description of rnd_init() is not
489+
correct. The rnd_init function is used on an open scan to reposition
490+
it back to first row. For ha_ndbinfo this means closing
491+
the scan and letting it be reopened.
492+
*/
493+
assert(scan); // "only makes sense if scan=1" (from rnd_init() description)
494+
495+
DBUG_PRINT("info", ("Closing scan to position it back to first row"));
496+
497+
// Release the scan operation
498+
g_ndbinfo->releaseScanOperation(m_impl.m_scan_op);
499+
m_impl.m_scan_op = NULL;
500+
501+
// Release pointers to the columns
502+
m_impl.m_columns.clear();
503+
}
504+
478505
assert(m_impl.m_scan_op == NULL); // No scan already ongoing
479506

480507
if (m_impl.m_first_use)

0 commit comments

Comments
 (0)
Please sign in to comment.