~ubuntu-branches/ubuntu/precise/mysql-5.5/precise-201203300109

« back to all changes in this revision

Viewing changes to mysql-test/r/udf.result

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-11-08 11:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20111108113113-3ulw01fvi4vn8m25
Tags: upstream-5.5.17
ImportĀ upstreamĀ versionĀ 5.5.17

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
drop table if exists t1;
 
2
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
3
CREATE FUNCTION myfunc_double RETURNS REAL SONAME "UDF_EXAMPLE_LIB";
 
4
CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
 
5
ERROR HY000: Can't find symbol 'myfunc_nonexist' in library
 
6
CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
 
7
CREATE FUNCTION sequence RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
 
8
CREATE FUNCTION lookup RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
9
CREATE FUNCTION reverse_lookup
 
10
RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
11
CREATE AGGREGATE FUNCTION avgcost
 
12
RETURNS REAL SONAME "UDF_EXAMPLE_LIB";
 
13
select myfunc_double();
 
14
ERROR HY000: Can't initialize function 'myfunc_double'; myfunc_double must have at least one argument
 
15
select myfunc_double(1);
 
16
myfunc_double(1)
 
17
49.00
 
18
select myfunc_double(78654);
 
19
myfunc_double(78654)
 
20
54.00
 
21
select myfunc_nonexist();
 
22
ERROR 42000: FUNCTION test.myfunc_nonexist does not exist
 
23
select myfunc_int();
 
24
myfunc_int()
 
25
0
 
26
select lookup();
 
27
ERROR HY000: Can't initialize function 'lookup'; Wrong arguments to lookup;  Use the source
 
28
select lookup("127.0.0.1");
 
29
lookup("127.0.0.1")
 
30
127.0.0.1
 
31
select lookup(127,0,0,1);
 
32
ERROR HY000: Can't initialize function 'lookup'; Wrong arguments to lookup;  Use the source
 
33
select lookup("localhost");
 
34
lookup("localhost")
 
35
127.0.0.1
 
36
select reverse_lookup();
 
37
ERROR HY000: Can't initialize function 'reverse_lookup'; Wrong number of arguments to reverse_lookup;  Use the source
 
38
select reverse_lookup("127.0.0.1");
 
39
select reverse_lookup(127,0,0,1);
 
40
select reverse_lookup("localhost");
 
41
select avgcost();
 
42
ERROR HY000: Can't initialize function 'avgcost'; wrong number of arguments: AVGCOST() requires two arguments
 
43
select avgcost(100,23.76);
 
44
ERROR HY000: Can't initialize function 'avgcost'; wrong argument type: AVGCOST() requires an INT and a REAL
 
45
create table t1(sum int, price float(24));
 
46
insert into t1 values(100, 50.00), (100, 100.00);
 
47
select avgcost(sum, price) from t1;
 
48
avgcost(sum, price)
 
49
75.0000
 
50
delete from t1;
 
51
insert into t1 values(100, 54.33), (200, 199.99);
 
52
select avgcost(sum, price) from t1;
 
53
avgcost(sum, price)
 
54
151.4367
 
55
drop table t1;
 
56
select metaphon('hello');
 
57
metaphon('hello')
 
58
HL
 
59
CREATE PROCEDURE `XXX1`(in testval varchar(10))
 
60
begin
 
61
select metaphon(testval);
 
62
end//
 
63
call XXX1('hello');
 
64
metaphon(testval)
 
65
HL
 
66
drop procedure xxx1;
 
67
CREATE PROCEDURE `XXX2`()
 
68
begin
 
69
declare testval varchar(10);
 
70
set testval = 'hello';
 
71
select metaphon(testval);
 
72
end//
 
73
call XXX2();
 
74
metaphon(testval)
 
75
HL
 
76
drop procedure xxx2;
 
77
CREATE TABLE bug19904(n INT, v varchar(10));
 
78
INSERT INTO bug19904 VALUES (1,'one'),(2,'two'),(NULL,NULL),(3,'three'),(4,'four');
 
79
SELECT myfunc_double(n) AS f FROM bug19904;
 
80
f
 
81
49.00
 
