1
by brian
clean slate |
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 |
INSERT INTO t1 VALUES(myfunc_int(100), myfunc_double(50.00));
|
|
59 |
INSERT INTO t1 VALUES(myfunc_int(10), myfunc_double(5.00));
|
|
60 |
INSERT INTO t1 VALUES(myfunc_int(200), myfunc_double(25.00));
|
|
61 |
INSERT INTO t1 VALUES(myfunc_int(1), myfunc_double(500.00));
|
|
62 |
SELECT * FROM t1 ORDER BY sum;
|
|
63 |
--disable_info
|
|
64 |
||
65 |
sync_slave_with_master;
|
|
66 |
||
67 |
# Check to see if data was replicated
|
|
68 |
--echo "Running on the slave" |
|
69 |
--enable_info
|
|
70 |
SELECT * FROM t1 ORDER BY sum;
|
|
71 |
||
72 |
# Check to see that the functions are available for execution on the slave
|
|
73 |
SELECT myfunc_int(25);
|
|
74 |
SELECT myfunc_double(75.00);
|
|
75 |
--disable_info
|
|
76 |
||
77 |
connection master;
|
|
78 |
||
79 |
# Drop the functions
|
|
80 |
--echo "Running on the master" |
|
81 |
--enable_info
|
|
82 |
DROP FUNCTION myfunc_double;
|
|
83 |
DROP FUNCTION myfunc_int;
|
|
84 |
SELECT * FROM mysql.func ORDER BY name;
|
|
85 |
--disable_info
|
|
86 |
||
87 |
sync_slave_with_master;
|
|
88 |
||
89 |
# Check to see if the UDFs were dropped on the slave
|
|
90 |
--echo "Running on the slave" |
|
91 |
--enable_info
|
|
92 |
SELECT * FROM mysql.func ORDER BY name;
|
|
93 |
--disable_info
|
|
94 |
||
95 |
connection master;
|
|
96 |
||
97 |
# Cleanup
|
|
98 |
--echo "Running on the master" |
|
99 |
--enable_info
|
|
100 |
DROP TABLE t1;
|
|
101 |
--disable_info
|
|
102 |
||
103 |
#
|
|
104 |
# Test 2) Test UDFs with SQL body
|
|
105 |
#
|
|
106 |
--echo "*** Test 2) Test UDFs with SQL body *** |
|
107 |
--echo "Running on the master" |
|
108 |
--enable_info |
|
109 |
CREATE FUNCTION myfuncsql_int(i INT) RETURNS INTEGER DETERMINISTIC RETURN i; |
|
110 |
CREATE FUNCTION myfuncsql_double(d DOUBLE) RETURNS INTEGER DETERMINISTIC RETURN d * 2.00; |
|
111 |
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name; |
|
112 |
--disable_info |
|
113 |
||
114 |
sync_slave_with_master; |
|
115 |
||
116 |
# Check to see that UDF CREATE statements were replicated |
|
117 |
--echo "Running on the slave" |
|
118 |
--enable_info |
|
119 |
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name; |
|
120 |
--disable_info |
|
121 |
||
122 |
connection master; |
|
123 |
||
124 |
# Use the UDFs to do something |
|
125 |
--echo "Running on the master" |
|
126 |
--enable_info |
|
127 |
eval CREATE TABLE t1(sum INT, price FLOAT(24)) ENGINE=$engine_type; |
|
128 |
INSERT INTO t1 VALUES(myfuncsql_int(100), myfuncsql_double(50.00)); |
|
129 |
INSERT INTO t1 VALUES(myfuncsql_int(10), myfuncsql_double(5.00)); |
|
130 |
INSERT INTO t1 VALUES(myfuncsql_int(200), myfuncsql_double(25.00)); |
|
131 |
INSERT INTO t1 VALUES(myfuncsql_int(1), myfuncsql_double(500.00)); |
|
132 |
SELECT * FROM t1 ORDER BY sum; |
|
133 |
--disable_info |
|
134 |
||
135 |
sync_slave_with_master; |
|
136 |
||
137 |
# Check to see if data was replicated |
|
138 |
--echo "Running on the slave" |
|
139 |
--enable_info |
|
140 |
SELECT * FROM t1 ORDER BY sum; |
|
141 |
--disable_info |
|
142 |
||
143 |
connection master; |
|
144 |
||
145 |
# Modify the UDFs to add a comment |
|
146 |
--echo "Running on the master" |
|
147 |
--enable_info |
|
148 |
ALTER FUNCTION myfuncsql_int COMMENT "This was altered."; |
|
149 |
ALTER FUNCTION myfuncsql_double COMMENT "This was altered."; |
|
150 |
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name; |
|
151 |
--disable_info |
|
152 |
||
153 |
sync_slave_with_master; |
|
154 |
||
155 |
# Check to see if data was replicated |
|
156 |
--echo "Running on the slave" |
|
157 |
--enable_info |
|
158 |
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name; |
|
159 |
||
160 |
# Check to see that the functions are available for execution on the slave |
|
161 |
SELECT myfuncsql_int(25); |
|
162 |
SELECT myfuncsql_double(75.00); |
|
163 |
--disable_info |
|
164 |
||
165 |
connection master; |
|
166 |
||
167 |
# Drop the functions |
|
168 |
--echo "Running on the master" |
|
169 |
--enable_info |
|
170 |
DROP FUNCTION myfuncsql_double; |
|
171 |
DROP FUNCTION myfuncsql_int; |
|
172 |
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name; |
|
173 |
--disable_info |
|
174 |
||
175 |
sync_slave_with_master; |
|
176 |
||
177 |
# Check to see if the UDFs were dropped on the slave |
|
178 |
--echo "Running on the slave" |
|
179 |
--enable_info |
|
180 |
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name; |
|
181 |
--disable_info |
|
182 |
||
183 |
connection master; |
|
184 |
||
185 |
# Cleanup |
|
186 |
--echo "Running on the master" |
|
187 |
--enable_info |
|
188 |
DROP TABLE t1; |
|
189 |
--disable_info |