@@ -70,7 +70,6 @@ class Session_sysvars_tracker : public State_tracker
70
70
71
71
class vars_list
72
72
{
73
- private:
74
73
/* *
75
74
Registered system variables. (@@session_track_system_variables)
76
75
A hash to store the name of all the system variables specified by the
@@ -101,12 +100,20 @@ class Session_sysvars_tracker : public State_tracker
101
100
}
102
101
}
103
102
104
- uchar* search (const sys_var *svar)
103
+ sysvar_node_st * search (const sys_var *svar)
105
104
{
106
- return (my_hash_search (&m_registered_sysvars, (const uchar *)&svar,
107
- sizeof (sys_var *)));
105
+ return reinterpret_cast <sysvar_node_st*>(
106
+ my_hash_search (&m_registered_sysvars,
107
+ reinterpret_cast <const uchar*>(&svar),
108
+ sizeof (sys_var*)));
108
109
}
109
110
111
+ sysvar_node_st *at (ulong i)
112
+ {
113
+ DBUG_ASSERT (i < m_registered_sysvars.records );
114
+ return reinterpret_cast <sysvar_node_st*>(
115
+ my_hash_element (&m_registered_sysvars, i));
116
+ }
110
117
public:
111
118
vars_list () :
112
119
buffer_length (0 )
@@ -129,22 +136,21 @@ class Session_sysvars_tracker : public State_tracker
129
136
}
130
137
}
131
138
132
- uchar* insert_or_search ( sysvar_node_st *node, const sys_var *svar)
139
+ sysvar_node_st *insert_or_search ( const sys_var *svar)
133
140
{
134
- uchar *res;
135
- res= search (svar);
141
+ sysvar_node_st *res= search (svar);
136
142
if (!res)
137
143
{
138
144
if (track_all)
139
145
{
140
- insert (node, svar, m_mem_flag );
146
+ insert (svar);
141
147
return search (svar);
142
148
}
143
149
}
144
150
return res;
145
151
}
146
152
147
- bool insert (sysvar_node_st *node, const sys_var *svar, myf mem_flag );
153
+ bool insert (const sys_var *svar);
148
154
void reinit ();
149
155
void reset ();
150
156
inline bool is_enabled ()
@@ -218,11 +224,6 @@ class Session_sysvars_tracker : public State_tracker
218
224
static uchar *sysvars_get_key (const char *entry, size_t *length,
219
225
my_bool not_used __attribute__ ((unused)));
220
226
221
- // hash iterators
222
- static my_bool name_array_filler (void *ptr, void *data_ptr);
223
- static my_bool store_variable (void *ptr, void *data_ptr);
224
- static my_bool reset_variable (void *ptr, void *data_ptr);
225
-
226
227
static bool check_var_list (THD *thd, LEX_STRING var_list, bool throw_error,
227
228
CHARSET_INFO *char_set, bool take_mutex);
228
229
};
@@ -313,25 +314,20 @@ void Session_sysvars_tracker::vars_list::copy(vars_list* from, THD *thd)
313
314
/* *
314
315
Inserts the variable to be tracked into m_registered_sysvars hash.
315
316
316
- @param node Node to be inserted.
317
317
@param svar address of the system variable
318
318
319
319
@retval false success
320
320
@retval true error
321
321
*/
322
322
323
- bool Session_sysvars_tracker::vars_list::insert (sysvar_node_st *node,
324
- const sys_var *svar,
325
- myf mem_flag)
323
+ bool Session_sysvars_tracker::vars_list::insert (const sys_var *svar)
326
324
{
327
- if (!node)
325
+ sysvar_node_st *node;
326
+ if (!(node= (sysvar_node_st *) my_malloc (sizeof (sysvar_node_st),
327
+ MYF (MY_WME | m_mem_flag))))
328
328
{
329
- if (!(node= (sysvar_node_st *) my_malloc (sizeof (sysvar_node_st),
330
- MYF (MY_WME | mem_flag))))
331
- {
332
- reinit ();
333
- return true ;
334
- }
329
+ reinit ();
330
+ return true ;
335
331
}
336
332
337
333
node->m_svar = (sys_var *)svar;
@@ -433,7 +429,7 @@ bool Session_sysvars_tracker::vars_list::parse_var_list(THD *thd,
433
429
else if ((svar=
434
430
find_sys_var_ex (thd, var.str , var.length , throw_error, true )))
435
431
{
436
- if (insert (NULL , svar, m_mem_flag ) == TRUE )
432
+ if (insert (svar) == TRUE )
437
433
goto error;
438
434
}
439
435
else if (throw_error && thd)
@@ -536,24 +532,6 @@ bool Session_sysvars_tracker::check_var_list(THD *thd,
536
532
return false ;
537
533
}
538
534
539
- struct name_array_filler_data
540
- {
541
- LEX_CSTRING **names;
542
- uint idx;
543
-
544
- };
545
-
546
- /* * Collects variable references into array */
547
- my_bool Session_sysvars_tracker::name_array_filler (void *ptr,
548
- void *data_ptr)
549
- {
550
- Session_sysvars_tracker::sysvar_node_st *node=
551
- (Session_sysvars_tracker::sysvar_node_st *)ptr;
552
- name_array_filler_data *data= (struct name_array_filler_data *)data_ptr;
553
- if (*node->test_load )
554
- data->names [data->idx ++]= &node->m_svar ->name ;
555
- return FALSE ;
556
- }
557
535
558
536
/* Sorts variable references array */
559
537
static int name_array_sorter (const void *a, const void *b)
@@ -573,7 +551,8 @@ static int name_array_sorter(const void *a, const void *b)
573
551
bool Session_sysvars_tracker::vars_list::construct_var_list (char *buf,
574
552
size_t buf_len)
575
553
{
576
- struct name_array_filler_data data;
554
+ LEX_CSTRING **names;
555
+ uint idx;
577
556
size_t left= buf_len;
578
557
size_t names_size= m_registered_sysvars.records * sizeof (LEX_CSTRING *);
579
558
const char separator= ' ,' ;
@@ -596,16 +575,19 @@ bool Session_sysvars_tracker::vars_list::construct_var_list(char *buf,
596
575
return false ;
597
576
}
598
577
599
- data.names = (LEX_CSTRING**)my_safe_alloca (names_size);
600
-
601
- if (unlikely (!data.names ))
578
+ if (unlikely (!(names= (LEX_CSTRING**) my_safe_alloca (names_size))))
602
579
return true ;
603
580
604
- data. idx = 0 ;
581
+ idx= 0 ;
605
582
606
583
mysql_mutex_lock (&LOCK_plugin);
607
- my_hash_iterate (&m_registered_sysvars, &name_array_filler, &data);
608
- DBUG_ASSERT (data.idx <= m_registered_sysvars.records );
584
+ for (ulong i= 0 ; i < m_registered_sysvars.records ; i++)
585
+ {
586
+ sysvar_node_st *node= at (i);
587
+ if (*node->test_load )
588
+ names[idx++]= &node->m_svar ->name ;
589
+ }
590
+ DBUG_ASSERT (idx <= m_registered_sysvars.records );
609
591
610
592
/*
611
593
We check number of records again here because number of variables
@@ -618,17 +600,16 @@ bool Session_sysvars_tracker::vars_list::construct_var_list(char *buf,
618
600
return false ;
619
601
}
620
602
621
- my_qsort (data.names , data.idx , sizeof (LEX_CSTRING *),
622
- &name_array_sorter);
603
+ my_qsort (names, idx, sizeof (LEX_CSTRING*), &name_array_sorter);
623
604
624
- for (uint i= 0 ; i < data. idx ; i++)
605
+ for (uint i= 0 ; i < idx; i++)
625
606
{
626
- LEX_CSTRING *nm= data. names [i];
607
+ LEX_CSTRING *nm= names[i];
627
608
size_t ln= nm->length + 1 ;
628
609
if (ln > left)
629
610
{
630
611
mysql_mutex_unlock (&LOCK_plugin);
631
- my_safe_afree (data. names , names_size);
612
+ my_safe_afree (names, names_size);
632
613
return true ;
633
614
}
634
615
memcpy (buf, nm->str , nm->length );
@@ -639,7 +620,7 @@ bool Session_sysvars_tracker::vars_list::construct_var_list(char *buf,
639
620
mysql_mutex_unlock (&LOCK_plugin);
640
621
641
622
buf--; buf[0 ]= ' \0 ' ;
642
- my_safe_afree (data. names , names_size);
623
+ my_safe_afree (names, names_size);
643
624
644
625
return false ;
645
626
}
@@ -724,24 +705,15 @@ bool Session_sysvars_tracker::update(THD *thd, set_var *var)
724
705
}
725
706
726
707
727
- /*
728
- Function and structure to support storing variables from hash to the buffer.
729
- */
730
-
731
- struct st_store_variable_param
732
- {
733
- THD *thd;
734
- String *buf;
735
- };
736
-
737
- my_bool Session_sysvars_tracker::store_variable (void *ptr, void *data_ptr)
708
+ bool Session_sysvars_tracker::vars_list::store (THD *thd, String *buf)
738
709
{
739
- Session_sysvars_tracker::sysvar_node_st *node=
740
- (Session_sysvars_tracker::sysvar_node_st *)ptr;
741
- if (node->m_changed )
710
+ for (ulong i= 0 ; i < m_registered_sysvars.records ; i++)
742
711
{
743
- THD *thd= ((st_store_variable_param *)data_ptr)->thd ;
744
- String *buf= ((st_store_variable_param *)data_ptr)->buf ;
712
+ sysvar_node_st *node= at (i);
713
+
714
+ if (!node->m_changed )
715
+ continue ;
716
+
745
717
char val_buf[SHOW_VAR_FUNC_BUFF_SIZE];
746
718
SHOW_VAR show;
747
719
CHARSET_INFO *charset;
@@ -750,7 +722,7 @@ my_bool Session_sysvars_tracker::store_variable(void *ptr, void *data_ptr)
750
722
if (!*node->test_load )
751
723
{
752
724
mysql_mutex_unlock (&LOCK_plugin);
753
- return false ;
725
+ continue ;
754
726
}
755
727
sys_var *svar= node->m_svar ;
756
728
bool is_plugin= svar->cast_pluginvar ();
@@ -795,11 +767,6 @@ my_bool Session_sysvars_tracker::store_variable(void *ptr, void *data_ptr)
795
767
return false ;
796
768
}
797
769
798
- bool Session_sysvars_tracker::vars_list::store (THD *thd, String *buf)
799
- {
800
- st_store_variable_param data= {thd, buf};
801
- return my_hash_iterate (&m_registered_sysvars, &store_variable, &data);
802
- }
803
770
804
771
/* *
805
772
Store the data for changed system variables in the specified buffer.
@@ -836,14 +803,13 @@ bool Session_sysvars_tracker::store(THD *thd, String *buf)
836
803
void Session_sysvars_tracker::mark_as_changed (THD *thd,
837
804
LEX_CSTRING *var)
838
805
{
839
- sysvar_node_st *node= NULL ;
806
+ sysvar_node_st *node;
840
807
sys_var *svar= (sys_var *)var;
841
808
/*
842
809
Check if the specified system variable is being tracked, if so
843
810
mark it as changed and also set the class's m_changed flag.
844
811
*/
845
- if (orig_list->is_enabled () &&
846
- (node= (sysvar_node_st *) (orig_list->insert_or_search (node, svar))))
812
+ if (orig_list->is_enabled () && (node= orig_list->insert_or_search (svar)))
847
813
{
848
814
node->m_changed = true ;
849
815
State_tracker::mark_as_changed (thd, var);
@@ -870,18 +836,10 @@ uchar *Session_sysvars_tracker::sysvars_get_key(const char *entry,
870
836
}
871
837
872
838
873
- /* Function to support resetting hash nodes for the variables */
874
-
875
- my_bool Session_sysvars_tracker::reset_variable (void *ptr,
876
- void *data_ptr)
877
- {
878
- ((Session_sysvars_tracker::sysvar_node_st *)ptr)->m_changed = false ;
879
- return false ;
880
- }
881
-
882
839
void Session_sysvars_tracker::vars_list::reset ()
883
840
{
884
- my_hash_iterate (&m_registered_sysvars, &reset_variable, NULL );
841
+ for (ulong i= 0 ; i < m_registered_sysvars.records ; i++)
842
+ at (i)->m_changed = false ;
885
843
}
886
844
887
845
static Session_sysvars_tracker* sysvar_tracker (THD *thd)
0 commit comments