~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to sql/sql_show.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
1
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
9
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
10
   GNU General Public License for more details.
11
11
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
12
   You should have received a copy of the GNU General Public License along
 
13
   with this program; if not, write to the Free Software Foundation, Inc.,
 
14
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA */
15
15
 
16
16
 
17
17
/* Function with list databases, tables or fields */
521
521
        continue;
522
522
 
523
523
      file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
524
 
      if (wild && wild_compare(uname, wild, 0))
525
 
        continue;
526
 
      if (!(file_name= 
527
 
            thd->make_lex_string(file_name, uname, file_name_len, TRUE)))
 
524
      if (wild)
528
525
      {
529
 
        my_dirend(dirp);
530
 
        DBUG_RETURN(FIND_FILES_OOM);
 
526
        if (lower_case_table_names)
 
527
        {
 
528
          if (my_wildcmp(files_charset_info,
 
529
                         uname, uname + file_name_len,
 
530
                         wild, wild + wild_length,
 
531
                         wild_prefix, wild_one,wild_many))
 
532
            continue;
 
533
        }
 
534
        else if (wild_compare(uname, wild, 0))
 
535
          continue;
531
536
      }
532
537
    }
533
538
    else
713
718
                      table_list->table_name));
714
719
 
715
720
  /* We want to preserve the tree for views. */
716
 
  thd->lex->view_prepare_mode= TRUE;
 
721
  thd->lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
717
722
 
718
723
  {
719
724
    Show_create_error_handler view_error_suppressor(thd, table_list);
2202
2207
                              bool ucase_names,
2203
2208
                              COND *cond)
2204
2209
{
2205
 
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
2206
 
  char * const buff= (char *) &buff_data;
 
2210
  my_aligned_storage<SHOW_VAR_FUNC_BUFF_SIZE, MY_ALIGNOF(long)> buffer;
 
2211
  char * const buff= buffer.data;
2207
2212
  char *prefix_end;
2208
2213
  /* the variable name should not be longer than 64 characters */
2209
2214
  char name_buffer[64];
2278
2283
          value= ((char *) status_var + (ulong) value);
2279
2284
          /* fall through */
2280
2285
        case SHOW_DOUBLE:
2281
 
          end= buff + my_sprintf(buff, (buff, "%f", *(double*) value));
 
2286
          end= buff + sprintf(buff, "%f", *(double*) value);
2282
2287
          break;
2283
2288
        case SHOW_LONG_STATUS:
2284
2289
          value= ((char *) status_var + (ulong) value);
2423
2428
}
2424
2429
 
2425
2430
 
2426
 
int make_table_list(THD *thd, SELECT_LEX *sel,
2427
 
                    LEX_STRING *db_name, LEX_STRING *table_name)
 
2431
static int make_table_list(THD *thd, SELECT_LEX *sel,
 
2432
                           LEX_STRING *db_name, LEX_STRING *table_name)