82
50.00
 
83
NULL
 
84
51.00
 
85
52.00
 
86
SELECT metaphon(v) AS f FROM bug19904;
 
87
f
 
88
ON
 
89
TW
 
90
NULL
 
91
0R
 
92
FR
 
93
DROP TABLE bug19904;
 
94
CREATE DEFINER=CURRENT_USER() FUNCTION should_not_parse
 
95
RETURNS STRING SONAME "should_not_parse.so";
 
96
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'RETURNS STRING SONAME "should_not_parse.so"' at line 2
 
97
CREATE DEFINER=someone@somewhere FUNCTION should_not_parse
 
98
RETURNS STRING SONAME "should_not_parse.so";
 
99
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'RETURNS STRING SONAME "should_not_parse.so"' at line 2
 
100
create table t1(f1 int);
 
101
insert into t1 values(1),(2);
 
102
explain select myfunc_int(f1) from t1 order by 1;
 
103
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
104
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2       Using temporary; Using filesort
 
105
drop table t1;
 
106
CREATE TABLE t1(a INT, b INT);
 
107
INSERT INTO t1 values (1,1),(2,2);
 
108
CREATE FUNCTION fn(a int) RETURNS int DETERMINISTIC
 
109
BEGIN
 
110
RETURN a;
 
111
END
 
112
||
 
113
CREATE VIEW v1 AS SELECT a, fn(MIN(b)) as c FROM t1 GROUP BY a;
 
114
SELECT myfunc_int(a AS attr_name) FROM t1;
 
115
myfunc_int(a AS attr_name)
 
116
1
 
117
2
 
118
EXPLAIN EXTENDED SELECT myfunc_int(a AS attr_name) FROM t1;
 
119
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
120
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2       100.00  
 
121
Warnings:
 
122
Note    1003    select myfunc_int(`test`.`t1`.`a` AS `attr_name`) AS `myfunc_int(a AS attr_name)` from `test`.`t1`
 
123
EXPLAIN EXTENDED SELECT myfunc_int(a) FROM t1;
 
124
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
125
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2       100.00  
 
126
Warnings:
 
127
Note    1003    select myfunc_int(`test`.`t1`.`a` AS `a`) AS `myfunc_int(a)` from `test`.`t1`
 
128
SELECT a,c FROM v1;
 
129
a       c
 
130
1       1
 
131
2       2
 
132
SELECT a, fn(MIN(b) xx) as c FROM t1 GROUP BY a;
 
133
ERROR 42000: Incorrect parameters in the call to stored function 'fn'
 
134
SELECT myfunc_int(fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
 
135
ERROR 42000: Incorrect parameters in the call to stored function 'fn'
 
136
SELECT myfunc_int(test.fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
 
137
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xx)) as c FROM t1 GROUP BY a' at line 1
 
