summaryrefslogtreecommitdiff
path: root/mysql-test/suite/perfschema/r/statement_program_non_nested.result
blob: 16e47b52927d9860e07446b9fab5c78cd931429d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
TRUNCATE TABLE performance_schema.events_statements_summary_by_program;
TRUNCATE TABLE performance_schema.events_statements_history_long;
################################################
# Quering PS statement summary and history_long#
################################################ 
# SET-UP 
CREATE DATABASE stored_programs;
USE stored_programs;
CREATE TABLE t1(
i INT NOT NULL,
j INT
);
CREATE TABLE t2(
name   CHAR(16) NOT NULL DEFAULT '',
id INT NOT NULL
);
CREATE TABLE t3(
d DATE,
n INT,
f DOUBLE,
s VARCHAR(32)
);
CREATE TABLE t4(
`k` int(10) unsigned NOT NULL AUTO_INCREMENT,
`word` varchar(100) NOT NULL,
`mean` varchar(300) NOT NULL,
PRIMARY KEY (`k`)
);
############################
# Creating Stored Programs #
############################
# Stored Routine ( Procedure & Function )
CREATE PROCEDURE SampleProc1(x1 INT, x2 INT, y INT)
BEGIN
INSERT INTO t1 VALUES (x1, y);
INSERT INTO t1 VALUES (x2, y);
END|
CREATE PROCEDURE SampleProc2(x CHAR(16), y INT)
BEGIN
DECLARE z1, z2 INT;
SET z1 = y;
SET z2 = z1+2;
INSERT INTO t2 VALUES (x, z2);
END|
CREATE PROCEDURE SampleProc3()
BEGIN
DECLARE ld DATE;
DECLARE li INT;
DECLARE lf DOUBLE;
DECLARE ls VARCHAR(32);
SET ld = NULL, li = NULL, lf = NULL, ls = NULL;
INSERT INTO t3 VALUES (ld, li, lf, ls);
INSERT INTO t3 (n, f, s) VALUES ((ld IS NULL), 1,    "ld is null"),
((li IS NULL), 1,    "li is null"),
((li = 0),     NULL, "li = 0"),
((lf IS NULL), 1,    "lf is null"),
((lf = 0),     NULL, "lf = 0"),
((ls IS NULL), 1,    "ls is null");
END|
CREATE PROCEDURE SampleProc4()
BEGIN
DECLARE x  INT;
SET x = 1;
WHILE x  <= 2 DO
INSERT INTO t4(word, mean) VALUES('a','a mean');
SET  x = x + 1;
END WHILE;
END|
CREATE FUNCTION append(s1 CHAR(8), s2 CHAR(8)) RETURNS CHAR(16)
RETURN concat(s1, s2)|
CREATE FUNCTION wt_avg(n1 INT, n2 INT, n3 INT, n4 INT)
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE avg INT;
SET avg = (n1+n2+n3*2+n4*4)/8;
RETURN avg;
END|
CREATE FUNCTION fac(n INT UNSIGNED) RETURNS BIGINT UNSIGNED
BEGIN
DECLARE f BIGINT UNSIGNED DEFAULT 1;
WHILE n > 1 DO
SET f = f * n;
SET n = n - 1;
END WHILE;
RETURN f;
END|
# Triggers
CREATE TRIGGER trg1 BEFORE INSERT ON t1 FOR EACH ROW
BEGIN
if isnull(new.j) then
SET new.j:= new.i * 10;
END if;
END|
CREATE TRIGGER trg2 AFTER INSERT ON t2 FOR EACH ROW
BEGIN
UPDATE t1 SET i=new.id+i ;
END|
CREATE TRIGGER trg3 AFTER UPDATE ON t2 FOR EACH ROW
SET @change:= @change + new.id - old.id|
CREATE TRIGGER trg4 BEFORE DELETE ON t1 FOR EACH ROW
SET @del:= @del + 1|
CREATE TRIGGER trg5 AFTER DELETE ON t1 FOR EACH ROW 
SET @del:= @del + 8 + old.j|
#####################
# Executing queries #
#####################
INSERT INTO t1 VALUES (10,20);
CALL SampleProc1(30,40,50);
SET @a=1;
SELECT @a;
@a
1
CALL SampleProc2("Jwalamukhi",34);
SELECT @a;
@a
1
CALL SampleProc3();
CALL SampleProc4();
SET @change=1;
SELECT @change;
@change
1
UPDATE t2 SET id=22 WHERE name="Jwalamukhi";
SELECT @change;
@change
-13
SET @del=1;
SELECT @del;
@del
1
DELETE FROM t1 WHERE i=76;
SELECT @del;
@del
60
SELECT wt_avg(1, 12, 1990, 1121990);
wt_avg(1, 12, 1990, 1121990)
561494
SELECT fac(5);
fac(5)
120
SELECT append("Bolly", "wood");
append("Bolly", "wood")
Bollywood
# Event
SET GLOBAL event_scheduler=ON;
CREATE TABLE table_t(a INT);
CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND DO
BEGIN
INSERT INTO table_t VALUES(1);
END|
SELECT * FROM table_t;
a
1
SET GLOBAL event_scheduler=OFF;
SELECT OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, COUNT_STAR, COUNT_STATEMENTS 
FROM performance_schema.events_statements_summary_by_program
WHERE OBJECT_SCHEMA='stored_programs' ORDER BY OBJECT_NAME;
OBJECT_TYPE	OBJECT_SCHEMA	OBJECT_NAME	COUNT_STAR	COUNT_STATEMENTS
FUNCTION	stored_programs	append	1	1
EVENT	stored_programs	e1	1	1
FUNCTION	stored_programs	fac	1	19
PROCEDURE	stored_programs	sampleproc1	1	2
PROCEDURE	stored_programs	sampleproc2	1	5
PROCEDURE	stored_programs	sampleproc3	1	10
PROCEDURE	stored_programs	sampleproc4	1	11
TRIGGER	stored_programs	trg1	3	3
TRIGGER	stored_programs	trg2	1	1
TRIGGER	stored_programs	trg3	1	1
TRIGGER	stored_programs	trg4	1	1
TRIGGER	stored_programs	trg5	1	1
FUNCTION	stored_programs	wt_avg	1	3
SELECT EVENT_NAME, SQL_TEXT, CURRENT_SCHEMA, OBJECT_TYPE, OBJECT_SCHEMA,
OBJECT_NAME, NESTING_EVENT_TYPE, NESTING_EVENT_LEVEL FROM
performance_schema.events_statements_history_long WHERE
CURRENT_SCHEMA='stored_programs' AND 
(SQL_TEXT not like '%count(*) = 1%' OR SQL_TEXT IS NULL)
ORDER BY OBJECT_NAME, NESTING_EVENT_LEVEL, SQL_TEXT;
EVENT_NAME	SQL_TEXT	CURRENT_SCHEMA	OBJECT_TYPE	OBJECT_SCHEMA	OBJECT_NAME	NESTING_EVENT_TYPE	NESTING_EVENT_LEVEL
statement/scheduler/event	NULL	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/call_procedure	CALL SampleProc1(30,40,50)	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/call_procedure	CALL SampleProc2("Jwalamukhi",34)	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/call_procedure	CALL SampleProc3()	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/call_procedure	CALL SampleProc4()	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_event	CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND DO
BEGIN
INSERT INTO table_t VALUES(1);
END	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_function	CREATE FUNCTION append(s1 CHAR(8), s2 CHAR(8)) RETURNS CHAR(16)
RETURN concat(s1, s2)	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_function	CREATE FUNCTION fac(n INT UNSIGNED) RETURNS BIGINT UNSIGNED
BEGIN
DECLARE f BIGINT UNSIGNED DEFAULT 1;
WHILE n > 1 DO
SET f = f * n;
SET n = n - 1;
END WHILE;
RETURN f;
END	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_function	CREATE FUNCTION wt_avg(n1 INT, n2 INT, n3 INT, n4 INT)
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE avg INT;
SET avg = (n1+n2+n3*2+n4*4)/8;
RETURN avg;
END	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_procedure	CREATE PROCEDURE SampleProc1(x1 INT, x2 INT, y INT)
BEGIN
INSERT INTO t1 VALUES (x1, y);
INSERT INTO t1 VALUES (x2, y);
END	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_procedure	CREATE PROCEDURE SampleProc2(x CHAR(16), y INT)
BEGIN
DECLARE z1, z2 INT;
SET z1 = y;
SET z2 = z1+2;
INSERT INTO t2 VALUES (x, z2);
END	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_procedure	CREATE PROCEDURE SampleProc3()
BEGIN
DECLARE ld DATE;
DECLARE li INT;
DECLARE lf DOUBLE;
DECLARE ls VARCHAR(32);
SET ld = NULL, li = NULL, lf = NULL, ls = NULL;
INSERT INTO t3 VALUES (ld, li, lf, ls);
INSERT INTO t3 (n, f, s) VALUES ((ld IS NULL), 1,    "ld is null"),
((li IS NULL), 1,    "li is null"),
((li = 0),     NULL, "li = 0"),
((lf IS NULL), 1,    "lf is null"),
((lf = 0),     NULL, "lf = 0"),
((ls IS NULL), 1,    "ls is null");
END	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_procedure	CREATE PROCEDURE SampleProc4()
BEGIN
DECLARE x  INT;
SET x = 1;
WHILE x  <= 2 DO
INSERT INTO t4(word, mean) VALUES('a','a mean');
SET  x = x + 1;
END WHILE;
END	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_table	CREATE TABLE t1(
i INT NOT NULL,
j INT
)	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_table	CREATE TABLE t2(
name   CHAR(16) NOT NULL DEFAULT '',
id INT NOT NULL
)	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_table	CREATE TABLE t3(
d DATE,
n INT,
f DOUBLE,
s VARCHAR(32)
)	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_table	CREATE TABLE t4(
`k` int(10) unsigned NOT NULL AUTO_INCREMENT,
`word` varchar(100) NOT NULL,
`mean` varchar(300) NOT NULL,
PRIMARY KEY (`k`)
)	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_table	CREATE TABLE table_t(a INT)	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_trigger	CREATE TRIGGER trg1 BEFORE INSERT ON t1 FOR EACH ROW
BEGIN
if isnull(new.j) then
SET new.j:= new.i * 10;
END if;
END	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_trigger	CREATE TRIGGER trg2 AFTER INSERT ON t2 FOR EACH ROW
BEGIN
UPDATE t1 SET i=new.id+i ;
END	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_trigger	CREATE TRIGGER trg3 AFTER UPDATE ON t2 FOR EACH ROW
SET @change:= @change + new.id - old.id	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_trigger	CREATE TRIGGER trg4 BEFORE DELETE ON t1 FOR EACH ROW
SET @del:= @del + 1	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/create_trigger	CREATE TRIGGER trg5 AFTER DELETE ON t1 FOR EACH ROW 
SET @del:= @del + 8 + old.j	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/delete	DELETE FROM t1 WHERE i=76	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/insert	INSERT INTO t1 VALUES (10,20)	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT * FROM table_t	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT 5 * 10	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT @a	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT @a	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT @change	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT @change	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT @del	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT @del	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT append("Bolly", "wood")	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT COUNT(*) = 0 FROM information_schema.processlist
WHERE user = 'event_scheduler'	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT fac(5)	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, COUNT_STAR, COUNT_STATEMENTS 
FROM performance_schema.events_statements_summary_by_program
WHERE OBJECT_SCHEMA='stored_programs' ORDER BY OBJECT_NAME	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/select	SELECT wt_avg(1, 12, 1990, 1121990)	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/set_option	SET @a=1	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/set_option	SET @change=1	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/set_option	SET @del=1	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/set_option	SET GLOBAL event_scheduler=OFF	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/set_option	SET GLOBAL event_scheduler=ON	stored_programs	NULL	NULL	NULL	NULL	0
statement/sql/update	UPDATE t2 SET id=22 WHERE name="Jwalamukhi"	stored_programs	NULL	NULL	NULL	NULL	0
statement/sp/freturn	NULL	stored_programs	FUNCTION	stored_programs	append	STATEMENT	1
statement/sp/stmt	INSERT INTO table_t VALUES(1)	stored_programs	EVENT	stored_programs	e1	STATEMENT	1
statement/sp/set	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/jump_if_not	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/set	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/set	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/jump	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/jump_if_not	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/set	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/set	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/jump	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/jump_if_not	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/set	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/set	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/jump	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/jump_if_not	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/set	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/set	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/jump	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/jump_if_not	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/freturn	NULL	stored_programs	FUNCTION	stored_programs	fac	STATEMENT	1
statement/sp/stmt	INSERT INTO t1 VALUES (x1, y)	stored_programs	PROCEDURE	stored_programs	sampleproc1	STATEMENT	1
statement/sp/stmt	INSERT INTO t1 VALUES (x2, y)	stored_programs	PROCEDURE	stored_programs	sampleproc1	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc2	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc2	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc2	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc2	STATEMENT	1
statement/sp/stmt	INSERT INTO t2 VALUES (x, z2)	stored_programs	PROCEDURE	stored_programs	sampleproc2	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc3	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc3	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc3	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc3	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc3	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc3	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc3	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc3	STATEMENT	1
statement/sp/stmt	INSERT INTO t3 (n, f, s) VALUES ((ld IS NULL), 1,    "ld is null"),
((li IS NULL), 1,    "li is null"),
((li = 0),     NULL, "li = 0"),
((lf IS NULL), 1,    "lf is null"),
((lf = 0),     NULL, "lf = 0"),
((ls IS NULL), 1,    "ls is null")	stored_programs	PROCEDURE	stored_programs	sampleproc3	STATEMENT	1
statement/sp/stmt	INSERT INTO t3 VALUES (ld, li, lf, ls)	stored_programs	PROCEDURE	stored_programs	sampleproc3	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc4	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc4	STATEMENT	1
statement/sp/jump_if_not	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc4	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc4	STATEMENT	1
statement/sp/jump	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc4	STATEMENT	1
statement/sp/jump_if_not	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc4	STATEMENT	1
statement/sp/set	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc4	STATEMENT	1
statement/sp/jump	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc4	STATEMENT	1
statement/sp/jump_if_not	NULL	stored_programs	PROCEDURE	stored_programs	sampleproc4	STATEMENT	1
statement/sp/stmt	INSERT INTO t4(word, mean) VALUES('a','a mean')	stored_programs	PROCEDURE	stored_programs	sampleproc4	STATEMENT	1
statement/sp/stmt	INSERT INTO t4(word, mean) VALUES('a','a mean')	stored_programs	PROCEDURE	stored_programs	sampleproc4	STATEMENT	1
statement/sp/jump_if_not	NULL	stored_programs	TRIGGER	stored_programs	trg1	TRANSACTION	1
statement/sp/jump_if_not	NULL	stored_programs	TRIGGER	stored_programs	trg1	TRANSACTION	2
statement/sp/jump_if_not	NULL	stored_programs	TRIGGER	stored_programs	trg1	TRANSACTION	2
statement/sp/stmt	UPDATE t1 SET i=new.id+i	stored_programs	TRIGGER	stored_programs	trg2	TRANSACTION	2
statement/sp/stmt	SET @change:= @change + new.id - old.id	stored_programs	TRIGGER	stored_programs	trg3	TRANSACTION	1
statement/sp/stmt	SET @del:= @del + 1	stored_programs	TRIGGER	stored_programs	trg4	TRANSACTION	1
statement/sp/stmt	SET @del:= @del + 8 + old.j	stored_programs	TRIGGER	stored_programs	trg5	TRANSACTION	1
statement/sp/set	NULL	stored_programs	FUNCTION	stored_programs	wt_avg	STATEMENT	1
statement/sp/set	NULL	stored_programs	FUNCTION	stored_programs	wt_avg	STATEMENT	1
statement/sp/freturn	NULL	stored_programs	FUNCTION	stored_programs	wt_avg	STATEMENT	1
# clean -up
TRUNCATE TABLE performance_schema.events_statements_summary_by_program;
TRUNCATE TABLE performance_schema.events_statements_history_long;
SELECT OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, COUNT_STAR, COUNT_STATEMENTS 
FROM performance_schema.events_statements_summary_by_program
WHERE OBJECT_SCHEMA='stored_programs' ORDER BY OBJECT_NAME;
OBJECT_TYPE	OBJECT_SCHEMA	OBJECT_NAME	COUNT_STAR	COUNT_STATEMENTS
FUNCTION	stored_programs	append	0	0
EVENT	stored_programs	e1	0	0
FUNCTION	stored_programs	fac	0	0
PROCEDURE	stored_programs	sampleproc1	0	0
PROCEDURE	stored_programs	sampleproc2	0	0
PROCEDURE	stored_programs	sampleproc3	0	0
PROCEDURE	stored_programs	sampleproc4	0	0
TRIGGER	stored_programs	trg1	0	0
TRIGGER	stored_programs	trg2	0	0
TRIGGER	stored_programs	trg3	0	0
TRIGGER	stored_programs	trg4	0	0
TRIGGER	stored_programs	trg5	0	0
FUNCTION	stored_programs	wt_avg	0	0
DROP PROCEDURE SampleProc1;
DROP PROCEDURE SampleProc2;
DROP PROCEDURE SampleProc3;
DROP PROCEDURE SampleProc4;
DROP FUNCTION wt_avg;
DROP FUNCTION fac;
DROP FUNCTION append;
DROP TRIGGER trg1;
DROP TRIGGER trg2;
DROP TRIGGER trg3;
DROP TRIGGER trg4;
DROP TRIGGER trg5;
DROP EVENT IF EXISTS e1;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
DROP TABLE table_t;
DROP DATABASE stored_programs;
SELECT OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, COUNT_STAR, COUNT_STATEMENTS 
FROM performance_schema.events_statements_summary_by_program
WHERE OBJECT_SCHEMA='stored_programs' ORDER BY OBJECT_NAME;
OBJECT_TYPE	OBJECT_SCHEMA	OBJECT_NAME	COUNT_STAR	COUNT_STATEMENTS
# SET-UP 
CREATE DATABASE stored_programs;
USE stored_programs;
CREATE TABLE t1(
i INT NOT NULL,
j INT
);
CREATE TABLE t2(
name   CHAR(16) NOT NULL DEFAULT '',
id INT NOT NULL
);
CREATE TABLE t3(
d DATE,
n INT,
f DOUBLE,
s VARCHAR(32)
);
CREATE TABLE t4(
`k` int(10) unsigned NOT NULL AUTO_INCREMENT,
`word` varchar(100) NOT NULL,
`mean` varchar(300) NOT NULL,
PRIMARY KEY (`k`)
);
############################
# Creating Stored Programs #
############################
# Stored Routine ( Procedure & Function )
CREATE PROCEDURE SampleProc1(x1 INT, x2 INT, y INT)
BEGIN
INSERT INTO t1 VALUES (x1, y);
INSERT INTO t1 VALUES (x2, y);
END|
CREATE PROCEDURE SampleProc2(x CHAR(16), y INT)
BEGIN
DECLARE z1, z2 INT;
SET z1 = y;
SET z2 = z1+2;
INSERT INTO t2 VALUES (x, z2);
END|
CREATE PROCEDURE SampleProc3()
BEGIN
DECLARE ld DATE;
DECLARE li INT;
DECLARE lf DOUBLE;
DECLARE ls VARCHAR(32);
SET ld = NULL, li = NULL, lf = NULL, ls = NULL;
INSERT INTO t3 VALUES (ld, li, lf, ls);
INSERT INTO t3 (n, f, s) VALUES ((ld IS NULL), 1,    "ld is null"),
((li IS NULL), 1,    "li is null"),
((li = 0),     NULL, "li = 0"),
((lf IS NULL), 1,    "lf is null"),
((lf = 0),     NULL, "lf = 0"),
((ls IS NULL), 1,    "ls is null");
END|
CREATE PROCEDURE SampleProc4()
BEGIN
DECLARE x  INT;
SET x = 1;
WHILE x  <= 2 DO
INSERT INTO t4(word, mean) VALUES('a','a mean');
SET  x = x + 1;
END WHILE;
END|
CREATE FUNCTION append(s1 CHAR(8), s2 CHAR(8)) RETURNS CHAR(16)
RETURN concat(s1, s2)|
CREATE FUNCTION wt_avg(n1 INT, n2 INT, n3 INT, n4 INT)
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE avg INT;
SET avg = (n1+n2+n3*2+n4*4)/8;
RETURN avg;
END|
CREATE FUNCTION fac(n INT UNSIGNED) RETURNS BIGINT UNSIGNED
BEGIN
DECLARE f BIGINT UNSIGNED DEFAULT 1;
WHILE n > 1 DO
SET f = f * n;
SET n = n - 1;
END WHILE;
RETURN f;
END|
# Triggers
CREATE TRIGGER trg1 BEFORE INSERT ON t1 FOR EACH ROW
BEGIN
if isnull(new.j) then
SET new.j:= new.i * 10;
END if;
END|
CREATE TRIGGER trg2 AFTER INSERT ON t2 FOR EACH ROW
BEGIN
UPDATE t1 SET i=new.id+i ;
END|
CREATE TRIGGER trg3 AFTER UPDATE ON t2 FOR EACH ROW
SET @change:= @change + new.id - old.id|
CREATE TRIGGER trg4 BEFORE DELETE ON t1 FOR EACH ROW
SET @del:= @del + 1|
CREATE TRIGGER trg5 AFTER DELETE ON t1 FOR EACH ROW 
SET @del:= @del + 8 + old.j|
update performance_schema.setup_instruments set enabled='YES', timed='NO'
  where name like "statement/sp/%" order by name;