2428
2433
{
2429
2434
  Table_ident *table_ident;
2430
2435
  table_ident= new Table_ident(thd, *db_name, *table_name, 1);
2431
 
  sel->init_query();
2432
2436
  if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
2433
2437
    return 1;
2434
2438
  return 0;
2690
2694
{
2691
2695
  LEX *lex= thd->lex;
2692
2696
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
 
2697
  bool rc= 0;
 
2698
 
2693
2699
  bzero((char*) lookup_field_values, sizeof(LOOKUP_FIELD_VALUES));
2694
2700
  switch (lex->sql_command) {
2695
2701
  case SQLCOM_SHOW_DATABASES:
2696
2702
    if (wild)
2697
2703
    {
2698
 
      lookup_field_values->db_value.str= (char*) wild;
2699
 
      lookup_field_values->db_value.length= strlen(wild);
 
2704
      thd->make_lex_string(&lookup_field_values->db_value, 
 
2705
                           wild, strlen(wild), 0);
2700
2706
      lookup_field_values->wild_db_value= 1;
2701
2707
    }
2702
 
    return 0;
 
2708
    break;
2703
2709
  case SQLCOM_SHOW_TABLES:
2704
2710
  case SQLCOM_SHOW_TABLE_STATUS:
2705
2711
  case SQLCOM_SHOW_TRIGGERS:
2706
2712
  case SQLCOM_SHOW_EVENTS:
2707
 
    lookup_field_values->db_value.str= lex->select_lex.db;
2708
 
    lookup_field_values->db_value.length=strlen(lex->select_lex.db);
 
2713
    thd->make_lex_string(&lookup_field_values->db_value, 
 
2714
                         lex->select_lex.db, strlen(lex->select_lex.db), 0);
2709
2715
    if (wild)
2710
2716
    {
2711
 
      lookup_field_values->table_value.str= (char*)wild;
2712
 
      lookup_field_values->table_value.length= strlen(wild);
 
2717
      thd->make_lex_string(&lookup_field_values->table_value, 
 
2718
                           wild, strlen(wild), 0);
2713
2719
      lookup_field_values->wild_table_value= 1;
2714
2720
    }
2715
 
    return 0;
 
2721
    break;
2716
2722
  default:
2717
2723
    /*
2718
2724
      The "default" is for queries over I_S.
2719
2725
      All previous cases handle SHOW commands.
2720
2726
    */
2721
 
    return calc_lookup_values_from_cond(thd, cond, tables, lookup_field_values);
2722
 
  }
 
2727
    rc= calc_lookup_values_from_cond(thd, cond, tables, lookup_field_values);
 
2728
    break;
 
2729
  }
 
2730
 
 
2731
  if (lower_case_table_names && !rc)
 
2732
  {
 
2733
    /* 
 
2734
      We can safely do in-place upgrades here since all of the above cases
 
2735
      are allocating a new memory buffer for these strings.
 
2736
    */  
 
2737
    if (lookup_field_values->db_value.str && lookup_field_values->db_value.str[0])
 
2738
      my_casedn_str(system_charset_info, lookup_field_values->db_value.str);
 
2739
    if (lookup_field_values->table_value.str && 
 
2740
        lookup_field_values->table_value.str[0])
 
2741
      my_casedn_str(system_charset_info, lookup_field_values->table_value.str);
 
2742
  }
 
2743
 
 
2744
  return rc;
2723
2745
}
2724
2746
 
2725
2747
 
