summaryrefslogtreecommitdiff
path: root/sql/sql_class.cc
diff options
context:
space:
mode:
authorunknown <konstantin@mysql.com>2004-10-08 02:21:19 +0400
committerunknown <konstantin@mysql.com>2004-10-08 02:21:19 +0400
commit5eba8d3ae590348c6b5dceb6a83fa53ec58e557e (patch)
treea5dc36f841657f3f8e88422732495d2f85a82a86 /sql/sql_class.cc
parent258e68ad1a953af8c1218b1456bde08db6a9622f (diff)
downloadmariadb-git-5eba8d3ae590348c6b5dceb6a83fa53ec58e557e.tar.gz
A fix for Bug#5748 "Prepared statement with BETWEEN and bigint values
crashes mysqld": implementation for a generic item tree modifications registry. Every item tree modification which should be rolled back for subsequent execution of a prepared statement or stored procedure should be saved in the registry. All such modifications are rolled back at once during cleanup stage of PS. Actual fix for the bug just adds a call to register modifications to convert_constant_item. Post review fixes implemented. mysql-test/r/ps.result: A fix for bug#5748, test results fixed. mysql-test/t/ps.test: A test case for Bug#5748 "Prepared statement with BETWEEN and bigint values crashes mysqld" sql/item.cc: Fix for Bug#5748 "Prepared statement with BETWEEN and bigint values crashes mysqld": First step in removing up item-specific cleanups: now all such tree modifications should be done using the genericm mechanism implemented in this changeset. sql/item.h: Fix for Bug#5748 "Prepared statement with BETWEEN and bigint values crashes mysqld": no need for an item-specific change record any more. sql/item_cmpfunc.cc: A fix for Bug#5748 "Prepared statement with BETWEEN and bigint values crashes mysqld": register item tree transformation performed by convert_constant_item. sql/sql_class.cc: Implementation for item tree transformations registry. sql/sql_class.h: Declarations, necessary for the tree transformations registry. sql/sql_parse.cc: Assert that the item tree transformations registry is not used for conventional execution. sql/sql_prepare.cc: Use of the item tree modifications registry in prepared statements: rollback all modifications in the end of statement prepare and execute. Also we now always set thd->current_arena to be able to determine that this is an execution of prepared statement inside the registry code. tests/client_test.c: A typo fixed.
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r--sql/sql_class.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 6cf01896b03..d38ad73a9f4 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -698,6 +698,54 @@ void THD::close_active_vio()
#endif
+struct Item_change_record: public ilink
+{
+ Item **place;
+ Item *old_value;
+ /* Placement new was hidden by `new' in ilink (TODO: check): */
+ static void *operator new(unsigned int size, void *mem) { return mem; }
+};
+
+
+/*
+ Register an item tree tree transformation, performed by the query
+ optimizer. We need a pointer to runtime_memroot because it may be !=
+ thd->mem_root (due to possible set_n_backup_item_arena called for thd).
+*/
+
+void THD::nocheck_register_item_tree_change(Item **place, Item *old_value,
+ MEM_ROOT *runtime_memroot)
+{
+ Item_change_record *change;
+ /*
+ Now we use one node per change, which adds some memory overhead,
+ but still is rather fast as we use alloc_root for allocations.
+ A list of item tree changes of an average query should be short.
+ */
+ void *change_mem= alloc_root(runtime_memroot, sizeof(*change));
+ if (change_mem == 0)
+ {
+ fatal_error();
+ return;
+ }
+ change= new (change_mem) Item_change_record;
+ change->place= place;
+ change->old_value= old_value;
+ change_list.push_back(change);
+}
+
+
+void THD::rollback_item_tree_changes()
+{
+ I_List_iterator<Item_change_record> it(change_list);
+ Item_change_record *change;
+ while ((change= it++))
+ *change->place= change->old_value;
+ /* We can forget about changes memory: it's allocated in runtime memroot */
+ change_list.empty();
+}
+
+
/*****************************************************************************
** Functions to provide a interface to select results
*****************************************************************************/