Skip to content

Commit

Permalink
various cleanups
Browse files Browse the repository at this point in the history
* remove a confusing method name - Field::set_default_expression()
* remove handler::register_columns_for_write()
* rename stuff
* add asserts
* remove unlikely unlikely
* remove redundant if() conditions
* fix mark_unsupported_function() to report the most important violation
* don't scan vfield list for default values (vfields don't have defaults)
* move handling for DROP CONSTRAINT IF EXIST where it belongs
* don't protect engines from Alter_inplace_info::ALTER_ADD_CONSTRAINT
* comments
  • Loading branch information
vuvova committed Jun 30, 2016
1 parent 047d762 commit f93a2a3
Show file tree
Hide file tree
Showing 20 changed files with 145 additions and 183 deletions.
22 changes: 17 additions & 5 deletions sql/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2291,11 +2291,22 @@ Field *Field::clone(MEM_ROOT *root, my_ptrdiff_t diff)
return tmp;
}

void Field::set_default_expression()
void Field::set_default()
{
table->in_use->reset_arena_for_cached_items(table->expr_arena);
(void) default_value->expr_item->save_in_field(this, 0);
table->in_use->reset_arena_for_cached_items(0);
if (default_value)
{
table->in_use->reset_arena_for_cached_items(table->expr_arena);
(void) default_value->expr_item->save_in_field(this, 0);
table->in_use->reset_arena_for_cached_items(0);
return;
}
/* Copy constant value stored in s->default_values */
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values -
table->record[0]);
memcpy(ptr, ptr + l_offset, pack_length());
if (maybe_null_in_table())
*null_ptr= ((*null_ptr & (uchar) ~null_bit) |
(null_ptr[l_offset] & null_bit));
}


Expand Down Expand Up @@ -9797,6 +9808,7 @@ bool Column_definition::check(THD *thd)
/* Initialize data for a computed field */
if (vcol_info)
{
DBUG_ASSERT(vcol_info->expr_item);
vcol_info->set_field_type(sql_type);
if (check_expression(vcol_info, "GENERATED ALWAYS AS", field_name,
vcol_info->stored_in_db))
Expand Down Expand Up @@ -10636,7 +10648,7 @@ Create_field *Create_field::clone(MEM_ROOT *mem_root) const

bool Column_definition::has_default_expression()
{
return (unlikely(default_value) &&
return (default_value &&
(!default_value->expr_item->basic_const_item() ||
(flags & BLOB_FLAG)));
}
Expand Down
17 changes: 1 addition & 16 deletions sql/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -891,22 +891,7 @@ class Field: public Value_source
my_ptrdiff_t l_offset= (my_ptrdiff_t) (record - table->record[0]);
return ptr + l_offset;
}
void set_default_expression();
virtual void set_default()
{
if (default_value)
{
set_default_expression();
return;
}
/* Copy constant value stored in s->default_values */
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values -
table->record[0]);
memcpy(ptr, ptr + l_offset, pack_length());
if (maybe_null_in_table())
*null_ptr= ((*null_ptr & (uchar) ~null_bit) |
(null_ptr[l_offset] & null_bit));
}
virtual void set_default();

bool has_insert_default_function() const
{
Expand Down
15 changes: 4 additions & 11 deletions sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3793,6 +3793,8 @@ int ha_partition::external_lock(THD *thd, int lock_type)
(void) (*file)->ha_external_lock(thd, lock_type);
} while (*(++file));
}
if (lock_type == F_WRLCK && m_part_info->part_expr)
m_part_info->part_expr->walk(&Item::register_field_in_read_map, 1, 0);
DBUG_RETURN(0);

err_handler:
Expand Down Expand Up @@ -3927,6 +3929,8 @@ int ha_partition::start_stmt(THD *thd, thr_lock_type lock_type)
/* Add partition to be called in reset(). */
bitmap_set_bit(&m_partitions_to_reset, i);
}
if (lock_type == F_WRLCK && m_part_info->part_expr)
m_part_info->part_expr->walk(&Item::register_field_in_read_map, 1, 0);
DBUG_RETURN(error);
}

