Bug #121231 Prepared statement uses stale div_precision_increment value after SESSION variable change
Submitted: 4 Sep 14:57
Reporter: Xiaoyuan Xie Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: Prepared statements Severity:S2 (Serious)
Version:9.7.0 OS:Any
Assigned to: CPU Architecture:Any

[4 Sep 14:57] Xiaoyuan Xie
Description:
A prepared statement continues to use the value of div_precision_increment that was active when the statement was prepared, even after the SESSION variable is restored to its default value. 
After restoration, @@SESSION.div_precision_increment is 4, but executing the prepared statement still produces a result whose scale corresponds to div_precision_increment=8.

How to repeat:
SET SESSION div_precision_increment = 8;

PREPARE s FROM
    'SELECT CAST(1 AS DECIMAL(10,2)) / 3 AS result';

SET SESSION div_precision_increment = DEFAULT;

SELECT @@SESSION.div_precision_increment;
-- 4

EXECUTE s;

Actual Result: 0.3333333333
Expected Result: 0.333333