Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/mysql_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ typedef struct st_net {
unsigned char compress;
my_bool pkt_nr_can_be_reset;
my_bool using_proxy_protocol;
/* proxy protocol: real client address has connect errors to reset on login */
my_bool have_proxy_protocol_connect_errors;
/*
Pointer to query object in query cache, do not equal NULL (0) for
queries in cache that have not stored its results yet
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/main/mysql_client_test.result
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ SET @old_general_log= @@global.general_log;
SET @old_slow_query_log= @@global.slow_query_log;
call mtr.add_suppression(" Error reading file './client_test_db/test_frm_bug.frm'");
call mtr.add_suppression(" IP address .* could not be resolved");
call mtr.add_suppression("Aborted connection .* host: '192.0.2.50'");
call mtr.add_suppression("Aborted connection .* host: 'santa.claus.ipv4.example.com'");
ok

# cat MYSQL_TMP_DIR/test_wl4435.out.log
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/main/mysql_client_test.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ SET @old_slow_query_log= @@global.slow_query_log;

call mtr.add_suppression(" Error reading file './client_test_db/test_frm_bug.frm'");
call mtr.add_suppression(" IP address .* could not be resolved");
call mtr.add_suppression("Aborted connection .* host: '192.0.2.50'");
call mtr.add_suppression("Aborted connection .* host: 'santa.claus.ipv4.example.com'");

# We run with different binaries for normal and --embedded-server
#
Expand Down
30 changes: 24 additions & 6 deletions mysql-test/suite/json/r/json_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ from t1, json_table(t1.json, '$' columns (value varchar(32) PATH '$.value')) T;
show create table tj1;
Table Create Table
tj1 CREATE TABLE `tj1` (
`value` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL
`value` varchar(32) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t1;
drop table tj1;
Expand Down Expand Up @@ -1100,23 +1100,23 @@ name VARCHAR(10) PATH '$.name'
)
) AS jt;
collation(name)
utf8mb4_general_ci
latin1_swedish_ci
SELECT collation(name)
FROM json_table('[{"name":"Jeans"}]', '$[*]'
COLUMNS(
name VARCHAR(10) COLLATE DEFAULT PATH '$.name'
)
) AS jt;
collation(name)
utf8mb4_general_ci
latin1_swedish_ci
SELECT collation(name)
FROM json_table('[{"name":"Jeans"}]', '$[*]'
COLUMNS(
name VARCHAR(10) BINARY PATH '$.name'
)
) AS jt;
collation(name)
utf8mb4_bin
latin1_bin
CREATE VIEW v1 AS
SELECT *
FROM json_table('[{"name":"Jeans"}]', '$[*]'
Expand All @@ -1129,7 +1129,7 @@ View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `jt`.`name` AS `name` from JSON_TABLE('[{"name":"Jeans"}]', '$[*]' COLUMNS (`name` varchar(10) PATH '$.name')) `jt` latin1 latin1_swedish_ci
SELECT collation(name) FROM v1;
collation(name)
utf8mb4_general_ci
latin1_swedish_ci
DROP VIEW v1;
CREATE VIEW v1 AS
SELECT *
Expand All @@ -1143,7 +1143,7 @@ View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `jt`.`name` AS `name` from JSON_TABLE('[{"name":"Jeans"}]', '$[*]' COLUMNS (`name` varchar(10) PATH '$.name')) `jt` latin1 latin1_swedish_ci
SELECT collation(name) FROM v1;
collation(name)
utf8mb4_general_ci
latin1_swedish_ci
DROP VIEW v1;
CREATE VIEW v1 AS
SELECT *
Expand Down Expand Up @@ -1280,4 +1280,22 @@ Second Element {
"value": 2
}
DROP VIEW test_view;
#
# MDEV-36764: Unexpected collation when using json_table
#
CREATE DATABASE collation_testing CHARACTER SET='utf8mb4' COLLATE='utf8mb4_uca1400_ai_ci';
USE collation_testing;
CREATE TABLE table_with_longtext_column (column_with_json LONGTEXT);
INSERT INTO table_with_longtext_column VALUES ('[{"property": "value"}]');
SELECT COLLATION(column_with_json) FROM table_with_longtext_column;
COLLATION(column_with_json)
utf8mb4_uca1400_ai_ci
SELECT COLLATION(JSON_VALUE(column_with_json, "$.value")) FROM table_with_longtext_column;
COLLATION(JSON_VALUE(column_with_json, "$.value"))
utf8mb4_uca1400_ai_ci
SELECT COLLATION(virtual_table_from_json.property) FROM JSON_TABLE((SELECT column_with_json FROM table_with_longtext_column),'$[*]' COLUMNS (property varchar(100) path '$.property')) AS virtual_table_from_json;
COLLATION(virtual_table_from_json.property)
utf8mb4_uca1400_ai_ci
DROP TABLE table_with_longtext_column;
DROP DATABASE collation_testing;
# End of 10.11 test
9 changes: 5 additions & 4 deletions mysql-test/suite/json/r/json_table_mysql.result
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,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 DEPENDENT SUBQUERY innr1 ALL NULL NULL NULL NULL 40 Table function: json_table; Using where
2 MATERIALIZED innr1 ALL NULL NULL NULL NULL 40 Table function: json_table
SELECT * FROM t1 WHERE col_varchar_key IN (
SELECT col_varchar_key FROM JSON_TABLE(
'[{"col_key": 1},{"col_key": 2}]', "$[*]" COLUMNS
Expand All @@ -1136,7 +1136,8 @@ 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 innr1 ALL NULL NULL NULL NULL 40 Table function: json_table; Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
DROP TABLE t1;
#
# Bug#26711551: WL8867:CONDITIONAL JUMP IN JSON_TABLE_COLUMN::CLEANUP
Expand Down Expand Up @@ -1467,15 +1468,15 @@ 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 utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL
`col` varchar(10) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SET @@SESSION.collation_connection = latin1_bin;
CREATE TABLE t2 SELECT a.col
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 utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL
`col` varchar(10) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
DROP TABLE t1, t2;
SET @@SESSION.character_set_connection = DEFAULT;
Expand Down
18 changes: 18 additions & 0 deletions mysql-test/suite/json/t/json_table.test
Original file line number Diff line number Diff line change
Expand Up @@ -1103,4 +1103,22 @@ SELECT * FROM JSON_TABLE('

DROP VIEW test_view;


--echo #
--echo # MDEV-36764: Unexpected collation when using json_table
--echo #

CREATE DATABASE collation_testing CHARACTER SET='utf8mb4' COLLATE='utf8mb4_uca1400_ai_ci';
USE collation_testing;

CREATE TABLE table_with_longtext_column (column_with_json LONGTEXT);
INSERT INTO table_with_longtext_column VALUES ('[{"property": "value"}]');

SELECT COLLATION(column_with_json) FROM table_with_longtext_column;
SELECT COLLATION(JSON_VALUE(column_with_json, "$.value")) FROM table_with_longtext_column;
SELECT COLLATION(virtual_table_from_json.property) FROM JSON_TABLE((SELECT column_with_json FROM table_with_longtext_column),'$[*]' COLUMNS (property varchar(100) path '$.property')) AS virtual_table_from_json;

DROP TABLE table_with_longtext_column;
DROP DATABASE collation_testing;

--echo # End of 10.11 test
3 changes: 2 additions & 1 deletion sql/json_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ TABLE *Create_json_table::start(THD *thd,
TABLE_SHARE *share;
DBUG_ENTER("Create_json_table::start");

param->table_charset= thd->variables.collation_database;
param->tmp_name= "json";
if (!(table= Create_tmp_table::start(thd, param, table_alias)))
DBUG_RETURN(0);
Expand Down Expand Up @@ -758,7 +759,7 @@ bool Create_json_table::add_json_table_fields(THD *thd, TABLE *table,
uint fieldnr= 0;
MEM_ROOT *mem_root_save= thd->mem_root;
List_iterator_fast<Json_table_column> jc_i(jt->m_columns);
Column_derived_attributes da(&my_charset_utf8mb4_general_ci);
Column_derived_attributes da(share->table_charset);
DBUG_ENTER("add_json_table_fields");

thd->mem_root= &table->mem_root;
Expand Down
14 changes: 10 additions & 4 deletions sql/net_serv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ my_bool my_net_init(NET *net, Vio *vio, void *thd, uint my_flags)
net->last_errno=0;
net->pkt_nr_can_be_reset= 0;
net->using_proxy_protocol= 0;
net->have_proxy_protocol_connect_errors= 0;
net->thread_specific_malloc= MY_TEST(my_flags & MY_THREAD_SPECIFIC);
net->thd= 0;
#ifdef MYSQL_SERVER
Expand Down Expand Up @@ -219,6 +220,7 @@ void net_end(NET *net)
my_free(net->buff);
net->buff=0;
net->using_proxy_protocol= 0;
net->have_proxy_protocol_connect_errors= 0;
DBUG_VOID_RETURN;
}

Expand Down Expand Up @@ -958,11 +960,15 @@ static handle_proxy_header_result handle_proxy_header(NET *net)
/* proxy header indicates LOCAL connection, no action necessary */
return RETRY;
/* Change peer address in THD and ACL structures.*/
uint host_errors;
uint host_errors= 0;
net->using_proxy_protocol= 1;
return (handle_proxy_header_result)thd_set_peer_addr(thd,
&(peer_info.peer_addr), NULL, peer_info.port,
false, &host_errors);
handle_proxy_header_result res=
(handle_proxy_header_result) thd_set_peer_addr(thd, &(peer_info.peer_addr),
NULL, peer_info.port, false, &host_errors);
/* Record the real client's connect errors for the login-success reset. */
if (host_errors)
net->have_proxy_protocol_connect_errors= 1;
return res;
#endif
}

