@@ -404,13 +404,14 @@ bool mysqld_show_privileges(THD *thd)
404
404
405
405
find_files_result
406
406
find_files (THD *thd, List<LEX_STRING> *files, const char *db,
407
- const char *path, const char *wild, bool dir)
407
+ const char *path, const char *wild, bool dir, MEM_ROOT *tmp_mem_root )
408
408
{
409
409
uint i;
410
410
char *ext;
411
411
MY_DIR *dirp;
412
412
FILEINFO *file;
413
413
LEX_STRING *file_name= 0 ;
414
+ MEM_ROOT **root_ptr= NULL , *old_root= NULL ;
414
415
uint file_name_len;
415
416
#ifndef NO_EMBEDDED_ACCESS_CHECKS
416
417
uint col_access=thd->col_access ;
@@ -440,6 +441,13 @@ find_files(THD *thd, List<LEX_STRING> *files, const char *db,
440
441
DBUG_RETURN (FIND_FILES_DIR);
441
442
}
442
443
444
+ if (tmp_mem_root)
445
+ {
446
+ root_ptr= my_pthread_getspecific_ptr (MEM_ROOT**, THR_MALLOC);
447
+ old_root= *root_ptr;
448
+ *root_ptr= tmp_mem_root;
449
+ }
450
+
443
451
for (i=0 ; i < (uint) dirp->number_off_files ; i++)
444
452
{
445
453
char uname[NAME_LEN + 1 ]; /* Unencoded name */
@@ -519,8 +527,11 @@ find_files(THD *thd, List<LEX_STRING> *files, const char *db,
519
527
continue ;
520
528
}
521
529
#endif
522
- if (!(file_name=
523
- thd->make_lex_string (file_name, uname, file_name_len, TRUE )) ||
530
+ if (!(file_name= tmp_mem_root ?
531
+ make_lex_string_root (tmp_mem_root, file_name, uname,
532
+ file_name_len, TRUE ) :
533
+ thd->make_lex_string (file_name, uname,
534
+ file_name_len, TRUE )) ||
524
535
files->push_back (file_name))
525
536
{
526
537
my_dirend (dirp);
@@ -532,6 +543,9 @@ find_files(THD *thd, List<LEX_STRING> *files, const char *db,
532
543
533
544
(void ) ha_find_files (thd, db, path, wild, dir, files);
534
545
546
+ if (tmp_mem_root)
547
+ *root_ptr= old_root;
548
+
535
549
DBUG_RETURN (FIND_FILES_OK);
536
550
}
537
551
@@ -2882,7 +2896,7 @@ enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table)
2882
2896
2883
2897
int make_db_list (THD *thd, List<LEX_STRING> *files,
2884
2898
LOOKUP_FIELD_VALUES *lookup_field_vals,
2885
- bool *with_i_schema)
2899
+ bool *with_i_schema, MEM_ROOT *tmp_mem_root )
2886
2900
{
2887
2901
LEX_STRING *i_s_name_copy= 0 ;
2888
2902
i_s_name_copy= thd->make_lex_string (i_s_name_copy,
@@ -2906,7 +2920,8 @@ int make_db_list(THD *thd, List<LEX_STRING> *files,
2906
2920
return 1 ;
2907
2921
}
2908
2922
return (find_files (thd, files, NullS, mysql_data_home,
2909
- lookup_field_vals->db_value .str , 1 ) != FIND_FILES_OK);
2923
+ lookup_field_vals->db_value .str , 1 , tmp_mem_root) !=
2924
+ FIND_FILES_OK);
2910
2925
}
2911
2926
2912
2927
@@ -2948,7 +2963,7 @@ int make_db_list(THD *thd, List<LEX_STRING> *files,
2948
2963
return 1 ;
2949
2964
*with_i_schema= 1 ;
2950
2965
return (find_files (thd, files, NullS,
2951
- mysql_data_home, NullS, 1 ) != FIND_FILES_OK);
2966
+ mysql_data_home, NullS, 1 , tmp_mem_root ) != FIND_FILES_OK);
2952
2967
}
2953
2968
2954
2969
@@ -3056,7 +3071,8 @@ int schema_tables_add(THD *thd, List<LEX_STRING> *files, const char *wild)
3056
3071
static int
3057
3072
make_table_name_list (THD *thd, List<LEX_STRING> *table_names, LEX *lex,
3058
3073
LOOKUP_FIELD_VALUES *lookup_field_vals,
3059
- bool with_i_schema, LEX_STRING *db_name)
3074
+ bool with_i_schema, LEX_STRING *db_name,
3075
+ MEM_ROOT *tmp_mem_root)
3060
3076
{
3061
3077
char path[FN_REFLEN + 1 ];
3062
3078
build_table_filename (path, sizeof (path) - 1 , db_name->str , " " , " " , 0 );
@@ -3110,7 +3126,8 @@ make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
3110
3126
lookup_field_vals->table_value .str ));
3111
3127
3112
3128
find_files_result res= find_files (thd, table_names, db_name->str , path,
3113
- lookup_field_vals->table_value .str , 0 );
3129
+ lookup_field_vals->table_value .str , 0 ,
3130
+ tmp_mem_root);
3114
3131
if (res != FIND_FILES_OK)
3115
3132
{
3116
3133
/*
@@ -3776,6 +3793,9 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
3776
3793
bool can_deadlock;
3777
3794
DBUG_ENTER (" get_all_tables" );
3778
3795
3796
+ MEM_ROOT tmp_mem_root;
3797
+ init_sql_alloc (&tmp_mem_root, TABLE_ALLOC_BLOCK_SIZE, 0 );
3798
+
3779
3799
/*
3780
3800
In cases when SELECT from I_S table being filled by this call is
3781
3801
part of statement which also uses other tables or is being executed
@@ -3867,7 +3887,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
3867
3887
goto err;
3868
3888
}
3869
3889
3870
- if (make_db_list (thd, &db_names, &lookup_field_vals, &with_i_schema))
3890
+ if (make_db_list (thd, &db_names, &lookup_field_vals, &with_i_schema, &tmp_mem_root ))
3871
3891
goto err;
3872
3892
it.rewind (); /* To get access to new elements in basis list */
3873
3893
while ((db_name= it++))
@@ -3885,7 +3905,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
3885
3905
List<LEX_STRING> table_names;
3886
3906
int res= make_table_name_list (thd, &table_names, lex,
3887
3907
&lookup_field_vals,
3888
- with_i_schema, db_name);
3908
+ with_i_schema, db_name, &tmp_mem_root );
3889
3909
if (res == 2 ) /* Not fatal error, continue */
3890
3910
continue ;
3891
3911
if (res)
@@ -3972,9 +3992,10 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
3972
3992
with_i_schema= 0 ;
3973
3993
}
3974
3994
}
3975
-
3976
3995
error= 0 ;
3977
3996
err:
3997
+
3998
+ free_root (&tmp_mem_root, MYF (0 ));
3978
3999
thd->restore_backup_open_tables_state (&open_tables_state_backup);
3979
4000
3980
4001
DBUG_RETURN (error);
@@ -4000,6 +4021,27 @@ int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
4000
4021
Returning error status in this case leads to client hangup.
4001
4022
*/
4002
4023
4024
+ /*
4025
+ * A temporary class is created to free tmp_mem_root when we return from
4026
+ * this function, since we have 'return' from this function from many
4027
+ * places. This is just to avoid goto.
4028
+ */
4029
+ class free_tmp_mem_root
4030
+ {
4031
+ public:
4032
+ free_tmp_mem_root ()
4033
+ {
4034
+ init_sql_alloc (&tmp_mem_root, TABLE_ALLOC_BLOCK_SIZE, 0 );
4035
+ }
4036
+ ~free_tmp_mem_root ()
4037
+ {
4038
+ free_root (&tmp_mem_root, MYF (0 ));
4039
+ }
4040
+ MEM_ROOT tmp_mem_root;
4041
+ };
4042
+
4043
+ free_tmp_mem_root dummy_member;
4044
+
4003
4045
LOOKUP_FIELD_VALUES lookup_field_vals;
4004
4046
List<LEX_STRING> db_names;
4005
4047
LEX_STRING *db_name;
@@ -4013,11 +4055,12 @@ int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
4013
4055
4014
4056
if (get_lookup_field_values (thd, cond, tables, &lookup_field_vals))
4015
4057
DBUG_RETURN (0 );
4058
+
4016
4059
DBUG_PRINT (" INDEX VALUES" ,(" db_name='%s', table_name='%s'" ,
4017
4060
lookup_field_vals.db_value .str ,
4018
4061
lookup_field_vals.table_value .str ));
4019
4062
if (make_db_list (thd, &db_names, &lookup_field_vals,
4020
- &with_i_schema))
4063
+ &with_i_schema, &dummy_member. tmp_mem_root ))
4021
4064
DBUG_RETURN (1 );
4022
4065
4023
4066
/*
0 commit comments