Commit 3c86786f authored by Yuchen Pei's avatar Yuchen Pei

MDEV-34915 Sort output of session track system variable in mysqltest

Updated the output format too.

Before:

-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- autocommit
-- ON
-- time_zone
-- SYSTEM
-- character_set_client
-- latin1
-- character_set_connection
-- latin1
-- redirect_url
--

After:

-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- autocommit: ON
-- character_set_client: latin1
-- character_set_connection: latin1
-- redirect_url:
-- time_zone: SYSTEM
parent 0a5e4a01
...@@ -7898,6 +7898,20 @@ static const char *trking_info_desc[SESSION_TRACK_END + 1]= ...@@ -7898,6 +7898,20 @@ static const char *trking_info_desc[SESSION_TRACK_END + 1]=
/** /**
@brief Append state change information (received through Ok packet) to the output. @brief Append state change information (received through Ok packet) to the output.
@details The appended string is lines prefixed with "-- ". Only
tracking types with info sent from the server are displayed. For
each tracking type, the first line is the type name e.g.
"-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES".
The subsequent lines are the actual tracking info. When type is
SESSION_TRACK_SYSTEM_VARIABLES, the actual tracking info is a list
of name-value pairs of lines, sorted by name, e.g. if the info
received from the server is "autocommit=ON;time_zone=SYSTEM", the
corresponding string is
-- autocommit: ON
-- time_zone: SYSTEM
@param [in,out] ds Dynamic string to hold the content to be printed. @param [in,out] ds Dynamic string to hold the content to be printed.
@param [in] mysql Connection handle. @param [in] mysql Connection handle.
*/ */
...@@ -7905,11 +7919,16 @@ static const char *trking_info_desc[SESSION_TRACK_END + 1]= ...@@ -7905,11 +7919,16 @@ static const char *trking_info_desc[SESSION_TRACK_END + 1]=
static void append_session_track_info(DYNAMIC_STRING *ds, MYSQL *mysql) static void append_session_track_info(DYNAMIC_STRING *ds, MYSQL *mysql)
{ {
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
DYNAMIC_STRING ds_sort, *ds_type= NULL;
for (unsigned int type= SESSION_TRACK_BEGIN; type <= SESSION_TRACK_END; type++) for (unsigned int type= SESSION_TRACK_BEGIN; type <= SESSION_TRACK_END; type++)
{ {
const char *data; const char *data;
size_t data_length; size_t data_length;
/*
Append the tracking type line, if any corresponding tracking
info is received.
*/
if (!mysql_session_track_get_first(mysql, if (!mysql_session_track_get_first(mysql,
(enum_session_state_type) type, (enum_session_state_type) type,
&data, &data_length)) &data, &data_length))
...@@ -7925,26 +7944,56 @@ static void append_session_track_info(DYNAMIC_STRING *ds, MYSQL *mysql) ...@@ -7925,26 +7944,56 @@ static void append_session_track_info(DYNAMIC_STRING *ds, MYSQL *mysql)
DBUG_ASSERT(0); DBUG_ASSERT(0);
dynstr_append_mem(ds, STRING_WITH_LEN("Tracker???\n")); dynstr_append_mem(ds, STRING_WITH_LEN("Tracker???\n"));
} }
dynstr_append_mem(ds, STRING_WITH_LEN("-- "));
dynstr_append_mem(ds, data, data_length);
} }
else else
continue; continue;
/*
The remaining of this function: format and append the actual
tracking info.
*/
if (type == SESSION_TRACK_SYSTEM_VARIABLES)
{
/* Prepare a string to be sorted before being appended. */
if (init_dynamic_string(&ds_sort, "", 1024, 1024))
die("Out of memory");
ds_type= &ds_sort;
}
else
ds_type= ds;
/* Append the first piece of info */
dynstr_append_mem(ds_type, STRING_WITH_LEN("-- "));
dynstr_append_mem(ds_type, data, data_length);
/* Whether we are appending the value of a variable */
bool appending_value= type == SESSION_TRACK_SYSTEM_VARIABLES;
/* Append remaining pieces */
while (!mysql_session_track_get_next(mysql, while (!mysql_session_track_get_next(mysql,
(enum_session_state_type) type, (enum_session_state_type) type,
&data, &data_length)) &data, &data_length))
{ {
dynstr_append_mem(ds, STRING_WITH_LEN("\n-- ")); if (appending_value)
dynstr_append_mem(ds_type, STRING_WITH_LEN(": "));
else
dynstr_append_mem(ds_type, STRING_WITH_LEN("\n-- "));
appending_value= !appending_value && type == SESSION_TRACK_SYSTEM_VARIABLES;
if (data == NULL) if (data == NULL)
{ {
DBUG_ASSERT(data_length == 0); DBUG_ASSERT(data_length == 0);
dynstr_append_mem(ds, STRING_WITH_LEN("<NULL>")); dynstr_append_mem(ds_type, STRING_WITH_LEN("<NULL>"));
} }
else else
dynstr_append_mem(ds, data, data_length); dynstr_append_mem(ds_type, data, data_length);
}
DBUG_ASSERT(!appending_value);
if (type == SESSION_TRACK_SYSTEM_VARIABLES)
{
dynstr_append_mem(ds_type, STRING_WITH_LEN("\n"));
dynstr_append_sorted(ds, ds_type, false);
dynstr_append_mem(ds, STRING_WITH_LEN("\n"));
dynstr_free(&ds_sort);
} }
dynstr_append_mem(ds, STRING_WITH_LEN("\n\n")); else
dynstr_append_mem(ds, STRING_WITH_LEN("\n\n"));
} }
#endif /* EMBEDDED_LIBRARY */ #endif /* EMBEDDED_LIBRARY */
} }
...@@ -12018,7 +12067,8 @@ void replace_dynstr_append_uint(DYNAMIC_STRING *ds, uint val) ...@@ -12018,7 +12067,8 @@ void replace_dynstr_append_uint(DYNAMIC_STRING *ds, uint val)
/* /*
Build a list of pointer to each line in ds_input, sort Build a list of pointer to each line in ds_input, sort
the list and use the sorted list to append the strings the list and use the sorted list to append the strings
sorted to the output ds sorted to the output ds. The string ds_input needs to
end with a newline.
SYNOPSIS SYNOPSIS
dynstr_append_sorted() dynstr_append_sorted()
......
...@@ -6,26 +6,22 @@ SET @@session.session_track_system_variables='character_set_connection'; ...@@ -6,26 +6,22 @@ SET @@session.session_track_system_variables='character_set_connection';
# tracking info on # tracking info on
SET NAMES 'utf8'; SET NAMES 'utf8';
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- character_set_connection -- character_set_connection: utf8
-- utf8
SET NAMES 'big5'; SET NAMES 'big5';
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- character_set_connection -- character_set_connection: big5
-- big5
# tracking info on once # tracking info on once
SET NAMES 'utf8'; SET NAMES 'utf8';
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- character_set_connection -- character_set_connection: utf8
-- utf8
SET NAMES 'big5'; SET NAMES 'big5';
# tracking info on # tracking info on
SET NAMES 'utf8'; SET NAMES 'utf8';
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- character_set_connection -- character_set_connection: utf8
-- utf8
# tracking info off once # tracking info off once
SET NAMES 'big5'; SET NAMES 'big5';
...@@ -37,8 +33,7 @@ set @save_optimizer_switch=@@optimizer_switch; ...@@ -37,8 +33,7 @@ set @save_optimizer_switch=@@optimizer_switch;
SET @@session.session_track_system_variables='optimizer_switch'; SET @@session.session_track_system_variables='optimizer_switch';
set optimizer_switch='index_merge=off,index_merge_union=off,index_merge_sort_union=off,index_merge_intersection=off,index_merge_sort_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=on,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=on,mrr_cost_based=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=on,table_elimination=off,extended_keys=off,exists_to_in=off,orderby_uses_equalities=off,condition_pushdown_for_derived=off'; set optimizer_switch='index_merge=off,index_merge_union=off,index_merge_sort_union=off,index_merge_intersection=off,index_merge_sort_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=on,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=on,mrr_cost_based=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=on,table_elimination=off,extended_keys=off,exists_to_in=off,orderby_uses_equalities=off,condition_pushdown_for_derived=off';
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- optimizer_switch -- optimizer_switch: index_merge=off,index_merge_union=off,index_merge_sort_union=off,index_merge_intersection=off,index_merge_sort_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=on,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=on,mrr_cost_based=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=on,table_elimination=off,extended_keys=off,exists_to_in=off,orderby_uses_equalities=off,condition_pushdown_for_derived=off,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on,not_null_range_scan=off
-- index_merge=off,index_merge_union=off,index_merge_sort_union=off,index_merge_intersection=off,index_merge_sort_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=on,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=on,mrr_cost_based=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=on,table_elimination=off,extended_keys=off,exists_to_in=off,orderby_uses_equalities=off,condition_pushdown_for_derived=off,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on,not_null_range_scan=off
Warnings: Warnings:
Warning 1681 'engine_condition_pushdown=on' is deprecated and will be removed in a future release Warning 1681 'engine_condition_pushdown=on' is deprecated and will be removed in a future release
...@@ -71,13 +66,11 @@ ERROR HY000: Unknown system variable 'a' ...@@ -71,13 +66,11 @@ ERROR HY000: Unknown system variable 'a'
connect con,localhost,root,,test; connect con,localhost,root,,test;
SET NAMES 'utf8'; SET NAMES 'utf8';
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- character_set_connection -- character_set_connection: utf8
-- utf8
SET NAMES 'big5'; SET NAMES 'big5';
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- character_set_connection -- character_set_connection: big5
-- big5
select @@session_track_system_variables; select @@session_track_system_variables;
@@session_track_system_variables @@session_track_system_variables
......
...@@ -5,31 +5,26 @@ SET gtid_seq_no=1000; ...@@ -5,31 +5,26 @@ SET gtid_seq_no=1000;
SET @@session.session_track_system_variables='last_gtid'; SET @@session.session_track_system_variables='last_gtid';
create table t1 (a int) engine=innodb; create table t1 (a int) engine=innodb;
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- last_gtid -- last_gtid: 0-1-1000
-- 0-1-1000
select @@last_gtid; select @@last_gtid;
@@last_gtid @@last_gtid
0-1-1000 0-1-1000
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- last_gtid -- last_gtid: 0-1-1000
-- 0-1-1000
insert into t1 values (1); insert into t1 values (1);
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- last_gtid -- last_gtid: 0-1-1001
-- 0-1-1001
select @@last_gtid; select @@last_gtid;
@@last_gtid @@last_gtid
0-1-1001 0-1-1001
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- last_gtid -- last_gtid: 0-1-1001
-- 0-1-1001
drop table t1; drop table t1;
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES -- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- last_gtid -- last_gtid: 0-1-1002
-- 0-1-1002
reset master; reset master;
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