2921
2943
  {
2922
2944
    if (with_i_schema)
2923
2945
    {
 
2946
      LEX_STRING *name;
2924
2947
      ST_SCHEMA_TABLE *schema_table=
2925
2948
        find_schema_table(thd, lookup_field_vals->table_value.str);
2926
2949
      if (schema_table && !schema_table->hidden)
2927
2950
      {
2928
 
        if (table_names->push_back(&lookup_field_vals->table_value))
 
2951
        if (!(name= 
 
2952
              thd->make_lex_string(NULL, schema_table->table_name,
 
2953
                                   strlen(schema_table->table_name), TRUE)) ||
 
2954
            table_names->push_back(name))
2929
2955
          return 1;
2930
2956
      }
2931
2957
    }
2964
2990
    */
2965
2991
    if (res == FIND_FILES_DIR)
2966
2992
    {
2967
 
      if (lex->sql_command != SQLCOM_SELECT)
 
2993
      if (sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND)
2968
2994
        return 1;
2969
2995
      thd->clear_error();
2970
2996
      return 2;
2976
3002
 
2977
3003
 
2978
3004
/**
2979
 
  @brief          Fill I_S table for SHOW COLUMNS|INDEX commands
2980
 
 
2981
 
  @param[in]      thd                      thread handler
2982
 
  @param[in]      tables                   TABLE_LIST for I_S table
2983
 
  @param[in]      schema_table             pointer to I_S structure
2984
 
  @param[in]      open_tables_state_backup pointer to Open_tables_state object
2985
 
                                           which is used to save|restore original
2986
 
                                           status of variables related to
2987
 
                                           open tables state
2988
 
 
2989
 
  @return         Operation status
2990
 
    @retval       0           success
2991
 
    @retval       1           error
 
3005
  Fill I_S table with data obtained by performing full-blown table open.
 
3006
 
 
3007
  @param  thd                       Thread handler.
 
3008
  @param  is_show_fields_or_keys    Indicates whether it is a legacy SHOW
 
3009
                                    COLUMNS or SHOW KEYS statement.
 
3010
  @param  table                     TABLE object for I_S table to be filled.
 
3011
  @param  schema_table              I_S table description structure.
 
3012
  @param  orig_db_name              Database name.
 
3013
  @param  orig_table_name           Table name.
 
3014
  @param  open_tables_state_backup  Open_tables_state object which is used
 
3015
                                    to save/restore original status of
 
3016
                                    variables related to open tables state.
 
3017
 
 
3018
  @retval FALSE - Success.
 
3019
  @retval TRUE  - Failure.
2992
3020
*/
2993
3021
 
2994
 
static int 
2995
 
fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables,
2996
 
                              ST_SCHEMA_TABLE *schema_table,
2997
 
                              Open_tables_state *open_tables_state_backup)
 
3022
static bool
 
3023
fill_schema_table_by_open(THD *thd, bool is_show_fields_or_keys,
 
3024
                          TABLE *table, ST_SCHEMA_TABLE *schema_table,
 
3025
                          LEX_STRING *orig_db_name,
 
3026
                          LEX_STRING *orig_table_name,
 
3027
                          Open_tables_state *open_tables_state_backup)
2998
3028
{
2999
 
  LEX *lex= thd->lex;
3000
 
  bool res;
3001
 
  LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
3002
 
  enum_sql_command save_sql_command= lex->sql_command;
3003
 
  TABLE_LIST *show_table_list= tables->schema_select_lex->table_list.first;
3004
 
  TABLE *table= tables->table;
3005
 
  int error= 1;
3006
 
  DBUG_ENTER("fill_schema_show");
3007
 
 
3008
 
  lex->all_selects_list= tables->schema_select_lex;
3009
 
  /*
3010
 
    Restore thd->temporary_tables to be able to process
3011
 
    temporary tables(only for 'show index' & 'show columns').
3012
 
    This should be changed when processing of temporary tables for
3013
 
    I_S tables will be done.
3014
 
  */
3015
 
  thd->temporary_tables= open_tables_state_backup->temporary_tables;
 
3029
  Query_arena i_s_arena(thd->mem_root,
 
3030
                        Query_arena::CONVENTIONAL_EXECUTION),
 
3031
              backup_arena, *old_arena;
 
3032
  LEX *old_lex= thd->lex, temp_lex, *lex;
 
3033
  LEX_STRING db_name, table_name;
 
3034
  TABLE_LIST *table_list;
 
3035
  bool result= true;
 
3036
 
 
3037
  /*
 
3038
    When a view is opened its structures are allocated on a permanent
 
3039
    statement arena and linked into the LEX tree for the current statement
 
3040
    (this happens even in cases when view is handled through TEMPTABLE
 
3041
    algorithm).
 
3042
 
 
3043
    To prevent this process from unnecessary hogging of memory in the permanent
 
3044
    arena of our I_S query and to avoid damaging its LEX we use temporary
 
3045
    arena and LEX for table/view opening.
 
3046
 
 
3047
    Use temporary arena instead of statement permanent arena. Also make
 
3048
    it active arena and save original one for successive restoring.
 
3049
  */
 
3050
  old_arena= thd->stmt_arena;
 
3051
  thd->stmt_arena= &i_s_arena;
 
3052
  thd->set_n_backup_active_arena(&i_s_arena, &backup_arena);
 
3053
 
 
3054
  /* Prepare temporary LEX. */
 
3055
  thd->lex= lex= &temp_lex;
 
3056
  lex_start(thd);
 
3057
 
 
3058
  /* Disable constant subquery evaluation as we won't be locking tables. */
 
3059
  lex->context_analysis_only= CONTEXT_ANALYSIS_ONLY_VIEW;
 
3060
 
 
3061
  /*
 
3062
    Some of process_table() functions rely on wildcard being passed from
 
3063
    old LEX (or at least being initialized).
 
3064
  */
 
3065
  lex->wild= old_lex->wild;
 
3066
 
 
3067
  /*
 
3068
    Since make_table_list() might change database and table name passed
 
3069
    to it we create copies of orig_db_name and orig_table_name here.
 
3070
    These copies are used for make_table_list() while unaltered values
 
3071
    are passed to process_table() functions.
 
3072
  */
 
3073
  if (!thd->make_lex_string(&db_name, orig_db_name->str,
 
3074
                            orig_db_name->length, FALSE) ||
 
3075
      !thd->make_lex_string(&table_name, orig_table_name->str,
 
3076
                            orig_table_name->length, FALSE))
 
3077
    goto end;
 
3078
 
 
3079
  /*
 
3080
    Create table list element for table to be open. Link it with the
 
3081
    temporary LEX. The latter is required to correctly open views and
 
3082
    produce table describing their structure.
 
3083
  */
 
3084
  if (make_table_list(thd, &lex->select_lex, &db_name, &table_name))
 
3085
    goto end;
 
3086
 
 
3087
  table_list= lex->select_lex.table_list.first;
 
3088
 
 
3089
  if (is_show_fields_or_keys)
 
3090
  {
 
3091
    /*
 
3092
      Restore thd->temporary_tables to be able to process
 
3093
      temporary tables (only for 'show index' & 'show columns').
 
3094
      This should be changed when processing of temporary tables for
 
3095
      I_S tables will be done.
 
3096
    */
 
3097
    thd->temporary_tables= open_tables_state_backup->temporary_tables;
 
3098
  }
 
3099
  else
 
3100
  {
 
3101
    /*
 
3102
      Apply optimization flags for table opening which are relevant for
 
3103
      this I_S table. We can't do this for SHOW COLUMNS/KEYS because of
 
3104
      backward compatibility.
 
3105
    */
 
3106
    table_list->i_s_requested_object= schema_table->i_s_requested_object;
 
3107
  }
 
3108
 
3016
3109
  /*
3017
3110
    Let us set fake sql_command so views won't try to merge
3018
3111
    themselves into main statement. If we don't do this,
3019
3112
    SELECT * from information_schema.xxxx will cause problems.
3020
 
    SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()' 
 
3113
    SQLCOM_SHOW_FIELDS is used because it satisfies
 
3114
    'only_view_structure()'.
3021
3115
  */
3022
3116
  lex->sql_command= SQLCOM_SHOW_FIELDS;
3023
 
  res= open_normal_and_derived_tables(thd, show_table_list,
3024
 
                                      MYSQL_LOCK_IGNORE_FLUSH);
3025
 
  lex->sql_command= save_sql_command;
3026
 
  /*
3027
 
    get_all_tables() returns 1 on failure and 0 on success thus
3028
 
    return only these and not the result code of ::process_table()
3029
 
 
3030
 
    We should use show_table_list->alias instead of 
3031
 
    show_table_list->table_name because table_name
3032
 
    could be changed during opening of I_S tables. It's safe
3033
 
    to use alias because alias contains original table name 
3034
 
    in this case(this part of code is used only for 
3035
 
    'show columns' & 'show statistics' commands).
3036
 
  */
3037
 
   table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
3038
 
                                    strlen(show_table_list->alias), FALSE);
3039
 
   if (!show_table_list->view)
3040
 
     db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
3041
 
                                   show_table_list->db_length, FALSE);