Expand Down
16 changes: 10 additions & 6 deletions sql/sql_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,9 @@ static int check_connection(THD *thd)
uint connect_errors= 0;
int auth_rc;
NET *net= &thd->net;
/* Socket peer IP address, the proxy host under PROXY protocol */
char ip[NI_MAXHOST];
ip[0]= 0;

DBUG_PRINT("info",
("New connection received on %s", vio_description(net->vio)));
Expand All @@ -1035,7 +1038,6 @@ static int check_connection(THD *thd)
if (!thd->main_security_ctx.host) // If TCP/IP connection
{
my_bool peer_rc;
char ip[NI_MAXHOST];
uint16 peer_port;

peer_rc= vio_peer_addr(net->vio, ip, &peer_port, NI_MAXHOST);
Expand Down Expand Up @@ -1153,14 +1155,16 @@ static int check_connection(THD *thd)
}

auth_rc= acl_authenticate(thd, 0);
if (auth_rc == 0 && connect_errors != 0)
if (auth_rc == 0)
{
/*
A client connection from this IP was successful,
after some previous failures.
Reset the connection error counter.
Successful login resets connect errors, for both the socket peer and,
under PROXY protocol, the real client - each by its own error count.
*/
reset_host_connect_errors(thd->main_security_ctx.ip);
if (connect_errors)
reset_host_connect_errors(ip);
if (net->have_proxy_protocol_connect_errors)
reset_host_connect_errors(thd->main_security_ctx.ip);
}

return auth_rc;
Expand Down
Loading