diff --git a/include/my_global.h b/include/my_global.h
index 5250d24d0e14fa3c85c9bb13d4589517ea91526f..ad86aeb749f58af958902b2d9d7838a034154ab5 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -424,6 +424,9 @@ C_MODE_END
 #ifdef HAVE_FLOAT_H
 #include <float.h>
 #endif
+#ifdef HAVE_FENV_H
+#include <fenv.h> /* For fesetround() */
+#endif
 
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
diff --git a/mysql-test/suite/sys_vars/r/completion_type_func.result b/mysql-test/suite/sys_vars/r/completion_type_func.result
index daee738c10dbbb48ceb696a9a7f5c08d0a06a4b8..f3ddcd287b6dc80f344a4d16f76720ef2d207801 100644
--- a/mysql-test/suite/sys_vars/r/completion_type_func.result
+++ b/mysql-test/suite/sys_vars/r/completion_type_func.result
@@ -2,76 +2,187 @@ DROP TABLE IF EXISTS t1;
 ## Creating new table ##
 CREATE TABLE t1
 (
-id INT NOT NULL AUTO_INCREMENT,
+id INT NOT NULL,
 PRIMARY KEY (id),
 name VARCHAR(30)
 ) ENGINE = INNODB;
-'#--------------------FN_DYNVARS_017_01-------------------------#'
-## Creating new connection ##
-INSERT INTO t1(name) VALUES('Record_1');
-SET @@autocommit = 0;
+## Creating new connections test_con1, test_con2 ##
+#########################################################
+#    Setting initial value of completion_type to zero   #
+#########################################################
+INSERT INTO t1 VALUES(1,'Record_1');
 SELECT * FROM t1;
 id	name
 1	Record_1
 ## Setting value of variable to 0 ##
 SET @@session.completion_type = 0;
 ## Here commit & rollback should work normally ##
+## test commit ##
 START TRANSACTION;
+INSERT INTO t1 VALUES(2,'Record_2');
+INSERT INTO t1 VALUES(3,'Record_3');
 SELECT * FROM t1;
 id	name
 1	Record_1
-INSERT INTO t1(name) VALUES('Record_2');
-INSERT INTO t1(name) VALUES('Record_3');
+2	Record_2
+3	Record_3
+Switching to connection test_con1
+## Don't expect to see id's 2 and 3 in the table w/o COMMIT ##
+SELECT * FROM t1;
+id	name
+1	Record_1
+Switching to default connection
+COMMIT;
+## test rollback ##
+START TRANSACTION;
+INSERT INTO t1 VALUES(4,'Record_4');
+INSERT INTO t1 VALUES(5,'Record_5');
+SELECT * FROM t1;
+id	name
+1	Record_1
+2	Record_2
+3	Record_3
+4	Record_4
+5	Record_5
+Switching to connection test_con1
+## Don't expect to see id's 4 and 5 here ##
+## Expect to see 3, Record_3 ##
 SELECT * FROM t1;
 id	name
 1	Record_1
 2	Record_2
 3	Record_3
-DELETE FROM t1 WHERE id = 2;
+Switching to connection default;
+ROLLBACK;
+## Don't expect to see id's 4 and 5 now ##
 SELECT * FROM t1;
 id	name
 1	Record_1
+2	Record_2
 3	Record_3
+
+#########################################################
+#    Setting initial value of completion_type to one    #
+#########################################################
+Switching to connection test_con1;
+SET @@session.completion_type = 1;
 START TRANSACTION;
 SELECT * FROM t1;
 id	name
 1	Record_1
+2	Record_2
 3	Record_3
-INSERT INTO t1(name) VALUES('Record_4');
-INSERT INTO t1(name) VALUES('Record_5');
+INSERT INTO t1 VALUES(6,'Record_6');
+INSERT INTO t1 VALUES(7,'Record_7');
 COMMIT;