3042
 
   else
3043
 
     db_name= &show_table_list->view_db;
3044
 
      
3045
 
 
3046
 
   error= test(schema_table->process_table(thd, show_table_list,
3047
 
                                           table, res, db_name,
3048
 
                                           table_name));
3049
 
   thd->temporary_tables= 0;
3050
 
   close_tables_for_reopen(thd, &show_table_list);
3051
 
   DBUG_RETURN(error);
 
3117
 
 
3118
  result= open_normal_and_derived_tables(thd, table_list,
 
3119
                                         MYSQL_LOCK_IGNORE_FLUSH);
 
3120
 
 
3121
  /*
 
3122
    Restore old value of sql_command back as it is being looked at in
 
3123
    process_table() function.
 
3124
  */
 
3125
  lex->sql_command= old_lex->sql_command;
 
3126
 
 
3127
  /*
 
3128
    XXX:  show_table_list has a flag i_is_requested,
 
3129
    and when it's set, open_normal_and_derived_tables()
 
3130
    can return an error without setting an error message
 
3131
    in THD, which is a hack. This is why we have to
 
3132
    check for res, then for thd->is_error() and only then
 
3133
    for thd->main_da.sql_errno().
 
3134
 
 
3135
    Again we don't do this for SHOW COLUMNS/KEYS because
 
3136
    of backward compatibility.
 
3137
  */
 