TRUNCATE TABLE performance_schema.events_statements_summary_by_program;
TRUNCATE TABLE performance_schema.events_statements_history_long;
#####################
# Executing queries #
#####################
INSERT INTO t1 VALUES (10,20);
CALL SampleProc1(30,40,50);
SET @a=1;
SELECT @a;
@a
1
CALL SampleProc2("Jwalamukhi",34);
SELECT @a;
@a
1
CALL SampleProc3();
CALL SampleProc4();
SET @change=1;
SELECT @change;
@change
1
UPDATE t2 SET id=22 WHERE name="Jwalamukhi";
SELECT @change;
@change
-13
SET @del=1;
SELECT @del;
@del
1
DELETE FROM t1 WHERE i=76;
SELECT @del;
@del
60
SELECT wt_avg(1, 12, 1990, 1121990);
wt_avg(1, 12, 1990, 1121990)
561494
SELECT fac(5);
fac(5)
120
SELECT append("Bolly", "wood");
append("Bolly", "wood")
Bollywood
# Event
SET GLOBAL event_scheduler=ON;
CREATE TABLE table_t(a INT);
CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND DO
BEGIN
INSERT INTO table_t VALUES(1);
END|
SELECT * FROM table_t;
a
1
SET GLOBAL event_scheduler=OFF;
SELECT EVENT_NAME, TIMER_START, TIMER_END, TIMER_WAIT FROM
performance_schema.events_statements_history_long WHERE
CURRENT_SCHEMA='stored_programs' AND EVENT_NAME like "statement/sp/%";
EVENT_NAME	TIMER_START	TIMER_END	TIMER_WAIT
statement/sp/jump_if_not	NULL	NULL	NULL
statement/sp/jump_if_not	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
statement/sp/jump_if_not	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/jump_if_not	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/jump	NULL	NULL	NULL
statement/sp/jump_if_not	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/jump	NULL	NULL	NULL
statement/sp/jump_if_not	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/freturn	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/jump_if_not	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/jump	NULL	NULL	NULL
statement/sp/jump_if_not	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/jump	NULL	NULL	NULL
statement/sp/jump_if_not	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/jump	NULL	NULL	NULL
statement/sp/jump_if_not	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/set	NULL	NULL	NULL
statement/sp/jump	NULL	NULL	NULL
statement/sp/jump_if_not	NULL	NULL	NULL
statement/sp/freturn	NULL	NULL	NULL
statement/sp/freturn	NULL	NULL	NULL
statement/sp/stmt	NULL	NULL	NULL
update performance_schema.setup_instruments set enabled='YES', timed='YES'
  where name like "statement/sp/%" order by name;
