[Commits] 0222f7b3988: MDEV-17036: BULK with replace doesn't take the first parameter in account

Oleksandr Byelkin sanja at mariadb.com
Thu Apr 25 14:43:31 EEST 2019


revision-id: 0222f7b3988496c7289321dc606967c888dc658e (mariadb-10.2.23-76-g0222f7b3988)
parent(s): bc145193c164b895a52b943e73fff53952d48a60
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2019-04-25 13:43:31 +0200
message:

MDEV-17036: BULK with replace doesn't take the first parameter in account

INSERT and REPLACE served by the same function, so flags (and processing) should be the same.

---
 sql/sql_parse.cc          |  3 ++-
 tests/mysql_client_test.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 146c4d2d02e..68a08dc2b3f 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -609,7 +609,8 @@ void init_update_queries(void)
                                             CF_CAN_GENERATE_ROW_EVENTS |
                                             CF_OPTIMIZER_TRACE |
                                             CF_CAN_BE_EXPLAINED |
-                                            CF_INSERTS_DATA | CF_SP_BULK_SAFE;
+                                            CF_INSERTS_DATA | CF_SP_BULK_SAFE |
+                                            CF_SP_BULK_OPTIMIZED;
   sql_command_flags[SQLCOM_REPLACE_SELECT]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
                                             CF_CAN_GENERATE_ROW_EVENTS |
                                             CF_OPTIMIZER_TRACE |
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index be16db0fc9e..365229e126f 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -19743,6 +19743,66 @@ static void test_bulk_delete()
   rc= mysql_query(mysql, "DROP TABLE t1");
   myquery(rc);
 }
+
+static void test_bulk_replace()
+{
+  int rc;
+  MYSQL_STMT *stmt;
+  MYSQL_BIND bind[2];
+  MYSQL_ROW  row;
+  int        i,
+             id[]= {1, 2, 3, 4},
+             val[]= {1, 1, 1, 1},
+             count= sizeof(id)/sizeof(id[0]);
+  MYSQL_RES *result;
+
+  rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+  myquery(rc);
+  rc= mysql_query(mysql, "CREATE TABLE t1 (id int not null primary key, active int)");
+  myquery(rc);
+  rc= mysql_query(mysql, "insert into t1 values (1, 0), (2, 0), (3, 0)");
+  myquery(rc);
+  verify_affected_rows(3);
+
+  stmt= mysql_stmt_init(mysql);
+  rc= mysql_stmt_prepare(stmt, "replace into t1 (id, active) values (?, ?)", -1);
+  check_execute(stmt, rc);
+
+  memset(bind, 0, sizeof(bind));
+  bind[0].buffer_type = MYSQL_TYPE_LONG;
+  bind[0].buffer = (void *)id;
+  bind[0].buffer_length = 0;
+  bind[1].buffer_type = MYSQL_TYPE_LONG;
+  bind[1].buffer = (void *)val;
+  bind[1].buffer_length = 0;
+
+  mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, (void*)&count);
+  rc= mysql_stmt_bind_param(stmt, bind);
+  check_execute(stmt, rc);
+
+  rc= mysql_stmt_execute(stmt);
+  check_execute(stmt, rc);
+
+  mysql_stmt_close(stmt);
+
+  rc= mysql_query(mysql, "SELECT active FROM t1");
+  myquery(rc);
+
+  result= mysql_store_result(mysql);
+  mytest(result);
+
+  i= 0;
+  while ((row= mysql_fetch_row(result)))
+  {
+    i++;
+    DIE_IF(atoi(row[0]) != 1);
+  }
+  DIE_IF(i != 4);
+  mysql_free_result(result);
+
+  rc= mysql_query(mysql, "DROP TABLE t1");
+  myquery(rc);
+}
 #endif
 
 static struct my_tests_st my_tests[]= {
@@ -20026,6 +20086,7 @@ static struct my_tests_st my_tests[]= {
   { "test_mdev12579", test_mdev12579 },
 #ifndef EMBEDDED_LIBRARY
   { "test_bulk_delete", test_bulk_delete },
+  { "test_bulk_replace", test_bulk_replace },
 #endif
   { 0, 0 }
 };


More information about the commits mailing list