Bug #27990 MYSQL_FIELD struct's member strings Bug 21635 not fixed for all cases
Submitted: 20 Apr 2007 19:13 Modified: 30 Oct 2007 23:47
Reporter: Tom Donovan (Candidate Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S2 (Serious)
Version:5.0.44-BK, 5.0.37 OS:Any
Assigned to: Evgeny Potemkin CPU Architecture:Any
Tags: expression, MYSQL_FIELD, org_name, qc

[20 Apr 2007 19:13] Tom Donovan
Description:
The fix for:

Bug 21635 
"MYSQL_FIELD struct's member strings seem to misbehave for expression cols" 

is ineffective if the optimizer chooses to use tmp fields to process the query.

How to repeat:
Run mysql_client_test "test_bug21635"  with server set to: default-storage-engine=INNODB

Suggested fix:
It's not clear how to fix this, as the info is lost when Item_sum objects are replaced by Item_field object at sql_select.cpp line 14038.

The problem does not depend on using INNODB. The problem happens in all cases where the optimizer chooses to call change_to_use_tmp_fields at sql_select.cpp line 14008.

Line numbers are from 5.0.37 source.
[14 Jun 2007 15:13] Valeriy Kravchuk
Thank you for a problem report. Verified just as described with latest 5.0.44-BK on Linux:

openxs@suse:~/dbs/5.0> bin/mysqld_safe --default-storage-engine=innodb &
[1] 15067
openxs@suse:~/dbs/5.0> Starting mysqld daemon with databases from /home/openxs/d
bs/5.0/var

openxs@suse:~/dbs/5.0> bin/mysql_client_test -uroot test_bug21635

#####################################
client_connect
#####################################

 Establishing a connection to '' ... OK
Connected to MySQL server version: 5.0.44-debug (50044)

 Creating a test database 'client_test_db' ... OK

#####################################
1 of (1/1): test_bug21635
#####################################
MIN(i) -> MIN(i) ... mysql_client_test.c:15523: check failed: 'field->db[0] == 0
 && field->org_table[0] == 0 && field->table[0] == 0 && field->org_name[0] == 0'

Aborted
openxs@suse:~/dbs/5.0> bin/mysqladmin -uroot shutdown
STOPPING server from pid file /home/openxs/dbs/5.0/var/suse.pid
070612 18:10:06  mysqld ended

[1]+  Done                    bin/mysqld_safe --default-storage-engine=innodb
openxs@suse:~/dbs/5.0> bin/mysqld_safe &
[1] 15108
openxs@suse:~/dbs/5.0> Starting mysqld daemon with databases from /home/openxs/d
bs/5.0/var

openxs@suse:~/dbs/5.0> bin/mysql_client_test -uroot test_bug21635

#####################################
client_connect
#####################################

 Establishing a connection to '' ... OK
Connected to MySQL server version: 5.0.44-debug (50044)

 Creating a test database 'client_test_db' ... OK

#####################################
1 of (1/1): test_bug21635
#####################################
MIN(i) -> MIN(i) ... OK
MIN(i) AS A1 -> A1 ... OK
MAX(i) -> MAX(i) ... OK
MAX(i) AS A2 -> A2 ... OK
COUNT(i) -> COUNT(i) ... OK
COUNT(i) AS A3 -> A3 ... OK

#####################################
client_disconnect
#####################################

 dropping the test database 'client_test_db' ... OK
 closing the connection ... OK

All '1' tests were successful (in '1' iterations)
  Total execution time: 0 SECS

!!! SUCCESS !!!
[13 Sep 2007 10:49] 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/34161

ChangeSet@1.2424, 2007-09-13 14:44:26+00:00, evgen@moonbone.local +3 -0
  Bug#27990: Wrong info in MYSQL_FIELD struct members when a tmp table was used.
  
  The change_to_use_tmp_fields function leaves the orig_table member of an
  expression's tmp table field filled for the new Item_field being created.
  Later orig_table is used by the Field::make_field function to provide some
  info about original table and field name to a user. This is ok for a field
  but for an expression it should be empty.
  
  The change_to_use_tmp_fields function now resets orig_table member of
  an expression's tmp table field to prevent providing a wrong info to a user.
  The Field::make_field function now resets the table_name and the org_col_name
  variables when the orig_table is set to 0.
[22 Sep 2007 9:52] 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/34482

ChangeSet@1.2424, 2007-09-22 11:35:11+04:00, evgen@sunlight.local +3 -0
  Bug#27990: Wrong info in MYSQL_FIELD struct members when a tmp table was used.
  
  The change_to_use_tmp_fields function leaves the orig_table member of an
  expression's tmp table field filled for the new Item_field being created.
  Later orig_table is used by the Field::make_field function to provide some
  info about original table and field name to a user. This is ok for a field
  but for an expression it should be empty.
  
  The change_to_use_tmp_fields function now resets orig_table member of
  an expression's tmp table field to prevent providing a wrong info to a user.
  The Field::make_field function now resets the table_name and the org_col_name
  variables when the orig_table is set to 0.
[29 Oct 2007 8:42] Bugs System
Pushed into 5.0.52
[29 Oct 2007 8:45] Bugs System
Pushed into 5.1.23-beta
[29 Oct 2007 8:49] Bugs System
Pushed into 6.0.4-alpha
[30 Oct 2007 23:47] Paul Dubois
Noted in 5.0.52, 5.1.23, 6.0.4 changelogs.

The metadata in some MYSQL_FIELD members could be incorrect when a
temporary table was used to evaluate a query.