TRUNCATE TABLE performance_schema.events_statements_summary_by_program;
TRUNCATE TABLE performance_schema.events_statements_history_long;
DROP PROCEDURE SampleProc1;
DROP PROCEDURE SampleProc2;
DROP PROCEDURE SampleProc3;
DROP PROCEDURE SampleProc4;
DROP FUNCTION wt_avg;
DROP FUNCTION fac;
DROP FUNCTION append;
DROP TRIGGER trg1;
DROP TRIGGER trg2;
DROP TRIGGER trg3;
DROP TRIGGER trg4;
DROP TRIGGER trg5;
DROP EVENT IF EXISTS e1;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
DROP TABLE table_t;
DROP DATABASE stored_programs;
# set-up
CREATE DATABASE sp;
USE sp;
CREATE TABLE t1(
a INT,
b INT
);
# let the creation of the following stored programs fail 
CREATE PROCEDURE fail1(IN a INT  OUT x CHAR(16)) 
SET a=1;
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 'OUT x CHAR(16)) 
SET a=1' at line 1
CREATE FUNCTION fail2(a INT , b INT) RETURNS INT
x=SELECT COUNT(*) FROM t;
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 '=SELECT COUNT(*) FROM t' at line 2
CREATE EVENT fail3 SCHEDULE EVERY MICROSECOND DO
DROP TABLE t;
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 'SCHEDULE EVERY MICROSECOND DO
DROP TABLE t' at line 1
# the below query on PS table doesn't show any rows 
# as the creation of stored programs failed 
SELECT OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, COUNT_STAR, COUNT_STATEMENTS
FROM performance_schema.events_statements_summary_by_program
WHERE OBJECT_SCHEMA='sp';
OBJECT_TYPE	OBJECT_SCHEMA	OBJECT_NAME	COUNT_STAR	COUNT_STATEMENTS
# create few stored programs 
CREATE PROCEDURE p(x1 INT, x2 INT)
BEGIN
INSERT INTO t1 VALUES (x1, x2);
END|
CREATE FUNCTION f(y1 INT, y2 INT) RETURNS INT
RETURN y1+y2;
CREATE TRIGGER trg AFTER INSERT ON t1 FOR EACH ROW
SET @neg=-1;
# execute the created stored programs such that they fail.
CALL p(7);
ERROR 42000: Incorrect number of arguments for PROCEDURE sp.p; expected 2, got 1
SELECT f("add",1,3);
ERROR 42000: Incorrect number of arguments for FUNCTION sp.f; expected 2, got 3
INSERT INTO t1;
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 '' at line 1
# the below query on PS table doesn't expose any statistics as 
# execution of the created stored porgrams failed.
SELECT OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, COUNT_STAR, COUNT_STATEMENTS
FROM performance_schema.events_statements_summary_by_program
WHERE OBJECT_SCHEMA='sp';
OBJECT_TYPE	OBJECT_SCHEMA	OBJECT_NAME	COUNT_STAR	COUNT_STATEMENTS
PROCEDURE	sp	p	0	0
FUNCTION	sp	f	0	0
#clean-up
DROP PROCEDURE p;
DROP FUNCTION f;
DROP TRIGGER trg;
DROP TABLE t1;
DROP DATABASE sp;