3138
  if (!is_show_fields_or_keys && result && thd->is_error() &&
 
3139
      thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
 
3140
  {
 
3141
    /*
 
3142
      Hide error for a non-existing table.
 
3143
      For example, this error can occur when we use a where condition
 
3144
      with a db name and table, but the table does not exist.
 
3145
    */
 
3146
    result= 0;
 
3147
    thd->clear_error();
 
3148
  }
 
3149
  else
 
3150
  {
 
3151
    result= schema_table->process_table(thd, table_list,
 
3152
                                        table, result,
 
3153
                                        orig_db_name,
 
3154
                                        orig_table_name);
 
3155
  }
 
3156
 
 
3157
end:
 
3158
  lex->unit.cleanup();
 
3159
 
 
3160
  /* Restore original LEX value, statement's arena and THD arena values. */
 
3161
  lex_end(thd->lex);
 
3162
 
 
3163
  if (i_s_arena.free_list)
 
3164
    i_s_arena.free_items();
 
3165
 
 
3166
  /*
 
3167
    For safety reset list of open temporary tables before closing
 
3168
    all tables open within this Open_tables_state.
 
3169
  */
 
3170
  thd->temporary_tables= NULL;
 
3171
  close_thread_tables(thd);
 
3172
  thd->lex= old_lex;
 
3173
 
 
3174
  thd->stmt_arena= old_arena;
 
3175
  thd->restore_active_arena(&i_s_arena, &backup_arena);
 
3176
 
 
3177
  return result;
3052
3178
}
3053
3179
 
3054
3180
 
3273
3399
{
3274
3400
  LEX *lex= thd->lex;
3275
3401
  TABLE *table= tables->table;
3276
 
  SELECT_LEX *old_all_select_lex= lex->all_selects_list;
3277
 
  enum_sql_command save_sql_command= lex->sql_command;
3278
3402
  SELECT_LEX *lsel= tables->schema_select_lex;
3279
3403
  ST_SCHEMA_TABLE *schema_table= tables->schema_table;
3280
 
  SELECT_LEX sel;
3281
3404
  LOOKUP_FIELD_VALUES lookup_field_vals;
3282
3405
  LEX_STRING *db_name, *table_name;
3283
3406
  bool with_i_schema;
3285
3408
  List<LEX_STRING> db_names;
3286
3409
  List_iterator_fast<LEX_STRING> it(db_names);
3287
3410
  COND *partial_cond= 0;
3288
 
  uint derived_tables= lex->derived_tables; 
3289
3411
  int error= 1;
3290
3412
  Open_tables_state open_tables_state_backup;
3291
 
  bool save_view_prepare_mode= lex->view_prepare_mode;
3292
 
  Query_tables_list query_tables_list_backup;
3293
3413
#ifndef NO_EMBEDDED_ACCESS_CHECKS
3294
3414
  Security_context *sctx= thd->security_ctx;
3295
3415
#endif
3296
3416
  uint table_open_method;
3297
3417
  DBUG_ENTER("get_all_tables");
3298
3418
 
3299
 
  lex->view_prepare_mode= TRUE;
3300
 
  lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
3301
 
 
3302
3419
  /*
3303
3420
    We should not introduce deadlocks even if we already have some
3304
3421
    tables open and locked, since we won't lock tables which we will
3313
3430
  */
3314
3431
  if (lsel && lsel->table_list.first)
3315
3432
  {
3316
 
    error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
3317
 
                                         &open_tables_state_backup);
 
3433
    LEX_STRING db_name, table_name;
 
3434
 
 
3435
    db_name.str= lsel->table_list.first->db;
 
3436
    db_name.length= lsel->table_list.first->db_length;
 
3437
 
 
3438
    table_name.str= lsel->table_list.first->table_name;
 
3439
    table_name.length= lsel->table_list.first->table_name_length;
 
3440
 
 
3441
    error= fill_schema_table_by_open(thd, TRUE,
 
3442
                                     table, schema_table,
 
3443
                                     &db_name, &table_name,
 
3444
                                     &open_tables_state_backup);
3318
3445
    goto err;
3319
3446
  }
