Bug #77083 ib_cursor_moveto() doesn't accept search tupple with smaller n_fields
Submitted: 19 May 2015 6:06 Modified: 25 May 2015 14:39
Reporter: Yasufumi Kinoshita Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.7.7 OS:Any
Assigned to: CPU Architecture:Any

[19 May 2015 6:06] Yasufumi Kinoshita
Description:
This is Bug of InnoDB API.

smaller n_fields serach_tuple for ib_cursor_moveto()
causes assertion error or segmentation fault.

How to repeat:
for the 2 tables like
table A (a, b, c) primary key (a)
table B (a, line, d, e) primary key (a, line)

I tried...

ib_sec_search_tuple_create(cursor for table A)
and used the search_tuple also for B, to scan matched lines. (a==search_tuple)
the search tuple was used for ib_cursor_moveto()

Suggested fix:
=== modified file 'storage/innobase/api/api0api.cc'
--- storage/innobase/api/api0api.cc     2015-05-15 01:58:58 +0000
+++ storage/innobase/api/api0api.cc     2015-05-19 05:07:52 +0000
@@ -1920,6 +1920,10 @@ ib_cursor_moveto(

        n_fields = dict_index_get_n_ordering_defined_by_user(prebuilt->index);

+       if (n_fields > dtuple_get_n_fields(tuple->ptr)) {
+               n_fields = dtuple_get_n_fields(tuple->ptr);
+       }
+
        dtuple_set_n_fields(search_tuple, n_fields);
        dtuple_set_n_fields_cmp(search_tuple, n_fields);
[20 May 2015 4:28] Yasufumi Kinoshita
Just we should use table name instead of table id.
[20 May 2015 4:29] Yasufumi Kinoshita
Sorry for wrong previous post.
[20 May 2015 13:50] MySQL Verification Team
This bug is verified by source code inspection and some debugging ...

The available fix is also quite small.
[25 May 2015 14:39] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 5.6.26, 5.7.8, 5.8.0 release, and here's the changelog entry:

The "ib_cursor_moveto" function did not accept a search tuple with fewer
fields than are defined for the index. 

Thank you for the bug report.