Skip to content

Commit cdeb071

Browse files
Sergey GlukhovSergey Glukhov
authored andcommitted
Bug#52120 create view cause Assertion failed: 0, file .\item_subselect.cc, line 817
We should disable const subselect item evaluation because subselect transformation does not happen in view_prepare_mode and thus val_...() methods can not be called. --BZR-- revision-id: [email protected] property-branch-nick: mysql-5.1-bugteam property-file-info: ld7:file_id69:sp1f-ctype_ucs.result-20030916112630-sohywipskzw3eqmbhfsqxqjteoun6t2g7:message10:test case property-file-info: 4:path29:mysql-test/r/ctype_ucs.resulted7:file_id64:sp1f-view.result-20040715221517-nqk3l34grrhprjiitidhfjyjqlgh6a5v7:message10:test case property-file-info: 4:path24:mysql-test/r/view.resulted7:file_id67:sp1f-ctype_ucs.test-20030916112631-7diba44oovwv3h5kqbswfqbveczwbrxv7:message10:test case property-file-info: 4:path27:mysql-test/t/ctype_ucs.tested7:file_id62:sp1f-view.test-20040715221517-2kxb7l4itrpl4mw266xe5gby4vftru3z7:message10:test case property-file-info: 4:path22:mysql-test/t/view.tested7:file_id60:sp1f-item.cc-19700101030959-u7hxqopwpfly4kf5ctlyk2dvrq4l3dhn7:message63:disabled const subselect item evaluation in property-file-info: view prepare mode. property-file-info: 4:path11:sql/item.cced7:file_id70:sp1f-item_subselect.cc-20020512204640-qep43aqhsfrwkqmrobni6czc3fqj36oo7:message104:added Item_subselect::safe_charset_converter which property-file-info: prevents const item evaluation in view prepare mode. property-file-info: 4:path21:sql/item_subselect.cced7:file_id69:sp1f-item_subselect.h-20020512204640-qdg77wil56cxyhtc2bjjdrppxq3wqgh37:message104:added Item_subselect::safe_charset_converter which property-file-info: prevents const item evaluation in view prepare mode. property-file-info: 4:path20:sql/item_subselect.hee testament3-sha1: e586f37101ccc723d9883ff8806b7d34052a817d
1 parent 891e446 commit cdeb071

7 files changed

Lines changed: 60 additions & 1 deletion

File tree

mysql-test/r/ctype_ucs.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,4 +1230,12 @@ SELECT HEX(DAYNAME(19700101));
12301230
HEX(DAYNAME(19700101))
12311231
0427043504420432043504400433
12321232
SET character_set_connection=latin1;
1233+
#
1234+
# Bug#52120 create view cause Assertion failed: 0, file .\item_subselect.cc, line 817
1235+
#
1236+
CREATE TABLE t1 (a CHAR(1) CHARSET ascii, b CHAR(1) CHARSET latin1);
1237+
CREATE VIEW v1 AS SELECT 1 from t1
1238+
WHERE t1.b <=> (SELECT a FROM t1 WHERE a < SOME(SELECT '1'));
1239+
DROP VIEW v1;
1240+
DROP TABLE t1;
12331241
End of 5.0 tests

mysql-test/r/view.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3874,6 +3874,14 @@ CREATE VIEW v1 AS SELECT 1 FROM t1 WHERE
38743874
ROW(1,1) >= ROW(1, (SELECT 1 FROM t1 WHERE f1 >= ANY ( SELECT '1' )));
38753875
DROP VIEW v1;
38763876
DROP TABLE t1;
3877+
#
3878+
# Bug#52120 create view cause Assertion failed: 0, file .\item_subselect.cc, line 817
3879+
#
3880+
CREATE TABLE t1 (a CHAR(1) CHARSET latin1, b CHAR(1) CHARSET utf8);
3881+
CREATE VIEW v1 AS SELECT 1 from t1
3882+
WHERE t1.b <=> (SELECT a FROM t1 WHERE a < SOME(SELECT '1'));
3883+
DROP VIEW v1;
3884+
DROP TABLE t1;
38773885
# -----------------------------------------------------------------
38783886
# -- End of 5.1 tests.
38793887
# -----------------------------------------------------------------

