Bug #79773 handler::my_eval_gcolumn_expr doesn't set correct null bit
Submitted: 25 Dec 2015 8:31 Modified: 5 Jan 2016 15:51
Reporter: Shaohua Wang Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:5.7.11 OS:Any
Assigned to: CPU Architecture:Any

[25 Dec 2015 8:31] Shaohua Wang
Description:
In innobase_get_computed_value(),  we call handler::my_eval_gcolumn_expr to compute virtual column value, but it doesn't set correct null bit when we expect to get a NULL value.

As we can see from the test case below:

select d from t;
d
0
0

SELECT * FROM t;
a	b	d
0	0	0
11	NULL	NULL

How to repeat:
CREATE TABLE t ( 
  a INT,
  b INT,
  c INT GENERATED ALWAYS AS(a+b),
  d INT GENERATED ALWAYS AS(a+b+b),
  KEY vidx (c, d)
)ENGINE=INNODB;

INSERT INTO t (a,b) VALUES (0, 0), (11, NULL);
SELECT * FROM t;

ALTER TABLE t DROP COLUMN c, ALGORITHM=INPLACE;

explain select d from t;
select d from t;  --value showed is not correct.

SELECT * FROM t;

DROP TABLE t;
[25 Dec 2015 8:34] Shaohua Wang
Posted by developer:
 
I found the bug when debugging a valgrind issue, and I think the bug is the root cause of valgrind issue too.

1)gcol.gcol_rollback
http://pb2.no.oracle.com/?template=mysql_show_test_failure&search=yes&push_id=8853722&test...

2)innodb.virtual_basic
http://pb2.no.oracle.com/?template=mysql_show_test_failure&search=yes&push_id=8853722&test...

3) innodb.virtual_debug_purge
http://pb2.no.oracle.com/?template=mysql_show_test_failure&search=yes&push_id=8853722&test...
[25 Dec 2015 10:33] Shaohua Wang
Posted by developer:
 
Benny, as you can see from BUG#22082762 RE-ENABLE SUPPORT FOR ADDING VIRTUAL INDEX WHILE DROPPING VIRTUAL COLUMN, we just enabled drop virtual column & add index(it was disabled due to some optimizer bugs).

would you please help to check why HANDLER::MY_EVAL_GCOLUMN_EXPR doesn't set NULL bit correctly in this case?
[5 Jan 2016 15:51] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 5.7.11, 5.8.0 releases, and here's the changelog entry:

Incorrect index values were returned while dropping a virtual column. The
altered table object was used to evaluate virtual column values.