summaryrefslogtreecommitdiff
path: root/sql/sql_show.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_show.cc')
-rw-r--r--sql/sql_show.cc160
1 files changed, 94 insertions, 66 deletions
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 1fdd2d7c8d0..6f0c9761b6c 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -2147,7 +2147,6 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
!foreign_db_mode;
bool check_options= !(sql_mode & MODE_IGNORE_BAD_TABLE_OPTIONS) &&
!create_info_arg;
- my_bitmap_map *old_map;
handlerton *hton;
int error= 0;
DBUG_ENTER("show_create_table");
@@ -2214,7 +2213,7 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
We have to restore the read_set if we are called from insert in case
of row based replication.
*/
- old_map= tmp_use_all_columns(table, table->read_set);
+ MY_BITMAP *old_map= tmp_use_all_columns(table, &table->read_set);
bool not_the_first_field= false;
for (ptr=table->field ; (field= *ptr); ptr++)
@@ -2259,8 +2258,13 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
/*
For string types dump collation name only if
collation is not primary for the given charset
+
+ For generated fields don't print the COLLATE clause if
+ the collation matches the expression's collation.
*/
- if (!(field->charset()->state & MY_CS_PRIMARY) && !field->vcol_info)
+ if (!(field->charset()->state & MY_CS_PRIMARY) &&
+ (!field->vcol_info ||
+ field->charset() != field->vcol_info->expr->collation.collation))
{
packet->append(STRING_WITH_LEN(" COLLATE "));
packet->append(field->charset()->name);
@@ -2516,7 +2520,7 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
}
}
#endif
- tmp_restore_column_map(table->read_set, old_map);
+ tmp_restore_column_map(&table->read_set, old_map);
DBUG_RETURN(error);
}
@@ -3252,11 +3256,8 @@ int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond)
}
DBUG_RETURN(bres);
}
- else
- {
- my_error(ER_NO_SUCH_THREAD, MYF(0), (ulong) thread_id);
- DBUG_RETURN(1);
- }
+ my_error(ER_NO_SUCH_THREAD, MYF(0), (ulong) thread_id);
+ DBUG_RETURN(1);
}
@@ -3832,6 +3833,9 @@ static bool show_status_array(THD *thd, const char *wild,
if (show_type == SHOW_SYS)
mysql_mutex_lock(&LOCK_global_system_variables);
+ else if (show_type >= SHOW_LONG_STATUS && scope == OPT_GLOBAL)
+ calc_sum_of_all_status_if_needed(status_var);
+
pos= get_one_variable(thd, var, scope, show_type, status_var,
&charset, buff, &length);
@@ -3889,7 +3893,6 @@ uint calc_sum_of_all_status(STATUS_VAR *to)
calc_sum_callback_arg arg(to);
DBUG_ENTER("calc_sum_of_all_status");
- *to= global_status_var;
to->local_memory_used= 0;
/* Add to this status from existing threads */
server_threads.iterate(calc_sum_callback, &arg);
@@ -5099,7 +5102,8 @@ public:
Sql_condition::enum_warning_level *level,
const char* msg, Sql_condition ** cond_hdl)
{
- if (sql_errno == ER_TRG_NO_DEFINER || sql_errno == ER_TRG_NO_CREATION_CTX)
+ if (sql_errno == ER_TRG_NO_DEFINER || sql_errno == ER_TRG_NO_CREATION_CTX
+ || sql_errno == ER_PARSE_ERROR)
return true;
if (*level != Sql_condition::WARN_LEVEL_ERROR)
@@ -5297,6 +5301,12 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
continue;
}
+ if (thd->killed == ABORT_QUERY)
+ {
+ error= 0;
+ goto err;
+ }
+
DEBUG_SYNC(thd, "before_open_in_get_all_tables");
if (fill_schema_table_by_open(thd, &tmp_mem_root, FALSE,
table, schema_table,
@@ -5865,7 +5875,7 @@ static bool print_anchor_data_type(const Spvar_definition *def,
Let's print it according to the current sql_mode.
It will make output in line with the value in mysql.proc.param_list,
so both I_S.XXX.DTD_IDENTIFIER and mysql.proc.param_list use the same notation:
- default or Oracle, according to the sql_mode at the SP creation time.
+ default or Oracle, according to the sql_mode at the SP creation time.
The caller must make sure to set thd->variables.sql_mode to the routine sql_mode.
*/
static bool print_anchor_dtd_identifier(THD *thd, const Spvar_definition *def,
@@ -7086,8 +7096,7 @@ static bool store_trigger(THD *thd, Trigger *trigger,
(my_time_t)(trigger->create_time/100));
/* timestamp is with 6 digits */
timestamp.second_part= (trigger->create_time % 100) * 10000;
- ((Field_temporal_with_date*) table->field[16])->store_time_dec(&timestamp,
- 2);
+ table->field[16]->store_time_dec(&timestamp, 2);
}
sql_mode_string_representation(thd, trigger->sql_mode, &sql_mode_rep);
@@ -7969,10 +7978,7 @@ int fill_status(THD *thd, TABLE_LIST *tables, COND *cond)
if (partial_cond)
partial_cond->val_int();
- if (scope == OPT_GLOBAL)
- {
- calc_sum_of_all_status(&tmp);
- }
+ tmp.local_memory_used= 0; // meaning tmp was not populated yet
mysql_rwlock_rdlock(&LOCK_all_status_vars);
res= show_status_array(thd, wild,
@@ -8704,57 +8710,72 @@ end:
}
-static int optimize_schema_tables_memory_usage(TABLE_LIST *table_list)
+bool optimize_schema_tables_memory_usage(List<TABLE_LIST> &tables)
{
- TABLE *table= table_list->table;
- THD *thd=table->in_use;
- if (!table->is_created())
- {
- TMP_TABLE_PARAM *p= table_list->schema_table_param;
- TMP_ENGINE_COLUMNDEF *from_recinfo, *to_recinfo;
- DBUG_ASSERT(table->s->keys == 0);
- DBUG_ASSERT(table->s->uniques == 0);
-
- uchar *cur= table->field[0]->ptr;
- /* first recinfo could be a NULL bitmap, not an actual Field */
- from_recinfo= to_recinfo= p->start_recinfo + (cur != table->record[0]);
- for (uint i=0; i < table->s->fields; i++, from_recinfo++)
- {
- Field *field= table->field[i];
- DBUG_ASSERT(field->vcol_info == 0);
- DBUG_ASSERT(from_recinfo->length);
- DBUG_ASSERT(from_recinfo->length == field->pack_length_in_rec());
- if (bitmap_is_set(table->read_set, i))
+ DBUG_ENTER("optimize_schema_tables_memory_usage");
+
+ List_iterator<TABLE_LIST> tli(tables);
+
+ while (TABLE_LIST *table_list= tli++)
+ {
+ if (!table_list->schema_table)
+ continue;
+
+ TABLE *table= table_list->table;
+ THD *thd=table->in_use;
+
+ if (!thd->fill_information_schema_tables())
+ continue;
+
+ if (!table->is_created())
+ {
+ TMP_TABLE_PARAM *p= table_list->schema_table_param;
+ TMP_ENGINE_COLUMNDEF *from_recinfo, *to_recinfo;
+ DBUG_ASSERT(table->s->keys == 0);
+ DBUG_ASSERT(table->s->uniques == 0);
+
+ uchar *cur= table->field[0]->ptr;
+ /* first recinfo could be a NULL bitmap, not an actual Field */
+ from_recinfo= to_recinfo= p->start_recinfo + (cur != table->record[0]);
+ for (uint i=0; i < table->s->fields; i++, from_recinfo++)
{
- field->move_field(cur);
- *to_recinfo++= *from_recinfo;
- cur+= from_recinfo->length;
+ Field *field= table->field[i];
+ DBUG_ASSERT(field->vcol_info == 0);
+ DBUG_ASSERT(from_recinfo->length);
+ DBUG_ASSERT(from_recinfo->length == field->pack_length_in_rec());
+ if (bitmap_is_set(table->read_set, i))
+ {
+ field->move_field(cur);
+ *to_recinfo++= *from_recinfo;
+ cur+= from_recinfo->length;
+ }
+ else
+ {
+ field= new (thd->mem_root) Field_string(cur, 0, field->null_ptr,
+ field->null_bit, Field::NONE,
+ &field->field_name, field->dtcollation());
+ field->init(table);
+ field->field_index= i;
+ DBUG_ASSERT(field->pack_length_in_rec() == 0);
+ table->field[i]= field;
+ }
}
- else
+ if ((table->s->reclength= (ulong)(cur - table->record[0])) == 0)
{
- field= new (thd->mem_root) Field_string(cur, 0, field->null_ptr,
- field->null_bit, Field::NONE,
- &field->field_name, field->dtcollation());
- field->init(table);
- field->field_index= i;
- DBUG_ASSERT(field->pack_length_in_rec() == 0);
- table->field[i]= field;
+ /* all fields were optimized away. Force a non-0-length row */
+ table->s->reclength= to_recinfo->length= 1;
+ to_recinfo->type= FIELD_NORMAL;
+ to_recinfo++;
}
- }
- if ((table->s->reclength= (ulong)(cur - table->record[0])) == 0)
- {
- /* all fields were optimized away. Force a non-0-length row */
- table->s->reclength= to_recinfo->length= 1;
- to_recinfo++;
- }
- p->recinfo= to_recinfo;
+ p->recinfo= to_recinfo;
- // TODO switch from Aria to Memory if all blobs were optimized away?
- if (instantiate_tmp_table(table, p->keyinfo, p->start_recinfo, &p->recinfo,
- table_list->select_lex->options | thd->variables.option_bits))
- return 1;
+ // TODO switch from Aria to Memory if all blobs were optimized away?
+ if (instantiate_tmp_table(table, p->keyinfo, p->start_recinfo, &p->recinfo,
+ table_list->select_lex->options | thd->variables.option_bits))
+ DBUG_RETURN(1);
+ }
}
- return 0;
+ DBUG_RETURN(0);
}
@@ -8778,9 +8799,6 @@ bool optimize_schema_tables_reads(JOIN *join)
TABLE_LIST *table_list= tab->table->pos_in_table_list;
if (table_list->schema_table && thd->fill_information_schema_tables())
{
- if (optimize_schema_tables_memory_usage(table_list))
- DBUG_RETURN(1);
-
/* A value of 0 indicates a dummy implementation */
if (table_list->schema_table->fill_table == 0)
continue;
@@ -8865,6 +8883,16 @@ bool get_schema_tables_result(JOIN *join,
if (table_list->schema_table->fill_table == 0)
continue;
+ /*
+ Do not fill in tables thare are marked as JT_CONST as these will never
+ be read and they also don't have a tab->read_record.table set!
+ This can happen with queries like
+ SELECT * FROM t1 LEFT JOIN (t1 AS t1b JOIN INFORMATION_SCHEMA.ROUTINES)
+ ON (t1b.a IS NULL);
+ */
+ if (tab->type == JT_CONST)
+ continue;
+
/* skip I_S optimizations specific to get_all_tables */
if (lex->describe &&
(table_list->schema_table->fill_table != get_all_tables))
@@ -9861,7 +9889,7 @@ ST_FIELD_INFO check_constraints_fields_info[]=
{"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
{"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
OPEN_FULL_TABLE},
- {"CHECK_CLAUSE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
+ {"CHECK_CLAUSE", MAX_FIELD_VARCHARLENGTH , MYSQL_TYPE_STRING, 0, 0, 0,
OPEN_FULL_TABLE},
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
};