Commit graph

380 commits

Author SHA1 Message Date
unknown
4a834b4b12 Merge kaamos.(none):/data/src/mysql-5.0
into  kaamos.(none):/data/src/opt/mysql-5.0-opt


mysql-test/r/variables.result:
  Auto merged
mysql-test/t/variables.test:
  Auto merged
sql/item.cc:
  Auto merged
sql/item_cmpfunc.cc:
  Auto merged
sql/sql_acl.cc:
  Auto merged
sql/sql_select.cc:
  Auto merged
sql/sql_yacc.yy:
  Auto merged
mysql-test/r/sp.result:
  Manual merge.
mysql-test/t/sp.test:
  Manual merge.
2008-02-17 14:37:39 +03:00
unknown
754c3f51ec Bug#30787: Stored function ignores user defined alias.
Simple subselects are pulled into upper selects. This operation substitutes the
pulled subselect for the first item from the select list of the subselect.
If an alias is defined for a subselect it is inherited by the replacement item.
As this is done after fix_fields phase this alias isn't showed if the
replacement item is a stored function. This happens because the Item_func_sp::make_field
function makes send field from its result_field and ignores the defined alias.

Now when an alias is defined the Item_func_sp::make_field function sets it for
the returned field.


mysql-test/t/sp.test:
  Added a test case for the bug#30787: Stored function ignores user defined alias.
mysql-test/r/sp.result:
  Added a test case for the bug#30787: Stored function ignores user defined alias.
sql/item_func.cc:
  Bug#30787: Stored function ignores user defined alias.
  Now when an alias is defined the Item_func_sp::make_field function sets it for
  the returned field.
2008-01-31 23:46:26 +03:00
unknown
e7b65baa3f Merge malff@bk-internal.mysql.com:/home/bk/mysql-5.0-runtime
into  lambda.hsd1.co.comcast.net.:/home/malff/TREE/mysql-5.0-33618


mysql-test/t/sp.test:
  Auto merged
sql/sp_head.cc:
  Auto merged
sql/sql_yacc.yy:
  Auto merged
2008-01-23 14:04:46 -07:00
unknown
e6a077e348 Bug#33618 (Crash in sp_rcontext)
Bug 33983 (Stored Procedures: wrong end <label> syntax is accepted)

The server used to crash when REPEAT or another control instruction
was used in conjunction with labels and a LEAVE instruction.

The crash was caused by a missing "pop" of handlers or cursors in the
code representing the stored program. When executing the code in a loop,
this missing "pop" would result in a stack overflow, corrupting memory.

Code generation has been fixed to produce the missing h_pop/c_pop
instructions.

Also, the logic checking that labels at the beginning and the end of a
statement are matched was incorrect, causing Bug 33983.
End labels, when used, must match the label used at the beginning of a block.


mysql-test/r/sp-code.result:
  Bug#33618 (Crash in sp_rcontext)
mysql-test/r/sp-error.result:
  Bug 33983 (Stored Procedures: wrong end <label> syntax is accepted)
mysql-test/r/sp.result:
  Bug#33618 (Crash in sp_rcontext)
mysql-test/t/sp-code.test:
  Bug#33618 (Crash in sp_rcontext)
mysql-test/t/sp-error.test:
  Bug 33983 (Stored Procedures: wrong end <label> syntax is accepted)
mysql-test/t/sp.test:
  Bug#33618 (Crash in sp_rcontext)
sql/sp_head.cc:
  Bug#33618 (Crash in sp_rcontext)
sql/sp_head.h:
  Bug#33618 (Crash in sp_rcontext)
sql/sp_rcontext.cc:
  Bug#33618 (Crash in sp_rcontext)
sql/sp_rcontext.h:
  Bug#33618 (Crash in sp_rcontext)
sql/sql_yacc.yy:
  Bug#33618 (Crash in sp_rcontext)
2008-01-23 13:26:41 -07:00
unknown
10b009d2bb Bug#29770 Two handlers are allowed to catch an error in an stored procedure.
Add test case.


mysql-test/r/sp.result:
  Add test case result for Bug#29770
mysql-test/t/sp.test:
  Add test case for Bug#29770
2008-01-08 18:43:25 -02:00
unknown
28ef3b2a7f Implementing code review comments
mysql-test/r/sp.result:
  Added tests for coverage
mysql-test/t/sp.test:
  Added tests for coverage
sql/sql_udf.cc:
  Code cleanup
2007-10-16 11:16:31 -06:00
unknown
77c5085882 Cleanup sp.test.
mysql-test/r/sp.result:
  Update result file.
2007-10-10 14:42:29 +04:00
unknown
7ac3645abd Merge bk-internal.mysql.com:/home/bk/mysql-5.0
into  bodhi.(none):/opt/local/work/mysql-5.0-runtime


mysql-test/r/sp.result:
  Auto merged
mysql-test/t/sp.test:
  Auto merged
sql/sql_parse.cc:
  Auto merged
