From 2d73b581019112e0e9b32b00dbcc6797889649c1 Mon Sep 17 00:00:00 2001
From: Sachin Setiya <sachin.setiya@mariadb.com>
Date: Tue, 30 Jan 2018 14:04:05 +0530
Subject: [PATCH] Mdev-15085 Invisible Column Non-constant Default value
 results...

Problem:- If we create table field with dynamic default value then that
 field always gets NULL value.

Analyze:- This is because in fill_record we simple continue at Invisible
 column because we though that share->default_values(default value is
 always copied into table->record[0] before insert) will have a default
 value for them(which is true for constant defaults , but not for dynamic
 defaults).

Solution:- We simple set all_fields_have_value to null , and this will
make call to update_default_fields (in the case of dynamic default), And
default expr will be evaluted and value will be set in field.
---
 mysql-test/r/invisible_field.result | 11 +++++++++++
 mysql-test/t/invisible_field.test   | 10 +++++++++-
 sql/sql_base.cc                     |  1 +
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/mysql-test/r/invisible_field.result b/mysql-test/r/invisible_field.result
index 0e6980f31e6..a58f34e39a0 100644
--- a/mysql-test/r/invisible_field.result
+++ b/mysql-test/r/invisible_field.result
@@ -524,3 +524,14 @@ a	b	c	d
 1	3	1	6
 2	2	2	6
 drop table t1;
+create table t1(a int default 5 invisible, b int);
+create table t2(a int default (b+11) invisible, b int);
+insert into t1 values(1);
+select a,b from t1;
+a	b
+5	1
+insert into t2 values(1);
+select a,b from t2;
+a	b
+12	1
+drop table t1,t2;
diff --git a/mysql-test/t/invisible_field.test b/mysql-test/t/invisible_field.test
index b1d28d882d7..a68e05cf320 100644
--- a/mysql-test/t/invisible_field.test
+++ b/mysql-test/t/invisible_field.test
@@ -213,4 +213,12 @@ execute insert_1;
 set @a=2,@b=2, @c=2;
 execute insert_2;
 select a,b,c,d from t1 order by a;
-drop table t1;
\ No newline at end of file
+drop table t1;
+#MDEV-15085 Non constant default getting Null values
+create table t1(a int default 5 invisible, b int);
+create table t2(a int default (b+11) invisible, b int);
+insert into t1 values(1);
+select a,b from t1;
+insert into t2 values(1);
+select a,b from t2;
+drop table t1,t2;
\ No newline at end of file
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index df5e947efa2..5fbf4ba4c81 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -8396,6 +8396,7 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
 
     if (field->invisible)
     {
+      all_fields_have_values= false;
       continue;
     }
     else
-- 
2.30.9