3320
3447
 
3324
3451
    error= 0;
3325
3452
    goto err;
3326
3453
  }
 
3454
 
3327
3455
  DBUG_PRINT("INDEX VALUES",("db_name='%s', table_name='%s'",
3328
3456
                             STR_OR_NIL(lookup_field_vals.db_value.str),
3329
3457
                             STR_OR_NIL(lookup_field_vals.table_value.str)));
3432
3560
                continue;
3433
3561
            }
3434
3562
 
3435
 
            int res;
3436
 
            LEX_STRING tmp_lex_string, orig_db_name;
3437
 
            /*
3438
 
              Set the parent lex of 'sel' because it is needed by
3439
 
              sel.init_query() which is called inside make_table_list.
3440
 
            */
3441
3563
            thd->no_warnings_for_error= 1;
3442
 
            sel.parent_lex= lex;
3443
 
            /* db_name can be changed in make_table_list() func */
3444
 
            if (!thd->make_lex_string(&orig_db_name, db_name->str,
3445
 
                                      db_name->length, FALSE))
3446
 
              goto err;
3447
 
            if (make_table_list(thd, &sel, db_name, table_name))
3448
 
              goto err;
3449
 
            TABLE_LIST *show_table_list= sel.table_list.first;
3450
 
            lex->all_selects_list= &sel;
3451
 
            lex->derived_tables= 0;
3452
 
            lex->sql_command= SQLCOM_SHOW_FIELDS;
3453
 
            show_table_list->i_s_requested_object=
3454
 
              schema_table->i_s_requested_object;
 
3564
 
3455
3565
            DEBUG_SYNC(thd, "before_open_in_get_all_tables");
3456
 
            res= open_normal_and_derived_tables(thd, show_table_list,
3457
 
                                                MYSQL_LOCK_IGNORE_FLUSH);
3458
 
            lex->sql_command= save_sql_command;
3459
 
            /*
3460
 
              XXX:  show_table_list has a flag i_is_requested,
3461
 
              and when it's set, open_normal_and_derived_tables()
3462
 
              can return an error without setting an error message
3463
 
              in THD, which is a hack. This is why we have to
3464
 
              check for res, then for thd->is_error() only then
3465
 
              for thd->main_da.sql_errno().
3466
 
            */
3467
 
            if (res && thd->is_error() &&
3468
 
                thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
3469
 
            {
3470
 
              /*
3471
 
                Hide error for not existing table.
3472
 
                This error can occur for example when we use
3473
 
                where condition with db name and table name and this
3474
 
                table does not exist.
3475
 
              */
3476
 
              res= 0;
3477
 
              thd->clear_error();
3478
 
            }
3479
 
            else
3480
 
            {
3481
 
              /*
3482
 
                We should use show_table_list->alias instead of 
3483
 
                show_table_list->table_name because table_name
3484
 
                could be changed during opening of I_S tables. It's safe
3485
 
                to use alias because alias contains original table name 
3486
 
                in this case.
3487
 
              */
3488
 
              thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
3489
 
                                   strlen(show_table_list->alias), FALSE);
3490
 
              res= schema_table->process_table(thd, show_table_list, table,
3491
 
                                               res, &orig_db_name,
3492
 
                                               &tmp_lex_string);
3493
 
              close_tables_for_reopen(thd, &show_table_list);
3494
 
            }
3495
 
            DBUG_ASSERT(!lex->query_tables_own_last);
3496
 
            if (res)
 
3566
 
 
3567
            if (fill_schema_table_by_open(thd, FALSE,
 
3568
                                          table, schema_table,
 
3569
                                          db_name, table_name,
 
3570
                                          &open_tables_state_backup))
3497
3571
              goto err;
3498
3572
          }
3499
3573
        }
3509
3583
  error= 0;
3510
3584
err:
3511
3585
  thd->restore_backup_open_tables_state(&open_tables_state_backup);
3512
 
  lex->restore_backup_query_tables_list(&query_tables_list_backup);
3513
 
  lex->derived_tables= derived_tables;
