summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <vva@eagle.mysql.r18.ru>2004-03-16 17:14:09 +0400
committerunknown <vva@eagle.mysql.r18.ru>2004-03-16 17:14:09 +0400
commitcff48963eafb8708f3ef320a5e9093c5196df871 (patch)
tree194206c4bdd0d20bc07e567b7685f00fe7909fdc
parentc7fd1fa4968b9649567895af2b5ebf11ca2f5e6c (diff)
parent1d3b16335a824df832bb94c447248cef925bdfaf (diff)
downloadmariadb-git-cff48963eafb8708f3ef320a5e9093c5196df871.tar.gz
Merge vvagin@bk-internal.mysql.com:/home/bk/mysql-4.1
into eagle.mysql.r18.ru:/home/vva/work/BUG_2709/mysql-4.1 sql/sql_class.h: Auto merged
-rw-r--r--client/mysqltest.c14
-rw-r--r--mysql-test/r/insert_update.result38
-rw-r--r--mysql-test/t/insert_update.test22
-rw-r--r--sql/sql_class.h1
-rw-r--r--sql/sql_insert.cc26
5 files changed, 85 insertions, 16 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c
index f30af82dabd..313850557f6 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -2331,11 +2331,17 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
mysql_free_result(warn_res);
}
}
- if (!disable_info && mysql_info(mysql))
+ if (!disable_info)
{
- dynstr_append(ds, "info: ");
- dynstr_append(ds, mysql_info(mysql));
- dynstr_append_mem(ds, "\n", 1);
+ char buf[40];
+ sprintf(buf,"affected rows: %ld\n",mysql_affected_rows(mysql));
+ dynstr_append(ds, buf);
+ if (mysql_info(mysql))
+ {
+ dynstr_append(ds, "info: ");
+ dynstr_append(ds, mysql_info(mysql));
+ dynstr_append_mem(ds, "\n", 1);
+ }
}
}
diff --git a/mysql-test/r/insert_update.result b/mysql-test/r/insert_update.result
index 3a7679ce1e3..53867bf4546 100644
--- a/mysql-test/r/insert_update.result
+++ b/mysql-test/r/insert_update.result
@@ -67,3 +67,41 @@ id select_type table type possible_keys key key_len ref rows Extra
Warnings:
Note 1003 select high_priority test.t1.a AS `a`,test.t1.b AS `b`,test.t1.c AS `c` from test.t1
DROP TABLE t1;
+create table t1(a int primary key, b int);
+insert into t1 values(1,1),(2,2),(3,3),(4,4),(5,5);
+select * from t1;
+a b
+1 1
+2 2
+3 3
+4 4
+5 5
+insert into t1 values(4,14),(5,15),(6,16),(7,17),(8,18)
+on duplicate key update b=b+10;
+affected rows: 7
+info: Records: 5 Duplicates: 2 Warnings: 0
+select * from t1;
+a b
+1 1
+2 2
+3 3
+4 14
+5 15
+6 16
+7 17
+8 18
+replace into t1 values(5,25),(6,26),(7,27),(8,28),(9,29);
+affected rows: 9
+info: Records: 5 Duplicates: 4 Warnings: 0
+select * from t1;
+a b
+1 1
+2 2
+3 3
+4 14
+5 25
+6 26
+7 27
+8 28
+9 29
+drop table t1;
diff --git a/mysql-test/t/insert_update.test b/mysql-test/t/insert_update.test
index 550bce867cd..d2a70208022 100644
--- a/mysql-test/t/insert_update.test
+++ b/mysql-test/t/insert_update.test
@@ -26,3 +26,25 @@ SELECT *, VALUES(a) FROM t1;
explain extended SELECT *, VALUES(a) FROM t1;
explain extended select * from t1 where values(a);
DROP TABLE t1;
+
+#
+# test for Bug #2709 "Affected Rows for ON DUPL.KEY undocumented,
+# perhaps illogical"
+#
+create table t1(a int primary key, b int);
+insert into t1 values(1,1),(2,2),(3,3),(4,4),(5,5);
+select * from t1;
+
+enable_info;
+insert into t1 values(4,14),(5,15),(6,16),(7,17),(8,18)
+ on duplicate key update b=b+10;
+disable_info;
+
+select * from t1;
+
+enable_info;
+replace into t1 values(5,25),(6,26),(7,27),(8,28),(9,29);
+disable_info;
+
+select * from t1;
+drop table t1;
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 33684f93d93..97be60f3d19 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -194,6 +194,7 @@ public:
typedef struct st_copy_info {
ha_rows records;
ha_rows deleted;
+ ha_rows updated;
ha_rows copied;
ha_rows error_count;
enum enum_duplicates handle_duplicates;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index ccb8296b929..9002aee1c91 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -236,7 +236,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
Fill in the given fields and dump it to the table file
*/
- info.records=info.deleted=info.copied=0;
+ info.records= info.deleted= info.copied= info.updated= 0;
info.handle_duplicates=duplic;
info.update_fields=&update_fields;
info.update_values=&update_values;
@@ -369,13 +369,14 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
For the transactional algorithm to work the invalidation must be
before binlog writing and ha_autocommit_...
*/
- if (info.copied || info.deleted)
+ if (info.copied || info.deleted || info.updated)
query_cache_invalidate3(thd, table_list, 1);
transactional_table= table->file->has_transactions();
log_delayed= (transactional_table || table->tmp_table);
- if ((info.copied || info.deleted) && (error <= 0 || !transactional_table))
+ if ((info.copied || info.deleted || info.updated) &&
+ (error <= 0 || !transactional_table))
{
mysql_update_log.write(thd, thd->query, thd->query_length);
if (mysql_bin_log.is_open())
@@ -416,7 +417,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
goto abort;
if (values_list.elements == 1 && (!(thd->options & OPTION_WARNINGS) ||
!thd->cuted_fields))
- send_ok(thd,info.copied+info.deleted,id);
+ send_ok(thd,info.copied+info.deleted+info.updated,id);
else
{
char buff[160];
@@ -426,8 +427,8 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
(ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
else
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
- (ulong) info.deleted, (ulong) thd->cuted_fields);
- ::send_ok(thd,info.copied+info.deleted,(ulonglong)id,buff);
+ (ulong) info.deleted+info.updated, (ulong) thd->cuted_fields);
+ ::send_ok(thd,info.copied+info.deleted+info.updated,(ulonglong)id,buff);
}
free_underlaid_joins(thd, &thd->lex->select_lex);
table->insert_values=0;
@@ -529,7 +530,7 @@ int write_record(TABLE *table,COPY_INFO *info)
goto err;
if ((error=table->file->update_row(table->record[1],table->record[0])))
goto err;
- info->deleted++;
+ info->updated++;
break;
}
else /* DUP_REPLACE */
@@ -1474,7 +1475,8 @@ void select_insert::send_error(uint errcode,const char *err)
error while inserting into a MyISAM table) we must write to the binlog (and
the error code will make the slave stop).
*/
- if ((info.copied || info.deleted) && !table->file->has_transactions())
+ if ((info.copied || info.deleted || info.updated) &&
+ !table->file->has_transactions())
{
if (last_insert_id)
thd->insert_id(last_insert_id); // For binary log
@@ -1488,7 +1490,7 @@ void select_insert::send_error(uint errcode,const char *err)
if (!table->tmp_table)
thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
}
- if (info.copied || info.deleted)
+ if (info.copied || info.deleted || info.updated)
query_cache_invalidate3(thd, table, 1);
ha_rollback_stmt(thd);
DBUG_VOID_RETURN;
@@ -1509,7 +1511,7 @@ bool select_insert::send_eof()
and ha_autocommit_...
*/
- if (info.copied || info.deleted)
+ if (info.copied || info.deleted || info.updated)
{
query_cache_invalidate3(thd, table, 1);
if (!(table->file->has_transactions() || table->tmp_table))
@@ -1543,8 +1545,8 @@ bool select_insert::send_eof()
(ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
else
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
- (ulong) info.deleted, (ulong) thd->cuted_fields);
- ::send_ok(thd,info.copied+info.deleted,last_insert_id,buff);
+ (ulong) info.deleted+info.updated, (ulong) thd->cuted_fields);
+ ::send_ok(thd,info.copied+info.deleted+info.updated,last_insert_id,buff);
DBUG_RETURN(0);
}