Bug #1180 optimized away part of WHERE clause cause incorect prepared satatement results
Submitted: 2 Sep 2003 8:51 Modified: 11 Sep 2003 23:10
Reporter: Oleksandr Byelkin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.0 OS:Any (any)
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[2 Sep 2003 8:51] Oleksandr Byelkin
Description:
optimizer change WHERE condition in way which is incorrect for other binded 
parameters 

How to repeat:
  mysql_query(mysql,"CREATE TABLE test_select(session_id  char(9) NOT NULL)"); 
  mysql_query(mysql,"INSERT INTO test_select VALUES (\"abc\")"); 
  strmov(query,"SELECT * FROM test_select WHERE ?=\"1111\" and session_id = 
\"abc\""); 
  stmt = mysql_prepare(mysql, query, strlen(query)); 
  strmov(szData,(char *)"abc"); 
  bind[0].buffer_type=FIELD_TYPE_STRING; 
  bind[0].buffer=(char *)szData; 
  bind[0].buffer_length= 10; 
  bind[0].length= &length[0]; 
  length[0]= 3; 
  bind[0].is_null=0; 
 
  /* return 0 row (corect) */ 
  rc = mysql_bind_param(stmt,bind); 
  rc = mysql_execute(stmt); 
 
  strmov(szData,(char *)"1111"); 
  bind[0].buffer_type=FIELD_TYPE_STRING; 
  bind[0].buffer=(char *)szData; 
  bind[0].buffer_length= 10; 
  bind[0].length= &length[0]; 
  length[0]= 4; 
  bind[0].is_null=0; 
 
  /* return 1 row (corect) */ 
  rc = mysql_bind_param(stmt,bind); 
  rc = mysql_execute(stmt); 
 
  strmov(szData,(char *)"abc"); 
  bind[0].buffer_type=FIELD_TYPE_STRING; 
  bind[0].buffer=(char *)szData; 
  bind[0].buffer_length= 10; 
  bind[0].length= &length[0]; 
  length[0]= 3; 
  bind[0].is_null=0; 
 
  /* return 1 row (incorrect) */ 
  rc = mysql_bind_param(stmt,bind); 
  rc = mysql_execute(stmt);
[2 Sep 2003 10:36] Oleksandr Byelkin
ChangeSet 
  1.1603 03/09/02 19:56:55 bell@sanja.is.com.ua +9 -0 
  fixed BUG#1180 (changing WHERE clause of prepared statements by 
optimisation)