Skip to content

Commit

Permalink
Fixed wrong initializations of Dynamic_array
Browse files Browse the repository at this point in the history
Other things:
- Added size() function to Dynamic_array()
  • Loading branch information
montywi committed Mar 20, 2021
1 parent 8f33f49 commit cccc96d
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sql/item_subselect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3022,7 +3022,7 @@ bool Item_exists_subselect::exists2in_processor(void *opt_arg)
Query_arena *arena= NULL, backup;
int res= FALSE;
List<Item> outer;
Dynamic_array<EQ_FIELD_OUTER> eqs(5, 5);
Dynamic_array<EQ_FIELD_OUTER> eqs(PSI_INSTRUMENT_MEM, 5, 5);
bool will_be_correlated;
DBUG_ENTER("Item_exists_subselect::exists2in_processor");

Expand Down
2 changes: 1 addition & 1 deletion sql/opt_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8027,7 +8027,7 @@ SEL_TREE *Item_func_in::get_func_row_mm_tree(RANGE_OPT_PARAM *param,
table_map param_comp= ~(param->prev_tables | param->read_tables |
param->current_table);
uint row_cols= key_row->cols();
Dynamic_array <Key_col_info> key_cols_info(row_cols);
Dynamic_array <Key_col_info> key_cols_info(PSI_INSTRUMENT_MEM,row_cols);
cmp_item_row *row_cmp_item;

if (array)
Expand Down
3 changes: 2 additions & 1 deletion sql/rowid_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ class Refpos_container_sorted_array : public Sql_alloc

bool alloc()
{
array= new Dynamic_array<char> (elem_size * max_elements,
array= new Dynamic_array<char> (PSI_INSTRUMENT_MEM,
elem_size * max_elements,
elem_size * max_elements/sizeof(char) + 1);
return array == NULL;
}
Expand Down
3 changes: 2 additions & 1 deletion sql/rpl_rli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,8 @@ scan_all_gtid_slave_pos_table(THD *thd, int (*cb)(THD *, LEX_CSTRING *, void *),
else
{
size_t i;
Dynamic_array<LEX_CSTRING*> files(dirp->number_of_files);
Dynamic_array<LEX_CSTRING*> files(PSI_INSTRUMENT_MEM,
dirp->number_of_files);
Discovered_table_list tl(thd, &files);
int err;

Expand Down
8 changes: 4 additions & 4 deletions sql/sql_acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ bool ROLE_GRANT_PAIR::init(MEM_ROOT *mem, const char *username,
#define ROLE_OPENED (1L << 3)

static DYNAMIC_ARRAY acl_hosts, acl_users, acl_proxy_users;
static Dynamic_array<ACL_DB> acl_dbs(PSI_INSTRUMENT_MEM, 0U, 50U);
static Dynamic_array<ACL_DB> acl_dbs(PSI_INSTRUMENT_MEM, 0, 50);
typedef Dynamic_array<ACL_DB>::CMP_FUNC acl_dbs_cmp;
static HASH acl_roles;
/*
Expand Down Expand Up @@ -2786,7 +2786,7 @@ void acl_free(bool end)
bool acl_reload(THD *thd)
{
DYNAMIC_ARRAY old_acl_hosts, old_acl_users, old_acl_proxy_users;
Dynamic_array<ACL_DB> old_acl_dbs(0U,0U);
Dynamic_array<ACL_DB> old_acl_dbs(PSI_INSTRUMENT_MEM, 0, 0);
HASH old_acl_roles, old_acl_roles_mappings;
MEM_ROOT old_mem;
int result;
Expand Down Expand Up @@ -6170,8 +6170,8 @@ static int traverse_role_graph_impl(ACL_USER_BASE *user, void *context,
It uses a Dynamic_array to reduce the number of
malloc calls to a minimum
*/
Dynamic_array<NODE_STATE> stack(20,50);
Dynamic_array<ACL_USER_BASE *> to_clear(20,50);
Dynamic_array<NODE_STATE> stack(PSI_INSTRUMENT_MEM, 20,50);
Dynamic_array<ACL_USER_BASE *> to_clear(PSI_INSTRUMENT_MEM, 20, 50);
NODE_STATE state; /* variable used to insert elements in the stack */
int result= 0;

Expand Down
4 changes: 3 additions & 1 deletion sql/sql_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ template <typename Element_type> class Bounds_checked_array

template <class Elem> class Dynamic_array
{
DYNAMIC_ARRAY array;
DYNAMIC_ARRAY array;
public:
Dynamic_array(PSI_memory_key psi_key, uint prealloc=16, uint increment=16)
{
Expand Down Expand Up @@ -170,6 +170,8 @@ template <class Elem> class Dynamic_array
return ((const Elem*)array.buffer) + array.elements - 1;
}

size_t size() const { return array.elements; }

const Elem *end() const
{
return back() + 1;
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ static bool find_db_tables_and_rm_known_files(THD *thd, MY_DIR *dirp,
DBUG_PRINT("enter",("path: %s", path));

/* first, get the list of tables */
Dynamic_array<LEX_CSTRING*> files(dirp->number_of_files);
Dynamic_array<LEX_CSTRING*> files(PSI_INSTRUMENT_MEM, dirp->number_of_files);
Discovered_table_list tl(thd, &files);
if (ha_discover_table_names(thd, &db, dirp, &tl, true))
DBUG_RETURN(1);
Expand Down

0 comments on commit cccc96d

Please sign in to comment.