Bug #22338 Valgrind warning: uninitialized variable in create_tmp_table
Submitted: 14 Sep 2006 10:44 Modified: 3 Oct 2006 19:42
Reporter: Timour Katchaounov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.x OS:
Assigned to: Dmitry Lenev CPU Architecture:Any
Tags: valgrind

[14 Sep 2006 10:44] Timour Katchaounov
Description:
The fix for BUG#21787 checks the value for
thd->lex->current_select->with_sum_func.
Valgrind complains as follows:
VALGRIND: 'Conditional jump or move depends on uninitialised value(s)'
    COUNT: 1
    FUNCTION: create_tmp_table(THD*,    FILES:    master.err
    TESTS:    sp-prelocking
    STACK: at 0x5FF04B: create_tmp_table(THD*, TMP_TABLE_PARAM*, List<Item>&, st_order*, bool, bool, unsigned long, unsigned long, char*) (sql_select.cc:9082)

Also see:

How to repeat:
Run mysqld under valgrind with the example below. The warning is
produced when you issue the last SELECT.

CREATE TABLE t1 (f1 BIGINT, f2 VARCHAR(20), f3 BIGINT);
INSERT INTO t1 SET f1 = 1, f2 = 'Schoenenbourg', f3 = 1;
CREATE FUNCTION func2() RETURNS BIGINT RETURN 1;
delimiter //
CREATE FUNCTION func1() RETURNS BIGINT
BEGIN
RETURN ( SELECT COUNT(*) FROM INFORMATION_SCHEMA.VIEWS);
END//
delimiter ;
CREATE VIEW v1 AS SELECT 1 FROM t1
WHERE f3 = (SELECT func2 ());
SELECT func1();
DROP TABLE t1;
DROP VIEW v1;
DROP FUNCTION func1;
DROP FUNCTION func2;
[14 Sep 2006 13:06] Timour Katchaounov
The warning is caused by the line:
  if (!group && !thd->lex->current_select->with_sum_func)
in create_tmp_table(), sql_select.cc.

I already chcked that:
* removing "thd->lex->current_select->with_sum_func" results in
  removing the valgrind warning, so it is for sure that
  the memeber SELECT_LEX::with_sum_func is not initialized in this
  case. Most likely the cause for this is wrong or incomplete or partly
  uninitialized SELECT_LEX object. 
* when valgrind issues the warning, the mehtod
  SELECT_LEX::init_select()
  was not called for the "thd->lex->current_select", which might be the
  cause of the bug (normally this method should be called for every new
  select).
[24 Sep 2006 13:36] 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/12447

ChangeSet@1.2273, 2006-09-24 17:36:59+04:00, dlenev@mockturtle.local +1 -0
  Proposed fix for bug#22338 "Valgrind warning: uninitialized variable in
  create_tmp_table()".
  
  The fix for bug 21787 "COUNT(*) + ORDER BY + LIMIT returns wrong result"
  introduced valgrind warnings which occured during execution of
  information_schema.test and sp-prelocking.test. There were no user
  visible effects.
  
  The latter fix made create_tmp_table() dependant on
  THD::lex::current_select value. Valgrind warnings occured when this
  function was executed and THD::lex::current_select member pointed
  to uninitialized SELECT_LEX instance.
  
  The proposed fix tries to remove this dependancy by moving some logic
  outside of create_tmp_table() function.
  
  Question for reviewer is marked by QQ.
[28 Sep 2006 19:47] 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/12771

ChangeSet@1.2553, 2006-09-28 23:47:49+04:00, dlenev@mockturtle.local +1 -0
  Fix for bug#22338 "Valgrind warning: uninitialized variable in
  create_tmp_table()".
  
  The fix for bug 21787 "COUNT(*) + ORDER BY + LIMIT returns wrong
  result" introduced valgrind warnings which occured during execution
  of information_schema.test and sp-prelocking.test in version 5.0.
  There were no user visible effects.
  
  The latter fix made create_tmp_table() dependant on
  THD::lex::current_select value. Valgrind warnings occured when this
  function was executed and THD::lex::current_select member pointed
  to uninitialized SELECT_LEX instance.
  
  This fix tries to remove this dependancy by moving some logic
  outside of create_tmp_table() function.
[3 Oct 2006 19:42] Dmitry Lenev
Bug #22938 was marked as duplicate of this bug.

This bug was fixed in 4.1.22, 5.0.27 and 5.1.12.

ChangeLog entry is not needed as this bug should not have any user observable effects.