MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rpl_udf.inc
1 #####################################################################
2 # Author: Chuck Bell #
3 # Date: 2006-12-21 #
4 # Purpose: To test that UDFs are replicated in both row based and #
5 # statement based format. This tests work completed in WL#3629. #
6 # #
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 #####################################################################
10 
11 --source include/have_udf.inc
12 
13 #
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
16 # the library are.
17 #
18 
19 connection master;
20 --disable_warnings
21 drop table if exists t1;
22 --enable_warnings
23 
24 #
25 # Test 1) Test UDFs via loadable libraries
26 #
27 --echo "*** Test 1) Test UDFs via loadable libraries ***
28 --echo "Running on the master"
29 --enable_info
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;
39 --disable_info
40 
41 save_master_pos;
42 connection slave;
43 sync_with_master;
44 
45 # Check to see that UDF CREATE statements were replicated
46 --echo "Running on the slave"
47 --enable_info
48 --replace_column 3 UDF_LIB
49 SELECT * FROM mysql.func ORDER BY name;
50 --disable_info
51 
52 connection master;
53 
54 # Use the UDFs to do something
55 --echo "Running on the master"
56 --enable_info
57 eval CREATE TABLE t1(sum INT, price FLOAT(24)) ENGINE=$engine_type;
58 --disable_warnings
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;
64 --enable_warnings
65 --disable_info
66 
67 sync_slave_with_master;
68 
69 # Check to see if data was replicated
70 --echo "Running on the slave"
71 --enable_info
72 SELECT * FROM t1 ORDER BY sum;
73 
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);
77 --disable_info
78 
79 connection master;
80 
81 # Drop the functions
82 --echo "Running on the master"
83 --enable_info
84 DROP FUNCTION myfunc_double;
85 DROP FUNCTION myfunc_int;
86 SELECT * FROM mysql.func ORDER BY name;
87 --disable_info
88 
89 sync_slave_with_master;
90 
91 # Check to see if the UDFs were dropped on the slave
92 --echo "Running on the slave"
93 --enable_info
94 SELECT * FROM mysql.func ORDER BY name;
95 --disable_info
96 
97 connection master;
98 
99 # Cleanup
100 --echo "Running on the master"
101 --enable_info
102 DROP TABLE t1;
103 --disable_info
104 
105 #
106 # Test 2) Test UDFs with SQL body
107 #
108 --echo "*** Test 2) Test UDFs with SQL body ***
109 --echo "Running on the master"
110 --enable_info
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;
114 --disable_info
115 
116 sync_slave_with_master;
117 
118 # Check to see that UDF CREATE statements were replicated
119 --echo "Running on the slave"
120 --enable_info
121 SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
122 --disable_info
123 
124 connection master;
125 
126 # Use the UDFs to do something
127 --echo "Running on the master"
128 --enable_info
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;
135 --disable_info
136 
137 sync_slave_with_master;
138 
139 # Check to see if data was replicated
140 --echo "Running on the slave"
141 --enable_info
142 SELECT * FROM t1 ORDER BY sum;
143 --disable_info
144 
145 connection master;
146 
147 # Modify the UDFs to add a comment
148 --echo "Running on the master"
149 --enable_info
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;
153 --disable_info
154 
155 sync_slave_with_master;
156 
157 # Check to see if data was replicated
158 --echo "Running on the slave"
159 --enable_info
160 SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
161 
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);
165 --disable_info
166 
167 connection master;
168 
169 # Drop the functions
170 --echo "Running on the master"
171 --enable_info
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;
175 --disable_info
176 
177 sync_slave_with_master;
178 
179 # Check to see if the UDFs were dropped on the slave
180 --echo "Running on the slave"
181 --enable_info
182 SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
183 --disable_info
184 
185 connection master;
186 
187 # Cleanup
188 --echo "Running on the master"
189 --enable_info
190 DROP TABLE t1;
191 --disable_info