Commit 10ca1ec0 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

merge

parents 0f3f6da6 e96932f4
......@@ -88,7 +88,7 @@
*/
#define make_atomic_add_body64 \
int64 tmp=*a; \
while (!my_atomic_cas64(a, &tmp, tmp+v)); \
while (!my_atomic_cas64(a, &tmp, tmp+v)) ; \
v=tmp;
/*
......
......@@ -77,13 +77,13 @@
#ifndef make_atomic_add_body
#define make_atomic_add_body(S) \
int ## S tmp=*a; \
while (!my_atomic_cas ## S(a, &tmp, tmp+v)); \
while (!my_atomic_cas ## S(a, &tmp, tmp+v)) ; \
v=tmp;
#endif
#ifndef make_atomic_fas_body
#define make_atomic_fas_body(S) \
int ## S tmp=*a; \
while (!my_atomic_cas ## S(a, &tmp, v)); \
while (!my_atomic_cas ## S(a, &tmp, v)) ; \
v=tmp;
#endif
#ifndef make_atomic_load_body
......
......@@ -61,10 +61,10 @@ create table t1 (a int unique);
create table t2 (a int);
drop function if exists f1;
Warnings:
Note 1305 FUNCTION f1 does not exist
Note 1305 FUNCTION test.f1 does not exist
drop function if exists f2;
Warnings:
Note 1305 FUNCTION f2 does not exist
Note 1305 FUNCTION test.f2 does not exist
create function f1() returns int
begin
insert into t1 (a) values (1);
......
......@@ -1231,7 +1231,7 @@ Warnings:
Note 1051 Unknown table 'test'
drop function if exists test_function;
Warnings:
Note 1305 FUNCTION test_function does not exist
Note 1305 FUNCTION test.test_function does not exist
drop view if exists v1;
Warnings:
Note 1051 Unknown table 'test.v1'
......
......@@ -2297,3 +2297,28 @@ t2 CREATE TABLE `t2` (
CONSTRAINT `x` FOREIGN KEY (`fk`) REFERENCES `t1` (`pk`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
drop table t2, t1;
#
# Bug#44613 SELECT statement inside FUNCTION takes a shared lock
#
DROP TABLE IF EXISTS t1;
DROP FUNCTION IF EXISTS f1;
CREATE TABLE t1(x INT PRIMARY KEY, y INT) ENGINE=innodb;
INSERT INTO t1 VALUES (1, 0), (2, 0);
CREATE FUNCTION f1(z INT) RETURNS INT READS SQL DATA
RETURN (SELECT x FROM t1 WHERE x = z);
# Connection default
START TRANSACTION;
SELECT f1(1);
f1(1)
1
# Connection con2
START TRANSACTION;
SELECT f1(1);
f1(1)
1
UPDATE t1 SET y = 1 WHERE x = 1;
COMMIT;
# Connection default
COMMIT;
DROP TABLE t1;
DROP FUNCTION f1;
......@@ -2181,7 +2181,7 @@ drop procedure peter_p1 $$
drop procedure peter_p2 $$
drop procedure if exists peter_p3 $$
Warnings:
Note 1305 PROCEDURE peter_p3 does not exist
Note 1305 PROCEDURE test.peter_p3 does not exist
create procedure peter_p3()
begin
declare continue handler for sqlexception
......
......@@ -46,7 +46,7 @@ call foo()|
ERROR 42000: PROCEDURE test.foo does not exist
drop procedure if exists foo|
Warnings:
Note 1305 PROCEDURE foo does not exist
Note 1305 PROCEDURE test.foo does not exist
show create procedure foo|
ERROR 42000: PROCEDURE foo does not exist
show create function foo|
......@@ -1028,7 +1028,7 @@ drop table t1|
drop function bug_13627_f|
drop function if exists bug12329;
Warnings:
Note 1305 FUNCTION bug12329 does not exist
Note 1305 FUNCTION test.bug12329 does not exist
create table t1 as select 1 a;
create table t2 as select 1 a;
create function bug12329() returns int return (select a from t1);
......
......@@ -394,10 +394,10 @@ CASE expression tests.
DROP PROCEDURE IF EXISTS p1;
Warnings:
Note 1305 PROCEDURE p1 does not exist
Note 1305 PROCEDURE test.p1 does not exist
DROP PROCEDURE IF EXISTS p2;
Warnings:
Note 1305 PROCEDURE p2 does not exist
Note 1305 PROCEDURE test.p2 does not exist
DROP TABLE IF EXISTS t1;
Warnings:
Note 1051 Unknown table 't1'
......
......@@ -2695,10 +2695,10 @@ delete from t3|
insert into t3 values(1)|
drop procedure if exists bug7992_1|
Warnings:
Note 1305 PROCEDURE bug7992_1 does not exist
Note 1305 PROCEDURE test.bug7992_1 does not exist
drop procedure if exists bug7992_2|
Warnings:
Note 1305 PROCEDURE bug7992_2 does not exist
Note 1305 PROCEDURE test.bug7992_2 does not exist
create procedure bug7992_1()
begin
declare i int;
......
......@@ -21,11 +21,11 @@ end|
call bug4902_2()|
show warnings|
Level Code Message
Note 1305 PROCEDURE bug4902_2 does not exist
Note 1305 PROCEDURE test.bug4902_2 does not exist
call bug4902_2()|
show warnings|
Level Code Message
Note 1305 PROCEDURE bug4902_2 does not exist
Note 1305 PROCEDURE test.bug4902_2 does not exist
drop procedure bug4902_2|
drop table if exists t1|
create table t1 (
......
......@@ -1183,7 +1183,7 @@ drop table t1;
create table t1 (col1 tinyint);
drop procedure if exists t1;
Warnings:
Note 1305 PROCEDURE t1 does not exist
Note 1305 PROCEDURE test.t1 does not exist
create procedure t1 () begin declare exit handler for sqlexception
select'a'; insert into t1 values (200); end;|
call t1();
......
......@@ -392,6 +392,52 @@ a
4
DROP FUNCTION sequence;
DROP TABLE t1,t2;
drop function if exists test.metaphon;
drop function if exists metaphon;
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
select metaphon("Hello");
metaphon("Hello")
HL
drop function if exists test.metaphon;
Warnings:
Note 1305 FUNCTION test.metaphon does not exist
select metaphon("Hello");
metaphon("Hello")
HL
drop function metaphon;
CREATE FUNCTION test.metaphon(a TEXT) RETURNS TEXT return "This is a SF";
create database db_31767;
use db_31767;
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
use test;
select metaphon("Hello");
metaphon("Hello")
HL
select test.metaphon("Hello");
test.metaphon("Hello")
This is a SF
drop function metaphon;
select metaphon("Hello");
metaphon("Hello")
This is a SF
drop function metaphon;
use db_31767;
drop database db_31767;
drop function if exists no_such_func;
Warnings:
Note 1305 FUNCTION (UDF) no_such_func does not exist
drop function no_such_func;
ERROR 42000: FUNCTION (UDF) no_such_func does not exist
drop function if exists test.no_such_func;
Warnings:
Note 1305 FUNCTION test.no_such_func does not exist
drop function test.no_such_func;
ERROR 42000: FUNCTION test.no_such_func does not exist
drop procedure if exists no_such_proc;
ERROR 3D000: No database selected
drop procedure no_such_proc;
ERROR 3D000: No database selected
use test;
#
# Bug#46259: 5.0.83 -> 5.1.36, query doesn't work
#
......
......@@ -2086,7 +2086,7 @@ CREATE TABLE t1 ( bug_table_seq INTEGER NOT NULL);
CREATE OR REPLACE VIEW v1 AS SELECT * from t1;
DROP PROCEDURE IF EXISTS p1;
Warnings:
Note 1305 PROCEDURE p1 does not exist
Note 1305 PROCEDURE test.p1 does not exist
CREATE PROCEDURE p1 ( )
BEGIN
DO (SELECT @next := IFNULL(max(bug_table_seq),0) + 1 FROM v1);
......@@ -4004,3 +4004,36 @@ CREATE VIEW t2 AS SELECT * FROM t1;
ERROR HY000: Can't execute the query because you have a conflicting read lock
UNLOCK TABLES;
DROP TABLE t1, t2;
#
# Bug#48315 Metadata lock is not taken for merged views that
# use an INFORMATION_SCHEMA table
#
DROP TABLE IF EXISTS t1;
DROP VIEW IF EXISTS v1;
DROP PROCEDURE IF EXISTS p1;
# Connection default
CREATE VIEW v1 AS SELECT schema_name FROM information_schema.schemata;
CREATE TABLE t1 (str VARCHAR(50));
CREATE PROCEDURE p1() INSERT INTO t1 SELECT * FROM v1;
# CALL p1() so the view is merged.
CALL p1();
# Connection 3
LOCK TABLE t1 READ;
# Connection default
# Try to CALL p1() again, this time it should block for t1.
# Sending:
CALL p1();
# Connection 2
# ... then try to drop the view. This should block.
# Sending:
DROP VIEW v1;
# Connection 3
# Now allow CALL p1() to complete
UNLOCK TABLES;
# Connection default
# Reaping: CALL p1()
# Connection 2
# Reaping: DROP VIEW v1
# Connection default
DROP PROCEDURE p1;
DROP TABLE t1;
......@@ -228,13 +228,13 @@ INSERT INTO t2 VALUES ( 'a`', 'a`' );
INSERT INTO t3 VALUES ( 'a`', 'a`', '1000-01-1' );
DROP PROCEDURE IF EXISTS sp1;
Warnings:
Note 1305 PROCEDURE sp1 does not exist
Note 1305 PROCEDURE test.sp1 does not exist
DROP PROCEDURE IF EXISTS sp2;
Warnings:
Note 1305 PROCEDURE sp2 does not exist
Note 1305 PROCEDURE test.sp2 does not exist
DROP PROCEDURE IF EXISTS sp3;
Warnings:
Note 1305 PROCEDURE sp3 does not exist
Note 1305 PROCEDURE test.sp3 does not exist
CREATE PROCEDURE sp1()
BEGIN
DECLARE x NUMERIC ZEROFILL;
......
......@@ -66,7 +66,7 @@ SET GLOBAL max_prepared_stmt_count=3;
** Creating procedure **
DROP PROCEDURE IF EXISTS sp_checkstmts;
Warnings:
Note 1305 PROCEDURE sp_checkstmts does not exist
Note 1305 PROCEDURE test.sp_checkstmts does not exist
CREATE PROCEDURE sp_checkstmts ()
BEGIN
PREPARE newstmt from "SELECT * FROM information_schema.CHARACTER_SETS C";
......
......@@ -555,3 +555,42 @@ create table t2 (fk int, key x (fk),
constraint x foreign key (FK) references t1 (PK)) engine=InnoDB;
show create table t2;
drop table t2, t1;
--echo #
--echo # Bug#44613 SELECT statement inside FUNCTION takes a shared lock
--echo #
--disable_warnings
DROP TABLE IF EXISTS t1;
DROP FUNCTION IF EXISTS f1;
--enable_warnings
CREATE TABLE t1(x INT PRIMARY KEY, y INT) ENGINE=innodb;
INSERT INTO t1 VALUES (1, 0), (2, 0);
CREATE FUNCTION f1(z INT) RETURNS INT READS SQL DATA
RETURN (SELECT x FROM t1 WHERE x = z);
--echo # Connection default
START TRANSACTION;
SELECT f1(1);
--echo # Connection con2
--disable_query_log
connect (con2, localhost, root);
--enable_query_log
START TRANSACTION;
SELECT f1(1);
# This next statement used to block.
UPDATE t1 SET y = 1 WHERE x = 1;
COMMIT;
disconnect con2;
--source include/wait_until_disconnected.inc
--echo # Connection default
connection default;
COMMIT;
DROP TABLE t1;
DROP FUNCTION f1;
......@@ -436,6 +436,75 @@ SELECT * FROM t2 WHERE a = sequence();
DROP FUNCTION sequence;
DROP TABLE t1,t2;
#
# Bug#31767 (DROP FUNCTION name resolution)
#
--disable_warnings
drop function if exists test.metaphon;
drop function if exists metaphon;
--enable_warnings
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_LIB";
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;
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_LIB";
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;
--echo #
--echo # Bug#46259: 5.0.83 -> 5.1.36, query doesn't work
--echo #
......
......@@ -6,6 +6,9 @@ drop database if exists mysqltest;
--enable_warnings
use test;
# Save the initial number of concurrent sessions.
--source include/count_sessions.inc
#
# some basic test of views and its functionality
#
......@@ -3975,3 +3978,79 @@ CREATE VIEW t2 AS SELECT * FROM t1;
UNLOCK TABLES;
DROP TABLE t1, t2;
--echo #
--echo # Bug#48315 Metadata lock is not taken for merged views that
--echo # use an INFORMATION_SCHEMA table
--echo #
--disable_warnings
DROP TABLE IF EXISTS t1;
DROP VIEW IF EXISTS v1;
DROP PROCEDURE IF EXISTS p1;
--enable_warnings
connect (con2, localhost, root);
connect (con3, localhost, root);
--echo # Connection default
connection default;
CREATE VIEW v1 AS SELECT schema_name FROM information_schema.schemata;
CREATE TABLE t1 (str VARCHAR(50));
CREATE PROCEDURE p1() INSERT INTO t1 SELECT * FROM v1;
--echo # CALL p1() so the view is merged.
CALL p1();
--echo # Connection 3
connection con3;
LOCK TABLE t1 READ;
--echo # Connection default
connection default;
--echo # Try to CALL p1() again, this time it should block for t1.
--echo # Sending:
--send CALL p1()
--echo # Connection 2
connection con2;
let $wait_condition=
SELECT COUNT(*) = 1 from information_schema.processlist
WHERE state = "Table lock" AND info = "INSERT INTO t1 SELECT * FROM v1";
--source include/wait_condition.inc
--echo # ... then try to drop the view. This should block.
--echo # Sending:
--send DROP VIEW v1
--echo # Connection 3
connection con3;
let $wait_condition=
SELECT COUNT(*) = 1 from information_schema.processlist
WHERE state = "Waiting for table" AND info = "DROP VIEW v1";
--source include/wait_condition.inc
--echo # Now allow CALL p1() to complete
UNLOCK TABLES;
--echo # Connection default
connection default;
--echo # Reaping: CALL p1()
--reap
--echo # Connection 2
connection con2;
--echo # Reaping: DROP VIEW v1
--reap
--echo # Connection default
connection default;
DROP PROCEDURE p1;
DROP TABLE t1;
disconnect con2;
disconnect con3;
# Check that all connections opened by test cases in this file are really
# gone so execution of other tests won't be affected by their presence.
--source include/wait_until_count_sessions.inc
......@@ -4168,9 +4168,18 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables,
TABLE_LIST is processed. This code works only during re-execution.
*/
if (tables->view)
goto process_view_routines;
if (!mysql_schema_table(thd, lex, tables) &&
!check_and_update_table_version(thd, tables, tables->table->s))
{
/*
We still need to take a MDL lock on the merged view to protect
it from concurrent changes.
*/
if (!open_table_get_mdl_lock(thd, tables, &tables->mdl_request,
ot_ctx, flags))
goto process_view_routines;
/* Fall-through to return error. */
}
else if (!mysql_schema_table(thd, lex, tables) &&
!check_and_update_table_version(thd, tables, tables->table->s))
{
goto end;
}
......
......@@ -4132,6 +4132,47 @@ case SQLCOM_PREPARE:
case SQLCOM_DROP_PROCEDURE:
case SQLCOM_DROP_FUNCTION:
{
#ifdef HAVE_DLOPEN
if (lex->sql_command == SQLCOM_DROP_FUNCTION &&
! lex->spname->m_explicit_name)
{
/* DROP FUNCTION <non qualified name> */
udf_func *udf = find_udf(lex->spname->m_name.str,
lex->spname->m_name.length);
if (udf)
{
if (check_access(thd, DELETE_ACL, "mysql", NULL, NULL, 1, 0))
goto error;
if (!(res = mysql_drop_function(thd, &lex->spname->m_name)))
{
my_ok(thd);
break;
}
my_error(ER_SP_DROP_FAILED, MYF(0),
"FUNCTION (UDF)", lex->spname->m_name.str);
goto error;
}
if (lex->spname->m_db.str == NULL)
{
if (lex->drop_if_exists)
{
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST),
"FUNCTION (UDF)", lex->spname->m_name.str);
res= FALSE;
my_ok(thd);
break;
}
my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
"FUNCTION (UDF)", lex->spname->m_name.str);
goto error;
}
/* Fall thought to test for a stored function */
}
#endif
int sp_result;
int type= (lex->sql_command == SQLCOM_DROP_PROCEDURE ?
TYPE_ENUM_PROCEDURE : TYPE_ENUM_FUNCTION);
......@@ -4178,34 +4219,6 @@ case SQLCOM_PREPARE:
}
#endif
}
else
{
#ifdef HAVE_DLOPEN
if (lex->sql_command == SQLCOM_DROP_FUNCTION)
{
udf_func *udf = find_udf(lex->spname->m_name.str,
lex->spname->m_name.length);
if (udf)
{
if (check_access(thd, DELETE_ACL, "mysql", NULL, NULL, 1, 0))
goto error;
if (!(res = mysql_drop_function(thd, &lex->spname->m_name)))
{
my_ok(thd);
break;
}
}
}
#endif
if (lex->spname->m_db.str)
sp_result= SP_KEY_NOT_FOUND;
else
{
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
goto error;
}
}
res= sp_result;
switch (sp_result) {
case SP_OK:
......@@ -4217,7 +4230,7 @@ case SQLCOM_PREPARE:
res= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST),
SP_COM_STRING(lex), lex->spname->m_name.str);
SP_COM_STRING(lex), lex->spname->m_qname.str);
if (!res)
my_ok(thd);
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment