Commit 1d9b043a authored by Alexander Barkov's avatar Alexander Barkov

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 derive from Item_field
but forgot to override some methods that apply only to true fields,
so the server code mixes Item_{default|insert}_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.
parent 9741e0ea
...@@ -220,3 +220,44 @@ NULL ...@@ -220,3 +220,44 @@ NULL
10 10
drop table t1, t2; drop table t1, t2;
End of 5.0 tests. 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
#
...@@ -166,3 +166,46 @@ drop table t1, t2; ...@@ -166,3 +166,46 @@ drop table t1, t2;
--echo End of 5.0 tests. --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 #
# Note, the problem was not repeatable with a non-fresh connection.
--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 #
...@@ -4326,6 +4326,10 @@ class Item_default_value : public Item_field ...@@ -4326,6 +4326,10 @@ class Item_default_value : public Item_field
int save_in_field(Field *field_arg, bool no_conversions); int save_in_field(Field *field_arg, bool no_conversions);
table_map used_tables() const { return (table_map)0L; } 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) bool walk(Item_processor processor, bool walk_subquery, uchar *args)
{ {
return (arg && arg->walk(processor, walk_subquery, args)) || return (arg && arg->walk(processor, walk_subquery, args)) ||
...@@ -4367,6 +4371,8 @@ class Item_insert_value : public Item_field ...@@ -4367,6 +4371,8 @@ class Item_insert_value : public Item_field
*/ */
table_map used_tables() const { return RAND_TABLE_BIT; } 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) bool walk(Item_processor processor, bool walk_subquery, uchar *args)
{ {
return arg->walk(processor, walk_subquery, args) || return arg->walk(processor, walk_subquery, args) ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment