Loading mysql-test/r/view.result +14 −0 Original line number Diff line number Diff line Loading @@ -1940,3 +1940,17 @@ s1 s2 DROP PROCEDURE p1; DROP VIEW v1; DROP TABLE t1; CREATE TABLE t1 (f1 char) ENGINE = innodb; INSERT INTO t1 VALUES ('A'); CREATE VIEW v1 AS SELECT * FROM t1; INSERT INTO t1 VALUES('B'); SELECT * FROM v1; f1 A B SELECT * FROM t1; f1 A B DROP VIEW v1; DROP TABLE t1; mysql-test/t/view.test +15 −0 Original line number Diff line number Diff line Loading @@ -1778,3 +1778,18 @@ CALL p1(); DROP PROCEDURE p1; DROP VIEW v1; DROP TABLE t1; # # Test for bug #11771: wrong query_id in SELECT * FROM <view> # CREATE TABLE t1 (f1 char) ENGINE = innodb; INSERT INTO t1 VALUES ('A'); CREATE VIEW v1 AS SELECT * FROM t1; INSERT INTO t1 VALUES('B'); SELECT * FROM v1; SELECT * FROM t1; DROP VIEW v1; DROP TABLE t1; sql/item.h +8 −0 Original line number Diff line number Diff line Loading @@ -641,6 +641,7 @@ class Item { virtual bool cleanup_processor(byte *arg); virtual bool collect_item_field_processor(byte * arg) { return 0; } virtual bool change_context_processor(byte *context) { return 0; } virtual bool reset_query_id_processor(byte *query_id) { return 0; } virtual Item *equal_fields_propagator(byte * arg) { return this; } virtual Item *set_no_const_sub(byte *arg) { return this; } Loading Loading @@ -895,6 +896,13 @@ class Item_field :public Item_ident bool is_null() { return field->is_null(); } Item *get_tmp_table_item(THD *thd); bool collect_item_field_processor(byte * arg); bool reset_query_id_processor(byte *arg) { field->query_id= *((query_id_t *) arg); if (result_field) result_field->query_id= field->query_id; return 0; } void cleanup(); Item_equal *find_item_equal(COND_EQUAL *cond_equal); Item *equal_fields_propagator(byte *arg); Loading sql/sql_base.cc +6 −0 Original line number Diff line number Diff line Loading @@ -3495,6 +3495,12 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, field->query_id=thd->query_id; table->used_keys.intersect(field->part_of_key); } else { Item *item= ((Field_iterator_view *) iterator)->item(); item->walk(&Item::reset_query_id_processor, (byte *)(&thd->query_id)); } } /* All fields are used in case if usual tables (in case of view used Loading Loading
mysql-test/r/view.result +14 −0 Original line number Diff line number Diff line Loading @@ -1940,3 +1940,17 @@ s1 s2 DROP PROCEDURE p1; DROP VIEW v1; DROP TABLE t1; CREATE TABLE t1 (f1 char) ENGINE = innodb; INSERT INTO t1 VALUES ('A'); CREATE VIEW v1 AS SELECT * FROM t1; INSERT INTO t1 VALUES('B'); SELECT * FROM v1; f1 A B SELECT * FROM t1; f1 A B DROP VIEW v1; DROP TABLE t1;
mysql-test/t/view.test +15 −0 Original line number Diff line number Diff line Loading @@ -1778,3 +1778,18 @@ CALL p1(); DROP PROCEDURE p1; DROP VIEW v1; DROP TABLE t1; # # Test for bug #11771: wrong query_id in SELECT * FROM <view> # CREATE TABLE t1 (f1 char) ENGINE = innodb; INSERT INTO t1 VALUES ('A'); CREATE VIEW v1 AS SELECT * FROM t1; INSERT INTO t1 VALUES('B'); SELECT * FROM v1; SELECT * FROM t1; DROP VIEW v1; DROP TABLE t1;
sql/item.h +8 −0 Original line number Diff line number Diff line Loading @@ -641,6 +641,7 @@ class Item { virtual bool cleanup_processor(byte *arg); virtual bool collect_item_field_processor(byte * arg) { return 0; } virtual bool change_context_processor(byte *context) { return 0; } virtual bool reset_query_id_processor(byte *query_id) { return 0; } virtual Item *equal_fields_propagator(byte * arg) { return this; } virtual Item *set_no_const_sub(byte *arg) { return this; } Loading Loading @@ -895,6 +896,13 @@ class Item_field :public Item_ident bool is_null() { return field->is_null(); } Item *get_tmp_table_item(THD *thd); bool collect_item_field_processor(byte * arg); bool reset_query_id_processor(byte *arg) { field->query_id= *((query_id_t *) arg); if (result_field) result_field->query_id= field->query_id; return 0; } void cleanup(); Item_equal *find_item_equal(COND_EQUAL *cond_equal); Item *equal_fields_propagator(byte *arg); Loading
sql/sql_base.cc +6 −0 Original line number Diff line number Diff line Loading @@ -3495,6 +3495,12 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, field->query_id=thd->query_id; table->used_keys.intersect(field->part_of_key); } else { Item *item= ((Field_iterator_view *) iterator)->item(); item->walk(&Item::reset_query_id_processor, (byte *)(&thd->query_id)); } } /* All fields are used in case if usual tables (in case of view used Loading