3514
 
  lex->all_selects_list= old_all_select_lex;
3515
 
  lex->view_prepare_mode= save_view_prepare_mode;
3516
 
  lex->sql_command= save_sql_command;
 
3586
 
3517
3587
  DBUG_RETURN(error);
3518
3588
}
3519
3589
 
3608
3678
{
3609
3679
  const char *tmp_buff;
3610
3680
  MYSQL_TIME time;
 
3681
  int info_error= 0;
3611
3682
  CHARSET_INFO *cs= system_charset_info;
3612
3683
  DBUG_ENTER("get_schema_tables_record");
3613
3684
 
3614
3685
  restore_record(table, s->default_values);
3615
3686
  table->field[1]->store(db_name->str, db_name->length, cs);
3616
3687
  table->field[2]->store(table_name->str, table_name->length, cs);
 
3688
 
3617
3689
  if (res)
3618
3690
  {
3619
 
    /*
3620
 
      there was errors during opening tables
3621
 
    */
3622
 
    const char *error= thd->is_error() ? thd->main_da.message() : "";
 
3691
    /* There was a table open error, so set the table type and return */
3623
3692
    if (tables->view)
3624
3693
      table->field[3]->store(STRING_WITH_LEN("VIEW"), cs);
3625
3694
    else if (tables->schema_table)
3626
3695
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
3627
3696
    else
3628
3697
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
3629
 
    table->field[20]->store(error, strlen(error), cs);
3630
 
    thd->clear_error();
 
3698
 
 
3699
    goto err;
3631
3700
  }
3632
 
  else if (tables->view)
 
3701
 
 
3702
  if (tables->view)
3633
3703
  {
3634
3704
    table->field[3]->store(STRING_WITH_LEN("VIEW"), cs);
3635
3705
    table->field[20]->store(STRING_WITH_LEN("VIEW"), cs);
3718
3788
    if (share->comment.str)
3719
3789
      table->field[20]->store(share->comment.str, share->comment.length, cs);
3720
3790
 
3721
 
    if(file)
 
3791
    if (file)
3722
3792
    {
3723
 
      file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO);
 
3793
      /* If info() fails, then there's nothing else to do */
 
3794
      if ((info_error= file->info(HA_STATUS_VARIABLE |
 
3795
                                  HA_STATUS_TIME |
 
3796
                                  HA_STATUS_AUTO)) != 0)
 
3797
        goto err;
 
3798
          
3724
3799
      enum row_type row_type = file->get_row_type();
3725
3800
      switch (row_type) {
3726
3801
      case ROW_TYPE_NOT_USED:
3798
3873
      }
3799
3874
    }
3800
3875
  }
 
3876
 
 
3877
err:
 
3878
  if (res || info_error)
 
3879
  {
 
3880
    /*
 
3881
      If an error was encountered, push a warning, set the TABLE COMMENT
 
3882
      column with the error text, and clear the error so that the operation
 
3883
      can continue.
 
3884
    */
 
3885
    const char *error= thd->is_error() ? thd->main_da.message() : "";
 
3886
    table->field[20]->store(error, strlen(error), cs);
 
3887
 
 
3888
    if (thd->is_error())
 
3889
    {
 
3890
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
3891
                   thd->main_da.sql_errno(), thd->main_da.message());
 
3892
      thd->clear_error();
 
3893
    }
 
3894
  }
 
3895
  
3801
3896
  DBUG_RETURN(schema_table_store_record(thd, table));
3802
3897
}
3803
3898
 
3845
3940
    uint flags=field->flags;
3846
3941
    char tmp[MAX_FIELD_WIDTH];
3847
3942
    String type(tmp,sizeof(tmp), system_charset_info);
3848
 
    char *end;
3849
3943
    int decimals, field_length;
3850
3944
 
3851
3945
    if (wild && wild[0] &&
3866
3960
                                 field->field_name) & COL_ACLS;
3867
3961
    if (!tables->schema_table && !col_access)
3868
3962
      continue;
3869
 
    end= tmp;
 
3963
    char *end= tmp;
3870
3964
    for (uint bitnr=0; col_access ; col_access>>=1,bitnr++)
