Skip to content

Commit 1d9b043

Browse files
author
Alexander Barkov
committed
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.
1 parent 9741e0e commit 1d9b043

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

mysql-test/r/default.result

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,44 @@ NULL
220220
10
221221
drop table t1, t2;
222222
End of 5.0 tests.
223+
#
224+
# Start of 10.0 tests
225+
#
226+
#
227+
# MDEV-11265 Access defied when CREATE VIIEW v1 AS SELECT DEFAULT(column) FROM t1
228+
#
229+
CREATE TABLE t1 (a INT DEFAULT 10);
230+
INSERT INTO t1 VALUES (11);
231+
CREATE VIEW v1 AS SELECT a AS a FROM t1;
232+
CREATE VIEW v2 AS SELECT DEFAULT(a) AS a FROM t1;
233+
CREATE VIEW v3 AS SELECT VALUES(a) AS a FROM t1;
234+
SELECT * FROM v1;
235+
a
236+
11
237+
SELECT * FROM v2;
238+
a
239+
10
240+
SELECT * FROM v3;
241+
a
242+
NULL
243+
UPDATE v2 SET a=123;
244+
ERROR HY000: Column 'a' is not updatable
245+
UPDATE v3 SET a=123;
246+
ERROR HY000: Column 'a' is not updatable
247+
DROP VIEW v3;
248+
DROP VIEW v2;
249+
DROP VIEW v1;
250+
DROP TABLE t1;
251+
#
252+
# MDEV-10780 Server crashes in in create_tmp_table
253+
#
254+
CREATE TABLE t1 (pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=MyISAM;
255+
INSERT INTO t1 VALUES ();
256+
INSERT INTO t1 VALUES ();
257+
SELECT DISTINCT DEFAULT (pk) FROM t1 GROUP BY RAND() WITH ROLLUP;
258+
DEFAULT (pk)
259+
0
260+
DROP TABLE t1;
261+
#
262+
# End of 10.0 tests
263+
#

mysql-test/t/default.test

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,46 @@ drop table t1, t2;
166166

167167
--echo End of 5.0 tests.
168168

169+
--echo #
170+
--echo # Start of 10.0 tests
171+
--echo #
172+
173+
--echo #
174+
--echo # MDEV-11265 Access defied when CREATE VIIEW v1 AS SELECT DEFAULT(column) FROM t1
175+
--echo #
176+
177+
CREATE TABLE t1 (a INT DEFAULT 10);
178+
INSERT INTO t1 VALUES (11);
179+
CREATE VIEW v1 AS SELECT a AS a FROM t1;
180+
CREATE VIEW v2 AS SELECT DEFAULT(a) AS a FROM t1;
181+
CREATE VIEW v3 AS SELECT VALUES(a) AS a FROM t1;
182+
SELECT * FROM v1;
183+
SELECT * FROM v2;
184+
SELECT * FROM v3;
185+
--error ER_NONUPDATEABLE_COLUMN
186+
UPDATE v2 SET a=123;
187+
--error ER_NONUPDATEABLE_COLUMN
188+
UPDATE v3 SET a=123;
189+
DROP VIEW v3;
190+
DROP VIEW v2;
191+
DROP VIEW v1;
192+
DROP TABLE t1;
193+
194+
--echo #
195+
--echo # MDEV-10780 Server crashes in in create_tmp_table
196+
--echo #
197+
198+
# Note, the problem was not repeatable with a non-fresh connection.
199+
--connect (con1,127.0.0.1,root,,test)
200+
CREATE TABLE t1 (pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=MyISAM;
201+
INSERT INTO t1 VALUES ();
202+
INSERT INTO t1 VALUES ();
203+
SELECT DISTINCT DEFAULT (pk) FROM t1 GROUP BY RAND() WITH ROLLUP;
204+
--disconnect con1
205+
--connection default
206+
DROP TABLE t1;
207+
208+
--echo #
209+
--echo # End of 10.0 tests
210+
--echo #
211+

sql/item.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4326,6 +4326,10 @@ class Item_default_value : public Item_field
43264326
int save_in_field(Field *field_arg, bool no_conversions);
43274327
table_map used_tables() const { return (table_map)0L; }
43284328

4329+
Field *get_tmp_table_field() { return 0; }
4330+
Item *get_tmp_table_item(THD *thd) { return this; }
4331+
Item_field *field_for_view_update() { return 0; }
4332+
43294333
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
43304334
{
43314335
return (arg && arg->walk(processor, walk_subquery, args)) ||
@@ -4367,6 +4371,8 @@ class Item_insert_value : public Item_field
43674371
*/
43684372
table_map used_tables() const { return RAND_TABLE_BIT; }
43694373

4374+
Item_field *field_for_view_update() { return 0; }
4375+
43704376
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
43714377
{
43724378
return arg->walk(processor, walk_subquery, args) ||

0 commit comments

Comments
 (0)