2007-10-08 02:05:55 +04:00
unknown
4f14c13a1c Fix for BUG#31035: select from function, group by result crasher.
This actually, fix for the patch for bug-27354. The problem with
the patch was that Item_func_sp::used_tables() was updated, but
Item_func_sp::const_item() was not. So, for Item_func_sp, we had
the following inconsistency:
  - used_tables() returned RAND_TABLE, which means that the item
    can produce "random" results;
  - but const_item() returned TRUE, which means that the item is
    a constant one.

The fix is to change Item_func_sp::const_item() behaviour: it must
return TRUE (an item is a constant one) only if a stored function
is deterministic and each of its arguments (if any) is a constant
item.


mysql-test/r/sp.result:
  Update result file.
mysql-test/t/sp.test:
  Add test cases for BUG-31035, BUG-31191, BUG-31226
sql/item_func.cc:
  Make Item::const_item() be consistent with Item::used_tables().
2007-10-04 17:19:14 +04:00
unknown
2978fcc3e9 Merge gleb.loc:/home/uchum/work/bk/5.0
into  gleb.loc:/home/uchum/work/bk/5.0-opt


sql/sql_yacc.yy:
  Auto merged
mysql-test/r/sp.result:
  SCCS merged
mysql-test/t/sp.test:
  SCCS merged
2007-09-12 23:41:35 +05:00
unknown
76e37a32b8 Merge gleb.loc:/home/uchum/work/bk/5.0
into  gleb.loc:/home/uchum/work/bk/5.0-opt


mysql-test/r/sp.result:
  Auto merged
mysql-test/t/sp.test:
  Auto merged
2007-09-06 22:27:13 +05:00
unknown
3a94137ce0 Merge weblab.(none):/home/marcsql/TREE/mysql-5.0-base
into  weblab.(none):/home/marcsql/TREE/mysql-5.0-rt-merge


mysql-test/r/sp.result:
  Auto merged
mysql-test/t/mysql.test:
  Auto merged
mysql-test/t/sp.test:
  Auto merged
2007-09-04 14:38:26 -06:00
unknown
ee0b7d895d Bug#29408 Cannot find view in columns table if the selection contains a function
Use view db name as thread default database, in order to ensure
that the view is parsed and prepared correctly.


mysql-test/r/sp.result:
  test result
mysql-test/t/sp.test:
  test case
sql/sql_parse.cc:
  copy thd->db_length to table_list->db_length
sql/sql_view.cc:
  Use view db name as thread default database, in order to ensure
  that the view is parsed and prepared correctly.
2007-09-03 12:22:56 +05:00
unknown
3d5440505c Test case for Bug#13675: DATETIME/DATE type in store proc param
seems to be converted as varbinary.

The bug has been already fixed. This CS just adds a test case for it.


mysql-test/r/sp.result:
  Update result file.
mysql-test/t/sp.test:
  Test case for BUG#13675.
2007-08-29 14:57:59 +04:00
unknown
02d18d3cf9 Merge 192.168.0.7:mysql/mysql-5.0-maint
into  pilot.(none):/data/msvensson/mysql/mysql-5.0-maint


mysql-test/r/sp.result:
  Auto merged
mysql-test/t/sp.test:
  Auto merged
2007-08-03 12:57:09 +02:00
unknown
8b265ffcc1 Cleanup created procedures in sp.test
mysql-test/r/sp.result:
  Cleanup created procedures
mysql-test/t/sp.test:
  Cleanup created procedures
2007-08-03 12:56:45 +02:00
unknown
33fc4ad4e1 Fixed bug #30120.
SP with local variables with non-ASCII names crashed the server.

The server replaces SP local variable names with NAME_CONST calls
when putting statements into the binary log. It used UTF8-encoded
item names as variable names for the replacement inside NAME_CONST
calls. However, statement string may be encoded by any
known character set by the SET NAMES statement.
The server used byte length of UTF8-encoded names to increment
the position in the query string that led to array index overrun.


sql/item.cc:
  Fixed bug #30120.
  The Item_splocal class constructor has been modified to
  accept new parameter `len_in_q': the byte length of
  variable name in the query string.
sql/item.h:
  Fixed bug #30120.
  The Item_splocal class has been modified to keep new
  field `len_in_query': the byte length of variable name in
  the query string.
sql/sp_head.cc:
  Fixed bug #30120.
  The subst_spvars function has been modified to increment
  position in the query string by the lengths of not
  encoded variable names instead of byte length of names
  encoded to UTF-8.
sql/sql_yacc.yy:
  Fixed bug #30120.
  The simple_ident rule action has been modified to
  pass the byte length of the local variable name token
  to the Item_splocal object constructor.
mysql-test/t/sp.test:
  Updated test case for bug #30120.
mysql-test/r/sp.result:
  Updated test case for bug #30120.
2007-07-30 04:35:16 +05:00
unknown
3c1716151e Merge gleb.loc:/home/uchum/work/bk/5.0-opt-29834
into  gleb.loc:/home/uchum/work/bk/5.0-opt