-'#--------------------FN_DYNVARS_017_02-------------------------#'
+## Expect to immediately have a new transaction ##
+INSERT INTO t1 VALUES(8,'Record_8');
+SELECT * FROM t1;
+id	name
+1	Record_1
+2	Record_2
+3	Record_3
+6	Record_6
+7	Record_7
+8	Record_8
+switching to test_con2
+## Do not expect to see 8, Record_8 as no COMMIT has occurred ##
+SELECT * FROM t1;
+id	name
+1	Record_1
+2	Record_2
+3	Record_3
+6	Record_6
+7	Record_7
+switch to connection test_con1
+## Testing ROLLBACK behavior
+START TRANSACTION;
+INSERT INTO t1 VALUES(9, 'Record_9');
+INSERT INTO t1 VALUES(10, 'Record_10');
+## Expect to see id's 8, 9, 10 here ##
+## 8, Record_8 COMMITted with the start of this transaction ##
+SELECT * FROM t1;
+id	name
+1	Record_1
+2	Record_2
+3	Record_3
+6	Record_6
+7	Record_7
+8	Record_8
+9	Record_9
+10	Record_10
+ROLLBACK;
+## id's 9 and 10 are gone now due to ROLLBACK ##
+SELECT * FROM t1;
+id	name
+1	Record_1
+2	Record_2
+3	Record_3
+6	Record_6
+7	Record_7
+8	Record_8
+## Expect a new transaction ##
+INSERT INTO t1 VALUES(9, 'Record_9');
+Switching to connection test_con2
+## Don't expect to see 9, Record_9 due to no COMMIT yet ##
+SELECT * FROM t1;
+id	name
+1	Record_1
+2	Record_2
+3	Record_3
+6	Record_6
+7	Record_7
+8	Record_8
+Switching to connection test_con1
+ROLLBACK;
+## Don't expect to see 9, Record_9
+SELECT * FROM t1;
+id	name
+1	Record_1
+2	Record_2
+3	Record_3
+6	Record_6
+7	Record_7
+8	Record_8
+#########################################################
+#    Setting initial value of completion_type to 2      #
+#########################################################
 SET @@session.completion_type = 2;
 ## Here commit should work as COMMIT RELEASE ##
 START TRANSACTION;
 SELECT * FROM t1;
 id	name
 1	Record_1
+2	Record_2
 3	Record_3
-4	Record_4
-5	Record_5
-INSERT INTO t1(name) VALUES('Record_6');
-INSERT INTO t1(name) VALUES('Record_7');
+6	Record_6
+7	Record_7
+8	Record_8
+INSERT INTO t1 VALUES(9,'Record_9');
+INSERT INTO t1 VALUES(10,'Record_10');
 COMMIT;
 ## Inserting rows should give error here because connection should ##
 ## disconnect after using COMMIT ##
-INSERT INTO t1(name) VALUES('Record_4');
+INSERT INTO t1 VALUES(4,'Record_4');
 Got one of the listed errors
-## Creating new connection test_con2 ##
+switch to connection test_con2
 SET @@session.completion_type = 2;
 ## Inserting rows and using Rollback which should Rollback & release ##
 START TRANSACTION;
 SELECT * FROM t1;
 id	name
 1	Record_1
+2	Record_2
 3	Record_3
-4	Record_4
-5	Record_5
 6	Record_6
 7	Record_7
-INSERT INTO t1(name) VALUES('Record_8');
-INSERT INTO t1(name) VALUES('Record_9');
+8	Record_8
+9	Record_9
+10	Record_10
+INSERT INTO t1 VALUES(11,'Record_11');
+INSERT INTO t1 VALUES(12,'Record_12');
 ROLLBACK;
-INSERT INTO t1(name) VALUES('Record_4');
+## Expect a failure due to COMMIT/ROLLBACK AND RELEASE behavior ##
+INSERT INTO t1 VALUES(4,'Record_4');
 Got one of the listed errors
 DROP TABLE t1;
