Skip to content

Commit 0cf5f65

Browse files
author
Tatjana Azundris Nuernberg
committed
WL#5928: Most statements should clear the diagnostic area
Previously, the errors/warnings list was only cleared when a statement accessed tables. This was non-standard. We now clear the DA for every procedure statement (mostly anything that is executed and is not a diagnostics statement like GET DIAGNOSTICS or SHOW WARNINGS). This changes both code and behaviour for - direct invocation - stored procedures/functions - prepared statements - query cache GET DIAGNOSTICS and the old SHOW WARNINGS, SHOW ERRORS, SHOW COUNT(*) WARNINGS, SHOW COUNT(*) ERRORS are diagnostics statements. They do not clear the diagnostics area even when issued repeatedly. @@error_count and @@warning_count are "diagnostics variables" and will appear in non-diagnostics statements like SELECT. For backward compatibility, they will contain the correct values describing the previous statement when queried immediately after execution of the previous statement: DROP TABLE does_not_exist; SELECT @@error_count; # renders 1 (result of DROP) SELECT @@error_count; # renders 0 (result of SELECT) This is discouraged; use GET DIAGNOSTICS instead. Likewise, SHOW WARNINGS could be used as the first statement of a HANDLER (or preceeded only by other diagnostics statements), but this is discouraged -- use GET [STACKED] DIAGNOSTICS instead. Errors during parsing correctly set the DA; any errors thrown there replace the previous command's diagnostics, even if it was a diagnostics statement the user failed at issuing. The SQL standard requires the diagnostics statement (GET DIAGNOSTICS) not to be preparable; likewise, SHOW WARNINGS, SHOW ERRORS, and statements containing @@error_count or @@warning_count must not be used in prepared statements. Code: DA resetting was sprinkled all over the code, sometimes in the form of a "maybe" (opt_reset_condition_info()). All occurences of the latter were removed. Care was taken to reduce the number of occurences of the former, usually to one central point for each subsystem (parsing, SP, PS, QC, signaling, logging). Self-printing of SP instructions was slightly extended and refactored. Tests: wl5928.test tests and documents the new expected behaviour. Various other tests were adapted to provided similarly expressive results as they used to under the previous circumstances.
1 parent c4e14bc commit 0cf5f65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2248
-694
lines changed

mysql-test/include/sp-vars.inc

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ BEGIN
3434
DECLARE v19 DECIMAL(64, 2) DEFAULT 11 + 1;
3535
DECLARE v20 DECIMAL(64, 2) DEFAULT 12 + 0.123;
3636

37+
SHOW WARNINGS;
38+
3739
SELECT v1, v1u, v2, v2u, v3, v3u, v4, v4u;
3840
SELECT v5, v5u, v6, v6u;
3941
SELECT v7, v8, v9, v10, v11, v12, v13, v14, v15, v16;
@@ -80,12 +82,16 @@ BEGIN
8082
SET d2 = 1234.12;
8183
SET d3 = 1234.1234;
8284

85+
SHOW WARNINGS;
86+
8387
SELECT d1, d2, d3;
8488

8589
SET d1 = 12 * 100 + 34;
8690
SET d2 = 12 * 100 + 34 + 0.12;
8791
SET d3 = 12 * 100 + 34 + 0.1234;
8892

93+
SHOW WARNINGS;
94+
8995
SELECT d1, d2, d3;
9096
END|
9197

mysql-test/r/get_diagnostics.result

+29-54
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ SET @cond = "invalid";
251251
GET DIAGNOSTICS CONDITION @cond @var1 = CLASS_ORIGIN;
252252
Warnings:
253253
Error 1758 Invalid condition number
254-
Error 1758 Invalid condition number
255254
SELECT COUNT(max_questions) INTO @var FROM mysql.user;
256255
CREATE PROCEDURE p1()
257256
BEGIN
@@ -267,6 +266,8 @@ DECLARE var INT;
267266
GET DIAGNOSTICS CONDITION cond var = CLASS_ORIGIN;
268267
END|
269268
CALL p1();
269+
Warnings:
270+
Error 1758 Invalid condition number
270271
DROP PROCEDURE p1;
271272
#
272273
# Test GET DIAGNOSTICS runtime
@@ -467,10 +468,6 @@ cursor_name
467468
message_text Truncated incorrect DECIMAL value: ''
468469
mysql_errno 1292
469470
returned_sqlstate 22007
470-
Warnings:
471-
Level Warning
472-
Code 1292
473-
Message Truncated incorrect DECIMAL value: ''
474471
DROP PROCEDURE p1;
475472
CREATE PROCEDURE p1()
476473
BEGIN
@@ -490,13 +487,6 @@ errno1 1292
490487
msg1 Truncated incorrect DECIMAL value: ''
491488
errno2 1758
492489
msg2 Invalid condition number
493-
Warnings:
494-
Level Warning
495-
Code 1292
496-
Message Truncated incorrect DECIMAL value: ''
497-
Level Error
498-
Code 1758
499-
Message Invalid condition number
500490
DROP PROCEDURE p1;
501491

