1 #####################################################################
4 # Purpose: To test that UDFs are replicated in both row based and #
5 # statement based format. This tests work completed in WL#3629. #
7 # This test is designed to exercise two of the three types of UDFs: #
8 # 1) UDFs via loadable libraries, and 2) UDFs with a SQL body. #
9 #####################################################################
11 --source include/have_udf.inc
14 # To run this tests the "sql/udf_example.c" need to be compiled into
15 # udf_example.so and LD_LIBRARY_PATH should be setup to point out where
21 drop
table if exists t1;
25 # Test 1) Test UDFs via loadable libraries
27 --echo
"*** Test 1) Test UDFs via loadable libraries ***
28 --echo "Running on the master
"
30 --replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
31 eval CREATE FUNCTION myfunc_double RETURNS REAL SONAME "$UDF_EXAMPLE_LIB
";
32 --replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
33 eval CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB
";
34 --replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
35 --error ER_CANT_FIND_DL_ENTRY
36 eval CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB
";
37 --replace_column 3 UDF_LIB
38 SELECT * FROM mysql.func ORDER BY name;
45 # Check to see that UDF CREATE statements were replicated
46 --echo "Running on the slave
"
48 --replace_column 3 UDF_LIB
49 SELECT * FROM mysql.func ORDER BY name;
54 # Use the UDFs to do something
55 --echo "Running on the master
"
57 eval CREATE TABLE t1(sum INT, price FLOAT(24)) ENGINE=$engine_type;
59 INSERT INTO t1 VALUES(myfunc_int(100), myfunc_double(50.00));
60 INSERT INTO t1 VALUES(myfunc_int(10), myfunc_double(5.00));
61 INSERT INTO t1 VALUES(myfunc_int(200), myfunc_double(25.00));
62 INSERT INTO t1 VALUES(myfunc_int(1), myfunc_double(500.00));
63 SELECT * FROM t1 ORDER BY sum;
67 sync_slave_with_master;
69 # Check to see if data was replicated
70 --echo "Running on the slave
"
72 SELECT * FROM t1 ORDER BY sum;
74 # Check to see that the functions are available for execution on the slave
75 SELECT myfunc_int(25);
76 SELECT myfunc_double(75.00);
82 --echo "Running on the master
"
84 DROP FUNCTION myfunc_double;
85 DROP FUNCTION myfunc_int;
86 SELECT * FROM mysql.func ORDER BY name;
89 sync_slave_with_master;
91 # Check to see if the UDFs were dropped on the slave
92 --echo "Running on the slave
"
94 SELECT * FROM mysql.func ORDER BY name;
100 --echo "Running on the master
"
106 # Test 2) Test UDFs with SQL body
108 --echo "***
Test 2)
Test UDFs with SQL body ***
109 --echo
"Running on the master"
111 CREATE FUNCTION myfuncsql_int(
i INT) RETURNS INTEGER DETERMINISTIC RETURN
i;
112 CREATE FUNCTION myfuncsql_double(d DOUBLE) RETURNS INTEGER DETERMINISTIC RETURN d * 2.00;
113 SELECT db,
name,
type, param_list, body, comment FROM mysql.proc WHERE db =
'test' AND name LIKE
'myfuncsql%' ORDER BY
name;
116 sync_slave_with_master;
118 # Check to see that UDF CREATE statements were replicated
119 --echo
"Running on the slave"
121 SELECT db,
name,
type, param_list, body, comment FROM mysql.proc WHERE db =
'test' AND name LIKE
'myfuncsql%' ORDER BY
name;
126 # Use the UDFs to do something
127 --echo
"Running on the master"
129 eval CREATE
TABLE t1(sum INT, price FLOAT(24)) ENGINE=$engine_type;
130 INSERT INTO t1 VALUES(myfuncsql_int(100), myfuncsql_double(50.00));
131 INSERT INTO t1 VALUES(myfuncsql_int(10), myfuncsql_double(5.00));
132 INSERT INTO t1 VALUES(myfuncsql_int(200), myfuncsql_double(25.00));
133 INSERT INTO t1 VALUES(myfuncsql_int(1), myfuncsql_double(500.00));
134 SELECT * FROM t1
ORDER BY sum;
137 sync_slave_with_master;
139 # Check to see if data was replicated
140 --echo
"Running on the slave"
142 SELECT * FROM t1
ORDER BY sum;
147 # Modify the UDFs to add a comment
148 --echo
"Running on the master"
150 ALTER FUNCTION myfuncsql_int COMMENT
"This was altered.";
151 ALTER FUNCTION myfuncsql_double COMMENT
"This was altered.";
152 SELECT db,
name,
type, param_list, body, comment FROM mysql.proc WHERE db =
'test' AND name LIKE
'myfuncsql%' ORDER BY
name;
155 sync_slave_with_master;
157 # Check to see if data was replicated
158 --echo
"Running on the slave"
160 SELECT db,
name,
type, param_list, body, comment FROM mysql.proc WHERE db =
'test' AND name LIKE
'myfuncsql%' ORDER BY
name;
162 # Check to see that the functions are available for execution on the slave
163 SELECT myfuncsql_int(25);
164 SELECT myfuncsql_double(75.00);
170 --echo
"Running on the master"
172 DROP FUNCTION myfuncsql_double;
173 DROP FUNCTION myfuncsql_int;
174 SELECT db,
name,
type, param_list, body, comment FROM mysql.proc WHERE db =
'test' AND name LIKE
'myfuncsql%' ORDER BY
name;
177 sync_slave_with_master;
179 # Check to see if the UDFs were dropped on the slave
180 --echo
"Running on the slave"
182 SELECT db,
name,
type, param_list, body, comment FROM mysql.proc WHERE db =
'test' AND name LIKE
'myfuncsql%' ORDER BY
name;
188 --echo
"Running on the master"