138
SELECT myfunc_int(fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
 
139
c
 
140
1
 
141
2
 
142
SELECT myfunc_int(test.fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
 
143
c
 
144
1
 
145
2
 
146
EXPLAIN EXTENDED SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
 
147
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
148
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using temporary; Using filesort
 
149
Warnings:
 
150
Note    1003    select myfunc_int(min(`test`.`t1`.`b`) AS `xx`) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
 
151
EXPLAIN EXTENDED SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
 
152
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
153
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using temporary; Using filesort
 
154
Warnings:
 
155
Note    1003    select `test`.`fn`(min(`test`.`t1`.`b`)) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
 
156
EXPLAIN EXTENDED SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
 
157
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
158
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using temporary; Using filesort
 
159
Warnings:
 
160
Note    1003    select myfunc_int(`fn`(min(`test`.`t1`.`b`)) AS `fn(MIN(b))`) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
 
161
EXPLAIN EXTENDED SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
 
162
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
163
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using temporary; Using filesort
 
164
Warnings:
 
165
Note    1003    select myfunc_int(`test`.`fn`(min(`test`.`t1`.`b`)) AS `test.fn(MIN(b))`) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
 
166
SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
 
167
c
 
168
1
 
169
2
 
170
SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
 
171
c
 
172
1
 
173
2
 
174
SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
 
175
c
 
176
1
 
177
2
 
178
SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
 
179
c
 
180
1
 
181
2
 
182
DROP VIEW v1;
 
183
DROP TABLE t1;
 
184
DROP FUNCTION fn;
 
185
End of 5.0 tests.
 
186
select myfunc_double(3);
 
187
myfunc_double(3)
 
188
51.00
 
189
select myfunc_double(3 AS three);
 
190
myfunc_double(3 AS three)
 
191
51.00
 
192
select myfunc_double(abs(3));
 
193
myfunc_double(abs(3))
 
194
51.00
 
195
select myfunc_double(abs(3) AS named_param);
 
196
myfunc_double(abs(3) AS named_param)
 
197
51.00
 
198
select abs(myfunc_double(3));
 
199
abs(myfunc_double(3))
 
200
51.00
 
201
select abs(myfunc_double(3 AS three));
 
202
abs(myfunc_double(3 AS three))
 
203
51.00
 
204
select myfunc_double(abs(3 AS wrong));
 
205
ERROR 42000: Incorrect parameters in the call to native function 'abs'
 
206
select abs(myfunc_double(3) AS wrong);
 
207
ERROR 42000: Incorrect parameters in the call to native function 'abs'
 
208
drop function if exists pi;
 
209
CREATE FUNCTION pi RETURNS STRING SONAME "should_not_parse.so";
 
210
ERROR HY000: This function 'pi' has the same name as a native function
 
211
DROP FUNCTION IF EXISTS metaphon;
 
212
CREATE FUNCTION metaphon(a int) RETURNS int
 
213
return 0;
 
214
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
215
DROP FUNCTION metaphon;
 
216
DROP FUNCTION metaphon;
 
217
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
218
CREATE FUNCTION metaphon(a int) RETURNS int
 
219
return 0;
 
220
ERROR HY000: Function 'metaphon' already exists
 
221
CREATE FUNCTION test.metaphon(a int) RETURNS int
 
222
return 0;
 
223
ERROR HY000: Function 'metaphon' already exists
 
224
DROP FUNCTION metaphon;
 
225
DROP FUNCTION myfunc_double;
 
226
DROP FUNCTION myfunc_nonexist;
 
227
ERROR 42000: FUNCTION test.myfunc_nonexist does not exist
 
228
DROP FUNCTION myfunc_int;
 
229
DROP FUNCTION sequence;
 
230
DROP FUNCTION lookup;
 
231
DROP FUNCTION reverse_lookup;
 
232
DROP FUNCTION avgcost;
 
233
select * from mysql.func;
 
234
name    ret     dl      type
 
235
CREATE FUNCTION is_const RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
236
select IS_const(3);
 
237
IS_const(3)
 
238
const
 
239
drop function IS_const;
 
240
select * from mysql.func;
 
241
name    ret     dl      type
 
242
select is_const(3);
 
243
ERROR 42000: FUNCTION test.is_const does not exist
 
244
CREATE FUNCTION is_const RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
245
select
 
246
is_const(3) as const,
 
247
is_const(3.14) as const,
 
248
is_const('fnord') as const,
 
249
is_const(2+3) as const,
 
250
is_const(rand()) as 'nc rand()',
 
251
is_const(sin(3.14)) as const,
 
252
is_const(upper('test')) as const;
 
253
const   const   const   const   nc rand()       const   const
 
254
const   const   const   const   not const       const   const
 
255
create table bug18761 (n int);
 
256
insert into bug18761 values (null),(2);
 
257
select
 
258
is_const(3) as const,
 
259
is_const(3.14) as const,
 
260
is_const('fnord') as const,
 
261
is_const(2+3) as const,
 
262
is_const(2+n) as 'nc  2+n  ',
 
263
is_const(sin(n)) as 'nc sin(n)',
 
264
is_const(sin(3.14)) as const,
 
265
is_const(upper('test')) as const,
 
266
is_const(rand()) as 'nc rand()',
 
267
is_const(n) as 'nc   n   ',
 
268
is_const(is_const(n)) as 'nc ic?(n)',
 
269
is_const(is_const('c')) as const
 
270
from
 
271
bug18761;
 
272
const   const   const   const   nc  2+n         nc sin(n)       const   const   nc rand()       nc   n          nc ic?(n)       const
 
273
const   const   const   const   not const       not const       const   const   not const       not const       not const       const
 
274
const   const   const   const   not const       not const       const   const   not const       not const       not const       const
 
275
drop table bug18761;
 
276
select is_const((1,2,3));
 
277
ERROR 21000: Operand should contain 1 column(s)
 
278
drop function if exists is_const;
 
279
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
280
CREATE FUNCTION myfunc_double RETURNS REAL SONAME "UDF_EXAMPLE_LIB";
 
281
CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
 
282
create function f1(p1 varchar(255))
 
283
returns varchar(255)
 
284
begin
 
285
return metaphon(p1);
 
286
end//
 
287
create function f2(p1 varchar(255))
 
288
returns double
 
289
begin
 
290
return myfunc_double(p1);
 
291
end//
 
292
create function f3(p1 varchar(255))
 
293
returns double
 
294
begin
 
295
return myfunc_int(p1);
 
296
end//
 
297
select f3(NULL);
 
298
f3(NULL)
 
299
0
 
300
select f2(NULL);
 
301
f2(NULL)
 
302
NULL
 
303
select f1(NULL);
 
304
f1(NULL)
 
305
NULL
 
306
drop function f1;
 
307
drop function f2;
 
308
drop function f3;
 
309
drop function metaphon;
 
310
drop function myfunc_double;
 
311
drop function myfunc_int;
 
312
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
313
create table t1 (a char);
 
314
set GLOBAL query_cache_size=1355776;
 
315
reset query cache;
 
316
select metaphon('MySQL') from t1;
 
317
metaphon('MySQL')
 
318
show status like "Qcache_hits";
 
319
Variable_name   Value
 
320
Qcache_hits     0
 
321
show status like "Qcache_queries_in_cache";
 
322
Variable_name   Value
 
323
Qcache_queries_in_cache 0
 
324
select metaphon('MySQL') from t1;
 
325
metaphon('MySQL')
 
326
show status like "Qcache_hits";
 
327
Variable_name   Value
 
328
Qcache_hits     0
 
329
show status like "Qcache_queries_in_cache";
 
330
Variable_name   Value
 
331
Qcache_queries_in_cache 0
 
332
drop table t1;
 
333
drop function metaphon;
 
334
set GLOBAL query_cache_size=default;
 
335
DROP DATABASE IF EXISTS mysqltest;
 
336
CREATE DATABASE mysqltest;
 
337
USE mysqltest;
 
338
DROP DATABASE mysqltest;
 
339
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
340
DROP FUNCTION metaphon;
 
341
USE test;
 
342
CREATE TABLE const_len_bug (
 
343
str_const varchar(4000),
 
344
result1 varchar(4000),
 
345
result2 varchar(4000)
 
346
);
 
347
CREATE TRIGGER check_const_len_trigger BEFORE INSERT ON const_len_bug FOR EACH ROW BEGIN
 
348
set NEW.str_const = 'bar';
 
349
set NEW.result2 = check_const_len(NEW.str_const);
 
350
END |
 
351
CREATE PROCEDURE check_const_len_sp (IN str_const VARCHAR(4000))
 
352
BEGIN
 
353
DECLARE result VARCHAR(4000);
 
354
SET result = check_const_len(str_const);
 
355
insert into const_len_bug values(str_const, result, "");
 
356
END |
 
357
CREATE FUNCTION check_const_len RETURNS string SONAME "UDF_EXAMPLE_LIB";
 
358
CALL check_const_len_sp("foo");
 
359
SELECT * from const_len_bug;
 
360
str_const       result1 result2
 
361
bar     Correct length  Correct length
 
362
DROP FUNCTION check_const_len;
 
363
DROP PROCEDURE check_const_len_sp;
 
364
DROP TRIGGER check_const_len_trigger;
 
365
DROP TABLE const_len_bug;
 
366
CREATE FUNCTION sequence RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
 
367
CREATE TABLE t1 (a INT);
 
368
CREATE TABLE t2 (a INT PRIMARY KEY);
 
369
INSERT INTO t1 VALUES (4),(3),(2),(1);
 
370
INSERT INTO t2 SELECT * FROM t1;
 
371
SELECT sequence() AS seq, a FROM t1 ORDER BY seq ASC;
 
372
seq     a
 
373
1       4
 
374
2       3
 
375
3       2
 
376
4       1
 
377
SELECT sequence() AS seq, a FROM t1 ORDER BY seq DESC;
 
378
seq     a
 
379
4       1
 
380
3       2
 
381
2       3
 
382
1       4
 
383
SELECT * FROM t1 WHERE a = sequence();
 
384
a
 
385
SELECT * FROM t2 WHERE a = sequence();
 
386
a
 
387
1
 
388
2
 
389
3
 
390
4
 
391
DROP FUNCTION sequence;
 
392
DROP TABLE t1,t2;
 
393
drop function if exists test.metaphon;
 
394
drop function if exists metaphon;
 
395
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
396
select metaphon("Hello");
 
397
metaphon("Hello")
 
398
HL
 
399
drop function if exists test.metaphon;
 
400
Warnings:
 
401
Note    1305    FUNCTION test.metaphon does not exist
 
402
select metaphon("Hello");
 
403
metaphon("Hello")
 
404
HL
 
405
drop function metaphon;
 
406
CREATE FUNCTION test.metaphon(a TEXT) RETURNS TEXT return "This is a SF";
 
407
create database db_31767;
 
408
use db_31767;
 
409
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 
410
use test;
 
411
select metaphon("Hello");
 
412
metaphon("Hello")
 
413
HL
 
414
select test.metaphon("Hello");
 
415
test.metaphon("Hello")
 
416
This is a SF
 
417
drop function metaphon;
 
418
select metaphon("Hello");
 
419
metaphon("Hello")
 
420
This is a SF
 
421
drop function metaphon;
 
422
use db_31767;
 
423
drop database db_31767;
 
424
drop function if exists no_such_func;
 
425
Warnings:
 
426
Note    1305    FUNCTION (UDF) no_such_func does not exist
 
427
drop function no_such_func;
 
428
ERROR 42000: FUNCTION (UDF) no_such_func does not exist
 
429
drop function if exists test.no_such_func;
 
430
Warnings:
 
431
Note    1305    FUNCTION test.no_such_func does not exist
 
432
drop function test.no_such_func;
 
433
ERROR 42000: FUNCTION test.no_such_func does not exist
 
434
drop procedure if exists no_such_proc;
 
435
ERROR 3D000: No database selected
 
436
drop procedure no_such_proc;
 
437
ERROR 3D000: No database selected
 
438
use test;
 
439
#
 
440
# Bug#46259: 5.0.83 -> 5.1.36, query doesn't work
 
441
#
 
442
CREATE TABLE t1 ( a INT );
 
443
INSERT INTO t1 VALUES (1), (2), (3);
 
444
SELECT IF( a = 1, a, a ) AS `b` FROM t1 ORDER BY field( `b` + 1, 1 );
 
445
b
 
446
1
 
447
2
 
448
3
 
449
SELECT IF( a = 1, a, a ) AS `b` FROM t1 ORDER BY field( `b`, 1 );
 
450
b
 
451
2
 
452
3
 
453
1
 
454
DROP TABLE t1;
 
455
End of 5.0 tests.
 
456
#
 
457
# Bug#33546: Slowdown on re-evaluation of constant expressions.
 
458
#
 
459
CREATE TABLE t1 (f1 INT);
 
460
INSERT INTO t1 VALUES(1),(50);
 
461
CREATE FUNCTION myfunc_double RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
 
462
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE f1=1 + myfunc_double(1);
 
463
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
464
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
465
Warnings:
 
466
Note    1003    select 1 AS `1` from `test`.`t1` where (`test`.`t1`.`f1` = <cache>((1 + myfunc_double(1 AS `1`))))
 
467
DROP FUNCTION myfunc_double;
 
468
DROP TABLE t1;
 
469
#
 
470
End of 5.1 tests.