Below is the list of changes that have just been committed into a local
5.0 repository of uchum. When uchum does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-04-12 01:10:10+05:00, gshchepa@uchum.(none) +4 -0
Bug#5507: TRUNCATE does not work with views.
Support of views wasn't implemented for the TRUNCATE statement.
Now TRUNCATE on views has the same semantics as DELETE FROM view:
mysql_truncate() checks whether the table is a view and falls back to delete
if so.
In order to initialize properly the LEX::updatable for a view
st_lex::can_use_merged() now allows usage of merged views for th TRUNCATE
statement.
mysql-test/r/truncate.result@stripped, 2007-04-12 01:04:17+05:00, gshchepa@uchum.(none) +27
-0
Added a test case for the Bug#5507: TRUNCATE does not work with views.
mysql-test/t/truncate.test@stripped, 2007-04-12 01:03:39+05:00, gshchepa@uchum.(none) +32 -0
Added a test case for the Bug#5507: TRUNCATE does not work with views.
sql/sql_delete.cc@stripped, 2007-04-12 01:00:24+05:00, gshchepa@uchum.(none) +6 -3
Bug#5507: TRUNCATE does not work with views.
1.mysql_truncate() was lacking of check whether the table is view. Added.
2.mysql_truncate() calls mysql_delete(), but mysql_delete() always reports errors as
"DELETE" errors. Fixed.
sql/sql_lex.cc@stripped, 2007-04-12 01:02:12+05:00, gshchepa@uchum.(none) +1 -0
Bug#5507: TRUNCATE does not work with views.
can_use_merged() was denying of usage of merged views for a TRUNCATE statement. This
results in improper initialization of view LEX::updatable. Fixed.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: gshchepa
# Host: uchum.(none)
# Root: /home/uchum/work/bk-trees/5507-ci
--- 1.195/sql/sql_delete.cc 2007-04-05 11:29:08 +05:00
+++ 1.196/sql/sql_delete.cc 2007-04-12 01:00:24 +05:00
@@ -369,6 +369,8 @@ bool mysql_prepare_delete(THD *thd, TABL
{
Item *fake_conds= 0;
SELECT_LEX *select_lex= &thd->lex->select_lex;
+ const char *operation = thd->lex->sql_command == SQLCOM_TRUNCATE ?
+ "TRUNCATE" : "DELETE";
DBUG_ENTER("mysql_prepare_delete");
List<Item> all_fields;
@@ -383,14 +385,14 @@ bool mysql_prepare_delete(THD *thd, TABL
DBUG_RETURN(TRUE);
if (!table_list->updatable || check_key_in_view(thd, table_list))
{
- my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "DELETE");
+ my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, operation);
DBUG_RETURN(TRUE);
}
{
TABLE_LIST *duplicate;
if ((duplicate= unique_table(thd, table_list, table_list->next_global, 0)))
{
- update_non_unique_table_error(table_list, "DELETE", duplicate);
+ update_non_unique_table_error(table_list, operation, duplicate);
DBUG_RETURN(TRUE);
}
}
@@ -895,7 +897,8 @@ bool mysql_truncate(THD *thd, TABLE_LIST
if (!dont_send_ok)
{
db_type table_type;
- mysql_frm_type(thd, path, &table_type);
+ if (mysql_frm_type(thd, path, &table_type) == FRMTYPE_VIEW)
+ goto trunc_by_del;
if (table_type == DB_TYPE_UNKNOWN)
{
my_error(ER_NO_SUCH_TABLE, MYF(0),
--- 1.217/sql/sql_lex.cc 2007-03-08 21:29:58 +04:00
+++ 1.218/sql/sql_lex.cc 2007-04-12 01:02:12 +05:00
@@ -1834,6 +1834,7 @@ bool st_lex::can_use_merged()
case SQLCOM_UPDATE_MULTI:
case SQLCOM_DELETE:
case SQLCOM_DELETE_MULTI:
+ case SQLCOM_TRUNCATE:
case SQLCOM_INSERT:
case SQLCOM_INSERT_SELECT:
case SQLCOM_REPLACE:
--- 1.11/mysql-test/r/truncate.result 2004-08-24 20:03:12 +05:00
+++ 1.12/mysql-test/r/truncate.result 2007-04-12 01:04:17 +05:00
@@ -53,3 +53,30 @@ a
3
4
drop table t1;
+create table t1 (s1 int);
+insert into t1 (s1) values (1), (2), (3), (4), (5);
+create view v1 as select * from t1;
+truncate table v1;
+select count(*) from t1;
+count(*)
+0
+insert into t1 (s1) values (1), (2), (3), (4), (5);
+create view v2 as select * from t1 where s1 > 3;
+truncate table v2;
+select * from t1;
+s1
+1
+2
+3
+select * from v2;
+s1
+delete from t1;
+create table t2 (s1 int, s2 int);
+create view v3 as select a.s1, b.s2 from t1 a join t2 b on a.s1 = b.s1 where a.s1 > 3;
+truncate table v3;
+ERROR HY000: Can not delete from join view 'test.v3'
+create view v4 as select * from t1 limit 1,1;
+truncate table v4;
+ERROR HY000: The target table v4 of the TRUNCATE is not updatable
+drop view v1, v2, v3, v4;
+drop table t1, t2;
--- 1.12/mysql-test/t/truncate.test 2005-07-28 05:21:50 +05:00
+++ 1.13/mysql-test/t/truncate.test 2007-04-12 01:03:39 +05:00
@@ -52,3 +52,35 @@ SELECT * from t1;
drop table t1;
# End of 4.1 tests
+
+# Test for buf #5507 "TRUNCATE should work with views"
+
+create table t1 (s1 int);
+
+insert into t1 (s1) values (1), (2), (3), (4), (5);
+create view v1 as select * from t1;
+truncate table v1;
+select count(*) from t1;
+
+insert into t1 (s1) values (1), (2), (3), (4), (5);
+create view v2 as select * from t1 where s1 > 3;
+truncate table v2;
+select * from t1;
+select * from v2;
+delete from t1;
+
+# The following should fail
+create table t2 (s1 int, s2 int);
+create view v3 as select a.s1, b.s2 from t1 a join t2 b on a.s1 = b.s1 where a.s1 > 3;
+--error 1395
+truncate table v3;
+
+# The following should fail
+create view v4 as select * from t1 limit 1,1;
+--error 1288
+truncate table v4;
+
+drop view v1, v2, v3, v4;
+drop table t1, t2;
+
+# End of 5.0 tests
| Thread |
|---|
| • bk commit into 5.0 tree (gshchepa:1.2442) BUG#5507 | gshchepa | 11 Apr |