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.cc133
1 files changed, 50 insertions, 83 deletions
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 38a13c49278..f8702657be7 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -1076,13 +1076,7 @@ find_files(THD *thd, Dynamic_array<LEX_CSTRING*> *files, LEX_CSTRING *db,
if (ha_discover_table_names(thd, db, dirp, &tl, false))
goto err;
}
-#if MYSQL_VERSION_ID < 100300
- /* incomplete optimization, but a less drastic change in GA version */
- if (!thd->lex->select_lex.order_list.elements &&
- !thd->lex->select_lex.group_list.elements)
-#else
if (is_show_command(thd))
-#endif
tl.sort();
#ifndef DBUG_OFF
else
@@ -1267,7 +1261,7 @@ mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list,
MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL) ||
mysql_handle_derived(thd->lex, DT_INIT | DT_PREPARE);
thd->pop_internal_handler();
- if (open_error && (thd->killed || thd->is_error()))
+ if (unlikely(open_error && (thd->killed || thd->is_error())))
goto exit;
}
@@ -3821,17 +3815,19 @@ bool schema_table_store_record(THD *thd, TABLE *table)
{
int error;
- if (thd->killed)
+ if (unlikely(thd->killed))
{
thd->send_kill_message();
return 1;
}
- if ((error= table->file->ha_write_tmp_row(table->record[0])))
+ if (unlikely((error= table->file->ha_write_tmp_row(table->record[0]))))
{
TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
- if (create_internal_tmp_table_from_heap(thd, table, param->start_recinfo,
- &param->recinfo, error, 0, NULL))
+ if (unlikely(create_internal_tmp_table_from_heap(thd, table,
+ param->start_recinfo,
+ &param->recinfo, error, 0,
+ NULL)))
return 1;
}
@@ -4596,7 +4592,7 @@ fill_schema_table_by_open(THD *thd, MEM_ROOT *mem_root,
else
{
char buf[NAME_CHAR_LEN + 1];
- if (thd->is_error())
+ if (unlikely(thd->is_error()))
get_table_engine_for_i_s(thd, buf, table_list, &db_name, &table_name);
result= schema_table->process_table(thd, table_list,
@@ -4678,13 +4674,14 @@ static int fill_schema_table_names(THD *thd, TABLE_LIST *tables,
else
table->field[3]->store(STRING_WITH_LEN("ERROR"), cs);
- if (thd->is_error() && thd->get_stmt_da()->sql_errno() == ER_NO_SUCH_TABLE)
+ if (unlikely(thd->is_error() &&
+ thd->get_stmt_da()->sql_errno() == ER_NO_SUCH_TABLE))
{
thd->clear_error();
return 0;
}
}
- if (schema_table_store_record(thd, table))
+ if (unlikely(schema_table_store_record(thd, table)))
return 1;
return 0;
}
@@ -5010,7 +5007,7 @@ public:
if (*level != Sql_condition::WARN_LEVEL_ERROR)
return false;
- if (!thd->get_stmt_da()->is_error())
+ if (likely(!thd->get_stmt_da()->is_error()))
thd->get_stmt_da()->set_error_status(sql_errno, msg, sqlstate, *cond_hdl);
return true; // handled!
}
@@ -5135,9 +5132,9 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
Dynamic_array<LEX_CSTRING*> table_names;
int res= make_table_name_list(thd, &table_names, lex,
&plan->lookup_field_vals, db_name);
- if (res == 2) /* Not fatal error, continue */
+ if (unlikely(res == 2)) /* Not fatal error, continue */
continue;
- if (res)
+ if (unlikely(res))
goto err;
for (size_t i=0; i < table_names.elements(); i++)
@@ -5496,13 +5493,13 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
/* Collect table info from the storage engine */
- if(file)
+ if (file)
{
/* If info() fails, then there's nothing else to do */
- if ((info_error= file->info(HA_STATUS_VARIABLE |
- HA_STATUS_TIME |
- HA_STATUS_VARIABLE_EXTRA |
- HA_STATUS_AUTO)) != 0)
+ if (unlikely((info_error= file->info(HA_STATUS_VARIABLE |
+ HA_STATUS_TIME |
+ HA_STATUS_VARIABLE_EXTRA |
+ HA_STATUS_AUTO)) != 0))
{
file->print_error(info_error, MYF(0));
goto err;
@@ -5601,7 +5598,7 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
}
err:
- if (res || info_error)
+ if (unlikely(res || info_error))
{
/*
If an error was encountered, push a warning, set the TABLE COMMENT
@@ -5635,8 +5632,6 @@ err:
static void store_column_type(TABLE *table, Field *field, CHARSET_INFO *cs,
uint offset)
{
- bool is_blob;
- int decimals, field_length;
const char *tmp_buff;
char column_type_buff[MAX_FIELD_WIDTH];
String column_type(column_type_buff, sizeof(column_type_buff), cs);
@@ -5662,22 +5657,18 @@ static void store_column_type(TABLE *table, Field *field, CHARSET_INFO *cs,
(tmp_buff ? (uint)(tmp_buff - column_type.ptr()) :
column_type.length()), cs);
- is_blob= (field->type() == MYSQL_TYPE_BLOB);
- if (field->has_charset() || is_blob ||
- field->real_type() == MYSQL_TYPE_VARCHAR || // For varbinary type
- field->real_type() == MYSQL_TYPE_STRING) // For binary type
- {
- uint32 octet_max_length= field->max_display_length();
- if (is_blob && octet_max_length != (uint32) UINT_MAX32)
- octet_max_length /= field->charset()->mbmaxlen;
- longlong char_max_len= is_blob ?
- (longlong) octet_max_length / field->charset()->mbminlen :
- (longlong) octet_max_length / field->charset()->mbmaxlen;
+ Information_schema_character_attributes cattr=
+ field->information_schema_character_attributes();
+ if (cattr.has_char_length())
+ {
/* CHARACTER_MAXIMUM_LENGTH column*/
- table->field[offset + 1]->store(char_max_len, TRUE);
+ table->field[offset + 1]->store((longlong) cattr.char_length(), true);
table->field[offset + 1]->set_notnull();
+ }
+ if (cattr.has_octet_length())
+ {
/* CHARACTER_OCTET_LENGTH column */
- table->field[offset + 2]->store((longlong) octet_max_length, TRUE);
+ table->field[offset + 2]->store((longlong) cattr.octet_length(), true);
table->field[offset + 2]->set_notnull();
}
@@ -5686,35 +5677,10 @@ static void store_column_type(TABLE *table, Field *field, CHARSET_INFO *cs,
They are set to -1 if they should not be set (we should return NULL)
*/
- field_length= -1;
- decimals= field->decimals();
+ Information_schema_numeric_attributes num=
+ field->information_schema_numeric_attributes();
+
switch (field->type()) {
- case MYSQL_TYPE_NEWDECIMAL:
- field_length= ((Field_new_decimal*) field)->precision;
- break;
- case MYSQL_TYPE_DECIMAL:
- field_length= field->field_length - (decimals ? 2 : 1);
- break;
- case MYSQL_TYPE_TINY:
- case MYSQL_TYPE_SHORT:
- case MYSQL_TYPE_LONG:
- case MYSQL_TYPE_INT24:
- field_length= field->max_display_length() - 1;
- break;
- case MYSQL_TYPE_LONGLONG:
- field_length= field->max_display_length() -
- ((field->flags & UNSIGNED_FLAG) ? 0 : 1);
- break;
- case MYSQL_TYPE_BIT:
- field_length= field->max_display_length();
- decimals= -1; // return NULL
- break;
- case MYSQL_TYPE_FLOAT:
- case MYSQL_TYPE_DOUBLE:
- field_length= field->field_length;
- if (decimals == NOT_FIXED_DEC)
- decimals= -1; // return NULL
- break;
case MYSQL_TYPE_TIME:
case MYSQL_TYPE_TIMESTAMP:
case MYSQL_TYPE_DATETIME:
@@ -5727,15 +5693,15 @@ static void store_column_type(TABLE *table, Field *field, CHARSET_INFO *cs,
}
/* NUMERIC_PRECISION column */
- if (field_length >= 0)
+ if (num.has_precision())
{
- table->field[offset + 3]->store((longlong) field_length, TRUE);
+ table->field[offset + 3]->store((longlong) num.precision(), true);
table->field[offset + 3]->set_notnull();
/* NUMERIC_SCALE column */
- if (decimals >= 0)
+ if (num.has_scale())
{
- table->field[offset + 4]->store((longlong) decimals, TRUE);
+ table->field[offset + 4]->store((longlong) num.scale(), true);
table->field[offset + 4]->set_notnull();
}
}
@@ -6564,7 +6530,7 @@ static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
rather than in SHOW KEYS
*/
- if (thd->is_error())
+ if (unlikely(thd->is_error()))
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
thd->get_stmt_da()->sql_errno(),
thd->get_stmt_da()->message());
@@ -6792,7 +6758,7 @@ static int get_schema_views_record(THD *thd, TABLE_LIST *tables,
if (schema_table_store_record(thd, table))
DBUG_RETURN(1);
- if (res && thd->is_error())
+ if (unlikely(res && thd->is_error()))
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
thd->get_stmt_da()->sql_errno(),
thd->get_stmt_da()->message());
@@ -6828,7 +6794,7 @@ static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
DBUG_ENTER("get_schema_constraints_record");
if (res)
{
- if (thd->is_error())
+ if (unlikely(thd->is_error()))
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
thd->get_stmt_da()->sql_errno(),
thd->get_stmt_da()->message());
@@ -6962,7 +6928,7 @@ static int get_schema_triggers_record(THD *thd, TABLE_LIST *tables,
*/
if (res)
{
- if (thd->is_error())
+ if (unlikely(thd->is_error()))
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
thd->get_stmt_da()->sql_errno(),
thd->get_stmt_da()->message());
@@ -7026,7 +6992,7 @@ static int get_schema_key_column_usage_record(THD *thd,
DBUG_ENTER("get_schema_key_column_usage_record");
if (res)
{
- if (thd->is_error())
+ if (unlikely(thd->is_error()))
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
thd->get_stmt_da()->sql_errno(),
thd->get_stmt_da()->message());
@@ -7313,7 +7279,7 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
if (res)
{
- if (thd->is_error())
+ if (unlikely(thd->is_error()))
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
thd->get_stmt_da()->sql_errno(),
thd->get_stmt_da()->message());
@@ -7725,8 +7691,9 @@ int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond)
TABLE *table= tables->table;
CHARSET_INFO *cs= system_charset_info;
OPEN_TABLE_LIST *open_list;
- if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db.str, wild))
- && thd->is_fatal_error)
+ if (unlikely(!(open_list= list_open_tables(thd, thd->lex->select_lex.db.str,
+ wild))) &&
+ unlikely(thd->is_fatal_error))
DBUG_RETURN(1);
for (; open_list ; open_list=open_list->next)
@@ -7736,7 +7703,7 @@ int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond)
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
table->field[2]->store((longlong) open_list->in_use, TRUE);
table->field[3]->store((longlong) open_list->locked, TRUE);
- if (schema_table_store_record(thd, table))
+ if (unlikely(schema_table_store_record(thd, table)))
DBUG_RETURN(1);
}
DBUG_RETURN(0);
@@ -7865,7 +7832,7 @@ get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
if (res)
{
- if (thd->is_error())
+ if (unlikely(thd->is_error()))
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
thd->get_stmt_da()->sql_errno(),
thd->get_stmt_da()->message());
@@ -8811,7 +8778,7 @@ bool get_schema_tables_result(JOIN *join,
}
}
thd->pop_internal_handler();
- if (thd->is_error())
+ if (unlikely(thd->is_error()))
{
/*
This hack is here, because I_S code uses thd->clear_error() a lot.
@@ -10310,14 +10277,14 @@ static void get_cs_converted_string_value(THD *thd,
try_val.copy(input_str->ptr(), input_str->length(), cs,
thd->variables.character_set_client, &try_conv_error);
- if (!try_conv_error)
+ if (likely(!try_conv_error))
{
String val;
uint conv_error= 0;
val.copy(input_str->ptr(), input_str->length(), cs,
system_charset_info, &conv_error);
- if (!conv_error)
+ if (likely(!conv_error))
{
append_unescaped(output_str, val.ptr(), val.length());
return;