diff --git a/mysql-test/suite/sys_vars/t/completion_type_func-master.opt b/mysql-test/suite/sys_vars/t/completion_type_func-master.opt
deleted file mode 100644
index 627becdbfb57cb49e0525c614f7089ec489859aa..0000000000000000000000000000000000000000
--- a/mysql-test/suite/sys_vars/t/completion_type_func-master.opt
+++ /dev/null
@@ -1 +0,0 @@
---innodb
diff --git a/mysql-test/suite/sys_vars/t/completion_type_func.test b/mysql-test/suite/sys_vars/t/completion_type_func.test
index ed0f04c37b4f167eed4e844139025920b331fe7d..8e363ed2a7dd793e7351523609b110e233a9f070 100644
--- a/mysql-test/suite/sys_vars/t/completion_type_func.test
+++ b/mysql-test/suite/sys_vars/t/completion_type_func.test
@@ -1,4 +1,4 @@
-############## mysql-test\t\completion_type_func.test ##########################
+############## mysql-test/suite/sys_vars/t/completion_type_func.test ###########
 #                                                                              #
 # Variable Name: completion_type                                               #
 # Scope: GLOBAL & SESSION                                                      #
@@ -25,84 +25,154 @@
 DROP TABLE IF EXISTS t1;
 --enable_warnings
 
-#########################
-#   Creating new table  #
-#########################
+##############################
+# Setup: Table + connections #
+##############################
 
 --echo ## Creating new table ##
 CREATE TABLE t1
 (
-id INT NOT NULL AUTO_INCREMENT,
+id INT NOT NULL,
 PRIMARY KEY (id),
 name VARCHAR(30)
 ) ENGINE = INNODB;
 
---echo '#--------------------FN_DYNVARS_017_01-------------------------#'
-#########################################################
-#    Setting initial value of completion_type to zero   #
-#########################################################
-
---echo ## Creating new connection ##
+--echo ## Creating new connections test_con1, test_con2 ##
 connect (test_con1,localhost,root,,);
-connection test_con1;
+connect (test_con2,localhost,root,,);
+
+connection default;
+
+--echo #########################################################
+--echo #    Setting initial value of completion_type to zero   #
+--echo #########################################################
 
-INSERT INTO t1(name) VALUES('Record_1');
-SET @@autocommit = 0;
+INSERT INTO t1 VALUES(1,'Record_1');
 SELECT * FROM t1;
 
 --echo ## Setting value of variable to 0 ##
 SET @@session.completion_type = 0;
 
 --echo ## Here commit & rollback should work normally ##
+--echo ## test commit ##
+START TRANSACTION;
+INSERT INTO t1 VALUES(2,'Record_2');
+INSERT INTO t1 VALUES(3,'Record_3');
+SELECT * FROM t1;
+
+--echo Switching to connection test_con1
+connection test_con1;
+--echo ## Don't expect to see id's 2 and 3 in the table w/o COMMIT ##
+SELECT * FROM t1;
+
+--echo Switching to default connection
+connection default;
+COMMIT;
+
+--echo ## test rollback ##
 START TRANSACTION;
+INSERT INTO t1 VALUES(4,'Record_4');
+INSERT INTO t1 VALUES(5,'Record_5');
 SELECT * FROM t1;
-INSERT INTO t1(name) VALUES('Record_2');
-INSERT INTO t1(name) VALUES('Record_3');
+
+--echo Switching to connection test_con1
+connection test_con1;
+--echo ## Don't expect to see id's 4 and 5 here ##
+--echo ## Expect to see 3, Record_3 ##
 SELECT * FROM t1;
-DELETE FROM t1 WHERE id = 2;
+
+--echo Switching to connection default;
+connection default;
+
+
+ROLLBACK;
+--echo ## Don't expect to see id's 4 and 5 now ##
 SELECT * FROM t1;
 
+--echo 
+--echo #########################################################
+--echo #    Setting initial value of completion_type to one    #
+--echo #########################################################
+
+--echo Switching to connection test_con1;
+connection test_con1;
+SET @@session.completion_type = 1;
 
 START TRANSACTION;
 SELECT * FROM t1;
-INSERT INTO t1(name) VALUES('Record_4');
-INSERT INTO t1(name) VALUES('Record_5');
+INSERT INTO t1 VALUES(6,'Record_6');
+INSERT INTO t1 VALUES(7,'Record_7');
 COMMIT;
 