502492
# Interaction with SIGNAL
@@ -607,7 +597,7 @@ SELECT var, @var;
607597
END|
608598
CALL p1();
609599
var @var
610-
1 1
600+
0 0
611601
DROP PROCEDURE p1;
612602

613603
# Setting TABLE_NAME is currently not implemented.
@@ -638,8 +628,6 @@ CREATE TABLE t1 (a INT);
638628
CALL p1();
639629
v
640630
T
641-
Warnings:
642-
Note 1050 Table 't1' already exists
643631
DROP TABLE t1;
644632
DROP PROCEDURE p1;
645633

@@ -678,13 +666,13 @@ SIGNAL SQLSTATE '01002';
678666
GET CURRENT DIAGNOSTICS CONDITION 1 @y = RETURNED_SQLSTATE;
679667
END;
680668
SIGNAL SQLSTATE '01001';
681-
SELECT @x, @y;
682669
END|
683670
CALL p1();
684-
@x @y
685-
01001 01002
686671
Warnings:
687672
Warning 1642 Unhandled user-defined warning condition
673+
SELECT @x, @y;
674+
@x @y
675+
01001 01002
688676
DROP PROCEDURE p1;
689677

690678
# Using OUT and INOUT parameters as the target variables.
@@ -854,35 +842,29 @@ CREATE PROCEDURE p1()
854842
BEGIN
855843
DECLARE EXIT HANDLER FOR SQLEXCEPTION
856844
BEGIN
857-
DECLARE msg1 TEXT;
858-
DECLARE errno1 INT;
859-
DECLARE msg2 TEXT;
860-
DECLARE errno2 INT;
861-
DECLARE msg4 TEXT;
862-
DECLARE errno4 INT;
863845
# Should be identical
864-
GET CURRENT DIAGNOSTICS CONDITION 1 msg1 = MESSAGE_TEXT, errno1 = MYSQL_ERRNO;
865-
SELECT msg1, errno1;
866-
GET STACKED DIAGNOSTICS CONDITION 1 msg2 = MESSAGE_TEXT, errno2 = MYSQL_ERRNO;
867-
SELECT msg2, errno2;
846+
GET CURRENT DIAGNOSTICS CONDITION 1 @msg1 = MESSAGE_TEXT, @errno1 = MYSQL_ERRNO;
847+
GET STACKED DIAGNOSTICS CONDITION 1 @msg2 = MESSAGE_TEXT, @errno2 = MYSQL_ERRNO;
848+
SELECT @msg1, @errno1;
849+
SELECT @msg2, @errno2;
868850
SELECT * FROM t1; # Clear first diagnostics area
869851
# CURRENT should be empty, STACKED unchanged
870852
GET CURRENT DIAGNOSTICS @cno = NUMBER;
871853
SELECT @cno;
872-
GET STACKED DIAGNOSTICS CONDITION 1 msg4 = MESSAGE_TEXT, errno4 = MYSQL_ERRNO;
873-
SELECT msg4, errno4;
854+
GET STACKED DIAGNOSTICS CONDITION 1 @msg4 = MESSAGE_TEXT, @errno4 = MYSQL_ERRNO;
855+
SELECT @msg4, @errno4;
874856
END;
875857
DROP TABLE non_existent;
876858
END|
877859
CALL p1();
878-
msg1 errno1
860+
@msg1 @errno1
879861
Unknown table 'test.non_existent' 1051
880-
msg2 errno2
862+
@msg2 @errno2
881863
Unknown table 'test.non_existent' 1051
882864
a
883865
@cno
884866
0
885-
msg4 errno4
867+
@msg4 @errno4
886868
Unknown table 'test.non_existent' 1051
887869
DROP PROCEDURE p1;
888870
DROP TABLE t1;
@@ -893,39 +875,32 @@ CREATE PROCEDURE p1()
893875
BEGIN
894876
DECLARE CONTINUE HANDLER FOR SQLWARNING
895877
BEGIN
896-
DECLARE msg1 TEXT;
897-
DECLARE errno1 INT;
898-
DECLARE msg2 TEXT;
899-
DECLARE errno2 INT;
900-
DECLARE msg3 TEXT;
901-
DECLARE errno3 INT;
902-
DECLARE msg4 TEXT;
903-
DECLARE errno4 INT;
904878
# Should be identical
905-
GET CURRENT DIAGNOSTICS CONDITION 1 msg1 = MESSAGE_TEXT, errno1 = MYSQL_ERRNO;
906-
SELECT msg1, errno1;
907-
GET STACKED DIAGNOSTICS CONDITION 1 msg2 = MESSAGE_TEXT, errno2 = MYSQL_ERRNO;
908-
SELECT msg2, errno2;
879+
GET CURRENT DIAGNOSTICS CONDITION 1 @msg1 = MESSAGE_TEXT, @errno1 = MYSQL_ERRNO;
880+
SELECT @msg1, @errno1;
881+
GET STACKED DIAGNOSTICS CONDITION 1 @msg2 = MESSAGE_TEXT, @errno2 = MYSQL_ERRNO;
882+
SELECT @msg2, @errno2;
909883
RESIGNAL SET MYSQL_ERRNO= 9999, MESSAGE_TEXT= 'Changed by resignal';
910884
# Should be changed, but still identical
911-
GET CURRENT DIAGNOSTICS CONDITION 1 msg3 = MESSAGE_TEXT, errno3 = MYSQL_ERRNO;
912-
SELECT msg3, errno3;
913-
GET STACKED DIAGNOSTICS CONDITION 1 msg4 = MESSAGE_TEXT, errno4 = MYSQL_ERRNO;
914-
SELECT msg4, errno4;
885+
GET CURRENT DIAGNOSTICS CONDITION 1 @msg3 = MESSAGE_TEXT, @errno3 = MYSQL_ERRNO;
886+
SELECT @msg3, @errno3;
887+
GET STACKED DIAGNOSTICS CONDITION 1 @msg4 = MESSAGE_TEXT, @errno4 = MYSQL_ERRNO;
888+
SELECT @msg4, @errno4;
889+
RESIGNAL SET MYSQL_ERRNO= 9999, MESSAGE_TEXT= 'Changed by resignal, for caller';
915890
END;
916891
SELECT 10 + 'a';
917892
END|
918893
CALL p1();
919894
10 + 'a'
920895
10
921-
msg1 errno1
896+
@msg1 @errno1
922897
Truncated incorrect DOUBLE value: 'a' 1292
923-
msg2 errno2
898+
@msg2 @errno2
924899
Truncated incorrect DOUBLE value: 'a' 1292
925-
msg3 errno3
900+
@msg3 @errno3
926901
Changed by resignal 9999
927-
msg4 errno4
902+
@msg4 @errno4
928903
Changed by resignal 9999
929904
Warnings:
930-
Warning 9999 Changed by resignal
905+
Warning 9999 Changed by resignal, for caller
931906
DROP PROCEDURE p1;