sql/sql_base.cc:
  Auto merged
mysql-test/r/sp.result:
  Merge with local tree.
mysql-test/t/sp.test:
  Merge with local tree.
2007-07-28 23:36:27 +05:00
unknown
90c5621d6c Fixed bug #29834.
Using view columns by their names during an execution of
a prepared SELECT statement or a SELECT statement inside
a SP caused a memory leak.


sql/sql_base.cc:
  Fixed bug #29834.
  The find_field_in_view function has been modified to
  use the execution memory root for the Item_direct_view_ref
  objects allocation at non-first executions of
  a PS/SP instead of the statement memory.
mysql-test/t/sp.test:
  Updated test case for bug #29834.
mysql-test/r/sp.result:
  Updated test case for bug #29834.
2007-07-28 23:10:38 +05:00
unknown
9260c30d36 Merge gleb.loc:/home/uchum/work/bk/5.0-opt-29338
into  gleb.loc:/home/uchum/work/bk/5.0-opt


mysql-test/r/sp.result:
  Auto merged
mysql-test/t/sp.test:
  Merge with local tree.
2007-07-22 01:52:13 +05:00
unknown
9cad4f08db sp.test, sp.result:
Additional test case fix for bug #29338.


mysql-test/t/sp.test:
  Additional test case fix for bug #29338.
mysql-test/r/sp.result:
  Additional test case fix for bug #29338.
2007-07-22 01:49:41 +05:00
unknown
aed9a5fee3 Merge gleb.loc:/home/uchum/work/bk/5.0-opt-29338
into  gleb.loc:/home/uchum/work/bk/5.0-opt


mysql-test/r/sp.result:
  Merge with local tree
mysql-test/t/sp.test:
  Merge with local tree
2007-07-22 00:40:14 +05:00
unknown
36f1e4848c Fixed bug #29338.
Optimization of queries with DETERMINISTIC functions in the
WHERE clause was not effective: sequential scan was always
used.
Now a SF with the DETERMINISTIC flags is treated as constant
when it's arguments are constants (or a SF doesn't has arguments).


sql/item_func.h:
  Fixed bug #29338.
  The Item_func_sp::used_tables has been removed
  (virtual Item_func::used_tables function is enough).
  The virtual Item_func_sp::update_used_tables function
  has been added.
sql/item_func.cc:
  Fixed bug #29338.
  The Item_func_sp::update_used_tables and the
  Item_func_sp::fix_field functions have been modified
  to take into account the DETERMINISTIC flag of SF definition.
mysql-test/r/sp.result:
  Updated test case for bug #29338.
mysql-test/t/sp.test:
  Updated test case for bug #29338.
2007-07-19 18:39:01 +05:00
unknown
b94fb82847 Merge bk-internal.mysql.com:/home/bk/mysql-5.0
into  bodhi.(none):/opt/local/work/mysql-5.0-runtime


mysql-test/t/sp.test:
  Auto merged
sql/item.h:
  Auto merged
sql/sql_parse.cc:
  Auto merged
sql/sql_show.cc:
  Auto merged
sql/sql_yacc.yy:
  Auto merged
mysql-test/r/innodb_mysql.result:
  Manual merge.
mysql-test/t/innodb_mysql.test:
  Manual merge.
2007-07-16 23:41:28 +04:00
unknown
e8966deecc A fix and a test case for Bug#29050 Creation of a legal stored procedure
fails if a database is not selected prior.

The problem manifested itself when a user tried to
create a routine that had non-fully-qualified identifiers in its bodies
and there was no current database selected.

This is a regression introduced by the fix for Bug 19022:

The patch for Bug 19022 changes the code to always produce a warning
if we can't resolve the current database in the parser. 
In this case this was not necessary, since even though the produced
parsed tree was incorrect, we never re-use sphead
that was obtained at first parsing of CREATE PROCEDURE.
The sphead that is anyhow used is always obtained through db_load_routine,
and there we change the current database to sphead->m_db before
calling yyparse.

The idea of the fix is to resolve the current database directly using 
lex->sphead->m_db member when parsing a stored routine body, when
such is present.

This patch removes the need to reset the current database
when loading a trigger or routine definition into SP cache.
The redundant code will be removed in 5.1.