Expand Down Expand Up @@ -8459,17 +8463,6 @@ uint ha_partition::min_record_length(uint options) const
return max;
}

/*
Register that we want to read partition columns. This is needed to ensure
that virtual columns are properly updated before we access them.
*/

void ha_partition::register_columns_for_write()
{
if (m_part_info->part_expr)
m_part_info->part_expr->walk(&Item::register_field_in_read_map, 1, 0);
}

/****************************************************************************
MODULE compare records
****************************************************************************/
Expand Down
1 change: 0 additions & 1 deletion sql/ha_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ class ha_partition :public handler
virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share);
virtual bool check_if_incompatible_data(HA_CREATE_INFO *create_info,
uint table_changes);
virtual void register_columns_for_write();
private:
int copy_partitions(ulonglong * const copied, ulonglong * const deleted);
void cleanup_new_partition(uint part_count);
Expand Down
8 changes: 4 additions & 4 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1679,11 +1679,12 @@ struct Table_scope_and_contents_source_st
enum_stats_auto_recalc stats_auto_recalc;
bool varchar; ///< 1 if table has a VARCHAR

List<Virtual_column_info> *check_constraint_list;

/* the following three are only for ALTER TABLE, check_if_incompatible_data() */
ha_table_option_struct *option_struct; ///< structure with parsed table options
ha_field_option_struct **fields_option_struct; ///< array of field option structures
ha_index_option_struct **indexes_option_struct; ///< array of index option structures
List<Virtual_column_info> *constraint_list;

/* The following is used to remember the old state for CREATE OR REPLACE */
TABLE *table;
Expand Down Expand Up @@ -1937,9 +1938,9 @@ class Alter_inplace_info
// ALTER TABLE for a partitioned table
static const HA_ALTER_FLAGS ALTER_PARTITIONED = 1L << 31;

static const HA_ALTER_FLAGS ALTER_ADD_CONSTRAINT = 1LL << 32;
static const HA_ALTER_FLAGS ALTER_ADD_CHECK_CONSTRAINT = 1LL << 32;

static const HA_ALTER_FLAGS ALTER_DROP_CONSTRAINT = 1LL << 33;
static const HA_ALTER_FLAGS ALTER_DROP_CHECK_CONSTRAINT= 1LL << 33;

/**
Create options (like MAX_ROWS) for the new version of table.
Expand Down Expand Up @@ -2865,7 +2866,6 @@ class handler :public Sql_alloc
size_t pack_frm_len);
int ha_drop_partitions(const char *path);
int ha_rename_partitions(const char *path);
virtual void register_columns_for_write() {}

void adjust_next_insert_id_after_explicit_value(ulonglong nr);
int update_auto_increment();
Expand Down
4 changes: 2 additions & 2 deletions sql/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ bool Item_field::register_field_in_read_map(void *arg)
TABLE *table= (TABLE *) arg;
if (field->table == table || !table)
bitmap_set_bit(field->table->read_set, field->field_index);
if (field->vcol_info && field->vcol_info->expr_item &&
if (field->vcol_info &&
!bitmap_is_set(field->table->vcol_set, field->field_index))
{
/* Ensure that the virtual fields is updated on read or write */
Expand Down Expand Up @@ -1417,7 +1417,7 @@ bool mark_unsupported_function(const char *where, void *store, uint result)
mark_unsupported_func(where, "check_vcol_func_processor");
res->errors|= result; /* Store type of expression */
/* Store the name to the highest violation (normally VCOL_IMPOSSIBLE) */
if (res->errors > old_errors)
if (result > old_errors)
res->name= where ? where : "";
return false;
}
Expand Down
1 change: 1 addition & 0 deletions sql/procedure.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Item_proc :public Item
unsigned int size_of() { return sizeof(*this);}
bool check_vcol_func_processor(void *arg)
{
DBUG_ASSERT(0); // impossible
return mark_unsupported_function("proc", arg, VCOL_IMPOSSIBLE);
}
};
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
alter_list(rhs.alter_list, mem_root),
key_list(rhs.key_list, mem_root),
create_list(rhs.create_list, mem_root),
constraint_list(rhs.constraint_list, mem_root),
check_constraint_list(rhs.check_constraint_list, mem_root),
flags(rhs.flags),
keys_onoff(rhs.keys_onoff),
partition_names(rhs.partition_names, mem_root),
Expand Down
8 changes: 4 additions & 4 deletions sql/sql_alter.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class Alter_info
// Set for ADD [COLUMN] FIRST | AFTER
static const uint ALTER_COLUMN_ORDER = 1L << 26;

