Add a new autoconf paremeter --{en,dis}able-community-features . The
default is disable for enterprise servers.
Though this is a 5.0 tree, it is only to be merged into the 5.0-community
tree and the global 5.1 tree, never to the 5.0-enterprise tree.
configure.in:
Add a new configure parameter, --enable-community-features for community
features.
mysql-test/t/profiling.test:
Add testing for whether profiling is enabled or not.
sql/mysqld.cc:
Add additional "COMMUNITY_SERVER" cpp definition test.
sql/set_var.cc:
Add additional "COMMUNITY_SERVER" cpp definition test.
sql/sql_class.cc:
Add additional "COMMUNITY_SERVER" cpp definition test.
sql/sql_class.h:
Add additional "COMMUNITY_SERVER" cpp definition test.
sql/sql_parse.cc:
Add additional "COMMUNITY_SERVER" cpp definition test.
sql/sql_prepare.cc:
Add additional "COMMUNITY_SERVER" cpp definition test.
sql/sql_profile.cc:
Add additional "COMMUNITY_SERVER" cpp definition test.
sql/sql_profile.h:
Add additional "COMMUNITY_SERVER" cpp definition test.
sql/sql_show.cc:
Add "COMMUNITY_SERVER" cpp definition test.
mysql-test/include/profiling.inc:
Add testing for whether profiling is enabled or not.
mysql-test/r/profiling.require:
Add testing for whether profiling is enabled or not.
halfway through a query (as happens in "SET SESSION PROFILING = ...")
has a few side-effects, the worst of which is a memory leak for
prepared statements, which poke directly from the parser into the
profiling code (we don't have the query text when we need it) and
that overwrites a pointer to heap-allocated memory when the previous
statement turns on profiling.
Instead, now set a flag when we begin a new statement that tracks
whether profiling is on _at the start_ of the query. Use that to
track whether we gather info.
Additionally, use that AND use the state of the profiling variable
after the end of a query to know whether to store information about
the query that just finished.
mysql-test/r/profiling.result:
Testing whether profiling is on at the beginning of a query and at
the end of a query makes "SET SESSION PROFILING = ..." statements
disappear from the profiling. They were never reliable before.
sql/sql_profile.cc:
Check to see if profiling was enabled at the beginning of this query
before trying to store query_source. This avoids a memory leak for
prepared statements, which get here by direct means.
If profiling was toggled in this query, then don't store this query
profile.
sql/sql_profile.h:
Keep track of whether profiling is on.
is a special case in "SHOW PROFILE FOR QUERY n". No one can get
the zero item (which is always the statement that turns on profiling),
because zero represents the final item, internally.
Now, order the queries starting at one.
mysql-test/r/profiling.result:
Renumber the query IDs.
sql/sql_profile.cc:
Start the profile_id_counter at 1, to overstep the special-case
value of zero.
Unrelated, but looks similar: don't use -1 to initialize an unsigned
integer field. That causes warnings in some environments.
B-g#27501: 5.0 significantly more sys ("kernel") time than 4.1 \
due to getrusage() calls
Even if profiling is turned off, the parser makes calls to reset
the state at the beginning of each query. That would eventually
instantiate a PROFILE_ENTRY, which does indeed capture resource
usage.
Instead, now check that profiling is active before progressing
far into the storage/expiration of old entries in the history.
This has the pleasant side-effect that queries to toggle profiling
are not recorded in the history.
mysql-test/r/profiling.result:
Now after we turn off profiling, the beginning of the next query
refuses to enter the profiling code and it discards the info.
sql/sql_profile.cc:
Add the same condition twice: Once to abort storing previous
query information and the other to abort initialization for this
query that is starting.
We do this symmetrically, before and after expiring old history
entries, so that the counts are correct.
B-g#26600: table PROFILING in INFORMATION SCHEMA has wrong data type
B-g#27047[partial]: INFORMATION_SCHEMA table cannot have BIGINT \
fields
No Information_schema table has ever needed floating-point data
before. Transforming all floating point to a string and back to a
number causes a real data problem on Windows, where the libc may
pad the exponent with more leading zeroes than we expect and the
significant digits are truncated away.
This also makes interpreting an unimplemented type as a string into
a fatal error in debug builds. Thus, we will catch problems when we
try to use those types in new I_S tables.
sql/sql_show.cc:
Add floating-point types to Information_schema output.
B-g#27060: SQL Profile utility may not be reporting right duration \
for each step
Whenever the profiler is reset at the beginning of a query, there's
a "hidden" profiling entry that represents that point in time. It
has no status description, as those are set by state changes and no
such point has yet been encountered. That profiling entry is not
in the list of entries generated when we change states.
The profiling code had the problem that each step of printing
profiling data subtracted the previous "step"'s data, but gave the
label to that data of the current step, which is wrong. The label/
state refers to the period beginning with that profiling data, not
ending with it.
Now, give a label to the first profiling pseudo-entry, so that we
have a name to assign to the period that ends with the first state
change. Now also use the state name of the previous step in showing
the delta values that end with this step.
sql/sql_profile.cc:
Store a status of "initializing" whenever we construct the first
profile entry -- the one that gets reset whenever we're starting
a new query, before the server sets a real status.
Additionally, associate the previous status with the time period
that ends with the current profile entry's stats.
Since we need yet another piece of info from the previous profiling
entry, take out the piecemeal ways we currently do it and make a
general pointer to the whole thing.
B-g#24795: SHOW PROFILE implementation
Don't use memory roots to store profiling information, because
memory roots make freeing the data a no-op, and thus long-running
processes with profiling turned on the whole time could eventually
use all available memory.
Instead, use regular heap allocation and deallocation calls to
manage profiling data. Replace the leaky List usage with a similar-
behaving structure named "Queue".
sql/sql_profile.cc:
Don't use C++ iterators on our simple Queue implementation. They're
not implemented and we don't really need them.
Rip out idea of swapping out the thd's mem_root.
sql/sql_profile.h:
Rip out idea of needing a mem_root.
Implement a Queue that looks and behaves very similarly to memroot-
using List.
Fixed bug #27362: crash at evaluation of IN predicate when one
of its argument happened to be a decimal expression returning
the NULL value.
The crash was due to the fact the function in_decimal::set did
not take into account that val_decimal() could return 0 if
the decimal expression had been evaluated to NULL.
mysql-test/r/func_in.result:
Added a test case for bug #27362.
mysql-test/t/func_in.test:
Added a test case for bug #27362.
sql/item_cmpfunc.cc:
Fixed bug #27362: crash at evaluation of IN predicate when one
of its argument happened to be a decimal expression returning
the NULL value.
The crash was due to the fact the function in_decimal::set did
not take into account that val_decimal() could return 0 if
the decimal expression had been evaluated to NULL.
into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community
VC++Files/sql/mysqld.vcproj:
Auto merged
include/config-win.h:
Auto merged
myisam/mi_open.c:
Auto merged
mysql-test/r/information_schema_db.result:
Auto merged
ndb/src/common/util/File.cpp:
Auto merged
sql/Makefile.am:
Auto merged
sql/ha_archive.cc:
Auto merged
sql/ha_berkeley.cc:
Auto merged
sql/ha_myisam.cc:
Auto merged
sql/ha_myisammrg.cc:
Auto merged
sql/ha_ndbcluster.cc:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_func.cc:
Auto merged
sql/lock.cc:
Auto merged
sql/log_event.cc:
Auto merged
sql/repl_failsafe.cc:
Auto merged
sql/set_var.cc:
Auto merged
sql/set_var.h:
Auto merged
sql/sp_head.cc:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_cache.cc:
Auto merged
sql/sql_class.cc:
Auto merged
sql/sql_class.h:
Auto merged
sql/sql_delete.cc:
Auto merged
sql/sql_insert.cc:
Auto merged
sql/sql_lex.cc:
Auto merged
sql/sql_lex.h:
Auto merged
sql/sql_prepare.cc:
Auto merged
sql/sql_repl.cc:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_show.cc:
Auto merged
sql/sql_table.cc:
Auto merged
sql/sql_update.cc:
Auto merged
sql/sql_view.cc:
Auto merged
sql/sql_yacc.yy:
Auto merged
sql/table.h:
Auto merged
support-files/mysql.spec.sh:
Auto merged
configure.in:
Manual merge.
include/my_dbug.h:
Manual merge.
sql/mysql_priv.h:
Manual merge.
sql/mysqld.cc:
Manual merge.
sql/slave.cc:
Manual merge.
sql/sql_parse.cc:
Manual merge.
- Problem: data separators were copied to a fixed-size buffer
on the stack; memcpy was used, without bounds checking; a
server crash could result if long FIELDS ENCLOSED BY, etc.,
was given
- Fix: write the separators directly, instead of copying to
a buffer first (in select_export::send_data())
sql/sql_class.cc:
In select_export::send_data(), write data separators
directly, instead of copying into a fixed-size memory
buffer before writing. This avoids a buffer overflow
when very large separators are specified.
sql/item_cmpfunc.cc:
Ensure both operands of a comparison are cast to "ulonglong", not just one only.
Without this, some 64-bit big-endian hosts failed test "func_in" when 5.0.38 builds were started.
Patch provided by Timothy.
- Build sql files for netware from the mysql_system_tables*.sq files
- Fix comments about mysql_create_system_tables.sh
- Use mysql_install_db.sh to create system tables for mysql_test-run-shell
- Fix mysql-test-run.pl to also look in share/mysql for the msyql_system*.sql files
Changeset coded today by Magnus Svensson, just the application to 5.0.38 is by Joerg Bruehe.
BitKeeper/deleted/.del-init_db.sql~e2b8d0c8390e8023:
Delete: netware/init_db.sql
BitKeeper/deleted/.del-test_db.sql:
Delete: netware/test_db.sql
BitKeeper/etc/ignore:
Added netware/init_db.sql netware/test_db.sql to the ignore list
mysql-test/install_test_db.sh:
Use mysql_install_db from install_test_db(which is used by mysql-test-run-shell)
to install the system tables
mysql-test/mysql-test-run.pl:
Look for the mysql_system_tables*.sql also in share/mysql
netware/Makefile.am:
Build netware/init_db.sql and netware/test_db.sql from
the sources in scripts/msyql_system_tables*.sql
scripts/make_binary_distribution.sh:
netware/init_db.sql and netware/test_db.sql are now built by the Makefiles
from the scripts/mysql_system_tables*.sql files
sql/mysql_priv.h:
Update comment remindging to update the MySQL system table definitions
when adding a new SQL_MODE
sql/sql_acl.h:
Update comment reminding to update the MySQL System tables
when changing the ACL defines
TABLE ... WRITE".
Memory and CPU hogging occured when connection which had to wait for table
lock was serviced by thread which previously serviced connection that was
killed (note that connections can reuse threads if thread cache is enabled).
One possible scenario which exposed this problem was when thread which
provided binlog dump to replication slave was implicitly/automatically
killed when the same slave reconnected and started pulling data through
different thread/connection.
The problem also occured when one killed particular query in connection
(using KILL QUERY) and later this connection had to wait for some table
lock.
This problem was caused by the fact that thread-specific mysys_var::abort
variable, which indicates that waiting operations on mysys layer should
be aborted (this includes waiting for table locks), was set by kill
operation but was never reset back. So this value was "inherited" by the
following statements or even other connections (which reused the same
physical thread). Such discrepancy between this variable and THD::killed
flag broke logic on SQL-layer and caused CPU and memory hogging.
This patch tries to fix this problem by properly resetting this member.
There is no test-case associated with this patch since it is hard to test
for memory/CPU hogging conditions in our test-suite.
sql/mysqld.cc:
We should not forget to reset THD::mysys_var::abort after kill operation
if we are going to use thread to which this operation was applied for
handling of other connections.
sql/sp_head.cc:
We should not forget to reset THD::mysys_var::abort after kill operation
if we are going to use thread to which this operation was applied for
handling of further statements.
sql/sql_parse.cc:
We should not forget to reset THD::mysys_var::abort after kill operation
if we are going to use thread to which this operation was applied for
handling of further statements.
TABLE ... WRITE".
CPU hogging occured when connection which had to wait for table lock was
serviced by thread which previously serviced connection that was killed
(note that connections can reuse threads if thread cache is enabled).
One possible scenario which exposed this problem was when thread which
provided binlog dump to replication slave was implicitly/automatically
killed when the same slave reconnected and started pulling data through
different thread/connection.
In 5.* versions memory hogging was added to CPU hogging. Moreover in
those versions the problem also occured when one killed particular query
in connection (using KILL QUERY) and later this connection had to wait for
some table lock.
This problem was caused by the fact that thread-specific mysys_var::abort
variable, which indicates that waiting operations on mysys layer should
be aborted (this includes waiting for table locks), was set by kill
operation but was never reset back. So this value was "inherited" by the
following statements or even other connections (which reused the same
physical thread). Such discrepancy between this variable and THD::killed
flag broke logic on SQL-layer and caused CPU and memory hogging.
This patch tries to fix this problem by properly resetting this member.
There is no test-case associated with this patch since it is hard to test
for memory/CPU hogging conditions in our test-suite.
sql/mysqld.cc:
We should not forget to reset THD::mysys_var::abort after kill operation
if we are going to use thread to which this operation was applied for
handling of other connections.
into mysql.com:/home/svoj/devel/mysql/BUG26881/mysql-5.0-engines
myisam/mi_create.c:
Auto merged
mysql-test/t/merge.test:
Auto merged
sql/ha_myisam.cc:
Auto merged
sql/sql_parse.cc:
Use local.
mysql-test/r/merge.result:
SCCS merged
differences in tables
Certain merge tables were wrongly reported as having incorrect definition:
- Some fields that are 1 byte long (e.g. TINYINT, CHAR(1)), might
be internally casted (in certain cases) to a different type on a
storage engine layer. (affects 4.1 and up)
- If tables in a merge (and a MERGE table itself) had short VARCHAR column (less
than 4 bytes) and at least one (but not all) tables were ALTER'ed (even to an
identical table: ALTER TABLE xxx ENGINE=yyy), table definitions went ouf of
sync. (affects 4.1 only)
This is fixed by relaxing a check for underlying conformance and setting
field type to FIELD_TYPE_STRING in case varchar is shorter than 4
when a table is created.
myisam/mi_create.c:
Added a comment.
mysql-test/r/merge.result:
A test case for bug#26881.
mysql-test/t/merge.test:
A test case for bug#26881.
sql/ha_myisam.cc:
Relaxed some checks performed by check_definition():
As comparing of fulltext keys (and key segments) is not yet implemented,
only return an error in case one of keys is fulltext and other is not.
Otherwise, if both keys are fulltext, accept them as is.
As comparing of spatial keys (and key segments) is not yet implemented,
only return an error in case one of keys is spatial and other is not.
Otherwise, if both keys are spatial, accept them as is.
A workaround to handle situation when field is casted from FIELD_SKIP_ZERO
to FIELD_NORMAL. This could happen only in case field length is 1 and row
format is fixed.
sql/sql_parse.cc:
When a table that has varchar field shorter than 4 is created, field type is
set to FIELD_TYPE_VAR_STRING. Later, when a table is modified using alter
table, field type is changed to FIELD_TYPE_STRING (see Field_string::type).
That means HA_OPTION_PACK_RECORD flag might be lost and thus null_bit might
be shifted by alter table, in other words alter table doesn't create 100%
equal table definition.
This is usually not a problem, since when a table is created/altered,
definition on a storage engine layer is based on one that is passed from
sql layer. But it is a problem for merge engine - null_bit is shifted when
a table (merge or underlying) is altered.
Set field type to FIELD_TYPE_STRING in case FIELD_TYPE_VAR_STRING is shorter
than 4 when a table is created as it is done in Field::type.
When the SUBSTRING() function was used over a LONGTEXT field the max_length of
the SUBSTRING() result was wrongly calculated and set to 0. As the max_length
parameter is used while tmp field creation it limits the length of the result
field and leads to printing an empty string instead of the correct result.
Now the Item_func_substr::fix_length_and_dec() function correctly calculates
the max_length parameter.
mysql-test/t/func_str.test:
Added a test case for the bug#15757: Wrong SUBSTRING() result when a tmp table was employed.
mysql-test/r/func_str.result:
Added a test case for the bug#15757: Wrong SUBSTRING() result when a tmp table was employed.
sql/item_strfunc.cc:
Bug#15757: Wrong SUBSTRING() result when a tmp table was employed.
Now the Item_func_substr::fix_length_and_dec() function correctly calculates
the max_length parameter.
into moonbone.local:/mnt/gentoo64/work/25373-bug-5.0-opt-mysql
mysql-test/r/func_str.result:
Auto merged
mysql-test/r/subselect.result:
Auto merged
mysql-test/r/union.result:
Auto merged
sql/item.cc:
Auto merged
Crash happened because the function get_best_group_min_max detected
joins with ROLLUP incorrectly.
mysql-test/r/olap.result:
Added a test case for bug #26830.
mysql-test/t/olap.test:
Added a test case for bug #26830.
away.
Additional fix for bug#22331. Now Item_field prints its value in the case of
the const field.
mysql-test/r/varbinary.result:
Corrected test case after fix for bug#22331.
mysql-test/r/union.result:
Corrected test case after fix for bug#22331.
mysql-test/r/subselect.result:
Corrected test case after fix for bug#22331.
mysql-test/r/func_test.result:
Corrected test case after fix for bug#22331.
mysql-test/r/having.result:
Corrected test case after fix for bug#22331.
mysql-test/r/func_regexp.result:
Corrected test case after fix for bug#22331.
mysql-test/r/func_str.result:
Corrected test case after fix for bug#22331.
mysql-test/r/func_default.result:
Corrected test case after fix for bug#22331.
mysql-test/r/explain.result:
Corrected test case after fix for bug#22331.
sql/sql_union.cc:
Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
away.
Cleanup of the SELECT_LEX::order_list list.
sql/item.h:
Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
away.
Added the print() member function to the Item_field class.
sql/item.cc:
Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
away.
Added the print() member function to the Item_field class.
into magare.gmz:/home/kgeorge/mysql/autopush/B26281-5.0-opt
sql/item_strfunc.cc:
Auto merged
mysql-test/r/func_str.result:
resolved test merge conflicts
mysql-test/t/func_str.test:
resolved test merge conflicts
Fixed boundry checks in the INSERT() function:
were one off.
mysql-test/r/func_str.result:
Bug #26281: test case
mysql-test/t/func_str.test:
Bug #26281: test case
sql/item_strfunc.cc:
Bug #26281: fixed boundry checks
construct references invalid name.
Derived tables currently cannot use outer references.
Thus there is no outer context for them.
The 4.1 code takes this fact into account while the
Item_field::fix_outer_field code of 5.0 lost the check that blocks
any attempts to resolve names in outer context for derived tables.
mysql-test/r/union.result:
Added a test case for bug #26661.
mysql-test/t/union.test:
Added a test case for bug #26661.
sql/item.cc:
Fixed bug #26661.
Derived tables currently cannot use outer references.
Thus there is no outer context for them.
The 4.1 code takes this fact into account while the
Item_field::fix_outer_field code of 5.0 lost the check that blocks
any attempts to resolve names in outer context for derived tables.
into mysql.com:/home/hf/work/mrg/mysql-5.0-opt
mysql-test/r/order_by.result:
Auto merged
mysql-test/r/subselect.result:
Auto merged
mysql-test/t/order_by.test:
Auto merged
mysql-test/t/sp.test:
Auto merged
sql/item.cc:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_cmpfunc.h:
Auto merged
sql/item_func.cc:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_insert.cc:
Auto merged
sql/sql_lex.cc:
Auto merged
sql/sql_lex.h:
Auto merged
sql/sql_load.cc:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_update.cc:
Auto merged
mysql-test/r/func_str.result:
merging
mysql-test/r/sp.result:
merging
mysql-test/r/view.result:
merging
mysql-test/t/func_str.test:
merging
mysql-test/t/view.test:
merging
into quadxeon.mysql.com:/benchmarks/ext3/TOSAVE/tsmith/bk/maint/mrg0306/50
sql/mysqld.cc:
Auto merged
sql/sql_class.cc:
Auto merged
sql/sql_class.h:
Auto merged
sql/sql_parse.cc:
Auto merged
Postfix for bug#22331 for windows platform.
explain.test, explain.result:
Cleanup after bugfix#22331.
mysql-test/t/explain.test:
Cleanup after bugfix#22331.
mysql-test/r/explain.result:
Cleanup after bugfix#22331.
sql/sql_select.cc:
Postfix for bug#22331 for windows platform.
into moonbone.local:/mnt/gentoo64/work/25373-bug-5.0-opt-mysql
mysql-test/r/subselect.result:
Auto merged
sql/sql_lex.h:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_lex.cc:
SCCS merged
result.
For built-in functions like sqrt() function names are hard-coded and can be
compared by pointer. But this isn't the case for a used-defined stored
functions - names there are dynamical and should be compared as strings.
Now the Item_func::eq() function employs my_strcasecmp() function to compare
used-defined stored functions names.
mysql-test/t/sp.test:
Added a test case for bug#25373: Stored functions wasn't compared correctly which leads to a wrong result.
mysql-test/r/sp.result:
Added a test case for bug#25373: Stored functions wasn't compared correctly which leads to a wrong result.
sql/item_func.cc:
Bug#25373: Stored functions wasn't compared correctly which leads to a wrong
result.
Now the Item_func::eq() function employs my_strcasecmp() function to compare
used-defined stored functions names.
away.
During optimization stage the WHERE conditions can be changed or even
be removed at all if they know for sure to be true of false. Thus they aren't
showed in the EXPLAIN EXTENDED which prints conditions after optimization.
Now if all elements of an Item_cond were removed this Item_cond is substituted
for an Item_int with the int value of the Item_cond.
If there were conditions that were totally optimized away then values of the
saved cond_value and having_value will be printed instead.
mysql-test/t/explain.test:
Added a test case for the bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized away.
mysql-test/r/subselect.result:
Corrected test case result after fix for bug#22331.
mysql-test/r/func_test.result:
Corrected test case result after fix for bug#22331.
mysql-test/r/explain.result:
Added a test case for the bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized away.
sql/sql_select.cc:
Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
away.
Now if all elements of an Item_cond were removed this Item_cond is substituted
for an Item_int with the int value of the Item_cond.
If there were conditions that were totally optimized away then values of the
saved cond_value and having_value will be printed instead.
sql/sql_lex.h:
Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
away.
The cond_value and the having_value variables are
added to the SELECT_LEX class.
sql/sql_lex.cc:
Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
away.
The initialization of the cond_value and the having_value variables.
sql/sql_select.h:
Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
away.
Now having_value is also stored in the JOIN class.
into bodhi.local:/opt/local/work/mysql-5.0-26750
sql/mysqld.cc:
Auto merged
sql/sql_class.cc:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_class.h:
Manual merge.
fixes).
The legend: on a replication slave, in case a trigger creation
was filtered out because of application of replicate-do-table/
replicate-ignore-table rule, the parsed definition of a trigger was not
cleaned up properly. LEX::sphead member was left around and leaked
memory. Until the actual implementation of support of
replicate-ignore-table rules for triggers by the patch for Bug 24478 it
was never the case that "case SQLCOM_CREATE_TRIGGER"
was not executed once a trigger was parsed,
so the deletion of lex->sphead there worked and the memory did not leak.
The fix:
The real cause of the bug is that there is no 1 or 2 places where
we can clean up the main LEX after parse. And the reason we
can not have just one or two places where we clean up the LEX is
asymmetric behaviour of MYSQLparse in case of success or error.
One of the root causes of this behaviour is the code in Item::Item()
constructor. There, a newly created item adds itself to THD::free_list
- a single-linked list of Items used in a statement. Yuck. This code
is unaware that we may have more than one statement active at a time,
and always assumes that the free_list of the current statement is
located in THD::free_list. One day we need to be able to explicitly
allocate an item in a given Query_arena.
Thus, when parsing a definition of a stored procedure, like
CREATE PROCEDURE p1() BEGIN SELECT a FROM t1; SELECT b FROM t1; END;
we actually need to reset THD::mem_root, THD::free_list and THD::lex
to parse the nested procedure statement (SELECT *).
The actual reset and restore is implemented in semantic actions
attached to sp_proc_stmt grammar rule.
The problem is that in case of a parsing error inside a nested statement
Bison generated parser would abort immediately, without executing the
restore part of the semantic action. This would leave THD in an
in-the-middle-of-parsing state.
This is why we couldn't have had a single place where we clean up the LEX
after MYSQLparse - in case of an error we needed to do a clean up
immediately, in case of success a clean up could have been delayed.
This left the door open for a memory leak.
One of the following possibilities were considered when working on a fix:
- patch the replication logic to do the clean up. Rejected
as breaks module borders, replication code should not need to know the
gory details of clean up procedure after CREATE TRIGGER.
- wrap MYSQLparse with a function that would do a clean up.
Rejected as ideally we should fix the problem when it happens, not
adjust for it outside of the problematic code.
- make sure MYSQLparse cleans up after itself by invoking the clean up
functionality in the appropriate places before return. Implemented in
this patch.
- use %destructor rule for sp_proc_stmt to restore THD - cleaner
than the prevoius approach, but rejected
because needs a careful analysis of the side effects, and this patch is
for 5.0, and long term we need to use the next alternative anyway
- make sure that sp_proc_stmt doesn't juggle with THD - this is a
large work that will affect many modules.
Cleanup: move main_lex and main_mem_root from Statement to its
only two descendants Prepared_statement and THD. This ensures that
when a Statement instance was created for purposes of statement backup,
we do not involve LEX constructor/destructor, which is fairly expensive.
In order to track that the transformation produces equivalent
functionality please check the respective constructors and destructors
of Statement, Prepared_statement and THD - these members were
used only there.
This cleanup is unrelated to the patch.
sql/log_event.cc:
THD::main_lex is private and should not be used.
sql/mysqld.cc:
Move MYSQLerror to sql_yacc.yy as it depends on LEX headers now.
sql/sql_class.cc:
Cleanup: move main_lex and main_mem_root to THD and Prepared_statement
sql/sql_class.h:
Cleanup: move main_lex and main_mem_root to THD and Prepared_statement
sql/sql_lex.cc:
Implement st_lex::restore_lex()
sql/sql_lex.h:
Declare st_lex::restore_lex().
sql/sql_parse.cc:
Consolidate the calls to unit.cleanup() and deletion of lex->sphead
in mysql_parse (COM_QUERY handler)
sql/sql_prepare.cc:
No need to delete lex->sphead to restore memory roots now in case of a
parse error - this is done automatically inside MYSQLparse
sql/sql_trigger.cc:
This code could lead to double deletion apparently, as in case
of an error lex.sphead was never reset.
sql/sql_yacc.yy:
Trap all returns from the parser to ensure that MySQL-specific cleanup
is invoked: we need to restore the global state of THD and LEX in
case of a parsing error. In case of a parsing success this happens as
part of normal grammar reduction process.
into quadxeon.mysql.com:/benchmarks/ext3/TOSAVE/tsmith/bk/maint/mrg0306/50
mysql-test/mysql-test-run.pl:
Auto merged
mysql-test/r/sp.result:
Auto merged
mysql-test/t/sp.test:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_cmpfunc.h:
Auto merged
sql/mysqld.cc:
Auto merged
sql/sql_class.cc:
Auto merged
sql/sql_class.h:
Auto merged
sql/sql_parse.cc:
Auto merged