mysql-test/r/sp.result:
  Update test results (Bug#29050)
mysql-test/r/trigger.result:
  Update results.
mysql-test/t/sp.test:
  Add a test case for Bug#29050
mysql-test/t/trigger.test:
  Fix wrong behavior covered with tests.
sql/sql_lex.cc:
  Implement st_lex::copy_db_to().
sql/sql_lex.h:
  Declare st_lex::copy_db_to().
sql/sql_parse.cc:
  Use st_lex::copy_db_to() in add_table_to_list, rather than
  THD::copy_db_to(). The former will use the database of the sphead,
  if we're parsing a stored routine, not the default database in
  THD. The default database is needed to initialize tables->db
  when the database part was not explicitly specified in the identifier.
sql/sql_yacc.yy:
  Use st_lex::copy_db_to() in the parser, rather than
  THD::copy_db_to(). The former will use the database of the sphead,
  if we're parsing a stored routine, not the default database in
  THD.
2007-07-05 11:34:04 +04:00
unknown
b1ec3b534d A fix and a teset case for Bug#28551 The warning
'No database selected' is reported when calling stored procedures

Remove the offending warning introduced by the fix for Bug
25082
This minimal patch relies on the intrinsic knowledge of the fact that
mysql_change_db is never called with 'force_switch' set to TRUE
when such a warning may be needed:
 * every stored routine belongs to a database (unlike, e.g., a 
user defined function, which does not), so if we're activating the
database of a stored routine, it can never be NULL.
Therefore, this branch is never called for activation.
 * if we're restoring the 'old' current database after routine
execution is complete, we should not issue a warning, since it's OK to 
call a routine without having previously selected the current database.

TODO: 'force_switch' is an ambiguous flag, since we do not actually
have to 'force' the switch in case of stored routines at all.
When we activate the routine's database, we should perform
all the checks as in case of 'use db', and so we already do (in this
case 'force_switch' is unused).
When we load a routine into cache, we should not use mysql_change_db
at all, since there it's enough to call thd->reset_db(). We
do it this way for triggers, but code for routines is different (wrongly). 

TODO: bugs are lurking in replication, since it bypasses mysql_change_db
and calls thd->[re_]set_db to set the current database.
The latter does not change thd->db_charset, thd->sctx->db_access
and thd->variables.collation_database (and this may have nasty side
effects).

These todo items are to be addressed in a separate patch, if at all.


mysql-test/r/sp.result:
  Update results (Bug#28551)
mysql-test/t/sp.test:
  Add a test case (Bug#28551)
sql/sp.cc:
  Remove an obsolete comment.
  Replace a check with an assert.
sql/sql_db.cc:
  Remove the offending warning introduced by the fix for Bug
  25082
  This minimal patch relies on the intrinsic knowledge of the fact that
  mysql_change_db is never called with 'force_switch' set to TRUE
  when such a warning may be needed.
2007-07-05 02:20:32 +04:00
unknown
c8dde6dfe6 Merge pilot.(none):/data/msvensson/mysql/bug28356/my50-bug28356
into  pilot.(none):/data/msvensson/mysql/mysql-5.0-maint


mysql-test/t/sp.test:
  Auto merged
2007-06-29 10:27:21 +02:00
unknown
61c423a2bd Change "exec rm" to "remove_file"
mysql-test/t/sp.test:
  Change "exec rm" to "remove_file"
  Change two "remove file if exists" to "check that file not exist"
2007-06-27 18:21:20 +02:00
unknown
5697c0c10c Merge bk-internal.mysql.com:/data0/bk/mysql-5.0
into  bk-internal.mysql.com:/data0/bk/mysql-5.0-opt


mysql-test/r/sp.result:
  Auto merged
mysql-test/t/sp.test:
  Auto merged
mysql-test/t/strict.test:
  Auto merged
mysql-test/t/subselect3.test:
  Auto merged
sql/mysqld.cc:
  Auto merged
sql/sp_head.cc:
  Auto merged
sql/sql_base.cc:
  Auto merged
sql/sql_class.h:
  Auto merged
sql/sql_table.cc:
  Auto merged
sql/sql_update.cc:
  Auto merged
sql/sql_view.cc:
  Manual merge
2007-06-02 00:57:25 +02:00
unknown
d8cd88cd2a Fix some mysqltest warnings.
mysql-test/r/sp.result:
  Update results.
mysql-test/t/mysql.test:
  Fix a typo.
mysql-test/t/mysqltest.test:
  Fix a typo.
mysql-test/t/order_by.test:
  Fix a typo.
mysql-test/t/row.test:
  Remove an unsupported command.
mysql-test/t/sp.test:
  Fix a typo.
mysql-test/t/subselect3.test:
  Fix  mysqltest warnings - now it warns when sees some suspicious --
  comment
2007-06-01 17:49:01 +04:00
unknown
9e06efb45c Bug #28605: SHOW CREATE VIEW with views using stored_procedures no
longer showing SP names.
SHOW CREATE VIEW uses Item::print() methods to reconstruct the 
statement text from the parse tree.
The print() method for stored procedure calls needs allocate 
space to print the function's quoted name.
It was incorrectly calculating the length of the buffer needed 
(was too short).
Fixed to reflect the actual space needed.


mysql-test/r/sp.result:
  Bug #28605: test case
mysql-test/t/sp.test:
  Bug #28605: test case
sql/item_func.cc:
  Bug #28605: fixed the string length calculation
2007-05-29 14:45:30 +03:00
unknown
03e7683565 Merge weblab.(none):/home/marcsql/TREE/mysql-5.0-base
into  weblab.(none):/home/marcsql/TREE/mysql-5.0-rt-merge


mysql-test/t/sp.test:
  Auto merged
sql/item.cc:
  Auto merged
sql/item_func.cc:
  Auto merged
sql/mysql_priv.h:
  Auto merged
sql/sql_lex.cc:
  Auto merged
sql/sql_parse.cc:
  Auto merged
2007-05-02 09:59:39 -06:00
unknown
1700feaa02 Bug#21513 (SP having body starting with quoted label rendered unusable)
Before this fix, the parser would sometime change where a token starts by
altering Lex_input_string::tok_start, which later confused the code in
sql_yacc.yy that needs to capture the source code of a SQL statement,
like to represent the body of a stored procedure.

This line of code in sql_lex.cc :

case MY_LEX_USER_VARIABLE_DELIMITER:
  lip->tok_start= lip->ptr; // Skip first `

would <skip the first back quote> ... and cause the bug reported.

In general, the responsibility of sql_lex.cc is to *find* where token are
in the SQL text, but is *not* to make up fake or incomplete tokens.
With a quoted label like `my_label`, the token starts on the first quote.
Extracting the token value should not change that (it did).

With this fix, the lexical analysis has been cleaned up to not change
lip->tok_start (in the case found for this bug).

The functions get_token() and get_quoted_token() now have an extra
parameters, used when some characters from the beginning of the token need
to be skipped when extracting a token value, like when extracting 'AB' from
'0xAB', for example, for a HEX_NUM token.

This exposed a bad assumption in Item_hex_string and Item_bin_string,
which has been fixed:

The assumption was that the string given, 'AB', was in fact preceded in
memory by '0x', which might be false (it can be preceded by "x'" and
followed by "'" -- or not be preceded by valid memory at all)

If a name is needed for Item_hex_string or Item_bin_string, the name is
taken from the original and true source code ('0xAB'), and assigned in
the select_item rule, instead of relying on assumptions related to how
memory is used.


mysql-test/r/sp.result:
  Lex_input_stream::tok_start must point at the real start of a token.
mysql-test/t/sp.test:
  Lex_input_stream::tok_start must point at the real start of a token.
sql/item.cc:
  Lex_input_stream::tok_start must point at the real start of a token.
sql/sql_lex.cc:
  Lex_input_stream::tok_start must point at the real start of a token.
sql/sql_yacc.yy:
  Lex_input_stream::tok_start must point at the real start of a token.
2007-04-27 17:14:25 -06:00
unknown
246232268c Fix test case that was broken for builds without InnoDB.
mysql-test/t/sp.test:
  Disable warnings during table creation in one place where engine=innodb is used, in order to make this test case work with a mysqld that was compiled without InnoDB.
2007-04-25 20:23:19 +02:00
unknown
594f7bd2fe Merge weblab.(none):/home/marcsql/TREE/mysql-5.0-base
into  weblab.(none):/home/marcsql/TREE/mysql-5.0-rt-merge


mysql-test/r/sp.result:
  Auto merged
mysql-test/t/sp.test:
  Auto merged
2007-04-20 15:34:04 -06:00
unknown
dc98df13b6 Test case for BUG#5274: Stored procedure crash if length
of CHAR variable too great.


mysql-test/r/sp.result:
  Update result file.
mysql-test/t/sp.test:
  Add test case for BUG#5274.
2007-04-12 19:42:45 +04:00
unknown
239b385933 Merge jamppa@bk-internal.mysql.com:/home/bk/mysql-5.0
into  ua141d10.elisa.omakaista.fi:/home/my/bk/mysql-5.0-marvel


client/mysqldump.c:
  Auto merged
mysql-test/t/sp.test:
  Auto merged
mysys/my_malloc.c:
  Auto merged
mysys/my_static.c:
  Auto merged
mysys/safemalloc.c:
  Auto merged
ndb/src/mgmclient/CommandInterpreter.cpp:
  Auto merged
sql/ha_archive.cc:
  Auto merged
sql/ha_innodb.cc:
  Auto merged
sql/ha_ndbcluster.cc:
  Auto merged
sql/handler.cc:
  Auto merged
sql/item_cmpfunc.cc:
  Auto merged
sql/item_func.h:
  Auto merged
sql/log.cc:
  Auto merged
sql/log_event.cc:
  Auto merged
sql/mysql_priv.h:
  Auto merged
sql-common/client.c:
  Auto merged
sql/sp.cc:
  Auto merged
sql/sp_head.cc:
  Auto merged
sql/sql_delete.cc:
  Auto merged
sql/sql_insert.cc:
  Auto merged
sql/sql_show.cc:
  Auto merged
sql/sql_table.cc:
  Auto merged
sql/sql_update.cc:
  Auto merged
sql/table.cc:
  Auto merged
sql-common/my_time.c:
  Auto merged
mysql-test/r/sp.result:
  Merged from main 5.0
sql/sql_load.cc:
  Merged from main 5.0
2007-04-12 12:50:02 +03:00
unknown
6a594ffd18 Fix for BUG#25082: default database change on trigger
execution breaks replication.

When a stored routine is executed, we switch current
database to the database, in which the routine
has been created. When the stored routine finishes,
we switch back to the original database.

The problem was that if the original database does not
exist (anymore) after routine execution, we raised an error.

The fix is to report a warning, and switch to the NULL database.


mysql-test/r/sp.result:
  Updated result file.
mysql-test/t/sp.test:
  Added test case for BUG#25082.
sql/mysql_priv.h:
  1. Change mysql_change_db() prototype;
  2. Polishing.
sql/sp.cc:
  Polishing.
sql/sp_head.cc:
  Polishing.
sql/sql_db.cc:
  1. Polishing.
  2. Fix mysql_change_db().
sql/sql_parse.cc:
  Polishing.
sql/sql_show.cc:
  Polishing.
2007-03-27 21:55:01 +04:00
unknown
e4dcf4e39c Corrected error in test case:
- 1.84e+15 converted to unsigned bigint should be
  18400000000000000000 < 18446744073709551615.
- The test will still fail on windows, and is extracted
  into a new bug report.
2007-03-27 18:05:17 +02:00
unknown
99d1dee473 Merge bk-internal.mysql.com:/home/bk/mysql-5.0-marvel
into  sergbook.mysql.com:/usr/home/serg/Abk/mysql-5.0


mysql-test/r/sp.result:
  Auto merged
mysql-test/t/sp.test:
  Auto merged
sql/ha_ndbcluster.cc:
  Auto merged
sql/handler.cc:
  Auto merged
sql/mysql_priv.h:
  Auto merged
sql/sp_head.cc:
  Auto merged
sql/sql_base.cc:
  Auto merged
sql/sql_class.h:
  Auto merged
sql/sql_insert.cc:
  Auto merged
sql/sql_table.cc:
  Auto merged
sql/sql_view.cc:
  Auto merged
2007-03-24 17:16:53 +02:00
unknown
cec241f456 Merge naruto.:C:/cpp/bug20777/my50-bug20777
into  naruto.:C:/cpp/mysql-5.0-runtime


mysql-test/r/sp.result:
  manual merge
mysql-test/t/sp.test:
  manual merge
sql/item_func.cc:
  manual merge
2007-03-23 19:14:13 +01:00
unknown
df3a48ea43 Bug #27354 stored function in where condition was always treated as const
Possible problems: function call could be eliminated from where class and only
be evaluated once; function can be evaluated during table and item setup phase which could
cause side effects not to be registered in binlog.

Fixed with introducing func_item_sp::used_tables() returning the correct table_map constant.



mysql-test/r/sp.result:
  results changed
mysql-test/t/sp.test:
  regression test demonstrating that function's returns match where condition
  of the top-level query table.
sql/item_func.h:
  private used_tables() method returning the correct table_bit with meaning the item is not
  a constant
2007-03-22 19:17:15 +02:00
unknown
14ab9bef52 Merge bk-internal.mysql.com:/home/bk/mysql-5.0
into  bodhi.local:/opt/local/work/mysql-5.0-runtime


sql/field.cc:
  Auto merged
sql/item.cc:
  Auto merged
sql/item.h:
  Auto merged
sql/item_func.cc:
  Auto merged
sql/sp_head.cc:
  Auto merged
sql/sql_base.cc:
  Auto merged
sql/sql_select.cc:
  Auto merged
sql/sql_show.cc:
  Auto merged
sql/sql_table.cc:
  Auto merged
sql/sql_yacc.yy:
  Auto merged
mysql-test/r/sp.result:
  SCCS merged
mysql-test/t/sp.test:
  SCCS merged
2007-03-19 23:59:53 +03:00
unknown
ffc605aad5 Bug#20777 Function w BIGINT UNSIGNED shows diff. behaviour with and without --ps-protocol
- Stored procedures returning unsinged values returns signed values if
  text protocol is used. The reason is that the stored proceedure item
  Item_func_sp wasn't initializing the member variables properly based
  on the information contained in the associated result field.
- The patch is to upon field-item association, ::fix_fields, initialize
  the member variables in appropriate order.
- Field type of an Item_func_sp was hard coded to MYSQL_TYPE_VARCHAR.
  This is changed to return the type of the actual result field.
- Member function name sp_result_field was refactored to the more 
  appropriate init_result_field.
- Member function name find_and_check_access was refactored to 
  sp_check_access.


mysql-test/r/sp.result:
  - Added test
mysql-test/t/sp.test:
  - Added test
sql/item_func.cc:
  Bug#20777 Function w BIGINT UNSIGNED shows diff. behaviour with and without --ps-protocol
  
  - Stored procedures returning unsinged values returns signed values if
    text protocol is used. The reason is that the stored proceedure item
    Item_func_sp wasn't initializing the member variables properly based
    on the information contained in the associated result field.
  - The patch is to upon field-item association, ::fix_fields, initialize
    the member variables in appropriate order.
  - Field type of an Item_func_sp was hard coded to MYSQL_TYPE_VARCHAR.
    This is changed to to return the type of the actual result field.
  - Member function name sp_result_field was refactored to the more 
    appropriate init_result_field.
  - Member function name find_and_check_access was refactored to 
    sp_check_access.
sql/item_func.h:
  Bug#20777 Function w BIGINT UNSIGNED shows diff. behaviour with and without --ps-protocol
  
  - Stored procedures returning unsinged values returns signed values if
    text protocol is used. The reason is that the stored proceedure item
    Item_func_sp wasn't initializing the member variables properly based
    on the information contained in the associated result field.
  - The patch is to upon field-item association, ::fix_fields, initialize
    the member variables in appropriate order.
  - Field type of an Item_func_sp was hard coded to MYSQL_TYPE_VARCHAR.
    This is changed to to return the type of the actual result field.
  - Member function name sp_result_field was refactored to the more 
    appropriate init_result_field.
  - Member function name find_and_check_access was refactored to 
    sp_check_access.
2007-03-16 14:25:11 +01:00
unknown
79344c7b67 Bug#26503 (Illegal SQL exception handler code causes the server to crash)
Before this fix, the parser would accept illegal code in SQL exceptions
handlers, that later causes the runtime to crash when executing the code,
due to memory violations in the exception handler stack.

The root cause of the problem is instructions within an exception handler
that jumps to code located outside of the handler. This is illegal according
to the SQL 2003 standard, since labels located outside the handler are not
supposed to be visible (they are "out of scope"), so any instruction that
jumps to these labels, like ITERATE or LEAVE, should not parse.

The section of the standard that is relevant for this is :
  SQL:2003 SQL/PSM (ISO/IEC 9075-4:2003)
  section 13.1 <compound statement>,
  syntax rule 4
<quote>
  The scope of the <beginning label> is CS excluding every <SQL schema
  statement> contained in CS and excluding every
  <local handler declaration list> contained in CS. <beginning label> shall
  not be equivalent to any other <beginning label>s within that scope.
</quote>

With this fix, the C++ class sp_pcontext, which represent the "parsing
context" tree (a.k.a symbol table) of a stored procedure, has been changed
as follows:
- constructors have been cleaned up, so that only building a root node for
the tree is public; building nodes inside a tree is not public.
- a new member, m_label_scope, indicates if a given syntactic context
belongs to a DECLARE HANDLER block,
- label resolution, in the method find_label(), has been changed to
implement the restriction of scope regarding labels used in a compound
statement.

The actions in the parser, when parsing the body of a SQL exception handler,
have been changed as follows:
- the implementation of an exception handler (DECLARE HANDLER) now creates
explicitly a new sp_pcontext, to isolate the code inside the handler from
the containing compound statement context.
- registering exception handlers as a result occurs in the parent context,
see the rule sp_hcond_element
- the code in sp_hcond_list has been cleaned up, to avoid code duplication

In addition, the flags IN_SIMPLE_CASE and IN_HANDLER, declared in sp_head.h
have been removed, since they are unused and broken by design (as seen with
Bug 19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation), representing a stack in a single flag is not possible.

Tests in sp-error have been added to show that illegal constructs are now
rejected.

Tests in sp have been added for code coverage, to show that ITERATE or LEAVE
statements are legal when jumping to a label in scope, inside the body of
an exception handler.


mysql-test/r/sp-error.result:
  SQL Exception handlers define a parsing context for label resolution.
mysql-test/r/sp.result:
  SQL Exception handlers define a parsing context for label resolution.
mysql-test/t/sp-error.test:
  SQL Exception handlers define a parsing context for label resolution.
mysql-test/t/sp.test:
  SQL Exception handlers define a parsing context for label resolution.
sql/sp_head.cc:
  Minor cleanup
sql/sp_head.h:
  Minor cleanup
sql/sp_pcontext.cc:
  SQL Exception handlers define a parsing context for label resolution.
sql/sp_pcontext.h:
  SQL Exception handlers define a parsing context for label resolution.
sql/sql_yacc.yy:
  SQL Exception handlers define a parsing context for label resolution.
2007-03-14 12:02:32 -06:00
unknown
12af658570 Merge bk@192.168.21.1:mysql-5.0
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
2007-03-08 21:42:41 +04:00
unknown
980569877a Merge moonlight.home:/home/tomash/src/mysql_ab/mysql-5.0
into  moonlight.home:/home/tomash/src/mysql_ab/mysql-5.0-bug20492


sql/sql_select.cc:
  Auto merged
mysql-test/r/sp.result:
  Manual merge.
mysql-test/t/sp.test:
  Manual merge.
2007-03-08 15:16:21 +03:00
unknown
11b533b8be Bug#25373: Stored functions wasn't compared correctly which leads to a wrong
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.
2007-03-07 22:11:57 +03:00
unknown
a966b0b71c Merge tsmith@bk-internal.mysql.com:/home/bk/mysql-5.0-runtime
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
2007-03-07 06:54:35 +01:00
unknown
266a7fff52 Bug#8407 (Stored functions/triggers ignore exception handler)
Bug 18914 (Calling certain SPs from triggers fail)
Bug 20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
Bug 21825 (Incorrect message error deleting records in a table with a
  trigger for inserting)
Bug 22580 (DROP TABLE in nested stored procedure causes strange dependency
  error)
Bug 25345 (Cursors from Functions)


This fix resolves a long standing issue originally reported with bug 8407,
which affect the behavior of Stored Procedures, Stored Functions and Trigger
in many different ways, causing symptoms reported by all the bugs listed.
In all cases, the root cause of the problem traces back to 8407 and how the
server locks tables involved with sub statements.

Prior to this fix, the implementation of stored routines would:
- compute the transitive closure of all the tables referenced by a top level
statement
- open and lock all the tables involved
- execute the top level statement
"transitive closure of tables" means collecting:
- all the tables,
- all the stored functions,
- all the views,
- all the table triggers
- all the stored procedures
involved, and recursively inspect these objects definition to find more
references to more objects, until the list of every object referenced does
not grow any more.
This mechanism is known as "pre-locking" tables before execution.
The motivation for locking all the tables (possibly) used at once is to
prevent dead locks.

One problem with this approach is that, if the execution path the code
really takes during runtime does not use a given table, and if the table is
missing, the server would not execute the statement.
This in particular has a major impact on triggers, since a missing table
referenced by an update/delete trigger would prevent an insert trigger to run.

Another problem is that stored routines might define SQL exception handlers
to deal with missing tables, but the server implementation would never give
user code a chance to execute this logic, since the routine is never
executed when a missing table cause the pre-locking code to fail.

With this fix, the internal implementation of the pre-locking code has been
relaxed of some constraints, so that failure to open a table does not
necessarily prevent execution of a stored routine.

In particular, the pre-locking mechanism is now behaving as follows:

1) the first step, to compute the transitive closure of all the tables
possibly referenced by a statement, is unchanged.

2) the next step, which is to open all the tables involved, only attempts
to open the tables added by the pre-locking code, but silently fails without
reporting any error or invoking any exception handler is the table is not
present. This is achieved by trapping internal errors with
Prelock_error_handler

3) the locking step only locks tables that were successfully opened.