+--echo ## Expect to immediately have a new transaction ##
+INSERT INTO t1 VALUES(8,'Record_8');
+SELECT * FROM t1;
+
+connection test_con2;
+--echo switching to test_con2
+--echo ## Do not expect to see 8, Record_8 as no COMMIT has occurred ##
+SELECT * FROM t1;
+
+--echo switch to connection test_con1
+connection test_con1;
+
+--echo ## Testing ROLLBACK behavior
+START TRANSACTION;
+INSERT INTO t1 VALUES(9, 'Record_9');
+INSERT INTO t1 VALUES(10, 'Record_10');
+--echo ## Expect to see id's 8, 9, 10 here ##
+--echo ## 8, Record_8 COMMITted with the start of this transaction ##
+SELECT * FROM t1;
+ROLLBACK;
+--echo ## id's 9 and 10 are gone now due to ROLLBACK ##
+SELECT * FROM t1;
+
+--echo ## Expect a new transaction ##
+INSERT INTO t1 VALUES(9, 'Record_9');
 
---echo '#--------------------FN_DYNVARS_017_02-------------------------#'
-#########################################################
-#    Setting initial value of completion_type to 2      #
-#########################################################
+--echo Switching to connection test_con2
+connection test_con2;
+--echo ## Don't expect to see 9, Record_9 due to no COMMIT yet ##
+SELECT * FROM t1;
+
+--echo Switching to connection test_con1
+connection test_con1;
+ROLLBACK;
+--echo ## Don't expect to see 9, Record_9
+SELECT * FROM t1;
+
+--echo #########################################################
+--echo #    Setting initial value of completion_type to 2      #
+--echo #########################################################
 
 SET @@session.completion_type = 2;
 
 --echo ## Here commit should work as COMMIT RELEASE ##
 START TRANSACTION;
 SELECT * FROM t1;
-INSERT INTO t1(name) VALUES('Record_6');
-INSERT INTO t1(name) VALUES('Record_7');
+INSERT INTO t1 VALUES(9,'Record_9');
+INSERT INTO t1 VALUES(10,'Record_10');
 COMMIT;
 
 --echo ## Inserting rows should give error here because connection should ##
 --echo ## disconnect after using COMMIT ##
---Error 2006,2013,1053
-INSERT INTO t1(name) VALUES('Record_4');
+--Error 2006,2013,ER_SERVER_SHUTDOWN
+INSERT INTO t1 VALUES(4,'Record_4');
 
---echo ## Creating new connection test_con2 ##
-connect (test_con2,localhost,root,,);
+--echo switch to connection test_con2
 connection test_con2;
 SET @@session.completion_type = 2;
 
 --echo ## Inserting rows and using Rollback which should Rollback & release ##
 START TRANSACTION;
 SELECT * FROM t1;
-INSERT INTO t1(name) VALUES('Record_8');
-INSERT INTO t1(name) VALUES('Record_9');
+INSERT INTO t1 VALUES(11,'Record_11');
+INSERT INTO t1 VALUES(12,'Record_12');
 ROLLBACK;
 
---Error 2006,2013,1053
-INSERT INTO t1(name) VALUES('Record_4');
+--echo ## Expect a failure due to COMMIT/ROLLBACK AND RELEASE behavior ##
+--Error 2006,2013,ER_SERVER_SHUTDOWN,
+INSERT INTO t1 VALUES(4,'Record_4');
 
 connection default;
 disconnect test_con1;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 7f78b410b050f8cbf20c80a12b25a86bc282dc98..bd1afc7f0cad7fb3da447dad5560e0db45034dda 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -178,9 +178,6 @@ int initgroups(const char *,unsigned int);
 typedef fp_except fp_except_t;
 #endif
 #endif /* __FreeBSD__ && HAVE_IEEEFP_H */
-#ifdef HAVE_FENV_H
-#include <fenv.h>
-#endif
 #ifdef HAVE_SYS_FPU_H
 /* for IRIX to use set_fpc_csr() */
 #include <sys/fpu.h>