mysql-test/r/partition.result

-4
Original file line numberDiff line numberDiff line change
@@ -1543,11 +1543,7 @@ ROLLBACK to savepoint t1_save;
15431543
COMMIT;
15441544
END|
15451545
CALL test.p1(12);
1546-
Warnings:
1547-
Warning 1196 Some non-transactional changed tables couldn't be rolled back
15481546
CALL test.p1(13);
1549-
Warnings:
1550-
Warning 1196 Some non-transactional changed tables couldn't be rolled back
15511547
drop table t1;
15521548
drop procedure test.p1;
15531549
CREATE TABLE t1 (a int not null)

mysql-test/r/ps.result

+2-26
Original file line numberDiff line numberDiff line change
@@ -2761,7 +2761,7 @@ drop procedure proc_1;
27612761
create function func_1() returns int begin show errors; return 1; end|
27622762
ERROR 0A000: Not allowed to return a result set from a function
27632763
prepare abc from "show errors";
2764-
deallocate prepare abc;
2764+
ERROR HY000: This command is not supported in the prepared statement protocol yet
27652765
drop table if exists t1;
27662766
drop table if exists t2;
27672767
create procedure proc_1() show warnings;
@@ -2770,46 +2770,22 @@ Warnings:
27702770
Note 1051 Unknown table 'test.t1'
27712771
call proc_1();
27722772
Level Code Message
2773-
Note 1051 Unknown table 'test.t1'
27742773
drop table if exists t2;
27752774
Warnings:
27762775
Note 1051 Unknown table 'test.t2'
27772776
call proc_1();
27782777
Level Code Message
2779-
Note 1051 Unknown table 'test.t2'
27802778
drop table if exists t1, t2;
27812779
Warnings:
27822780
Note 1051 Unknown table 'test.t1'
27832781
Note 1051 Unknown table 'test.t2'
27842782
call proc_1();
27852783
Level Code Message
2786-
Note 1051 Unknown table 'test.t1'
2787-
Note 1051 Unknown table 'test.t2'
27882784
drop procedure proc_1;
27892785
create function func_1() returns int begin show warnings; return 1; end|
27902786
ERROR 0A000: Not allowed to return a result set from a function
27912787
prepare abc from "show warnings";
2792-
drop table if exists t1;
2793-
Warnings:
2794-
Note 1051 Unknown table 'test.t1'
2795-
execute abc;
2796-
Level Code Message
2797-
Note 1051 Unknown table 'test.t1'
2798-
drop table if exists t2;
2799-
Warnings:
2800-
Note 1051 Unknown table 'test.t2'
2801-
execute abc;
2802-
Level Code Message
2803-
Note 1051 Unknown table 'test.t2'
2804-
drop table if exists t1, t2;
2805-
Warnings:
2806-
Note 1051 Unknown table 'test.t1'
2807-
Note 1051 Unknown table 'test.t2'
2808-
execute abc;
2809-
Level Code Message
2810-
Note 1051 Unknown table 'test.t1'
2811-
Note 1051 Unknown table 'test.t2'
2812-
deallocate prepare abc;
2788+
ERROR HY000: This command is not supported in the prepared statement protocol yet
28132789
set @my_password="password";
28142790
set @my_data="clear text to encode";
28152791
prepare stmt1 from 'select decode(encode(?, ?), ?)';

