Bug #8722 prepared statement with view crashes server
Submitted: 23 Feb 2005 9:04 Modified: 23 Mar 2005 21:45
Reporter: Georg Richter Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.0.3 OS:Linux (Linux)
Assigned to: Konstantin Osipov CPU Architecture:Any

[23 Feb 2005 9:04] Georg Richter
Description:
mysql_stmt_prepare with a view crashes the mysql server.

I don't think it's related to bug #8703 - a simple query works ok. Also if a query was executed before, mysql_stmt_prepare doesn't crash.

How to repeat:
Tables and Views:

CREATE TABLE t1 (c1 varchar(10), c2 varchar(10), c3 varchar(10) , c4 varchar(10), c5 varchar(10), c6 varchar(10), c7 varchar(10), c8 varchar(10), c9 varchar(10), c10 varchar(10));

CREATE TABLE t2 LIKE t1;

INSERT INTO t1 VALUES (1,2,3,4,5,6,7,8,9,10);
INSERT INTO t2 VALUES (1,2,3,4,5,6,7,8,9,10);

CREATE VIEW v1 AS SELECT t1.* FROM t1 join t2 WHERE t1.c1=t2.c1;

Test program:
#include <mysql.h>
#include <stdio.h>

int main (int argc, char **argv)
{
	MYSQL 		*mysql;
	MYSQL_STMT 	*stmt;
	MYSQL_RES 	*res;
	char *query = "SELECT * FROM v1";

	mysql = mysql_init(NULL);
	mysql_real_connect(mysql, "localhost", "root", "", "test", 0, NULL, 0);

/**********************************************************
 Note: if you uncomment following block everything works fine 
 **********************************************************/
/*
	if (mysql_query(mysql, query)) {
		printf("Error (query): %s\n", mysql_error(mysql));
		exit(-1);
	}
	res = mysql_store_result(mysql);
	mysql_free_result(res);
*/

	stmt = mysql_stmt_init(mysql);
	if (mysql_stmt_prepare(stmt, query, strlen(query))) {
		printf("Error (statement): %s\n", mysql_stmt_error(stmt));
		exit (-1);
	}

	mysql_stmt_close(stmt);
	mysql_close(mysql);
}
[23 Feb 2005 11:13] MySQL Verification Team
Hi,

I can't reproduce it with 5.0.3 built yesterday. Have you tested it with latest 5.0.3?
[23 Feb 2005 11:40] Georg Richter
Victoria, sorry! I pasted wrong view definition from another testcase:

correct should be:

CREATE VIEW v1 AS SELECT * FROM t1;

Also no need for table t2.

I pulled this morning. Last changeset 1.1884 from Jim
[23 Mar 2005 21:43] 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/internals/23330
[23 Mar 2005 21:45] Konstantin Osipov
I can't repeat the bug. Adding the test case to mysql_client_test.c though.

Subject: bk commit - 5.0 tree (konstantin:1.1852) BUG#8722

ChangeSet
  1.1852 05/03/24 00:42:40 konstantin@mysql.com +1 -0
  Add the test case for Bug#8722 "prepared statement with view crashes
  server" to the test suite, the bug is no longer repeatable.