4) when executing sub statements, the list of tables used by each statements
is evaluated as before. The tables needed by the sub statement are expected
to be already opened and locked. Statement referencing tables that were not
opened in step 2) will fail to find the table in the open list, and only at
this point will execution of the user code fail.

5) when a runtime exception is raised at 4), the instruction continuation
destination (the next instruction to execute in case of SQL continue
handlers) is evaluated.
This is achieved with sp_instr::exec_open_and_lock_tables()

6) if a user exception handler is present in the stored routine, that
handler is invoked as usual, so that ER_NO_SUCH_TABLE exceptions can be
trapped by stored routines. If no handler exists, then the runtime execution
will fail as expected.

With all these changes, a side effect is that view security is impacted, in
two different ways.

First, a view defined as "select stored_function()", where the stored
function references a table that may not exist, is considered valid.
The rationale is that, because the stored function might trap exceptions
during execution and still return a valid result, there is no way to decide
when the view is created if a missing table really cause the view to be invalid.

Secondly, testing for existence of tables is now done later during
execution. View security, which consist of trapping errors and return a
generic ER_VIEW_INVALID (to prevent disclosing information) was only
implemented at very specific phases covering *opening* tables, but not
covering the runtime execution. Because of this existing limitation,
errors that were previously trapped and converted into ER_VIEW_INVALID are
not trapped, causing table names to be reported to the user.
This change is exposing an existing problem, which is independent and will
be resolved separately.


mysql-test/r/information_schema_db.result:
  Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp-error.result:
  Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp.result:
  Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/trigger.result:
  Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/view.result:
  Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp-error.test:
  Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp.test:
  Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/trigger.test:
  Revised the pre-locking code implementation, aligned the tests.
sql/lock.cc:
  table->placeholder now checks for schema_table
sql/mysqld.cc:
  my_message_sql(): invoke internal exception handlers
sql/sp_head.cc:
  exec_open_and_lock_tables(): open and lock tables, or return the
  continuation destination of this instruction
sql/sp_head.h:
  exec_open_and_lock_tables(): open and lock tables, or return the
  continuation destination of this instruction
sql/sql_base.cc:
  Prelock_error_handler: delay open table errors until execution
sql/sql_class.cc:
  THD: add internal error handler, as an exception mechanism.
sql/sql_class.h:
  THD: add internal error handler, as an exception mechanism.
sql/sql_update.cc:
  table->placeholder now checks for schema_table
sql/table.cc:
  st_table_list::hide_view_error(): masked more errors for view security
sql/table.h:
  table->placeholder now checks for schema_table, and unopened tables
2007-03-05 19:42:07 -07:00