← Back to team overview

maria-developers team mailing list archive

Re: Please review a fix for MDEV-10780 (and likely for MDEV-10806 and MDEV-10910)

 

Hello Sanja,


On 11/10/2016 01:13 AM, Oleksandr Byelkin wrote:
Hi, Alexander!

On 09.11.2016 16:28, Alexander Barkov wrote:
Hello Sanja, Elena, Wlad,

Sanja, please review a patch for MDEV-10780.

The patch is for 10.1. I could not reproduce it in 10.0.
But it should be safe to push it into 10.0 anyway.

This patch is most likely fixing MDEV-10806 (assigned to Sanja)
and MDEV-10910 (assigned to Elena).

The patch is good, but I definitely want to see commit comment (it is
also important part of the fix). Could you send it, of commit and
forward me the commit e-mail?

Here's an updated version with a comment and with a
very small addition fixing another bugs.

Thanks!




[skip]
commit 253e89d50d40610acac42a3e3462dd43f49e8d65
Author: Alexander Barkov <bar@xxxxxxxxxxx>
Date:   Thu Nov 10 16:39:14 2016 +0400

    A join patch for MDEV-10780 and MDEV-11265
    
    MDEV-10780 Server crashes in in create_tmp_table
    MDEV-11265 Access defied when CREATE VIIEW v1 AS SELECT DEFAULT(column) FROM t1
    
    Item_default_value and Item_insert_value erroneously derives from Item_field
    but forgot to override some methods that apply only to true fields,
    so the server code mixes Item_default_value instances with real
    table fields (i.e. true Item_field) in some cases.
    Overriding a few methods to avoid this.
    
    TODO: we should eventually derive Item_default_value (and Item_insert_value)
    directly from Item, as they don't really need the entire Item_field,
    Item_ident and Item_result_field functionality.
    Only the member "Field *field" related functionality is actually needed,
    like val_xxx(), is_null(), get_geometry_type(), charset_for_protocol(), etc.

diff --git a/mysql-test/r/default.result b/mysql-test/r/default.result
index 685b534..4057c18 100644
--- a/mysql-test/r/default.result
+++ b/mysql-test/r/default.result
@@ -223,6 +223,47 @@ NULL
 drop table t1, t2;
 End of 5.0 tests.
 #
+# Start of 10.0 tests
+#
+#
+# MDEV-11265 Access defied when CREATE VIIEW v1 AS SELECT DEFAULT(column) FROM t1
+#
+CREATE TABLE t1 (a INT DEFAULT 10);
+INSERT INTO t1 VALUES (11);
+CREATE VIEW v1 AS SELECT a AS a FROM t1;
+CREATE VIEW v2 AS SELECT DEFAULT(a) AS a FROM t1;
+CREATE VIEW v3 AS SELECT VALUES(a) AS a FROM t1;
+SELECT * FROM v1;
+a
+11
+SELECT * FROM v2;
+a
+10
+SELECT * FROM v3;
+a
+NULL
+UPDATE v2 SET a=123;
+ERROR HY000: Column 'a' is not updatable
+UPDATE v3 SET a=123;
+ERROR HY000: Column 'a' is not updatable
+DROP VIEW v3;
+DROP VIEW v2;
+DROP VIEW v1;
+DROP TABLE t1;
+#
+# MDEV-10780 Server crashes in in create_tmp_table
+#
+CREATE TABLE t1 (pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ();
+INSERT INTO t1 VALUES ();
+SELECT DISTINCT DEFAULT (pk) FROM t1 GROUP BY RAND() WITH ROLLUP;
+DEFAULT (pk)
+0
+DROP TABLE t1;
+#
+# End of 10.0 tests
+#
+#
 # Start of 10.1 tests
 #
 CREATE TABLE t1 (a INT DEFAULT 100, b INT DEFAULT NULL);
diff --git a/mysql-test/t/default.test b/mysql-test/t/default.test
index 17f4383..957f79b 100644
--- a/mysql-test/t/default.test
+++ b/mysql-test/t/default.test
@@ -169,6 +169,50 @@ drop table t1, t2;
 --echo End of 5.0 tests.
 
 --echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-11265 Access defied when CREATE VIIEW v1 AS SELECT DEFAULT(column) FROM t1
+--echo #
+
+CREATE TABLE t1 (a INT DEFAULT 10);
+INSERT INTO t1 VALUES (11);
+CREATE VIEW v1 AS SELECT a AS a FROM t1;
+CREATE VIEW v2 AS SELECT DEFAULT(a) AS a FROM t1;
+CREATE VIEW v3 AS SELECT VALUES(a) AS a FROM t1;
+SELECT * FROM v1;
+SELECT * FROM v2;
+SELECT * FROM v3;
+--error ER_NONUPDATEABLE_COLUMN
+UPDATE v2 SET a=123;
+--error ER_NONUPDATEABLE_COLUMN
+UPDATE v3 SET a=123;
+DROP VIEW v3;
+DROP VIEW v2;
+DROP VIEW v1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-10780 Server crashes in in create_tmp_table
+--echo #
+
+--connect (con1,127.0.0.1,root,,test)
+CREATE TABLE t1 (pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ();
+INSERT INTO t1 VALUES ();
+SELECT DISTINCT DEFAULT (pk) FROM t1 GROUP BY RAND() WITH ROLLUP;
+--disconnect con1
+--connection default
+DROP TABLE t1;
+
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
+
+--echo #
 --echo # Start of 10.1 tests
 --echo #
 
diff --git a/sql/item.h b/sql/item.h
index 1905e0f..4ac6fe7 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -4822,6 +4822,10 @@ class Item_default_value : public Item_field
   int save_in_field(Field *field_arg, bool no_conversions);
   table_map used_tables() const { return (table_map)0L; }
 
+  Field *get_tmp_table_field() { return 0; }
+  Item *get_tmp_table_item(THD *thd) { return this; }
+  Item_field *field_for_view_update() { return 0; }
+
   bool walk(Item_processor processor, bool walk_subquery, uchar *args)
   {
     return (arg && arg->walk(processor, walk_subquery, args)) ||
@@ -4863,6 +4867,8 @@ class Item_insert_value : public Item_field
   */
   table_map used_tables() const { return RAND_TABLE_BIT; }
 
+  Item_field *field_for_view_update() { return 0; }
+
   bool walk(Item_processor processor, bool walk_subquery, uchar *args)
   {
     return arg->walk(processor, walk_subquery, args) ||

Follow ups

References