static const uint ALTER_ADD_CONSTRAINT = 1L << 27;
static const uint ALTER_DROP_CONSTRAINT = 1L << 28;
static const uint ALTER_ADD_CHECK_CONSTRAINT = 1L << 27;
static const uint ALTER_DROP_CHECK_CONSTRAINT = 1L << 28;

enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };

Expand Down Expand Up @@ -174,7 +174,7 @@ class Alter_info
List<Key> key_list;
// List of columns, used by both CREATE and ALTER TABLE.
List<Create_field> create_list;
List<Virtual_column_info> constraint_list;
List<Virtual_column_info> check_constraint_list;
// Type of ALTER TABLE operation.
uint flags;
// Enable or disable keys.
Expand Down Expand Up @@ -203,7 +203,7 @@ class Alter_info
alter_list.empty();
key_list.empty();
create_list.empty();
constraint_list.empty();
check_constraint_list.empty();
flags= 0;
keys_onoff= LEAVE_AS_IS;
num_parts= 0;
Expand Down
12 changes: 7 additions & 5 deletions sql/sql_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7817,15 +7817,17 @@ void switch_to_nullable_trigger_fields(List<Item> &items, TABLE *table)
table->field_to_fill(), if needed.
*/

void switch_to_nullable_trigger_fields(Field **info, TABLE *table)
void switch_defaults_to_nullable_trigger_fields(TABLE *table)
{
if (!table->default_field)
return; // no defaults

Field **trigger_field= table->field_to_fill();

/* True if we have virtual fields and non_null fields and before triggers */
if (info && trigger_field != table->field)
/* True if we have NOT NULL fields and BEFORE triggers */
if (trigger_field != table->field)
{
Field **field_ptr;
for (field_ptr= info; *field_ptr ; field_ptr++)
for (Field **field_ptr= table->default_field; *field_ptr ; field_ptr++)
{
Field *field= (*field_ptr);
field->default_value->expr_item->walk(&Item::switch_to_nullable_fields_processor, 1, trigger_field);
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ TABLE_LIST *find_table_in_list(TABLE_LIST *table,
const char *table_name);
void close_thread_tables(THD *thd);
void switch_to_nullable_trigger_fields(List<Item> &items, TABLE *);
void switch_to_nullable_trigger_fields(Field **info, TABLE *table);
void switch_defaults_to_nullable_trigger_fields(TABLE *table);
bool fill_record_n_invoke_before_triggers(THD *thd, TABLE *table,
List<Item> &fields,
List<Item> &values,
Expand Down
6 changes: 3 additions & 3 deletions sql/sql_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class Key_part_spec :public Sql_alloc {

class Alter_drop :public Sql_alloc {
public:
enum drop_type {KEY, COLUMN, FOREIGN_KEY, CONSTRAINT_CHECK };
enum drop_type {KEY, COLUMN, FOREIGN_KEY, CHECK_CONSTRAINT };
const char *name;
enum drop_type type;
bool drop_if_exists;
Expand All @@ -279,8 +279,8 @@ class Alter_column :public Sql_alloc {
public:
const char *name;
Virtual_column_info *default_value;
Alter_column(const char *par_name, Virtual_column_info *literal)
:name(par_name), default_value(literal) {}
Alter_column(const char *par_name, Virtual_column_info *expr)
:name(par_name), default_value(expr) {}
/**
Used to make a clone of this object for ALTER/CREATE TABLE
@sa comment for Key_part_spec::clone
Expand Down
3 changes: 1 addition & 2 deletions sql/sql_insert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2498,8 +2498,7 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd)
*dfield_ptr= 0;
}

switch_to_nullable_trigger_fields(copy->vfield, copy);
switch_to_nullable_trigger_fields(copy->default_field, copy);
switch_defaults_to_nullable_trigger_fields(copy);

/* Adjust in_use for pointing to client thread */
copy->in_use= client_thd;
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -2991,7 +2991,7 @@ struct LEX: public Query_tables_list
bool add_constraint(LEX_STRING *name, Virtual_column_info *constr)
{
constr->name= *name;
alter_info.constraint_list.push_back(constr);
alter_info.check_constraint_list.push_back(constr);
return false;
}
void set_command(enum_sql_command command,
Expand Down
55 changes: 15 additions & 40 deletions sql/sql_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,46 +104,21 @@ static const char *end_paren_str= ")";
static const char *begin_paren_str= "(";
static const char *comma_str= ",";

int get_partition_id_list_col(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
int get_partition_id_list(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
int get_partition_id_range_col(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
int get_partition_id_range(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
static int get_part_id_charset_func_part(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
static int get_part_id_charset_func_subpart(partition_info *part_info,
uint32 *part_id);
int get_partition_id_hash_nosub(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
int get_partition_id_key_nosub(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
int get_partition_id_linear_hash_nosub(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
int get_partition_id_linear_key_nosub(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
int get_partition_id_with_sub(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
int get_partition_id_hash_sub(partition_info *part_info,
uint32 *part_id);
int get_partition_id_key_sub(partition_info *part_info,
uint32 *part_id);
int get_partition_id_linear_hash_sub(partition_info *part_info,
uint32 *part_id);
int get_partition_id_linear_key_sub(partition_info *part_info,
uint32 *part_id);
static int get_partition_id_list_col(partition_info *, uint32 *, longlong *);
static int get_partition_id_list(partition_info *, uint32 *, longlong *);
static int get_partition_id_range_col(partition_info *, uint32 *, longlong *);
static int get_partition_id_range(partition_info *, uint32 *, longlong *);
static int get_part_id_charset_func_part(partition_info *, uint32 *, longlong *);
static int get_part_id_charset_func_subpart(partition_info *, uint32 *);
static int get_partition_id_hash_nosub(partition_info *, uint32 *, longlong *);
static int get_partition_id_key_nosub(partition_info *, uint32 *, longlong *);
static int get_partition_id_linear_hash_nosub(partition_info *, uint32 *, longlong *);
static int get_partition_id_linear_key_nosub(partition_info *, uint32 *, longlong *);
static int get_partition_id_with_sub(partition_info *, uint32 *, longlong *);
static int get_partition_id_hash_sub(partition_info *part_info, uint32 *part_id);
static int get_partition_id_key_sub(partition_info *part_info, uint32 *part_id);
static int get_partition_id_linear_hash_sub(partition_info *part_info, uint32 *part_id);
static int get_partition_id_linear_key_sub(partition_info *part_info, uint32 *part_id);
static uint32 get_next_partition_via_walking(PARTITION_ITERATOR*);
static void set_up_range_analysis_info(partition_info *part_info);
static uint32 get_next_subpartition_via_walking(PARTITION_ITERATOR*);
Expand Down
Loading

0 comments on commit f93a2a3

Please sign in to comment.