Bug #51772 filesort Sort Aborted
Submitted: 5 Mar 2010 16:44 Modified: 10 Mar 2010 10:11
Reporter: Steven Carr Email Updates:
Status: Not a Bug Impact on me:
Category:MySQL Server: General Severity:S2 (Serious)
Version:5.1.43 OS:Linux (CentOS 5.4 x86_64)
Assigned to: CPU Architecture:Any
Tags: 1028, filesort, sort aborted

[5 Mar 2010 16:44] Steven Carr
Data warehousing application, fully loaded sun x4540 systems.  CentOS 5.4 30,000 massive tables (>12TB total).

Select anything,whatever order by anything;

Causes a Sort Abort Error.

I tracked the problem down to an innocent assumption error on a developers part.

in filesort.cc maxbuffer computation is incorrect

NOTE: This is simplified, and not the actual code...

In include/my_sys.h...
#define my_b_tell(info) (info->read + (info->current - info->requested))

referenced in filesort.cc
maxbuffer = my_b_tell(info) / sizeof(struct);


maxbuffer  = info->read + (info->current - info->requested) / sizeof(struct);

My Dear Aunt Sally!!!!

What the developer *appeared to want* is  
max buffer = (info->read + (info->current - info->requested)) / sizeof(struct);

But it is evaluated by the compiler like:
maxbuffer = info->read + ((info->current - info->requested) / sizeof(struct));

How to repeat:
I have no idea.

Suggested fix:
wrap the my_b_tell macro in another set of parenthesis

In include/my_sys.h...

#define my_b_tell(info) (info->read + (info->current - info->requested))
#define my_b_tell(info) ((info->read + (info->current - info->requested)))
[6 Mar 2010 9:09] Sveta Smirnova
Thank you for the report.

But in both BZR development tree and 5.1.43 source package my_b_tell defined as:

#define my_b_tell(info) ((info)->pos_in_file + \
                         (size_t) (*(info)->current_pos - (info)->request_pos))

So in double parenthesizes. Which distribution do you use? Please indicate file name and URL you used to download it.
[10 Mar 2010 10:11] Sveta Smirnova
Thank you for the feedback.

I am closing the report as "Not a Bug", because initial description about parenthesis is not related to bugs in MySQL. If you are able to repeat the problem feel free to provide repeatable test case and reopen the report.