Commit 91cd3c8f authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-25353 JSON_TABLE: Illegal mix of collations upon executing PS once, or SP/function twice.

Do not adapt to the argument charset anymore. Just use the utf8mb4 as
the default cherset.
parent 59f3399e
......@@ -1081,7 +1081,7 @@ SELECT col_varchar_key FROM JSON_TABLE(
(col_varchar_key VARCHAR(10) PATH "$.col_key")) AS innr1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 MATERIALIZED innr1 ALL NULL NULL NULL NULL 40 Table function: json_table
2 DEPENDENT SUBQUERY innr1 ALL NULL NULL NULL NULL 40 Table function: json_table; Using where
SELECT * FROM t1 WHERE col_varchar_key IN (
SELECT col_varchar_key FROM JSON_TABLE(
'[{"col_key": 1},{"col_key": 2}]', "$[*]" COLUMNS
......@@ -1094,8 +1094,7 @@ SELECT col_varchar_key FROM JSON_TABLE(
(col_varchar_key VARCHAR(10) PATH "$.col_key")) AS innr1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 13 func 1 Using where
2 MATERIALIZED innr1 ALL NULL NULL NULL NULL 40 Table function: json_table
1 PRIMARY innr1 ALL NULL NULL NULL NULL 40 Table function: json_table; Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
DROP TABLE t1;
#
# Bug#26711551: WL8867:CONDITIONAL JUMP IN JSON_TABLE_COLUMN::CLEANUP
......@@ -1422,7 +1421,7 @@ FROM JSON_TABLE('"test"', '$' COLUMNS(col VARCHAR(10) PATH '$')) AS a;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`col` varchar(10) CHARACTER SET ascii DEFAULT NULL
`col` varchar(10) CHARACTER SET utf8mb4 DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SET @@SESSION.collation_connection = latin1_bin;
CREATE TABLE t2 SELECT a.col
......@@ -1430,7 +1429,7 @@ FROM JSON_TABLE('"test"', '$' COLUMNS(col VARCHAR(10) PATH '$')) AS a;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`col` varchar(10) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL
`col` varchar(10) CHARACTER SET utf8mb4 DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1, t2;
SET @@SESSION.character_set_connection = DEFAULT;
......
......@@ -735,6 +735,18 @@ SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(
a TEXT EXISTS PATH '$', b VARCHAR(40) PATH '$', c BIT(60) PATH '$', d VARCHAR(60) PATH '$', e BIT(62) PATH '$',
f FOR ORDINALITY, g INT PATH '$', h VARCHAR(36) PATH '$', i DATE PATH '$', j CHAR(4) PATH '$'
)) AS jt;
--echo #
--echo # MDEV-25373 JSON_TABLE: Illegal mix of collations upon executing PS once, or SP/function twice.
--echo #
SELECT * FROM JSON_TABLE (CONVERT('[1,2]' USING koi8u), '$[*]' COLUMNS(a CHAR(8) PATH '$')) AS jt1 NATURAL JOIN JSON_TABLE (CONVERT('[2,3]' USING eucjpms), '$[*]' COLUMNS(a CHAR(8) PATH '$')) AS jt2;
PREPARE stmt1 FROM "
SELECT * FROM JSON_TABLE (CONVERT('[1,2]' USING koi8u), '$[*]' COLUMNS(a CHAR(8) PATH '$')) AS jt1 NATURAL JOIN JSON_TABLE (CONVERT('[2,3]' USING eucjpms), '$[*]' COLUMNS(a CHAR(8) PATH '$')) AS jt2;
";
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
--echo #
--echo # End of 10.6 tests
--echo #
......@@ -1077,40 +1077,6 @@ int Table_function_json_table::setup(THD *thd, TABLE_LIST *sql_table,
return TRUE;
}
{
/*
The m_json defines it's charset during the fix_fields stage so we're
changing the field's current charsets with it.
The complicated part is that the length of the field can be changed so
in this case we should move all the consequent fiedlds.
*/
List_iterator_fast<Json_table_column> jc_i(m_columns);
int field_offset= 0;
Field *f;
for (uint i= 0; (f= t->field[i]); i++)
{
Json_table_column *jc= jc_i++;
uint32 old_pack_length= f->pack_length();
f->change_charset(
jc->m_explicit_cs ? jc->m_explicit_cs : m_json->collation);
if (field_offset)
f->move_field(f->ptr + field_offset, f->null_ptr, f->null_bit);
f->reset();
field_offset= (field_offset + f->pack_length()) - old_pack_length;
/*
The m_field->charset is going to be reused if it's the prepared
statement running several times. So should restored the original
value.
*/
jc->m_field->charset= jc->m_explicit_cs;
}
store_record(t, s->default_values);
}
return FALSE;
}
......
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