2006-02-15 17:11:24 +01:00
|
|
|
--source include/have_udf.inc
|
|
|
|
#
|
2006-07-29 04:41:50 +02:00
|
|
|
# To run this tests the "sql/udf_example.c" need to be compiled into
|
2006-03-10 10:41:04 +01:00
|
|
|
# udf_example.so and LD_LIBRARY_PATH should be setup to point out where
|
2006-02-15 17:11:24 +01:00
|
|
|
# the library are.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
--disable_warnings
|
|
|
|
drop table if exists t1;
|
|
|
|
--enable_warnings
|
|
|
|
|
2006-03-10 10:41:04 +01:00
|
|
|
#
|
2006-02-15 17:11:24 +01:00
|
|
|
# Create the example functions from udf_example
|
|
|
|
#
|
|
|
|
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION myfunc_double RETURNS REAL SONAME "$UDF_EXAMPLE_SO";
|
2006-02-15 17:11:24 +01:00
|
|
|
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
2006-03-10 10:41:04 +01:00
|
|
|
--error ER_CANT_FIND_DL_ENTRY
|
2010-06-10 11:11:52 +02:00
|
|
|
eval CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME "$UDF_EXAMPLE_SO";
|
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "$UDF_EXAMPLE_SO";
|
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
MDEV-10139 Support for SEQUENCE objects
Working features:
CREATE OR REPLACE [TEMPORARY] SEQUENCE [IF NOT EXISTS] name
[ INCREMENT [ BY | = ] increment ]
[ MINVALUE [=] minvalue | NO MINVALUE ]
[ MAXVALUE [=] maxvalue | NO MAXVALUE ]
[ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ]
ENGINE=xxx COMMENT=".."
SELECT NEXT VALUE FOR sequence_name;
SELECT NEXTVAL(sequence_name);
SELECT PREVIOUS VALUE FOR sequence_name;
SELECT LASTVAL(sequence_name);
SHOW CREATE SEQUENCE sequence_name;
SHOW CREATE TABLE sequence_name;
CREATE TABLE sequence-structure ... SEQUENCE=1
ALTER TABLE sequence RENAME TO sequence2;
RENAME TABLE sequence TO sequence2;
DROP [TEMPORARY] SEQUENCE [IF EXISTS] sequence_names
Missing features
- SETVAL(value,sequence_name), to be used with replication.
- Check replication, including checking that sequence tables are marked
not transactional.
- Check that a commit happens for NEXT VALUE that changes table data (may
already work)
- ALTER SEQUENCE. ANSI SQL version of setval.
- Share identical sequence entries to not add things twice to table list.
- testing insert/delete/update/truncate/load data
- Run and fix Alibaba sequence tests (part of mysql-test/suite/sql_sequence)
- Write documentation for NEXT VALUE / PREVIOUS_VALUE
- NEXTVAL in DEFAULT
- Ensure that NEXTVAL in DEFAULT uses database from base table
- Two NEXTVAL for same row should give same answer.
- Oracle syntax sequence_table.nextval, without any FOR or FROM.
- Sequence tables are treated as 'not read constant tables' by SELECT; Would
be better if we would have a separate list for sequence tables so that
select doesn't know about them, except if refereed to with FROM.
Other things done:
- Improved output for safemalloc backtrack
- frm_type_enum changed to Table_type
- Removed lex->is_view and replaced with lex->table_type. This allows
use to more easy check if item is view, sequence or table.
- Added table flag HA_CAN_TABLES_WITHOUT_ROLLBACK, needed for handlers
that want's to support sequences
- Added handler calls:
- engine_name(), to simplify getting engine name for partition and sequences
- update_first_row(), to be able to do efficient sequence implementations.
- Made binlog_log_row() global to be able to call it from ha_sequence.cc
- Added handler variable: row_already_logged, to be able to flag that the
changed row is already logging to replication log.
- Added CF_DB_CHANGE and CF_SCHEMA_CHANGE flags to simplify
deny_updates_if_read_only_option()
- Added sp_add_cfetch() to avoid new conflicts in sql_yacc.yy
- Moved code for add_table_options() out from sql_show.cc::show_create_table()
- Added String::append_longlong() and used it in sql_show.cc to simplify code.
- Added extra option to dd_frm_type() and ha_table_exists to indicate if
the table is a sequence. Needed by DROP SQUENCE to not drop a table.
2017-03-25 22:36:56 +01:00
|
|
|
eval CREATE FUNCTION udf_sequence RETURNS INTEGER SONAME "$UDF_EXAMPLE_SO";
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION lookup RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
2006-04-27 16:32:40 +02:00
|
|
|
eval CREATE FUNCTION reverse_lookup
|
2010-06-10 11:11:52 +02:00
|
|
|
RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
2006-04-27 16:32:40 +02:00
|
|
|
eval CREATE AGGREGATE FUNCTION avgcost
|
2010-06-10 11:11:52 +02:00
|
|
|
RETURNS REAL SONAME "$UDF_EXAMPLE_SO";
|
2006-02-15 17:11:24 +01:00
|
|
|
|
2007-10-31 22:31:57 +01:00
|
|
|
--error ER_CANT_INITIALIZE_UDF
|
2006-02-15 17:11:24 +01:00
|
|
|
select myfunc_double();
|
|
|
|
select myfunc_double(1);
|
|
|
|
select myfunc_double(78654);
|
2006-03-10 10:41:04 +01:00
|
|
|
--error 1305
|
2006-03-10 12:12:08 +01:00
|
|
|
select myfunc_nonexist();
|
2006-02-15 17:11:24 +01:00
|
|
|
select myfunc_int();
|
2007-10-31 22:31:57 +01:00
|
|
|
--error ER_CANT_INITIALIZE_UDF
|
2006-02-15 17:11:24 +01:00
|
|
|
select lookup();
|
|
|
|
select lookup("127.0.0.1");
|
2007-10-31 22:31:57 +01:00
|
|
|
--error ER_CANT_INITIALIZE_UDF
|
2006-02-15 17:11:24 +01:00
|
|
|
select lookup(127,0,0,1);
|
|
|
|
select lookup("localhost");
|
2007-10-31 22:31:57 +01:00
|
|
|
--error ER_CANT_INITIALIZE_UDF
|
2006-02-15 17:11:24 +01:00
|
|
|
select reverse_lookup();
|
2006-03-10 12:12:08 +01:00
|
|
|
|
2010-03-18 11:26:27 +01:00
|
|
|
# These two function calls should return "localhost", but it's
|
2006-03-10 12:12:08 +01:00
|
|
|
# depending on configuration, so just call them and don't log the result
|
|
|
|
--disable_result_log
|
2006-02-15 17:11:24 +01:00
|
|
|
select reverse_lookup("127.0.0.1");
|
|
|
|
select reverse_lookup(127,0,0,1);
|
2006-03-10 12:12:08 +01:00
|
|
|
|
2010-03-18 11:26:27 +01:00
|
|
|
# This function call may return different results depending on platform,
|
|
|
|
# so ignore results (see Bug#52060).
|
2006-02-15 17:11:24 +01:00
|
|
|
select reverse_lookup("localhost");
|
2010-03-18 11:26:27 +01:00
|
|
|
--enable_result_log
|
|
|
|
|
2007-10-31 22:31:57 +01:00
|
|
|
--error ER_CANT_INITIALIZE_UDF
|
2006-02-15 17:11:24 +01:00
|
|
|
select avgcost();
|
2007-10-31 22:31:57 +01:00
|
|
|
--error ER_CANT_INITIALIZE_UDF
|
2006-02-15 17:11:24 +01:00
|
|
|
select avgcost(100,23.76);
|
|
|
|
create table t1(sum int, price float(24));
|
|
|
|
insert into t1 values(100, 50.00), (100, 100.00);
|
|
|
|
select avgcost(sum, price) from t1;
|
|
|
|
delete from t1;
|
|
|
|
insert into t1 values(100, 54.33), (200, 199.99);
|
|
|
|
select avgcost(sum, price) from t1;
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
# BUG#17261 Passing a variable from a stored procedure to UDF crashes mysqld
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
2006-03-10 10:41:04 +01:00
|
|
|
select metaphon('hello');
|
2006-02-15 17:11:24 +01:00
|
|
|
|
|
|
|
delimiter //;
|
|
|
|
CREATE PROCEDURE `XXX1`(in testval varchar(10))
|
2006-03-10 10:41:04 +01:00
|
|
|
begin
|
|
|
|
select metaphon(testval);
|
2006-02-15 17:11:24 +01:00
|
|
|
end//
|
|
|
|
delimiter ;//
|
|
|
|
|
|
|
|
call XXX1('hello');
|
|
|
|
drop procedure xxx1;
|
|
|
|
|
|
|
|
delimiter //;
|
|
|
|
CREATE PROCEDURE `XXX2`()
|
2006-03-10 10:41:04 +01:00
|
|
|
begin
|
2006-02-15 17:11:24 +01:00
|
|
|
declare testval varchar(10);
|
|
|
|
set testval = 'hello';
|
2006-03-10 10:41:04 +01:00
|
|
|
select metaphon(testval);
|
2006-02-15 17:11:24 +01:00
|
|
|
end//
|
|
|
|
delimiter ;//
|
|
|
|
|
|
|
|
call XXX2();
|
|
|
|
drop procedure xxx2;
|
|
|
|
|
2006-06-08 19:25:28 +02:00
|
|
|
#
|
|
|
|
# Bug#19904: UDF: not initialized *is_null per row
|
|
|
|
#
|
|
|
|
|
|
|
|
CREATE TABLE bug19904(n INT, v varchar(10));
|
|
|
|
INSERT INTO bug19904 VALUES (1,'one'),(2,'two'),(NULL,NULL),(3,'three'),(4,'four');
|
|
|
|
SELECT myfunc_double(n) AS f FROM bug19904;
|
|
|
|
SELECT metaphon(v) AS f FROM bug19904;
|
|
|
|
DROP TABLE bug19904;
|
|
|
|
|
2006-07-31 21:01:43 +02:00
|
|
|
#
|
|
|
|
# Bug#21269: DEFINER-clause is allowed for UDF-functions
|
|
|
|
#
|
|
|
|
|
Bug#28318 (CREATE FUNCTION (UDF) requires a schema) -- part II
The root cause of the issue was that the CREATE FUNCTION grammar,
for User Defined Functions, was using the sp_name rule.
The sp_name rule is intended for fully qualified stored procedure names,
like either ident.ident, or just ident but with a default database
implicitly selected.
A UDF does not have a fully qualified name, only a name (ident), and should
not use the sp_name grammar fragment during parsing.
The fix is to re-organize the CREATE FUNCTION grammar, to better separate:
- creating UDF (no definer, can have AGGREGATE, simple ident)
- creating Stored Functions (definer, no AGGREGATE, fully qualified name)
With the test case provided, another issue was exposed which is also fixed:
the DROP FUNCTION statement was using sp_name and also failing when no database
is implicitly selected, when droping UDF functions.
The fix is also to change the grammar so that DROP FUNCTION works with
both the ident.ident syntax (to drop a stored function), or just the ident
syntax (to drop either a UDF or a Stored Function, in the current database)
mysql-test/r/sp-error.result:
Adjust test results
mysql-test/r/udf.result:
Adjust test results
mysql-test/t/sp-error.test:
Adjust test results
mysql-test/t/udf.test:
Adjust test results
sql/sql_parse.cc:
CREATE UDF FUNCTION does not use a fully qualified name.
sql/sql_yacc.yy:
Fix grammar for CREATE / DROP FUNCTION, FOR udf
Improve error messages for select no_such_function()
2007-10-16 03:15:38 +02:00
|
|
|
--error ER_PARSE_ERROR
|
2006-07-31 21:01:43 +02:00
|
|
|
CREATE DEFINER=CURRENT_USER() FUNCTION should_not_parse
|
|
|
|
RETURNS STRING SONAME "should_not_parse.so";
|
|
|
|
|
Bug#28318 (CREATE FUNCTION (UDF) requires a schema) -- part II
The root cause of the issue was that the CREATE FUNCTION grammar,
for User Defined Functions, was using the sp_name rule.
The sp_name rule is intended for fully qualified stored procedure names,
like either ident.ident, or just ident but with a default database
implicitly selected.
A UDF does not have a fully qualified name, only a name (ident), and should
not use the sp_name grammar fragment during parsing.
The fix is to re-organize the CREATE FUNCTION grammar, to better separate:
- creating UDF (no definer, can have AGGREGATE, simple ident)
- creating Stored Functions (definer, no AGGREGATE, fully qualified name)
With the test case provided, another issue was exposed which is also fixed:
the DROP FUNCTION statement was using sp_name and also failing when no database
is implicitly selected, when droping UDF functions.
The fix is also to change the grammar so that DROP FUNCTION works with
both the ident.ident syntax (to drop a stored function), or just the ident
syntax (to drop either a UDF or a Stored Function, in the current database)
mysql-test/r/sp-error.result:
Adjust test results
mysql-test/r/udf.result:
Adjust test results
mysql-test/t/sp-error.test:
Adjust test results
mysql-test/t/udf.test:
Adjust test results
sql/sql_parse.cc:
CREATE UDF FUNCTION does not use a fully qualified name.
sql/sql_yacc.yy:
Fix grammar for CREATE / DROP FUNCTION, FOR udf
Improve error messages for select no_such_function()
2007-10-16 03:15:38 +02:00
|
|
|
--error ER_PARSE_ERROR
|
2006-07-31 21:01:43 +02:00
|
|
|
CREATE DEFINER=someone@somewhere FUNCTION should_not_parse
|
|
|
|
RETURNS STRING SONAME "should_not_parse.so";
|
2006-07-25 22:31:29 +02:00
|
|
|
#
|
|
|
|
# Bug#19862: Sort with filesort by function evaluates function twice
|
|
|
|
#
|
|
|
|
create table t1(f1 int);
|
|
|
|
insert into t1 values(1),(2);
|
|
|
|
explain select myfunc_int(f1) from t1 order by 1;
|
|
|
|
drop table t1;
|
2006-10-24 14:26:41 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Bug #21809: Error 1356 while selecting from view with grouping though
|
|
|
|
# underlying select OK.
|
|
|
|
#
|
|
|
|
CREATE TABLE t1(a INT, b INT); INSERT INTO t1 values (1,1),(2,2);
|
|
|
|
|
|
|
|
DELIMITER ||;
|
|
|
|
CREATE FUNCTION fn(a int) RETURNS int DETERMINISTIC
|
|
|
|
BEGIN
|
|
|
|
RETURN a;
|
|
|
|
END
|
|
|
|
||
|
|
|
|
DELIMITER ;||
|
|
|
|
|
|
|
|
CREATE VIEW v1 AS SELECT a, fn(MIN(b)) as c FROM t1 GROUP BY a;
|
|
|
|
|
|
|
|
SELECT myfunc_int(a AS attr_name) FROM t1;
|
|
|
|
EXPLAIN EXTENDED SELECT myfunc_int(a AS attr_name) FROM t1;
|
|
|
|
EXPLAIN EXTENDED SELECT myfunc_int(a) FROM t1;
|
|
|
|
SELECT a,c FROM v1;
|
|
|
|
|
Bug#24736: UDF functions parsed as Stored Functions
Before this fix, a call to a User Defined Function (UDF) could,
under some circumstances, be interpreted as a call to a Stored function
instead. This occurred if a native function was invoked in the parameters
for the UDF, as in "select my_udf(abs(x))".
The root cause of this defect is the introduction, by the fix for Bug 21809,
of st_select_lex::udf_list, and it's usage in the parser in sql_yacc.yy
in the rule function_call_generic (in 5.1).
While the fix itself for Bug 21809 is correct in 5.0, the code change
merged into the 5.1 release created the issue, because the calls in 5.1 to :
- lex->current_select->udf_list.push_front(udf)
- lex->current_select->udf_list.pop()
are not balanced in case of native functions, causing the udf_list,
which is really a stack, to be out of sync with the internal stack
maintained by the bison parser.
Instead of moving the call to udf_list.pop(), which would have fixed the
symptom, this patch goes further and removes the need for udf_list.
This is motivated by two reasons:
a) Maintaining a stack in the MySQL code in sync with the stack maintained
internally in sql_yacc.cc (not .yy) is extremely dependent of the
implementation of yacc/bison, and extremely difficult to maintain.
It's also totally dependent of the structure of the grammar, and has a risk
to break with regression defects each time the grammar itself is changed.
b) The previous code did report construct like "foo(expr AS name)" as
syntax errors (ER_PARSER_ERROR), which is incorrect, and misleading.
The syntax is perfectly valid, as this expression is valid when "foo" is
a UDF. Whether this syntax is legal or not depends of the semantic of "foo".
With this change:
a) There is only one stack (in bison), and no List<udf_func> to maintain.
b) "foo(expr AS name)", when used incorrectly, is reported as semantic error:
- ER_WRONG_PARAMETERS_TO_NATIVE_FCT (for native functions)
- ER_WRONG_PARAMETERS_TO_STORED_FCT (for stored functions)
This is achieved by the changes implemented in item_create.cc
mysql-test/r/parser.result:
New tests
mysql-test/r/udf.result:
New tests
mysql-test/t/parser.test:
New tests
mysql-test/t/udf.test:
New tests
sql/item_create.cc:
Semantic checks for named parameters, as in "foo(expr AS name)".
sql/share/errmsg.txt:
New error message
sql/sql_lex.cc:
Remove usage of udf_list.
sql/sql_lex.h:
Remove usage of udf_list.
sql/sql_yacc.yy:
Remove usage of udf_list.
2006-12-02 03:16:03 +01:00
|
|
|
--error ER_WRONG_PARAMETERS_TO_STORED_FCT
|
2006-10-24 14:26:41 +02:00
|
|
|
SELECT a, fn(MIN(b) xx) as c FROM t1 GROUP BY a;
|
Bug#24736: UDF functions parsed as Stored Functions
Before this fix, a call to a User Defined Function (UDF) could,
under some circumstances, be interpreted as a call to a Stored function
instead. This occurred if a native function was invoked in the parameters
for the UDF, as in "select my_udf(abs(x))".
The root cause of this defect is the introduction, by the fix for Bug 21809,
of st_select_lex::udf_list, and it's usage in the parser in sql_yacc.yy
in the rule function_call_generic (in 5.1).
While the fix itself for Bug 21809 is correct in 5.0, the code change
merged into the 5.1 release created the issue, because the calls in 5.1 to :
- lex->current_select->udf_list.push_front(udf)
- lex->current_select->udf_list.pop()
are not balanced in case of native functions, causing the udf_list,
which is really a stack, to be out of sync with the internal stack
maintained by the bison parser.
Instead of moving the call to udf_list.pop(), which would have fixed the
symptom, this patch goes further and removes the need for udf_list.
This is motivated by two reasons:
a) Maintaining a stack in the MySQL code in sync with the stack maintained
internally in sql_yacc.cc (not .yy) is extremely dependent of the
implementation of yacc/bison, and extremely difficult to maintain.
It's also totally dependent of the structure of the grammar, and has a risk
to break with regression defects each time the grammar itself is changed.
b) The previous code did report construct like "foo(expr AS name)" as
syntax errors (ER_PARSER_ERROR), which is incorrect, and misleading.
The syntax is perfectly valid, as this expression is valid when "foo" is
a UDF. Whether this syntax is legal or not depends of the semantic of "foo".
With this change:
a) There is only one stack (in bison), and no List<udf_func> to maintain.
b) "foo(expr AS name)", when used incorrectly, is reported as semantic error:
- ER_WRONG_PARAMETERS_TO_NATIVE_FCT (for native functions)
- ER_WRONG_PARAMETERS_TO_STORED_FCT (for stored functions)
This is achieved by the changes implemented in item_create.cc
mysql-test/r/parser.result:
New tests
mysql-test/r/udf.result:
New tests
mysql-test/t/parser.test:
New tests
mysql-test/t/udf.test:
New tests
sql/item_create.cc:
Semantic checks for named parameters, as in "foo(expr AS name)".
sql/share/errmsg.txt:
New error message
sql/sql_lex.cc:
Remove usage of udf_list.
sql/sql_lex.h:
Remove usage of udf_list.
sql/sql_yacc.yy:
Remove usage of udf_list.
2006-12-02 03:16:03 +01:00
|
|
|
--error ER_WRONG_PARAMETERS_TO_STORED_FCT
|
2006-10-24 14:26:41 +02:00
|
|
|
SELECT myfunc_int(fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
|
|
|
|
--error ER_PARSE_ERROR
|
|
|
|
SELECT myfunc_int(test.fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
|
|
|
|
|
|
|
|
SELECT myfunc_int(fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
|
|
|
|
SELECT myfunc_int(test.fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
|
|
|
|
|
|
|
|
EXPLAIN EXTENDED SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
|
|
|
|
EXPLAIN EXTENDED SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
|
|
|
|
EXPLAIN EXTENDED SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
|
|
|
|
EXPLAIN EXTENDED SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
|
|
|
|
SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
|
|
|
|
SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
|
|
|
|
SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
|
|
|
|
SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
|
|
|
|
DROP VIEW v1;
|
|
|
|
DROP TABLE t1;
|
|
|
|
DROP FUNCTION fn;
|
|
|
|
|
2006-06-08 19:25:28 +02:00
|
|
|
--echo End of 5.0 tests.
|
2006-02-15 17:11:24 +01:00
|
|
|
|
Bug#24736: UDF functions parsed as Stored Functions
Before this fix, a call to a User Defined Function (UDF) could,
under some circumstances, be interpreted as a call to a Stored function
instead. This occurred if a native function was invoked in the parameters
for the UDF, as in "select my_udf(abs(x))".
The root cause of this defect is the introduction, by the fix for Bug 21809,
of st_select_lex::udf_list, and it's usage in the parser in sql_yacc.yy
in the rule function_call_generic (in 5.1).
While the fix itself for Bug 21809 is correct in 5.0, the code change
merged into the 5.1 release created the issue, because the calls in 5.1 to :
- lex->current_select->udf_list.push_front(udf)
- lex->current_select->udf_list.pop()
are not balanced in case of native functions, causing the udf_list,
which is really a stack, to be out of sync with the internal stack
maintained by the bison parser.
Instead of moving the call to udf_list.pop(), which would have fixed the
symptom, this patch goes further and removes the need for udf_list.
This is motivated by two reasons:
a) Maintaining a stack in the MySQL code in sync with the stack maintained
internally in sql_yacc.cc (not .yy) is extremely dependent of the
implementation of yacc/bison, and extremely difficult to maintain.
It's also totally dependent of the structure of the grammar, and has a risk
to break with regression defects each time the grammar itself is changed.
b) The previous code did report construct like "foo(expr AS name)" as
syntax errors (ER_PARSER_ERROR), which is incorrect, and misleading.
The syntax is perfectly valid, as this expression is valid when "foo" is
a UDF. Whether this syntax is legal or not depends of the semantic of "foo".
With this change:
a) There is only one stack (in bison), and no List<udf_func> to maintain.
b) "foo(expr AS name)", when used incorrectly, is reported as semantic error:
- ER_WRONG_PARAMETERS_TO_NATIVE_FCT (for native functions)
- ER_WRONG_PARAMETERS_TO_STORED_FCT (for stored functions)
This is achieved by the changes implemented in item_create.cc
mysql-test/r/parser.result:
New tests
mysql-test/r/udf.result:
New tests
mysql-test/t/parser.test:
New tests
mysql-test/t/udf.test:
New tests
sql/item_create.cc:
Semantic checks for named parameters, as in "foo(expr AS name)".
sql/share/errmsg.txt:
New error message
sql/sql_lex.cc:
Remove usage of udf_list.
sql/sql_lex.h:
Remove usage of udf_list.
sql/sql_yacc.yy:
Remove usage of udf_list.
2006-12-02 03:16:03 +01:00
|
|
|
#
|
|
|
|
# Bug#24736: UDF functions parsed as Stored Functions
|
|
|
|
#
|
|
|
|
|
|
|
|
select myfunc_double(3);
|
|
|
|
select myfunc_double(3 AS three);
|
|
|
|
select myfunc_double(abs(3));
|
|
|
|
select myfunc_double(abs(3) AS named_param);
|
|
|
|
select abs(myfunc_double(3));
|
|
|
|
select abs(myfunc_double(3 AS three));
|
|
|
|
|
|
|
|
-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT
|
|
|
|
select myfunc_double(abs(3 AS wrong));
|
|
|
|
-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT
|
|
|
|
select abs(myfunc_double(3) AS wrong);
|
|
|
|
|
Bug#18239 (Possible to overload internal functions with stored functions)
Bug#21025 (misleading error message when creating functions named 'x', or 'y')
Bug#22619 (Spaces considered harmful)
This change contains a fix to report warnings or errors, and multiple tests
cases.
Before this fix, name collisions between:
- Native functions
- User Defined Functions
- Stored Functions
were not systematically reported, leading to confusing behavior.
I) Native / User Defined Function
Before this fix, is was possible to create a UDF named "foo", with the same
name as a native function "foo", but it was impossible to invoke the UDF,
since the syntax "foo()" always refer to the native function.
After this fix, creating a UDF fails with an error if there is a name
collision with a native function.
II) Native / Stored Function
Before this fix, is was possible to create a SF named "db.foo", with the same
name as a native function "foo", but this was confusing since the syntax
"foo()" would refer to the native function. To refer to the Stored Function,
the user had to use the "db.foo()" syntax.
After this fix, creating a Stored Function reports a warning if there is a
name collision with a native function.
III) User Defined Function / Stored Function
Before this fix, creating a User Defined Function "foo" and a Stored Function
"db.foo" are mutually exclusive operations. Whenever the second function is
created, an error is reported. However, the test suite did not cover this
behavior.
After this fix, the behavior is unchanged, and is now covered by test cases.
Note that the code change in this patch depends on the fix for Bug 21114.
mysql-test/r/sp.result:
New test cases.
mysql-test/r/udf.result:
New test cases.
mysql-test/t/sp.test:
New test cases.
mysql-test/t/udf.test:
New test cases.
sql/sql_lex.cc:
Name collisions with native functions.
sql/sql_lex.h:
Name collisions with native functions.
sql/sql_yacc.yy:
Name collisions with native functions.
sql/share/errmsg.txt:
Name collisions with native functions.
mysql-test/r/sp_gis.result:
New test cases.
mysql-test/t/sp_gis.test:
New test cases.
2006-11-15 03:34:16 +01:00
|
|
|
#
|
|
|
|
# BUG#18239: Possible to overload internal functions with stored functions
|
|
|
|
#
|
|
|
|
|
|
|
|
--disable_warnings
|
|
|
|
drop function if exists pi;
|
|
|
|
--enable_warnings
|
|
|
|
|
|
|
|
--error ER_NATIVE_FCT_NAME_COLLISION
|
|
|
|
CREATE FUNCTION pi RETURNS STRING SONAME "should_not_parse.so";
|
|
|
|
|
|
|
|
# Verify that Stored Functions and UDF are mutually exclusive
|
|
|
|
DROP FUNCTION IF EXISTS metaphon;
|
|
|
|
|
|
|
|
CREATE FUNCTION metaphon(a int) RETURNS int
|
|
|
|
return 0;
|
|
|
|
|
2007-10-17 04:47:08 +02:00
|
|
|
# this currently passes, and eclipse the stored function
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
Bug#18239 (Possible to overload internal functions with stored functions)
Bug#21025 (misleading error message when creating functions named 'x', or 'y')
Bug#22619 (Spaces considered harmful)
This change contains a fix to report warnings or errors, and multiple tests
cases.
Before this fix, name collisions between:
- Native functions
- User Defined Functions
- Stored Functions
were not systematically reported, leading to confusing behavior.
I) Native / User Defined Function
Before this fix, is was possible to create a UDF named "foo", with the same
name as a native function "foo", but it was impossible to invoke the UDF,
since the syntax "foo()" always refer to the native function.
After this fix, creating a UDF fails with an error if there is a name
collision with a native function.
II) Native / Stored Function
Before this fix, is was possible to create a SF named "db.foo", with the same
name as a native function "foo", but this was confusing since the syntax
"foo()" would refer to the native function. To refer to the Stored Function,
the user had to use the "db.foo()" syntax.
After this fix, creating a Stored Function reports a warning if there is a
name collision with a native function.
III) User Defined Function / Stored Function
Before this fix, creating a User Defined Function "foo" and a Stored Function
"db.foo" are mutually exclusive operations. Whenever the second function is
created, an error is reported. However, the test suite did not cover this
behavior.
After this fix, the behavior is unchanged, and is now covered by test cases.
Note that the code change in this patch depends on the fix for Bug 21114.
mysql-test/r/sp.result:
New test cases.
mysql-test/r/udf.result:
New test cases.
mysql-test/t/sp.test:
New test cases.
mysql-test/t/udf.test:
New test cases.
sql/sql_lex.cc:
Name collisions with native functions.
sql/sql_lex.h:
Name collisions with native functions.
sql/sql_yacc.yy:
Name collisions with native functions.
sql/share/errmsg.txt:
Name collisions with native functions.
mysql-test/r/sp_gis.result:
New test cases.
mysql-test/t/sp_gis.test:
New test cases.
2006-11-15 03:34:16 +01:00
|
|
|
|
2007-10-17 04:47:08 +02:00
|
|
|
DROP FUNCTION metaphon;
|
Bug#18239 (Possible to overload internal functions with stored functions)
Bug#21025 (misleading error message when creating functions named 'x', or 'y')
Bug#22619 (Spaces considered harmful)
This change contains a fix to report warnings or errors, and multiple tests
cases.
Before this fix, name collisions between:
- Native functions
- User Defined Functions
- Stored Functions
were not systematically reported, leading to confusing behavior.
I) Native / User Defined Function
Before this fix, is was possible to create a UDF named "foo", with the same
name as a native function "foo", but it was impossible to invoke the UDF,
since the syntax "foo()" always refer to the native function.
After this fix, creating a UDF fails with an error if there is a name
collision with a native function.
II) Native / Stored Function
Before this fix, is was possible to create a SF named "db.foo", with the same
name as a native function "foo", but this was confusing since the syntax
"foo()" would refer to the native function. To refer to the Stored Function,
the user had to use the "db.foo()" syntax.
After this fix, creating a Stored Function reports a warning if there is a
name collision with a native function.
III) User Defined Function / Stored Function
Before this fix, creating a User Defined Function "foo" and a Stored Function
"db.foo" are mutually exclusive operations. Whenever the second function is
created, an error is reported. However, the test suite did not cover this
behavior.
After this fix, the behavior is unchanged, and is now covered by test cases.
Note that the code change in this patch depends on the fix for Bug 21114.
mysql-test/r/sp.result:
New test cases.
mysql-test/r/udf.result:
New test cases.
mysql-test/t/sp.test:
New test cases.
mysql-test/t/udf.test:
New test cases.
sql/sql_lex.cc:
Name collisions with native functions.
sql/sql_lex.h:
Name collisions with native functions.
sql/sql_yacc.yy:
Name collisions with native functions.
sql/share/errmsg.txt:
Name collisions with native functions.
mysql-test/r/sp_gis.result:
New test cases.
mysql-test/t/sp_gis.test:
New test cases.
2006-11-15 03:34:16 +01:00
|
|
|
DROP FUNCTION metaphon;
|
|
|
|
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
Bug#18239 (Possible to overload internal functions with stored functions)
Bug#21025 (misleading error message when creating functions named 'x', or 'y')
Bug#22619 (Spaces considered harmful)
This change contains a fix to report warnings or errors, and multiple tests
cases.
Before this fix, name collisions between:
- Native functions
- User Defined Functions
- Stored Functions
were not systematically reported, leading to confusing behavior.
I) Native / User Defined Function
Before this fix, is was possible to create a UDF named "foo", with the same
name as a native function "foo", but it was impossible to invoke the UDF,
since the syntax "foo()" always refer to the native function.
After this fix, creating a UDF fails with an error if there is a name
collision with a native function.
II) Native / Stored Function
Before this fix, is was possible to create a SF named "db.foo", with the same
name as a native function "foo", but this was confusing since the syntax
"foo()" would refer to the native function. To refer to the Stored Function,
the user had to use the "db.foo()" syntax.
After this fix, creating a Stored Function reports a warning if there is a
name collision with a native function.
III) User Defined Function / Stored Function
Before this fix, creating a User Defined Function "foo" and a Stored Function
"db.foo" are mutually exclusive operations. Whenever the second function is
created, an error is reported. However, the test suite did not cover this
behavior.
After this fix, the behavior is unchanged, and is now covered by test cases.
Note that the code change in this patch depends on the fix for Bug 21114.
mysql-test/r/sp.result:
New test cases.
mysql-test/r/udf.result:
New test cases.
mysql-test/t/sp.test:
New test cases.
mysql-test/t/udf.test:
New test cases.
sql/sql_lex.cc:
Name collisions with native functions.
sql/sql_lex.h:
Name collisions with native functions.
sql/sql_yacc.yy:
Name collisions with native functions.
sql/share/errmsg.txt:
Name collisions with native functions.
mysql-test/r/sp_gis.result:
New test cases.
mysql-test/t/sp_gis.test:
New test cases.
2006-11-15 03:34:16 +01:00
|
|
|
|
|
|
|
--error ER_UDF_EXISTS
|
|
|
|
CREATE FUNCTION metaphon(a int) RETURNS int
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
--error ER_UDF_EXISTS
|
|
|
|
CREATE FUNCTION test.metaphon(a int) RETURNS int
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
# End of Bug#18239
|
|
|
|
|
2006-03-10 10:41:04 +01:00
|
|
|
#
|
2006-02-15 17:11:24 +01:00
|
|
|
# Drop the example functions from udf_example
|
|
|
|
#
|
|
|
|
|
|
|
|
DROP FUNCTION metaphon;
|
|
|
|
DROP FUNCTION myfunc_double;
|
2006-03-10 10:41:04 +01:00
|
|
|
--error ER_SP_DOES_NOT_EXIST
|
2006-03-10 12:12:08 +01:00
|
|
|
DROP FUNCTION myfunc_nonexist;
|
2006-02-15 17:11:24 +01:00
|
|
|
DROP FUNCTION myfunc_int;
|
MDEV-10139 Support for SEQUENCE objects
Working features:
CREATE OR REPLACE [TEMPORARY] SEQUENCE [IF NOT EXISTS] name
[ INCREMENT [ BY | = ] increment ]
[ MINVALUE [=] minvalue | NO MINVALUE ]
[ MAXVALUE [=] maxvalue | NO MAXVALUE ]
[ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ]
ENGINE=xxx COMMENT=".."
SELECT NEXT VALUE FOR sequence_name;
SELECT NEXTVAL(sequence_name);
SELECT PREVIOUS VALUE FOR sequence_name;
SELECT LASTVAL(sequence_name);
SHOW CREATE SEQUENCE sequence_name;
SHOW CREATE TABLE sequence_name;
CREATE TABLE sequence-structure ... SEQUENCE=1
ALTER TABLE sequence RENAME TO sequence2;
RENAME TABLE sequence TO sequence2;
DROP [TEMPORARY] SEQUENCE [IF EXISTS] sequence_names
Missing features
- SETVAL(value,sequence_name), to be used with replication.
- Check replication, including checking that sequence tables are marked
not transactional.
- Check that a commit happens for NEXT VALUE that changes table data (may
already work)
- ALTER SEQUENCE. ANSI SQL version of setval.
- Share identical sequence entries to not add things twice to table list.
- testing insert/delete/update/truncate/load data
- Run and fix Alibaba sequence tests (part of mysql-test/suite/sql_sequence)
- Write documentation for NEXT VALUE / PREVIOUS_VALUE
- NEXTVAL in DEFAULT
- Ensure that NEXTVAL in DEFAULT uses database from base table
- Two NEXTVAL for same row should give same answer.
- Oracle syntax sequence_table.nextval, without any FOR or FROM.
- Sequence tables are treated as 'not read constant tables' by SELECT; Would
be better if we would have a separate list for sequence tables so that
select doesn't know about them, except if refereed to with FROM.
Other things done:
- Improved output for safemalloc backtrack
- frm_type_enum changed to Table_type
- Removed lex->is_view and replaced with lex->table_type. This allows
use to more easy check if item is view, sequence or table.
- Added table flag HA_CAN_TABLES_WITHOUT_ROLLBACK, needed for handlers
that want's to support sequences
- Added handler calls:
- engine_name(), to simplify getting engine name for partition and sequences
- update_first_row(), to be able to do efficient sequence implementations.
- Made binlog_log_row() global to be able to call it from ha_sequence.cc
- Added handler variable: row_already_logged, to be able to flag that the
changed row is already logging to replication log.
- Added CF_DB_CHANGE and CF_SCHEMA_CHANGE flags to simplify
deny_updates_if_read_only_option()
- Added sp_add_cfetch() to avoid new conflicts in sql_yacc.yy
- Moved code for add_table_options() out from sql_show.cc::show_create_table()
- Added String::append_longlong() and used it in sql_show.cc to simplify code.
- Added extra option to dd_frm_type() and ha_table_exists to indicate if
the table is a sequence. Needed by DROP SQUENCE to not drop a table.
2017-03-25 22:36:56 +01:00
|
|
|
DROP FUNCTION udf_sequence;
|
2006-02-15 17:11:24 +01:00
|
|
|
DROP FUNCTION lookup;
|
|
|
|
DROP FUNCTION reverse_lookup;
|
|
|
|
DROP FUNCTION avgcost;
|
|
|
|
|
2006-12-15 10:38:30 +01:00
|
|
|
#
|
|
|
|
# Bug #15439: UDF name case handling forces DELETE FROM mysql.func to remove
|
|
|
|
# the UDF
|
|
|
|
#
|
|
|
|
select * from mysql.func;
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION is_const RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
2006-12-15 10:38:30 +01:00
|
|
|
|
|
|
|
select IS_const(3);
|
|
|
|
|
|
|
|
drop function IS_const;
|
|
|
|
|
|
|
|
select * from mysql.func;
|
|
|
|
|
|
|
|
--error 1305
|
|
|
|
select is_const(3);
|
|
|
|
|
2006-11-13 19:13:44 +01:00
|
|
|
#
|
|
|
|
# Bug#18761: constant expression as UDF parameters not passed in as constant
|
|
|
|
#
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION is_const RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
2006-11-13 19:13:44 +01:00
|
|
|
|
|
|
|
select
|
|
|
|
is_const(3) as const,
|
|
|
|
is_const(3.14) as const,
|
|
|
|
is_const('fnord') as const,
|
|
|
|
is_const(2+3) as const,
|
|
|
|
is_const(rand()) as 'nc rand()',
|
|
|
|
is_const(sin(3.14)) as const,
|
|
|
|
is_const(upper('test')) as const;
|
|
|
|
|
|
|
|
create table bug18761 (n int);
|
|
|
|
insert into bug18761 values (null),(2);
|
|
|
|
select
|
|
|
|
is_const(3) as const,
|
|
|
|
is_const(3.14) as const,
|
|
|
|
is_const('fnord') as const,
|
|
|
|
is_const(2+3) as const,
|
|
|
|
is_const(2+n) as 'nc 2+n ',
|
|
|
|
is_const(sin(n)) as 'nc sin(n)',
|
|
|
|
is_const(sin(3.14)) as const,
|
|
|
|
is_const(upper('test')) as const,
|
|
|
|
is_const(rand()) as 'nc rand()',
|
|
|
|
is_const(n) as 'nc n ',
|
|
|
|
is_const(is_const(n)) as 'nc ic?(n)',
|
|
|
|
is_const(is_const('c')) as const
|
|
|
|
from
|
|
|
|
bug18761;
|
|
|
|
drop table bug18761;
|
|
|
|
|
|
|
|
--error 1241
|
|
|
|
select is_const((1,2,3));
|
|
|
|
|
|
|
|
drop function if exists is_const;
|
2007-01-18 16:33:38 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# Bug #25382: Passing NULL to an UDF called from stored procedures
|
|
|
|
# crashes server
|
|
|
|
#
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
2007-01-18 16:33:38 +01:00
|
|
|
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION myfunc_double RETURNS REAL SONAME "$UDF_EXAMPLE_SO";
|
2007-01-18 16:33:38 +01:00
|
|
|
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "$UDF_EXAMPLE_SO";
|
2007-01-18 16:33:38 +01:00
|
|
|
|
|
|
|
delimiter //;
|
|
|
|
create function f1(p1 varchar(255))
|
|
|
|
returns varchar(255)
|
|
|
|
begin
|
|
|
|
return metaphon(p1);
|
|
|
|
end//
|
|
|
|
|
|
|
|
create function f2(p1 varchar(255))
|
|
|
|
returns double
|
|
|
|
begin
|
|
|
|
return myfunc_double(p1);
|
|
|
|
end//
|
|
|
|
|
|
|
|
create function f3(p1 varchar(255))
|
|
|
|
returns double
|
|
|
|
begin
|
|
|
|
return myfunc_int(p1);
|
|
|
|
end//
|
|
|
|
|
|
|
|
delimiter ;//
|
|
|
|
|
|
|
|
select f3(NULL);
|
|
|
|
select f2(NULL);
|
|
|
|
select f1(NULL);
|
|
|
|
|
|
|
|
drop function f1;
|
|
|
|
drop function f2;
|
|
|
|
drop function f3;
|
|
|
|
drop function metaphon;
|
|
|
|
drop function myfunc_double;
|
|
|
|
drop function myfunc_int;
|
|
|
|
|
2007-10-10 01:46:33 +02:00
|
|
|
#
|
|
|
|
# Bug#28318 CREATE FUNCTION (UDF) requires a schema
|
|
|
|
#
|
|
|
|
|
|
|
|
--disable_warnings
|
|
|
|
DROP DATABASE IF EXISTS mysqltest;
|
|
|
|
--enable_warnings
|
|
|
|
CREATE DATABASE mysqltest;
|
|
|
|
USE mysqltest;
|
|
|
|
DROP DATABASE mysqltest;
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
2007-10-10 01:46:33 +02:00
|
|
|
DROP FUNCTION metaphon;
|
|
|
|
USE test;
|
2007-06-18 23:55:12 +02:00
|
|
|
|
2007-08-06 03:37:55 +02:00
|
|
|
#
|
|
|
|
# Bug #29804 UDF parameters don't contain correct string length
|
|
|
|
#
|
|
|
|
|
|
|
|
CREATE TABLE const_len_bug (
|
|
|
|
str_const varchar(4000),
|
|
|
|
result1 varchar(4000),
|
|
|
|
result2 varchar(4000)
|
|
|
|
);
|
|
|
|
|
|
|
|
DELIMITER |;
|
|
|
|
CREATE TRIGGER check_const_len_trigger BEFORE INSERT ON const_len_bug FOR EACH ROW BEGIN
|
|
|
|
set NEW.str_const = 'bar';
|
|
|
|
set NEW.result2 = check_const_len(NEW.str_const);
|
|
|
|
END |
|
|
|
|
|
|
|
|
CREATE PROCEDURE check_const_len_sp (IN str_const VARCHAR(4000))
|
|
|
|
BEGIN
|
|
|
|
DECLARE result VARCHAR(4000);
|
|
|
|
SET result = check_const_len(str_const);
|
|
|
|
insert into const_len_bug values(str_const, result, "");
|
|
|
|
END |
|
|
|
|
DELIMITER ;|
|
|
|
|
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION check_const_len RETURNS string SONAME "$UDF_EXAMPLE_SO";
|
2007-08-06 03:37:55 +02:00
|
|
|
|
|
|
|
CALL check_const_len_sp("foo");
|
|
|
|
|
|
|
|
SELECT * from const_len_bug;
|
|
|
|
|
|
|
|
DROP FUNCTION check_const_len;
|
|
|
|
DROP PROCEDURE check_const_len_sp;
|
|
|
|
DROP TRIGGER check_const_len_trigger;
|
|
|
|
DROP TABLE const_len_bug;
|
|
|
|
|
2007-11-27 16:16:52 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# Bug #30355: Incorrect ordering of UDF results
|
|
|
|
#
|
|
|
|
|
2010-06-10 11:11:52 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
MDEV-10139 Support for SEQUENCE objects
Working features:
CREATE OR REPLACE [TEMPORARY] SEQUENCE [IF NOT EXISTS] name
[ INCREMENT [ BY | = ] increment ]
[ MINVALUE [=] minvalue | NO MINVALUE ]
[ MAXVALUE [=] maxvalue | NO MAXVALUE ]
[ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ]
ENGINE=xxx COMMENT=".."
SELECT NEXT VALUE FOR sequence_name;
SELECT NEXTVAL(sequence_name);
SELECT PREVIOUS VALUE FOR sequence_name;
SELECT LASTVAL(sequence_name);
SHOW CREATE SEQUENCE sequence_name;
SHOW CREATE TABLE sequence_name;
CREATE TABLE sequence-structure ... SEQUENCE=1
ALTER TABLE sequence RENAME TO sequence2;
RENAME TABLE sequence TO sequence2;
DROP [TEMPORARY] SEQUENCE [IF EXISTS] sequence_names
Missing features
- SETVAL(value,sequence_name), to be used with replication.
- Check replication, including checking that sequence tables are marked
not transactional.
- Check that a commit happens for NEXT VALUE that changes table data (may
already work)
- ALTER SEQUENCE. ANSI SQL version of setval.
- Share identical sequence entries to not add things twice to table list.
- testing insert/delete/update/truncate/load data
- Run and fix Alibaba sequence tests (part of mysql-test/suite/sql_sequence)
- Write documentation for NEXT VALUE / PREVIOUS_VALUE
- NEXTVAL in DEFAULT
- Ensure that NEXTVAL in DEFAULT uses database from base table
- Two NEXTVAL for same row should give same answer.
- Oracle syntax sequence_table.nextval, without any FOR or FROM.
- Sequence tables are treated as 'not read constant tables' by SELECT; Would
be better if we would have a separate list for sequence tables so that
select doesn't know about them, except if refereed to with FROM.
Other things done:
- Improved output for safemalloc backtrack
- frm_type_enum changed to Table_type
- Removed lex->is_view and replaced with lex->table_type. This allows
use to more easy check if item is view, sequence or table.
- Added table flag HA_CAN_TABLES_WITHOUT_ROLLBACK, needed for handlers
that want's to support sequences
- Added handler calls:
- engine_name(), to simplify getting engine name for partition and sequences
- update_first_row(), to be able to do efficient sequence implementations.
- Made binlog_log_row() global to be able to call it from ha_sequence.cc
- Added handler variable: row_already_logged, to be able to flag that the
changed row is already logging to replication log.
- Added CF_DB_CHANGE and CF_SCHEMA_CHANGE flags to simplify
deny_updates_if_read_only_option()
- Added sp_add_cfetch() to avoid new conflicts in sql_yacc.yy
- Moved code for add_table_options() out from sql_show.cc::show_create_table()
- Added String::append_longlong() and used it in sql_show.cc to simplify code.
- Added extra option to dd_frm_type() and ha_table_exists to indicate if
the table is a sequence. Needed by DROP SQUENCE to not drop a table.
2017-03-25 22:36:56 +01:00
|
|
|
eval CREATE FUNCTION udf_sequence RETURNS INTEGER SONAME "$UDF_EXAMPLE_SO";
|
2007-11-27 16:16:52 +01:00
|
|
|
CREATE TABLE t1 (a INT);
|
|
|
|
CREATE TABLE t2 (a INT PRIMARY KEY);
|
|
|
|
INSERT INTO t1 VALUES (4),(3),(2),(1);
|
|
|
|
INSERT INTO t2 SELECT * FROM t1;
|
|
|
|
|
MDEV-10139 Support for SEQUENCE objects
Working features:
CREATE OR REPLACE [TEMPORARY] SEQUENCE [IF NOT EXISTS] name
[ INCREMENT [ BY | = ] increment ]
[ MINVALUE [=] minvalue | NO MINVALUE ]
[ MAXVALUE [=] maxvalue | NO MAXVALUE ]
[ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ]
ENGINE=xxx COMMENT=".."
SELECT NEXT VALUE FOR sequence_name;
SELECT NEXTVAL(sequence_name);
SELECT PREVIOUS VALUE FOR sequence_name;
SELECT LASTVAL(sequence_name);
SHOW CREATE SEQUENCE sequence_name;
SHOW CREATE TABLE sequence_name;
CREATE TABLE sequence-structure ... SEQUENCE=1
ALTER TABLE sequence RENAME TO sequence2;
RENAME TABLE sequence TO sequence2;
DROP [TEMPORARY] SEQUENCE [IF EXISTS] sequence_names
Missing features
- SETVAL(value,sequence_name), to be used with replication.
- Check replication, including checking that sequence tables are marked
not transactional.
- Check that a commit happens for NEXT VALUE that changes table data (may
already work)
- ALTER SEQUENCE. ANSI SQL version of setval.
- Share identical sequence entries to not add things twice to table list.
- testing insert/delete/update/truncate/load data
- Run and fix Alibaba sequence tests (part of mysql-test/suite/sql_sequence)
- Write documentation for NEXT VALUE / PREVIOUS_VALUE
- NEXTVAL in DEFAULT
- Ensure that NEXTVAL in DEFAULT uses database from base table
- Two NEXTVAL for same row should give same answer.
- Oracle syntax sequence_table.nextval, without any FOR or FROM.
- Sequence tables are treated as 'not read constant tables' by SELECT; Would
be better if we would have a separate list for sequence tables so that
select doesn't know about them, except if refereed to with FROM.
Other things done:
- Improved output for safemalloc backtrack
- frm_type_enum changed to Table_type
- Removed lex->is_view and replaced with lex->table_type. This allows
use to more easy check if item is view, sequence or table.
- Added table flag HA_CAN_TABLES_WITHOUT_ROLLBACK, needed for handlers
that want's to support sequences
- Added handler calls:
- engine_name(), to simplify getting engine name for partition and sequences
- update_first_row(), to be able to do efficient sequence implementations.
- Made binlog_log_row() global to be able to call it from ha_sequence.cc
- Added handler variable: row_already_logged, to be able to flag that the
changed row is already logging to replication log.
- Added CF_DB_CHANGE and CF_SCHEMA_CHANGE flags to simplify
deny_updates_if_read_only_option()
- Added sp_add_cfetch() to avoid new conflicts in sql_yacc.yy
- Moved code for add_table_options() out from sql_show.cc::show_create_table()
- Added String::append_longlong() and used it in sql_show.cc to simplify code.
- Added extra option to dd_frm_type() and ha_table_exists to indicate if
the table is a sequence. Needed by DROP SQUENCE to not drop a table.
2017-03-25 22:36:56 +01:00
|
|
|
SELECT udf_sequence() AS seq, a FROM t1 ORDER BY seq ASC;
|
|
|
|
SELECT udf_sequence() AS seq, a FROM t1 ORDER BY seq DESC;
|
2007-11-27 16:16:52 +01:00
|
|
|
|
MDEV-10139 Support for SEQUENCE objects
Working features:
CREATE OR REPLACE [TEMPORARY] SEQUENCE [IF NOT EXISTS] name
[ INCREMENT [ BY | = ] increment ]
[ MINVALUE [=] minvalue | NO MINVALUE ]
[ MAXVALUE [=] maxvalue | NO MAXVALUE ]
[ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ]
ENGINE=xxx COMMENT=".."
SELECT NEXT VALUE FOR sequence_name;
SELECT NEXTVAL(sequence_name);
SELECT PREVIOUS VALUE FOR sequence_name;
SELECT LASTVAL(sequence_name);
SHOW CREATE SEQUENCE sequence_name;
SHOW CREATE TABLE sequence_name;
CREATE TABLE sequence-structure ... SEQUENCE=1
ALTER TABLE sequence RENAME TO sequence2;
RENAME TABLE sequence TO sequence2;
DROP [TEMPORARY] SEQUENCE [IF EXISTS] sequence_names
Missing features
- SETVAL(value,sequence_name), to be used with replication.
- Check replication, including checking that sequence tables are marked
not transactional.
- Check that a commit happens for NEXT VALUE that changes table data (may
already work)
- ALTER SEQUENCE. ANSI SQL version of setval.
- Share identical sequence entries to not add things twice to table list.
- testing insert/delete/update/truncate/load data
- Run and fix Alibaba sequence tests (part of mysql-test/suite/sql_sequence)
- Write documentation for NEXT VALUE / PREVIOUS_VALUE
- NEXTVAL in DEFAULT
- Ensure that NEXTVAL in DEFAULT uses database from base table
- Two NEXTVAL for same row should give same answer.
- Oracle syntax sequence_table.nextval, without any FOR or FROM.
- Sequence tables are treated as 'not read constant tables' by SELECT; Would
be better if we would have a separate list for sequence tables so that
select doesn't know about them, except if refereed to with FROM.
Other things done:
- Improved output for safemalloc backtrack
- frm_type_enum changed to Table_type
- Removed lex->is_view and replaced with lex->table_type. This allows
use to more easy check if item is view, sequence or table.
- Added table flag HA_CAN_TABLES_WITHOUT_ROLLBACK, needed for handlers
that want's to support sequences
- Added handler calls:
- engine_name(), to simplify getting engine name for partition and sequences
- update_first_row(), to be able to do efficient sequence implementations.
- Made binlog_log_row() global to be able to call it from ha_sequence.cc
- Added handler variable: row_already_logged, to be able to flag that the
changed row is already logging to replication log.
- Added CF_DB_CHANGE and CF_SCHEMA_CHANGE flags to simplify
deny_updates_if_read_only_option()
- Added sp_add_cfetch() to avoid new conflicts in sql_yacc.yy
- Moved code for add_table_options() out from sql_show.cc::show_create_table()
- Added String::append_longlong() and used it in sql_show.cc to simplify code.
- Added extra option to dd_frm_type() and ha_table_exists to indicate if
the table is a sequence. Needed by DROP SQUENCE to not drop a table.
2017-03-25 22:36:56 +01:00
|
|
|
SELECT * FROM t1 WHERE a = udf_sequence();
|
|
|
|
SELECT * FROM t2 WHERE a = udf_sequence();
|
2007-11-27 16:16:52 +01:00
|
|
|
|
MDEV-10139 Support for SEQUENCE objects
Working features:
CREATE OR REPLACE [TEMPORARY] SEQUENCE [IF NOT EXISTS] name
[ INCREMENT [ BY | = ] increment ]
[ MINVALUE [=] minvalue | NO MINVALUE ]
[ MAXVALUE [=] maxvalue | NO MAXVALUE ]
[ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ]
ENGINE=xxx COMMENT=".."
SELECT NEXT VALUE FOR sequence_name;
SELECT NEXTVAL(sequence_name);
SELECT PREVIOUS VALUE FOR sequence_name;
SELECT LASTVAL(sequence_name);
SHOW CREATE SEQUENCE sequence_name;
SHOW CREATE TABLE sequence_name;
CREATE TABLE sequence-structure ... SEQUENCE=1
ALTER TABLE sequence RENAME TO sequence2;
RENAME TABLE sequence TO sequence2;
DROP [TEMPORARY] SEQUENCE [IF EXISTS] sequence_names
Missing features
- SETVAL(value,sequence_name), to be used with replication.
- Check replication, including checking that sequence tables are marked
not transactional.
- Check that a commit happens for NEXT VALUE that changes table data (may
already work)
- ALTER SEQUENCE. ANSI SQL version of setval.
- Share identical sequence entries to not add things twice to table list.
- testing insert/delete/update/truncate/load data
- Run and fix Alibaba sequence tests (part of mysql-test/suite/sql_sequence)
- Write documentation for NEXT VALUE / PREVIOUS_VALUE
- NEXTVAL in DEFAULT
- Ensure that NEXTVAL in DEFAULT uses database from base table
- Two NEXTVAL for same row should give same answer.
- Oracle syntax sequence_table.nextval, without any FOR or FROM.
- Sequence tables are treated as 'not read constant tables' by SELECT; Would
be better if we would have a separate list for sequence tables so that
select doesn't know about them, except if refereed to with FROM.
Other things done:
- Improved output for safemalloc backtrack
- frm_type_enum changed to Table_type
- Removed lex->is_view and replaced with lex->table_type. This allows
use to more easy check if item is view, sequence or table.
- Added table flag HA_CAN_TABLES_WITHOUT_ROLLBACK, needed for handlers
that want's to support sequences
- Added handler calls:
- engine_name(), to simplify getting engine name for partition and sequences
- update_first_row(), to be able to do efficient sequence implementations.
- Made binlog_log_row() global to be able to call it from ha_sequence.cc
- Added handler variable: row_already_logged, to be able to flag that the
changed row is already logging to replication log.
- Added CF_DB_CHANGE and CF_SCHEMA_CHANGE flags to simplify
deny_updates_if_read_only_option()
- Added sp_add_cfetch() to avoid new conflicts in sql_yacc.yy
- Moved code for add_table_options() out from sql_show.cc::show_create_table()
- Added String::append_longlong() and used it in sql_show.cc to simplify code.
- Added extra option to dd_frm_type() and ha_table_exists to indicate if
the table is a sequence. Needed by DROP SQUENCE to not drop a table.
2017-03-25 22:36:56 +01:00
|
|
|
DROP FUNCTION udf_sequence;
|
2007-11-27 16:16:52 +01:00
|
|
|
DROP TABLE t1,t2;
|
|
|
|
|
2010-02-23 19:43:26 +01:00
|
|
|
#
|
|
|
|
# Bug#31767 (DROP FUNCTION name resolution)
|
|
|
|
#
|
|
|
|
|
|
|
|
--disable_warnings
|
|
|
|
drop function if exists test.metaphon;
|
|
|
|
drop function if exists metaphon;
|
|
|
|
--enable_warnings
|
|
|
|
|
2011-04-25 17:22:25 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
2010-02-23 19:43:26 +01:00
|
|
|
|
|
|
|
select metaphon("Hello");
|
|
|
|
|
|
|
|
# The UDF should not be dropped
|
|
|
|
drop function if exists test.metaphon;
|
|
|
|
|
|
|
|
select metaphon("Hello");
|
|
|
|
|
|
|
|
drop function metaphon;
|
|
|
|
|
|
|
|
CREATE FUNCTION test.metaphon(a TEXT) RETURNS TEXT return "This is a SF";
|
|
|
|
|
|
|
|
create database db_31767;
|
|
|
|
use db_31767;
|
|
|
|
|
2011-04-25 17:22:25 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
2010-02-23 19:43:26 +01:00
|
|
|
|
|
|
|
use test;
|
|
|
|
|
|
|
|
# Uses the UDF
|
|
|
|
select metaphon("Hello");
|
|
|
|
|
|
|
|
# Uses the SF
|
|
|
|
select test.metaphon("Hello");
|
|
|
|
|
|
|
|
# Should drop the UDF, resolving the name the same way select does.
|
|
|
|
drop function metaphon;
|
|
|
|
|
|
|
|
# Should call the SF
|
|
|
|
select metaphon("Hello");
|
|
|
|
|
|
|
|
# Drop the SF
|
|
|
|
drop function metaphon;
|
|
|
|
|
|
|
|
# Change the current database to none.
|
|
|
|
use db_31767;
|
|
|
|
drop database db_31767;
|
|
|
|
|
|
|
|
drop function if exists no_such_func;
|
|
|
|
|
|
|
|
--error ER_SP_DOES_NOT_EXIST
|
|
|
|
drop function no_such_func;
|
|
|
|
|
|
|
|
drop function if exists test.no_such_func;
|
|
|
|
|
|
|
|
--error ER_SP_DOES_NOT_EXIST
|
|
|
|
drop function test.no_such_func;
|
|
|
|
|
|
|
|
--error ER_NO_DB_ERROR
|
|
|
|
drop procedure if exists no_such_proc;
|
|
|
|
|
|
|
|
--error ER_NO_DB_ERROR
|
|
|
|
drop procedure no_such_proc;
|
|
|
|
|
|
|
|
use test;
|
|
|
|
|
|
|
|
|
2009-09-07 11:57:22 +02:00
|
|
|
--echo #
|
|
|
|
--echo # Bug#46259: 5.0.83 -> 5.1.36, query doesn't work
|
|
|
|
--echo #
|
|
|
|
CREATE TABLE t1 ( a INT );
|
|
|
|
|
|
|
|
INSERT INTO t1 VALUES (1), (2), (3);
|
|
|
|
|
|
|
|
SELECT IF( a = 1, a, a ) AS `b` FROM t1 ORDER BY field( `b` + 1, 1 );
|
|
|
|
SELECT IF( a = 1, a, a ) AS `b` FROM t1 ORDER BY field( `b`, 1 );
|
|
|
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2007-01-18 16:33:38 +01:00
|
|
|
--echo End of 5.0 tests.
|
2009-12-01 22:25:51 +01:00
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Bug#33546: Slowdown on re-evaluation of constant expressions.
|
|
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (f1 INT);
|
|
|
|
INSERT INTO t1 VALUES(1),(50);
|
2011-04-25 17:22:25 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION myfunc_double RETURNS INTEGER SONAME "$UDF_EXAMPLE_SO";
|
2009-12-01 22:25:51 +01:00
|
|
|
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE f1=1 + myfunc_double(1);
|
|
|
|
DROP FUNCTION myfunc_double;
|
|
|
|
DROP TABLE t1;
|
|
|
|
--echo #
|
|
|
|
--echo End of 5.1 tests.
|
|
|
|
|
2016-06-09 14:42:49 +02:00
|
|
|
--echo #
|
|
|
|
--echo # MDEV-10134 Add full support for DEFAULT
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_SO";
|
|
|
|
SELECT METAPHON('Hello');
|
|
|
|
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT METAPHON(a));
|
2016-06-29 21:10:35 +02:00
|
|
|
SHOW CREATE TABLE t1;
|
2016-06-09 14:42:49 +02:00
|
|
|
INSERT INTO t1 (a) VALUES ('Hello');
|
|
|
|
SELECT * FROM t1;
|
|
|
|
DROP FUNCTION METAPHON;
|
|
|
|
# QQ: this should return an error
|
|
|
|
#INSERT INTO t1 (a) VALUES ('Hello');
|
|
|
|
#SELECT * FROM t1;
|
|
|
|
DROP TABLE t1;
|
2018-12-19 14:27:14 +01:00
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # MDEV-15424: Unreasonal SQL Error (1356) on select from view
|
|
|
|
--echo #
|
|
|
|
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "$UDF_EXAMPLE_SO";
|
|
|
|
create table t1(a int , b int);
|
|
|
|
insert into t1 values(100, 54), (200, 199);
|
|
|
|
create view v1 as select myfunc_int(max(a) over (order by b) , b) from t1;
|
|
|
|
select * from v1;
|
|
|
|
drop view v1;
|
|
|
|
drop function myfunc_int;
|
|
|
|
drop table t1;
|