Bug #47609 Many compile warnings are reported for Optimizer in PB2
Submitted: 24 Sep 2009 12:56 Modified: 11 Dec 2010 17:48
Reporter: Jørgen Løland Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:5.6 OS:Any
Assigned to: Guilhem Bichot CPU Architecture:Any

[24 Sep 2009 12:56] Jørgen Løland
Description:
There are many compile warnings from the optimizer code in PB2

*** At line 9912 of the build log, in sql_select.cc:11530:
sql_select.cc:11530: warning: dereferencing type-punned pointer will break strict-aliasing rules

*** At line 9928 of the build log, in sql_select.cc:6227:
sql_select.cc:6227: warning: 'loose_scan_opt.Loose_scan_opt::best_max_loose_keypart' may be used uninitialized in this function

*** At line 9945 of the build log, in sql_select.cc:7880:
sql_select.cc:7880: warning: 'first' may be used uninitialized in this function

How to repeat:
See compile logs in PB2 (e.g. in the mysql-6.0-codebase-bugfixing branch)

Suggested fix:
Fix the warnings
[29 Nov 2010 8:26] Alexander Nozdrin
These warnings are now in trunk (5.6).

sql/sql_select produces the following warnings during build on
'linux x86_64 werror':

------------------------------------------------------
/export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829: warning: 'loose_scan_opt.Loose_scan_opt::bound_sj_equalities' may be used uninitialized in this function /export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829: warning: 'loose_scan_opt.Loose_scan_opt::quick_max_loose_keypart' may be used uninitialized in this function /export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829: warning: 'loose_scan_opt.Loose_scan_opt::best_loose_scan_key' may be used uninitialized in this function /export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829: warning: 'loose_scan_opt.Loose_scan_opt::best_loose_scan_records' may be used uninitialized in this function /export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829: warning: 'loose_scan_opt.Loose_scan_opt::best_max_loose_keypart' may be used uninitialized in this function /export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829: warning: 'loose_scan_opt.Loose_scan_opt::best_loose_scan_start_key' may be used uninitialized in this function
------------------------------------------------------

The thing is that those variables are left uninitialized intentionally.
Here is what a comment in sql_select.cc says:

------------------------------------------------------
We needn't initialize:
bound_sj_equalities - protected by try_loosescan
quick_max_loose_keypart - protected by quick_uses_applicable_index
best_loose_scan_key - protected by best_loose_scan_cost != DBL_MAX
best_loose_scan_records - same
best_max_loose_keypart - same
best_loose_scan_start_key - same
Not initializing them causes compiler warnings, but using UNINIT_VAR()
would cause a 2% CPU time loss in a 20-table plan search.
So, until UNINIT_VAR(x) doesn't do x=0 for any C++ code, it's not used
here.
------------------------------------------------------
[29 Nov 2010 8:27] Alexander Nozdrin
Triage: please consider removing TEAMTREE, since the problem now is in mysql-trunk. Thanks!
[30 Nov 2010 9:59] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/125466

3393 Guilhem Bichot	2010-11-30
      Fix for BUG#47609 "Many compile warnings are reported for Optimizer in PB2"
     @ CMakeLists.txt
        detect -Werror
     @ config.h.cmake
        convert COMPILE_FLAG_WERROR into #define in my_config.h
     @ sql/sql_select.cc
        do useless initializations if really needed
[30 Nov 2010 10:01] Guilhem Bichot
queued to trunk-bugfixing. No changelog needed.
[5 Dec 2010 12:43] Bugs System
Pushed into mysql-trunk 5.6.1 (revid:alexander.nozdrin@oracle.com-20101205122447-6x94l4fmslpbttxj) (version source revid:alexander.nozdrin@oracle.com-20101205122447-6x94l4fmslpbttxj) (merge vers: 5.6.1) (pib:23)
[11 Dec 2010 17:48] Paul Dubois
Bug does not appear in any released 5.6.x version. No changelog entry needed.