mysql-test/r/ps_1general.result

+2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ prepare stmt4 from ' show master status ';
319319
prepare stmt4 from ' show master logs ';
320320
prepare stmt4 from ' show slave status ';
321321
prepare stmt4 from ' show warnings limit 20 ';
322+
ERROR HY000: This command is not supported in the prepared statement protocol yet
322323
prepare stmt4 from ' show errors limit 20 ';
324+
ERROR HY000: This command is not supported in the prepared statement protocol yet
323325
prepare stmt4 from ' show storage engines ';
324326
execute stmt4;
325327
drop table if exists t5;

mysql-test/r/query_cache.result

+33
Original file line numberDiff line numberDiff line change
@@ -1777,3 +1777,36 @@ COUNT(*)
17771777
DROP TABLE t1;
17781778
SET GLOBAL query_cache_size= @qc;
17791779
#
1780+
1781+
# WL5928: Most statements should clear the diagnostic area
1782+
# Show this also works when we serve from query-cache!
1783+
#
1784+
SELECT @@session.query_cache_type INTO @qc_type;
1785+
SET SESSION query_cache_type=2;
1786+
CREATE TABLE t1 (f1 VARCHAR(16));
1787+
INSERT INTO t1 VALUES ("cat"),("dog"),("wombat"),("elephant");
1788+
1789+
DROP TABLE no_such_table;
1790+
ERROR 42S02: Unknown table 'test.no_such_table'
1791+
SELECT SQL_CACHE * FROM t1;
1792+
f1
1793+
cat
1794+
dog
1795+
wombat
1796+
elephant
1797+
SHOW WARNINGS;
1798+
Level Code Message
1799+
1800+
DROP TABLE no_such_table;
1801+
ERROR 42S02: Unknown table 'test.no_such_table'
1802+
SELECT SQL_CACHE * FROM t1;
1803+
f1
1804+
cat
1805+
dog
1806+
wombat
1807+
elephant
1808+
SHOW WARNINGS;
1809+
Level Code Message
1810+
1811+
DROP TABLE t1;
1812+
SET SESSION query_cache_type=@qc_type;

mysql-test/r/rollback.result

+5-8
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,21 @@ insert into t1 values (5);
66
rollback;
77
Warnings:
88
Warning 1196 Some non-transactional changed tables couldn't be rolled back
9-
select @@warning_count;
10-
@@warning_count
11-
1
12-
select @@error_count;
13-
@@error_count
14-
0
159
show warnings;
1610
Level Code Message
1711
Warning 1196 Some non-transactional changed tables couldn't be rolled back
1812
show errors;
1913
Level Code Message
14+
select @@warning_count,@@error_count;
15+
@@warning_count @@error_count
16+
1 0
2017
select * from t1;
2118
n
2219
4
2320
5
21+
show warnings;
22+
Level Code Message
2423
select @@warning_count;
2524
@@warning_count
2625
0
27-
show warnings;
28-
Level Code Message
2926
drop table t1;

0 commit comments

Comments
 (0)