From 3f480fcb9f726f65925526045e036b16ecc2d8fa Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Mar 2006 13:16:12 +0400 Subject: [PATCH 1/3] Bug#16315 XML: extractvalue() handles self badly xml.result, xml.test: Adding test case. item_xmlfunc.cc: Adding a special function to handle "self" axis. Previously "child" and "self" were handled the same. sql/item_xmlfunc.cc: Bug#16315 XML: extractvalue() handles self badly Adding a special function to handle "self" axis. Previously "child" and "self" were handled the same. mysql-test/t/xml.test: Adding test case. mysql-test/r/xml.result: Adding test case. --- mysql-test/r/xml.result | 12 ++++++++++++ mysql-test/t/xml.test | 8 ++++++++ sql/item_xmlfunc.cc | 29 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/mysql-test/r/xml.result b/mysql-test/r/xml.result index 3ed3df546d1..f9b8e9c9dab 100644 --- a/mysql-test/r/xml.result +++ b/mysql-test/r/xml.result @@ -65,6 +65,9 @@ c1 SELECT extractValue(@xml,'/a/child::*'); extractValue(@xml,'/a/child::*') b1 b2 +SELECT extractValue(@xml,'/a/self::*'); +extractValue(@xml,'/a/self::*') +a1 a2 SELECT extractValue(@xml,'/a/descendant::*'); extractValue(@xml,'/a/descendant::*') b1 c1 b2 @@ -546,3 +549,12 @@ select extractvalue('A','/'); ERROR HY000: XPATH syntax error: '>' select extractvalue('bb!','//b!'); ERROR HY000: XPATH syntax error: '!' +select extractvalue('ABC','/a/descendant::*'); +extractvalue('ABC','/a/descendant::*') +B C +select extractvalue('ABC','/a/self::*'); +extractvalue('ABC','/a/self::*') +A +select extractvalue('ABC','/a/descendant-or-self::*'); +extractvalue('ABC','/a/descendant-or-self::*') +A B C diff --git a/mysql-test/t/xml.test b/mysql-test/t/xml.test index e69ab5ee58b..ee4f7a94ba2 100644 --- a/mysql-test/t/xml.test +++ b/mysql-test/t/xml.test @@ -23,6 +23,7 @@ SELECT extractValue(@xml,'/*/*'); SELECT extractValue(@xml,'/*/*/*'); SELECT extractValue(@xml,'/a/child::*'); +SELECT extractValue(@xml,'/a/self::*'); SELECT extractValue(@xml,'/a/descendant::*'); SELECT extractValue(@xml,'/a/descendant-or-self::*'); SELECT extractValue(@xml,'/a/attribute::*'); @@ -243,3 +244,10 @@ select extractvalue('A','/'); # --error 1105 select extractvalue('bb!','//b!'); + +# +# Bug #16315 XML: extractvalue() handles self badly +# +select extractvalue('ABC','/a/descendant::*'); +select extractvalue('ABC','/a/self::*'); +select extractvalue('ABC','/a/descendant-or-self::*'); diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc index aad9e12f6c5..8fc3a2b170c 100644 --- a/sql/item_xmlfunc.cc +++ b/sql/item_xmlfunc.cc @@ -252,6 +252,18 @@ public: }; +/* Returns self */ +class Item_nodeset_func_selfbyname: public Item_nodeset_func_axisbyname +{ +public: + Item_nodeset_func_selfbyname(Item *a, const char *n_arg, uint l_arg, + String *pxml): + Item_nodeset_func_axisbyname(a, n_arg, l_arg, pxml) {} + const char *func_name() const { return "xpath_selfbyname"; } + String *val_nodeset(String *nodeset); +}; + + /* Returns children */ class Item_nodeset_func_childbyname: public Item_nodeset_func_axisbyname { @@ -572,6 +584,20 @@ String * Item_nodeset_func_union::val_nodeset(String *nodeset) } +String *Item_nodeset_func_selfbyname::val_nodeset(String *nodeset) +{ + prepare(nodeset); + for (MY_XPATH_FLT *flt= fltbeg; flt < fltend; flt++) + { + uint pos= 0; + MY_XML_NODE *self= &nodebeg[flt->num]; + if (validname(self)) + ((XPathFilter*)nodeset)->append_element(flt->num,pos++); + } + return nodeset; +} + + String *Item_nodeset_func_childbyname::val_nodeset(String *nodeset) { prepare(nodeset); @@ -945,6 +971,9 @@ static Item* nametestfunc(MY_XPATH *xpath, case MY_XPATH_AXIS_ATTRIBUTE: res= new Item_nodeset_func_attributebyname(arg, beg, len, xpath->pxml); break; + case MY_XPATH_AXIS_SELF: + res= new Item_nodeset_func_selfbyname(arg, beg, len, xpath->pxml); + break; default: res= new Item_nodeset_func_childbyname(arg, beg, len, xpath->pxml); } From 62f7005a3d13132e1208607c7c7ad74887e5d11d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Mar 2006 18:23:00 +0100 Subject: [PATCH 2/3] Bug #17827 cluster: rename of several tables in one statement, gets multiply logged - redo log table query for log, split into separate entries per rename, to avoid duplicates, also to only log renames that relate to ndb tables sql/ha_ndbcluster_binlog.h: Bug #17827 cluster: rename of several tables in one statement, gets multiply logged --- sql/ha_ndbcluster.cc | 7 +++++-- sql/ha_ndbcluster_binlog.cc | 30 ++++++++++++++++++++---------- sql/ha_ndbcluster_binlog.h | 4 +++- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index dc95ead2e97..2b356ca5214 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -4728,13 +4728,14 @@ int ha_ndbcluster::final_drop_index(TABLE *table_arg) int ha_ndbcluster::rename_table(const char *from, const char *to) { NDBDICT *dict; + char old_dbname[FN_HEADLEN]; char new_tabname[FN_HEADLEN]; const NDBTAB *orig_tab; int result; DBUG_ENTER("ha_ndbcluster::rename_table"); DBUG_PRINT("info", ("Renaming %s to %s", from, to)); - set_dbname(from); + set_dbname(from, old_dbname); set_tabname(from); set_tabname(to, new_tabname); @@ -4742,6 +4743,7 @@ int ha_ndbcluster::rename_table(const char *from, const char *to) DBUG_RETURN(my_errno= HA_ERR_NO_CONNECTION); Ndb *ndb= get_ndb(); + ndb->setDatabaseName(old_dbname); dict= ndb->getDictionary(); if (!(orig_tab= dict->getTable(m_tabname))) ERR_RETURN(dict->getNdbError()); @@ -4833,7 +4835,8 @@ int ha_ndbcluster::rename_table(const char *from, const char *to) current_thd->query, current_thd->query_length, m_dbname, new_tabname, 0, 0, - SOT_RENAME_TABLE); + SOT_RENAME_TABLE, + old_dbname, m_tabname); } if (share) free_share(&share); diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc index b756e1e3fe8..f88c118b46e 100644 --- a/sql/ha_ndbcluster_binlog.cc +++ b/sql/ha_ndbcluster_binlog.cc @@ -885,7 +885,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, const char *db, const char *table_name, uint32 ndb_table_id, uint32 ndb_table_version, - enum SCHEMA_OP_TYPE type) + enum SCHEMA_OP_TYPE type, + const char *old_db, const char *old_table_name) { DBUG_ENTER("ndbcluster_log_schema_op"); Thd_ndb *thd_ndb= get_thd_ndb(thd); @@ -919,10 +920,19 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, query= tmp_buf2; query_length= (uint) (strxmov(tmp_buf2, "drop table `", table_name, "`", NullS) - tmp_buf2); - // fall through - case SOT_CREATE_TABLE: - // fall through + if (!share) + get_a_share= 1; + break; case SOT_RENAME_TABLE: + /* redo the rename table query as is may contain several tables */ + query= tmp_buf2; + query_length= (uint) (strxmov(tmp_buf2, "rename table `", + old_db, ".", old_table_name, "` to `", + db, ".", table_name, "`", NullS) - tmp_buf2); + if (!share) + get_a_share= 1; + break; + case SOT_CREATE_TABLE: // fall through case SOT_ALTER_TABLE: if (!share) @@ -983,8 +993,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, } Ndb *ndb= thd_ndb->ndb; - char old_db[FN_REFLEN]; - strcpy(old_db, ndb->getDatabaseName()); + char save_db[FN_REFLEN]; + strcpy(save_db, ndb->getDatabaseName()); char tmp_buf[SCHEMA_QUERY_SIZE]; NDBDICT *dict= ndb->getDictionary(); @@ -1091,7 +1101,7 @@ end: if (trans) ndb->closeTransaction(trans); - ndb->setDatabaseName(old_db); + ndb->setDatabaseName(save_db); /* Wait for other mysqld's to acknowledge the table operation @@ -1169,8 +1179,8 @@ ndbcluster_update_slock(THD *thd, const NdbError *ndb_error= 0; uint32 node_id= g_ndb_cluster_connection->node_id(); Ndb *ndb= check_ndb_in_thd(thd); - char old_db[128]; - strcpy(old_db, ndb->getDatabaseName()); + char save_db[FN_HEADLEN]; + strcpy(save_db, ndb->getDatabaseName()); char tmp_buf[SCHEMA_QUERY_SIZE]; NDBDICT *dict= ndb->getDictionary(); @@ -1292,7 +1302,7 @@ end: db, table_name); if (trans) ndb->closeTransaction(trans); - ndb->setDatabaseName(old_db); + ndb->setDatabaseName(save_db); DBUG_RETURN(0); } diff --git a/sql/ha_ndbcluster_binlog.h b/sql/ha_ndbcluster_binlog.h index d9c8812b3b6..91ef53edd6b 100644 --- a/sql/ha_ndbcluster_binlog.h +++ b/sql/ha_ndbcluster_binlog.h @@ -95,7 +95,9 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, const char *db, const char *table_name, uint32 ndb_table_id, uint32 ndb_table_version, - enum SCHEMA_OP_TYPE type); + enum SCHEMA_OP_TYPE type, + const char *old_db= 0, + const char *old_table_name= 0); int ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, NDB_SHARE *share); void ndb_rep_event_name(String *event_name, From e371dcb675af11ac0219b7c996624d4ff18ab5f5 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 2 Mar 2006 08:44:11 +0100 Subject: [PATCH 3/3] fixed order by in test --- mysql-test/r/ndb_partition_range.result | 6 +++--- mysql-test/t/ndb_partition_range.test | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/ndb_partition_range.result b/mysql-test/r/ndb_partition_range.result index 5297e2a733d..cb79f04873e 100644 --- a/mysql-test/r/ndb_partition_range.result +++ b/mysql-test/r/ndb_partition_range.result @@ -246,17 +246,17 @@ PARTITION BY RANGE(f1) PARTITION part2 VALUES LESS THAN (1000)); INSERT INTO t1 VALUES(1, '---1---'); INSERT INTO t1 VALUES(2, '---2---'); -select * from t1; +select * from t1 order by f1; f1 f2 1 ---1--- 2 ---2--- UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 2; -select * from t1; +select * from t1 order by f1; f1 f2 1 ---1--- 6 ---2--- UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 1; -select * from t1; +select * from t1 order by f1; f1 f2 5 ---1--- 6 ---2--- diff --git a/mysql-test/t/ndb_partition_range.test b/mysql-test/t/ndb_partition_range.test index e64dc80886a..981467d4055 100644 --- a/mysql-test/t/ndb_partition_range.test +++ b/mysql-test/t/ndb_partition_range.test @@ -252,9 +252,9 @@ PARTITION BY RANGE(f1) PARTITION part2 VALUES LESS THAN (1000)); INSERT INTO t1 VALUES(1, '---1---'); INSERT INTO t1 VALUES(2, '---2---'); -select * from t1; +select * from t1 order by f1; UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 2; -select * from t1; +select * from t1 order by f1; UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 1; -select * from t1; +select * from t1 order by f1; drop table t1;