summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorkonstantin@mysql.com <>2005-04-30 09:54:35 +0400
committerkonstantin@mysql.com <>2005-04-30 09:54:35 +0400
commit6040b0abf64ea66f9394b038eba18f4a33d26e42 (patch)
treef06357f2351844fc1200d435fac767983c3c39cf /tests
parentf35c1a18749b1a614deea6bd97486ceb637c8dcb (diff)
downloadmariadb-git-6040b0abf64ea66f9394b038eba18f4a33d26e42.tar.gz
A fix and a test case for Bug#9520 "SELECT DISTINCT crashes server
with cursor". The patch refactors do_select/sub_select functions, which implement the nested loop algorithm, and reuses them to fetch rows for cursors as well. Pushing with view.test failing (--ps-protocol).
Diffstat (limited to 'tests')
-rw-r--r--tests/mysql_client_test.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 9b7c8281043..e5818449fcb 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -12854,6 +12854,59 @@ static void test_bug9159()
myquery(rc);
}
+
+/* Crash when opening a cursor to a query with DISTICNT and no key */
+
+static void test_bug9520()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind[1];
+ char a[6];
+ ulong a_len;
+ int rc, row_count= 0;
+
+ myheader("test_bug9520");
+
+ mysql_query(mysql, "drop table if exists t1");
+ mysql_query(mysql, "create table t1 (a char(5), b char(5), c char(5),"
+ " primary key (a, b, c))");
+ rc= mysql_query(mysql, "insert into t1 values ('x', 'y', 'z'), "
+ " ('a', 'b', 'c'), ('k', 'l', 'm')");
+ myquery(rc);
+
+ stmt= open_cursor("select distinct b from t1");
+
+ /*
+ Not crashes with:
+ stmt= open_cursor("select distinct a from t1");
+ */
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ bzero(bind, sizeof(bind));
+ bind[0].buffer_type= MYSQL_TYPE_STRING;
+ bind[0].buffer= (char*) a;
+ bind[0].buffer_length= sizeof(a);
+ bind[0].length= &a_len;
+
+ mysql_stmt_bind_result(stmt, bind);
+
+ while (!(rc= mysql_stmt_fetch(stmt)))
+ row_count++;
+
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+
+ printf("Fetched %d rows\n", row_count);
+ DBUG_ASSERT(row_count == 3);
+
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+
/*
Read and parse arguments and MySQL options from my.cnf
*/
@@ -13079,6 +13132,7 @@ static struct my_tests_st my_tests[]= {
{ "test_bug8722", test_bug8722 },
{ "test_bug8880", test_bug8880 },
{ "test_bug9159", test_bug9159 },
+ { "test_bug9520", test_bug9520 },
{ 0, 0 }
};