mysql-test/t/ctype_ucs.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,4 +732,13 @@ SELECT HEX(MONTHNAME(19700101));
732732
SELECT HEX(DAYNAME(19700101));
733733
SET character_set_connection=latin1;
734734

735+
--echo #
736+
--echo # Bug#52120 create view cause Assertion failed: 0, file .\item_subselect.cc, line 817
737+
--echo #
738+
CREATE TABLE t1 (a CHAR(1) CHARSET ascii, b CHAR(1) CHARSET latin1);
739+
CREATE VIEW v1 AS SELECT 1 from t1
740+
WHERE t1.b <=> (SELECT a FROM t1 WHERE a < SOME(SELECT '1'));
741+
DROP VIEW v1;
742+
DROP TABLE t1;
743+
735744
--echo End of 5.0 tests

mysql-test/t/view.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,6 +3916,15 @@ ROW(1,1) >= ROW(1, (SELECT 1 FROM t1 WHERE f1 >= ANY ( SELECT '1' )));
39163916
DROP VIEW v1;
39173917
DROP TABLE t1;
39183918

3919+
--echo #
3920+
--echo # Bug#52120 create view cause Assertion failed: 0, file .\item_subselect.cc, line 817
3921+
--echo #
3922+
CREATE TABLE t1 (a CHAR(1) CHARSET latin1, b CHAR(1) CHARSET utf8);
3923+
CREATE VIEW v1 AS SELECT 1 from t1
3924+
WHERE t1.b <=> (SELECT a FROM t1 WHERE a < SOME(SELECT '1'));
3925+
DROP VIEW v1;
3926+
DROP TABLE t1;
3927+
39193928
--echo # -----------------------------------------------------------------
39203929
--echo # -- End of 5.1 tests.
39213930
--echo # -----------------------------------------------------------------

sql/item.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,16 @@ bool agg_item_set_converter(DTCollation &coll, const char *fname,
17131713

17141714
if (!(conv= (*arg)->safe_charset_converter(coll.collation)) &&
17151715
((*arg)->collation.repertoire == MY_REPERTOIRE_ASCII))
1716-
conv= new Item_func_conv_charset(*arg, coll.collation, 1);
1716+
{
1717+
/*
1718+
We should disable const subselect item evaluation because
1719+
subselect transformation does not happen in view_prepare_mode
1720+
and thus val_...() methods can not be called for const items.
1721+
*/
1722+
bool resolve_const= ((*arg)->type() == Item::SUBSELECT_ITEM &&
1723+
thd->lex->view_prepare_mode) ? FALSE : TRUE;
1724+
conv= new Item_func_conv_charset(*arg, coll.collation, resolve_const);
1725+
}
17171726

17181727
if (!conv)
17191728
{

sql/item_subselect.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ void Item_subselect::cleanup()
122122
DBUG_VOID_RETURN;
123123
}
124124

125+
126+
/*
127+
We cannot use generic Item::safe_charset_converter() because
128+
Subselect transformation does not happen in view_prepare_mode
129+
and thus we can not evaluate val_...() for const items.
130+
*/
131+
132+
Item *Item_subselect::safe_charset_converter(CHARSET_INFO *tocs)
133+
{
134+
Item_func_conv_charset *conv=
135+
new Item_func_conv_charset(this, tocs, thd->lex->view_prepare_mode ? 0 : 1);
136+
return conv->safe ? conv : NULL;
137+
}
138+
139+
125140
void Item_singlerow_subselect::cleanup()
126141
{
127142
DBUG_ENTER("Item_singlerow_subselect::cleanup");

sql/item_subselect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class Item_subselect :public Item_result_field
126126
virtual void reset_value_registration() {}
127127
enum_parsing_place place() { return parsing_place; }
128128
bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
129+
Item *safe_charset_converter(CHARSET_INFO *tocs);
129130

130131
/**
131132
Get the SELECT_LEX structure associated with this Item.

0 commit comments

Comments
 (0)