3871
3965
    {
3872
3966
      if (col_access & 1)
3942
4036
    case MYSQL_TYPE_TINY:
3943
4037
    case MYSQL_TYPE_SHORT:
3944
4038
    case MYSQL_TYPE_LONG:
3945
 
    case MYSQL_TYPE_LONGLONG:
3946
4039
    case MYSQL_TYPE_INT24:
3947
4040
      field_length= field->max_display_length() - 1;
3948
4041
      break;
 
4042
    case MYSQL_TYPE_LONGLONG:
 
4043
      field_length= field->max_display_length() - 
 
4044
        ((field->flags & UNSIGNED_FLAG) ? 0 : 1);
 
4045
      break;
3949
4046
    case MYSQL_TYPE_BIT:
3950
4047
      field_length= field->max_display_length();
3951
4048
      decimals= -1;                             // return NULL
3989
4086
    table->field[15]->store((const char*) pos,
3990
4087
                            strlen((const char*) pos), cs);
3991
4088
 
3992
 
    end= tmp;
3993
4089
    if (field->unireg_check == Field::NEXT_NUMBER)
3994
4090
      table->field[16]->store(STRING_WITH_LEN("auto_increment"), cs);
3995
4091
    if (show_table->timestamp_field == field &&
4593
4689
    TABLE *show_table= tables->table;
4594
4690
    KEY *key_info=show_table->key_info;
4595
4691
    uint primary_key= show_table->s->primary_key;
4596
 
    show_table->file->info(HA_STATUS_VARIABLE | 
4597
 
                           HA_STATUS_NO_LOCK |
4598
 
                           HA_STATUS_TIME);
 
4692
 
 
4693
    // This is not needed since no statistics are displayed.
 
4694
    // show_table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME);
 
4695
 
4599
4696
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
4600
4697
    {
4601
4698
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
4777
4874
    TABLE *show_table= tables->table;
4778
4875
    KEY *key_info=show_table->key_info;
4779
4876
    uint primary_key= show_table->s->primary_key;
4780
 
    show_table->file->info(HA_STATUS_VARIABLE | 
4781
 
                           HA_STATUS_NO_LOCK |
4782
 
                           HA_STATUS_TIME);
 
4877
 
 
4878
    // This is not needed since no statistics are displayed.
 
4879
    // show_table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME);
 
4880
 
4783
4881
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
4784
4882
    {
4785
4883
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
5508
5606
  {
5509
5607
    List<FOREIGN_KEY_INFO> f_key_list;
5510
5608
    TABLE *show_table= tables->table;
5511
 
    show_table->file->info(HA_STATUS_VARIABLE | 
5512
 
                           HA_STATUS_NO_LOCK |
5513
 
                           HA_STATUS_TIME);
 
5609
 
 
5610
    // This is not needed since no statistics are displayed.
 
5611
    // show_table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME);
5514
5612
 
5515
5613
    show_table->file->get_foreign_key_list(thd, &f_key_list);
5516
5614
    FOREIGN_KEY_INFO *f_key_info;
6895
6993
  ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
6896
6994
  DBUG_ENTER("finalize_schema_table");
6897
6995
 
6898
 
  if (schema_table && plugin->plugin->deinit)
 
6996
  if (schema_table)
6899
6997
  {
6900
 
    DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str));
6901
 
    if (plugin->plugin->deinit(NULL))
 
6998
    if (plugin->plugin->deinit)
6902
6999
    {
6903
 
      DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
6904
 
                             plugin->name.str));
 
7000
      DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str));
 
7001
      if (plugin->plugin->deinit(NULL))
 
7002
      {
 
7003
        DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
 
7004
                               plugin->name.str));
 
7005
      }
6905
7006
    }
6906
7007
    my_free(schema_table, MYF(0));
6907
7008
  }
7089
7190
 
7090
7191
  if (!(table= (TABLE_LIST *)thd->calloc(sizeof(TABLE_LIST))))
7091
7192
  {
7092
 
    my_error(ER_OUTOFMEMORY, MYF(0), sizeof(TABLE_LIST));
 
7193
    my_error(ER_OUTOFMEMORY, MYF(0), static_cast<int>(sizeof(TABLE_LIST)));
7093
7194
    return NULL;
7094
7195
  }
7095
7196